@@ -2,12 +2,8 @@ use borsh::BorshDeserialize;
22use borsh:: BorshSerialize ;
33use solana_sdk:: instruction:: Instruction ;
44use solana_sdk:: pubkey:: Pubkey ;
5- use solana_sdk:: transaction:: TransactionError ;
6- use trident_svm:: prelude:: TridentTransactionProcessingResult ;
7- use trident_svm:: processor:: InstructionError ;
5+ use trident_svm:: prelude:: TridentTransactionResult ;
86
9- use crate :: trident:: transaction_result:: TransactionResult ;
10- use crate :: trident:: transaction_result:: TransactionReturnData ;
117use crate :: trident:: Trident ;
128use crate :: AccountDiscriminator ;
139
@@ -46,7 +42,7 @@ impl Trident {
4642 & mut self ,
4743 instructions : & [ Instruction ] ,
4844 log_as : Option < & str > ,
49- ) -> TransactionResult {
45+ ) -> TridentTransactionResult {
5046 let fuzzing_metrics = std:: env:: var ( "FUZZING_METRICS" ) ;
5147 let fuzzing_debug = std:: env:: var ( "TRIDENT_FUZZ_DEBUG" ) ;
5248
@@ -63,8 +59,9 @@ impl Trident {
6359 ) ;
6460 }
6561 let processing_data = self . process_instructions ( instructions) ;
62+ self . handle_tx_result ( & processing_data, log_as, instructions) ;
6663
67- self . handle_tx_result ( & processing_data, log_as , instructions )
64+ processing_data
6865 }
6966
7067 /// Deploys an entrypoint program to the SVM runtime
@@ -284,10 +281,7 @@ impl Trident {
284281 panic ! ( "Not yet implemented for TridentSVM" ) ;
285282 }
286283
287- fn process_instructions (
288- & mut self ,
289- instructions : & [ Instruction ] ,
290- ) -> TridentTransactionProcessingResult {
284+ fn process_instructions ( & mut self , instructions : & [ Instruction ] ) -> TridentTransactionResult {
291285 // there should be at least 1 RW fee-payer account.
292286 // But we do not pay for TX currently so has to be manually updated
293287 // tx.message.header.num_required_signatures = 1;
@@ -393,131 +387,58 @@ impl Trident {
393387
394388 fn handle_tx_result (
395389 & mut self ,
396- tx_processing_result : & TridentTransactionProcessingResult ,
390+ tx_processing_result : & TridentTransactionResult ,
397391 log_as : Option < & str > ,
398392 instructions : & [ Instruction ] ,
399- ) -> TransactionResult {
393+ ) {
400394 let fuzzing_metrics = std:: env:: var ( "FUZZING_METRICS" ) ;
401395 let fuzzing_debug = std:: env:: var ( "TRIDENT_FUZZ_DEBUG" ) ;
402396
403- // NOTE: for now we just expect that one transaction was executed
404- let tx_result = & tx_processing_result. get_result ( ) . processing_results [ 0 ] ;
397+ let is_program_failed_to_complete = tx_processing_result. is_program_failed_to_complete ( ) ;
398+
399+ let log_messages = tx_processing_result. logs ( ) ;
400+
401+ if is_program_failed_to_complete && fuzzing_metrics. is_ok ( ) {
402+ if fuzzing_debug. is_ok ( ) {
403+ trident_svm:: prelude:: trident_svm_log:: log_message (
404+ "TRANSACTION PANICKED" ,
405+ trident_svm:: prelude:: Level :: Error ,
406+ ) ;
407+ }
408+ if let Some ( log_as) = log_as {
409+ let rng = self . rng . get_seed ( ) ;
410+ // TODO format instructions
411+ let tx = format ! ( "{:#?}" , instructions) ;
412+ self . fuzzing_data . add_transaction_panicked (
413+ log_as,
414+ rng,
415+ "Program failed to complete" . to_string ( ) ,
416+ Some ( log_messages. clone ( ) ) ,
417+ tx,
418+ ) ;
419+ }
420+ }
405421
406- let transaction_timestamp = tx_processing_result. get_transaction_timestamp ( ) ;
422+ let tx_result = & tx_processing_result. status ( ) ;
407423
408424 match tx_result {
409- Ok ( result) => match result {
410- trident_svm:: prelude:: solana_svm:: transaction_processing_result:: ProcessedTransaction :: Executed ( executed_transaction) => match & executed_transaction. execution_details . status {
411- Ok ( _) => {
412- let transaction_return_data = executed_transaction
413- . execution_details
414- . return_data
415- . clone ( )
416- . map ( |return_data| TransactionReturnData {
417- program_id : return_data. program_id ,
418- data : return_data. data ,
419- } ) ;
420- // Record successful execution
421- if fuzzing_metrics. is_ok ( ) && log_as. is_some ( ) {
422- if let Some ( log_as) = log_as {
423- self . fuzzing_data
424- . add_successful_transaction ( log_as) ;
425- }
426- }
427- TransactionResult :: new (
428- Ok ( ( ) ) ,
429- executed_transaction
430- . execution_details
431- . log_messages
432- . clone ( )
433- . unwrap_or_default ( ) ,
434- transaction_timestamp,
435- transaction_return_data,
436- )
437- } ,
438- Err ( transaction_error) => {
439- let transaction_return_data = executed_transaction
440- . execution_details
441- . return_data
442- . clone ( )
443- . map ( |return_data| TransactionReturnData {
444- program_id : return_data. program_id ,
445- data : return_data. data ,
446- } ) ;
447- if let TransactionError :: InstructionError ( _error_code, instruction_error) =
448- & transaction_error
449- {
450- match instruction_error {
451- InstructionError :: ProgramFailedToComplete => {
452- if fuzzing_metrics. is_ok ( ) {
453- if fuzzing_debug. is_ok ( ) {
454- trident_svm:: prelude:: trident_svm_log:: log_message (
455- "TRANSACTION PANICKED" ,
456- trident_svm:: prelude:: Level :: Error ,
457- ) ;
458- }
459- if let Some ( log_as) = log_as {
460- let rng = self . rng . get_seed ( ) ;
461- // TODO format instructions
462- let tx = format ! ( "{:#?}" , instructions) ;
463- self . fuzzing_data . add_transaction_panicked (
464- log_as,
465- rng,
466- instruction_error. to_string ( ) ,
467- executed_transaction. execution_details . log_messages . clone ( ) ,
468- tx,
469- ) ;
470- }
471- }
472- }
473- InstructionError :: Custom ( error_code) => {
474- if fuzzing_metrics. is_ok ( ) && log_as. is_some ( ) {
475- if let Some ( log_as) = log_as {
476- self . fuzzing_data . add_custom_instruction_error (
477- log_as,
478- error_code,
479- executed_transaction. execution_details . log_messages . clone ( ) ,
480- ) ;
481- }
482- }
483- }
484- _ => {
485- if fuzzing_metrics. is_ok ( ) && log_as. is_some ( ) {
486- if let Some ( log_as) = log_as {
487- self . fuzzing_data . add_failed_transaction (
488- log_as,
489- instruction_error. to_string ( ) ,
490- executed_transaction. execution_details . log_messages . clone ( ) ,
491- ) ;
492- }
493- }
494- }
495- }
496- } else if fuzzing_metrics. is_ok ( ) && log_as. is_some ( ) {
497- if let Some ( log_as) = log_as {
498- self . fuzzing_data . add_failed_transaction (
499- log_as,
500- transaction_error. to_string ( ) ,
501- executed_transaction. execution_details . log_messages . clone ( ) ,
502- ) ;
503- }
504- }
505- TransactionResult :: new (
506- Err ( transaction_error. clone ( ) ) ,
507- executed_transaction
508- . execution_details
509- . log_messages
510- . clone ( )
511- . unwrap_or_default ( ) ,
512- transaction_timestamp,
513- transaction_return_data,
514- )
515- } ,
516- } ,
517- trident_svm:: prelude:: solana_svm:: transaction_processing_result:: ProcessedTransaction :: FeesOnly ( _) => todo ! ( ) ,
518- } ,
425+ Ok ( _) => {
426+ if fuzzing_metrics. is_ok ( ) && log_as. is_some ( ) {
427+ if let Some ( log_as) = log_as {
428+ self . fuzzing_data . add_successful_transaction ( log_as) ;
429+ }
430+ }
431+ }
519432 Err ( transaction_error) => {
520- TransactionResult :: new ( Err ( transaction_error. clone ( ) ) , vec ! [ ] , transaction_timestamp, None )
433+ if fuzzing_metrics. is_ok ( ) && log_as. is_some ( ) {
434+ if let Some ( log_as) = log_as {
435+ self . fuzzing_data . add_failed_transaction (
436+ log_as,
437+ transaction_error. to_string ( ) ,
438+ Some ( log_messages) ,
439+ ) ;
440+ }
441+ }
521442 }
522443 }
523444 }
0 commit comments