@@ -22,9 +22,8 @@ use solana_rpc_client_api::request::RpcRequest;
2222
2323use super :: * ;
2424use crate :: {
25- intent_executor:: {
26- task_info_fetcher:: { CacheTaskInfoFetcher , RpcTaskInfoFetcher } ,
27- IntentExecutionResult ,
25+ intent_executor:: task_info_fetcher:: {
26+ CacheTaskInfoFetcher , RpcTaskInfoFetcher ,
2827 } ,
2928 persist:: IntentPersisterImpl ,
3029 tasks:: {
@@ -141,23 +140,18 @@ type Executor =
141140
142141fn executor (
143142 steps : Vec < Preparation > ,
144- errors : & [ Option < & str > ] ,
143+ error : Option < & str > ,
145144 timeout : Duration ,
146145) -> Executor {
147146 let mut mocks = MocksMap :: default ( ) ;
148- for error in errors {
149- let err = error. unwrap_or ( "null" ) ;
150- let status = error. map_or_else (
151- || r#"{"Ok":null}"# . to_string ( ) ,
152- |err| format ! ( r#"{{"Err":{err}}}"# ) ,
153- ) ;
147+ if let Some ( error) = error {
154148 mocks. insert (
155149 RpcRequest :: GetSignatureStatuses ,
156150 format ! (
157151 r#"{{
158152 "context": {{"slot": 1}},
159- "value": [{{"slot": 1, "confirmations": null, "err": {err },
160- "status": {status }, "confirmationStatus": "finalized"}}]
153+ "value": [{{"slot": 1, "confirmations": null, "err": {error },
154+ "status": {{"Err":{error}} }, "confirmationStatus": "finalized"}}]
161155 }}"#
162156 )
163157 . parse ( )
@@ -241,13 +235,6 @@ fn split(follow_up: Vec<BaseTaskImpl>) -> StrategyExecutionMode {
241235 }
242236}
243237
244- fn instruction_error ( error : & str ) -> String {
245- format ! (
246- r#"{{"InstructionError":[{},{error}]}}"# ,
247- TransactionUtils :: COMPUTE_BUDGET_INSTRUCTION_COUNT
248- )
249- }
250-
251238#[ tokio:: test( start_paused = true ) ]
252239async fn timeout_skips_empty_follow_up_and_keeps_undelegation ( ) {
253240 // - `[Action]` → `[]`: skip the empty follow-up.
@@ -264,7 +251,7 @@ async fn timeout_skips_empty_follow_up_and_keeps_undelegation() {
264251 } else {
265252 vec ! [ action( ) ]
266253 } ;
267- let executor = executor ( steps, & [ ] , Duration :: from_secs ( 60 ) ) ;
254+ let executor = executor ( steps, None , Duration :: from_secs ( 60 ) ) ;
268255 let mut report = IntentExecutionReport :: default ( ) ;
269256 let output = TransactionExecutor :: new (
270257 & executor,
@@ -330,7 +317,7 @@ async fn timeout_skips_empty_follow_up_and_keeps_undelegation() {
330317#[ tokio:: test( start_paused = true ) ]
331318async fn timeout_keeps_attempts_already_spent_on_current_transaction ( ) {
332319 let executor =
333- executor ( vec ! [ Preparation :: Wait ] , & [ ] , Duration :: from_millis ( 10 ) ) ;
320+ executor ( vec ! [ Preparation :: Wait ] , None , Duration :: from_millis ( 10 ) ) ;
334321 let mut report = IntentExecutionReport :: default ( ) ;
335322 let mut runner = TransactionExecutor :: new (
336323 & executor,
@@ -352,176 +339,91 @@ async fn timeout_keeps_attempts_already_spent_on_current_transaction() {
352339}
353340
354341#[ tokio:: test]
355- async fn preparation_failure_surrenders_current_and_pending_resources ( ) {
356- let executor =
357- executor ( vec ! [ Preparation :: Fail ] , & [ ] , Duration :: from_secs ( 60 ) ) ;
358- let mut report = IntentExecutionReport :: default ( ) ;
359- let result = TransactionExecutor :: new (
360- & executor,
361- & mut report,
362- 42 ,
363- & [ ACCOUNT ] ,
364- split ( vec ! [ undelegate( ) , action( ) ] ) ,
365- )
366- . execute ( & None :: < IntentPersisterImpl > )
367- . await ;
368- assert ! ( matches!(
369- result,
370- Err ( IntentExecutorError :: FailedCommitPreparationError ( _) )
371- ) ) ;
372- assert_eq ! ( report. junk( ) . len( ) , 2 ) ;
373- assert_eq ! ( report. junk( ) [ 0 ] . lookup_tables_keys, vec![ RESERVED_ALT_KEY ] ) ;
374- assert_eq ! ( report. junk( ) [ 1 ] . optimized_tasks. len( ) , 2 ) ;
375- assert ! ( executor
376- . actions_callback_executor
377- . 0
378- . lock( )
379- . unwrap( )
380- . is_empty( ) ) ;
381- }
382-
383- #[ tokio:: test]
384- async fn nonce_fetch_failure_surrenders_both_strategies ( ) {
385- let nonce_error = instruction_error ( & format ! (
386- r#"{{"Custom":{}}}"# ,
342+ async fn execution_failure_surrenders_current_and_pending_resources ( ) {
343+ let nonce_error = format ! (
344+ r#"{{"InstructionError":[{},{{"Custom":{}}}]}}"# ,
345+ TransactionUtils :: COMPUTE_BUDGET_INSTRUCTION_COUNT ,
387346 dlp_api:: error:: DlpError :: NonceOutOfOrder as u32
388- ) ) ;
389- let executor =
390- executor ( vec ! [ ] , & [ Some ( & nonce_error) ] , Duration :: from_secs ( 60 ) ) ;
391- let mut report = IntentExecutionReport :: default ( ) ;
347+ ) ;
392348 // The RPC mock has no delegation record, so nonce recovery fails after
393349 // preparing the first transaction and receiving its on-chain nonce error.
394- let result = TransactionExecutor :: new (
395- & executor,
396- & mut report,
397- 42 ,
398- & [ ACCOUNT ] ,
399- split ( vec ! [ undelegate( ) ] ) ,
400- )
401- . execute ( & None :: < IntentPersisterImpl > )
402- . await ;
403- assert ! (
404- matches!( result, Err ( IntentExecutorError :: TaskBuilderError ( _) ) ) ,
405- "{result:?}"
406- ) ;
407- assert_eq ! (
408- executor
409- . transaction_preparator
410- . prepared
411- . lock( )
412- . unwrap( )
413- . len( ) ,
414- 1
415- ) ;
416- assert_eq ! ( report. junk( ) . len( ) , 2 ) ;
417- assert_eq ! ( report. junk( ) [ 0 ] . lookup_tables_keys, vec![ RESERVED_ALT_KEY ] ) ;
418- assert ! ( matches!(
419- report. junk( ) [ 1 ] . optimized_tasks. as_slice( ) ,
420- [ BaseTaskImpl :: Undelegate ( _) ]
421- ) ) ;
422- }
423-
424- #[ tokio:: test]
425- async fn follow_up_preparation_failure_does_not_retry_confirmed_commit ( ) {
426- let executor = executor (
427- vec ! [ Preparation :: Ready , Preparation :: Fail ] ,
428- & [ ] ,
429- Duration :: from_secs ( 60 ) ,
430- ) ;
431- let mut report = IntentExecutionReport :: default ( ) ;
432- let result = TransactionExecutor :: new (
433- & executor,
434- & mut report,
435- 42 ,
436- & [ ACCOUNT ] ,
437- split ( vec ! [ undelegate( ) ] ) ,
438- )
439- . execute ( & None :: < IntentPersisterImpl > )
440- . await ;
441- assert ! ( matches!(
442- result,
443- Err ( IntentExecutorError :: FailedFinalizePreparationError ( _) )
444- ) ) ;
445- let result = IntentExecutionResult {
446- inner : result,
447- patched_errors : vec ! [ ] ,
448- callbacks_report : vec ! [ ] ,
449- } ;
450- assert ! ( !result. is_retriable( true ) ) ;
451- let prepared = executor. transaction_preparator . prepared . lock ( ) . unwrap ( ) ;
452- assert_eq ! ( prepared. len( ) , 2 ) ;
453- assert ! ( matches!(
454- prepared[ 0 ] . as_slice( ) ,
455- [ BaseTaskImpl :: CommitFinalize ( _) ]
456- ) ) ;
457- assert ! ( matches!(
458- prepared[ 1 ] . as_slice( ) ,
459- [ BaseTaskImpl :: Undelegate ( _) ]
460- ) ) ;
461- assert_eq ! (
462- report
463- . junk( )
464- . iter( )
465- . filter( |strategy| strategy
466- . lookup_tables_keys
467- . contains( & RESERVED_ALT_KEY ) )
468- . count( ) ,
469- 2
470- ) ;
471- }
472-
473- #[ tokio:: test]
474- async fn empty_follow_up_preserves_action_and_undelegation_outcomes ( ) {
475- for failed_action in [ true , false ] {
476- let error = instruction_error ( r#"{"Custom":1}"# ) ;
477- let executor =
478- executor ( vec ! [ ] , & [ None , Some ( & error) ] , Duration :: from_secs ( 60 ) ) ;
350+ for ( steps, error) in [
351+ ( vec ! [ Preparation :: Fail ] , None ) ,
352+ ( vec ! [ Preparation :: Ready ] , Some ( nonce_error. as_str ( ) ) ) ,
353+ ( vec ! [ Preparation :: Ready , Preparation :: Fail ] , None ) ,
354+ ] {
355+ let expected_preparations = steps. len ( ) ;
356+ let executor = executor ( steps, error, Duration :: from_secs ( 60 ) ) ;
479357 let mut report = IntentExecutionReport :: default ( ) ;
480- let follow_up = if failed_action {
481- action ( )
482- } else {
483- undelegate ( )
484- } ;
485358 let result = TransactionExecutor :: new (
486359 & executor,
487360 & mut report,
488361 42 ,
489362 & [ ACCOUNT ] ,
490- split ( vec ! [ follow_up ] ) ,
363+ split ( vec ! [ undelegate ( ) , action ( ) ] ) ,
491364 )
492365 . execute ( & None :: < IntentPersisterImpl > )
493366 . await ;
494- assert_eq ! (
495- executor
496- . transaction_preparator
497- . prepared
498- . lock( )
499- . unwrap( )
500- . len( ) ,
501- 2 ,
502- "must not prepare an empty retry"
503- ) ;
504- if failed_action {
367+ if error. is_some ( ) {
505368 assert ! (
506- matches!( result, Ok ( ExecutionOutput :: TwoStage { commit_signature, finalize_signature } ) if commit_signature == finalize_signature) ,
369+ matches!( result, Err ( IntentExecutorError :: TaskBuilderError ( _) ) ) ,
370+ "{result:?}"
371+ ) ;
372+ } else if expected_preparations == 1 {
373+ assert ! (
374+ matches!(
375+ result,
376+ Err ( IntentExecutorError :: FailedCommitPreparationError ( _) )
377+ ) ,
507378 "{result:?}"
508379 ) ;
509- let calls = executor. actions_callback_executor . 0 . lock ( ) . unwrap ( ) ;
510- assert_eq ! ( calls. len( ) , 1 ) ;
511- assert ! ( matches!( calls[ 0 ] . 1 , Err ( ActionError :: ActionsError ( ..) ) ) ) ;
512- assert_eq ! ( report. patched_errors( ) . len( ) , 1 ) ;
513380 } else {
514381 assert ! (
515382 matches!(
516383 result,
517- Err ( IntentExecutorError :: FailedToFinalizeError {
518- commit_signature: Some ( _) ,
519- ..
520- } )
384+ Err ( IntentExecutorError :: FailedFinalizePreparationError ( _) )
521385 ) ,
522386 "{result:?}"
523387 ) ;
524- assert ! ( !result. unwrap_err( ) . is_transient( ) ) ;
525388 }
389+ let prepared = executor. transaction_preparator . prepared . lock ( ) . unwrap ( ) ;
390+ assert_eq ! ( prepared. len( ) , expected_preparations) ;
391+ assert ! ( matches!(
392+ prepared[ 0 ] . as_slice( ) ,
393+ [ BaseTaskImpl :: CommitFinalize ( _) ]
394+ ) ) ;
395+ if expected_preparations == 2 {
396+ assert ! ( matches!(
397+ prepared[ 1 ] . as_slice( ) ,
398+ [ BaseTaskImpl :: Undelegate ( _) , BaseTaskImpl :: BaseAction ( _) ]
399+ ) ) ;
400+ }
401+ assert ! ( executor
402+ . actions_callback_executor
403+ . 0
404+ . lock( )
405+ . unwrap( )
406+ . is_empty( ) ) ;
407+ let disposed: Vec < _ > = report
408+ . junk ( )
409+ . iter ( )
410+ . filter ( |strategy| !strategy. optimized_tasks . is_empty ( ) )
411+ . collect ( ) ;
412+ assert_eq ! ( disposed. len( ) , 2 ) ;
413+ assert ! ( matches!(
414+ disposed[ 1 ] . optimized_tasks. as_slice( ) ,
415+ [ BaseTaskImpl :: Undelegate ( _) , BaseTaskImpl :: BaseAction ( _) ]
416+ ) ) ;
417+ assert_eq ! ( disposed[ 0 ] . lookup_tables_keys, vec![ RESERVED_ALT_KEY ] ) ;
418+ assert_eq ! (
419+ report
420+ . junk( )
421+ . iter( )
422+ . filter( |strategy| strategy
423+ . lookup_tables_keys
424+ . contains( & RESERVED_ALT_KEY ) )
425+ . count( ) ,
426+ expected_preparations,
427+ ) ;
526428 }
527429}
0 commit comments