@@ -37,7 +37,9 @@ use crate::{
3737 evm:: OpBlockEvmFactory ,
3838 gas_limiter:: AddressGasLimiter ,
3939 hardforks:: ActiveHardforks ,
40- metrics:: { OpRBuilderMetrics , record_tx_simulation_duration} ,
40+ metrics:: {
41+ OpRBuilderMetrics , TxResult , TxSource , record_tx_gas_used, record_tx_simulation_duration,
42+ } ,
4143 primitives:: reth:: { ExecutionInfo , TxnExecutionResult } ,
4244 traits:: PayloadTxsBounds ,
4345} ;
@@ -387,10 +389,17 @@ impl OpPayloadJobCtx {
387389 ) -> Result < Option < ( ) > , PayloadBuilderError > {
388390 let execute_txs_start_time = Instant :: now ( ) ;
389391 let mut num_txs_considered = 0 ;
390- let mut num_txs_simulated = 0 ;
391392 let mut num_txs_simulated_success = 0 ;
392393 let mut num_txs_simulated_fail = 0 ;
393- let mut num_bundles_reverted = 0 ;
394+ let mut num_mempool_txs_simulated_success = 0 ;
395+ let mut num_mempool_txs_simulated_revert = 0 ;
396+ let mut num_mempool_txs_simulated_halt = 0 ;
397+ let mut num_bundle_txs_simulated_success = 0 ;
398+ let mut num_bundle_txs_simulated_revert = 0 ;
399+ let mut num_bundle_txs_simulated_halt = 0 ;
400+ let mut num_backrun_txs_simulated_success = 0 ;
401+ let mut num_backrun_txs_simulated_revert = 0 ;
402+ let mut num_backrun_txs_simulated_halt = 0 ;
394403 let mut reverted_gas_used: u64 = 0 ;
395404 let mut num_backruns_considered = 0usize ;
396405 let mut num_backruns_successful = 0usize ;
@@ -421,6 +430,11 @@ impl OpPayloadJobCtx {
421430
422431 let is_bundle_tx = tx. is_bundle ( ) ;
423432 let revert_protected = tx. revert_protected ( ) ;
433+ let tx_source = if is_bundle_tx {
434+ TxSource :: Bundle
435+ } else {
436+ TxSource :: Mempool
437+ } ;
424438
425439 let tx = tx. into_consensus ( ) ;
426440 let tx_hash = tx. tx_hash ( ) ;
@@ -529,14 +543,14 @@ impl OpPayloadJobCtx {
529543 } ;
530544
531545 let tx_simulation_elapsed = tx_simulation_start_time. elapsed ( ) ;
546+ let tx_result = TxResult :: from_execution_result ( & result) ;
532547 record_tx_simulation_duration (
533548 tx_simulation_elapsed,
534- is_bundle_tx ,
535- !result . is_success ( ) ,
549+ tx_source ,
550+ tx_result ,
536551 revert_protected,
537552 ) ;
538553 self . metrics . tx_byte_size . record ( tx. inner ( ) . size ( ) as f64 ) ;
539- num_txs_simulated += 1 ;
540554
541555 // Run the per-address gas limiting before checking if the tx has
542556 // reverted or not, as this is a check against maliciously searchers
@@ -565,16 +579,34 @@ impl OpPayloadJobCtx {
565579 continue ;
566580 }
567581
582+ record_tx_gas_used ( gas_used, tx_source, tx_result, revert_protected) ;
568583 if result. is_success ( ) {
569584 log_txn ( TxnExecutionResult :: Success ) ;
570585 num_txs_simulated_success += 1 ;
571- self . metrics . successful_tx_gas_used . record ( gas_used as f64 ) ;
586+ match tx_source {
587+ TxSource :: Mempool => num_mempool_txs_simulated_success += 1 ,
588+ TxSource :: Bundle => num_bundle_txs_simulated_success += 1 ,
589+ TxSource :: Backrun => unreachable ! ( "backruns are handled in the backrun loop" ) ,
590+ }
572591 } else {
573592 num_txs_simulated_fail += 1 ;
574593 reverted_gas_used += gas_used;
575- self . metrics . reverted_tx_gas_used . record ( gas_used as f64 ) ;
576- if is_bundle_tx {
577- num_bundles_reverted += 1 ;
594+ match tx_source {
595+ TxSource :: Mempool => match tx_result {
596+ TxResult :: Revert => num_mempool_txs_simulated_revert += 1 ,
597+ TxResult :: Halt => num_mempool_txs_simulated_halt += 1 ,
598+ TxResult :: Success => {
599+ unreachable ! ( "successes are handled in the success branch" )
600+ }
601+ } ,
602+ TxSource :: Bundle => match tx_result {
603+ TxResult :: Revert => num_bundle_txs_simulated_revert += 1 ,
604+ TxResult :: Halt => num_bundle_txs_simulated_halt += 1 ,
605+ TxResult :: Success => {
606+ unreachable ! ( "successes are handled in the success branch" )
607+ }
608+ } ,
609+ TxSource :: Backrun => unreachable ! ( "backruns are handled in the backrun loop" ) ,
578610 }
579611 if revert_protected {
580612 log_txn ( TxnExecutionResult :: RevertedAndExcluded ) ;
@@ -703,8 +735,8 @@ impl OpPayloadJobCtx {
703735 // - [x] log when tx execution fails
704736 // - [x] inc num_txs_simulated_success or num_txs_simulated_fail
705737 // - [x] inc reverted_gas_used
706- // - [x] metrics use successful_tx_gas_used and reverted_tx_gas_used
707- // - [x] inc num_bundles_reverted
738+ // - [x] meter tx_gas_used
739+ // - [x] meter payload simulated counts by source/result
708740 // - [x] enforce self.max_gas_per_txn
709741 // - [x] increase info.{cumulative_gas_used, cumulative_da_bytes_used}
710742 // - [x] push receipt to info.receipts
@@ -813,16 +845,16 @@ impl OpPayloadJobCtx {
813845 continue ;
814846 }
815847 } ;
848+ let br_tx_result = TxResult :: from_execution_result ( & br_result) ;
816849 record_tx_simulation_duration (
817850 br_simulation_start. elapsed ( ) ,
818- true ,
819- !br_result . is_success ( ) ,
851+ TxSource :: Backrun ,
852+ br_tx_result ,
820853 true ,
821854 ) ;
822855 self . metrics
823856 . tx_byte_size
824857 . record ( bundle. backrun_tx . inner ( ) . size ( ) as f64 ) ;
825- num_txs_simulated += 1 ;
826858
827859 let br_gas_used = br_result. gas_used ( ) ;
828860
@@ -835,11 +867,17 @@ impl OpPayloadJobCtx {
835867 continue ;
836868 }
837869
870+ record_tx_gas_used ( br_gas_used, TxSource :: Backrun , br_tx_result, true ) ;
838871 if !br_result. is_success ( ) {
839872 num_txs_simulated_fail += 1 ;
840- num_bundles_reverted += 1 ;
841873 reverted_gas_used += br_gas_used;
842- self . metrics . reverted_tx_gas_used . record ( br_gas_used as f64 ) ;
874+ match br_tx_result {
875+ TxResult :: Revert => num_backrun_txs_simulated_revert += 1 ,
876+ TxResult :: Halt => num_backrun_txs_simulated_halt += 1 ,
877+ TxResult :: Success => {
878+ unreachable ! ( "successes are handled in the success branch" )
879+ }
880+ }
843881 log_br_txn ( TxnExecutionResult :: RevertedAndExcluded ) ;
844882 continue ;
845883 }
@@ -868,10 +906,8 @@ impl OpPayloadJobCtx {
868906 }
869907
870908 num_txs_simulated_success += 1 ;
909+ num_backrun_txs_simulated_success += 1 ;
871910 num_backruns_successful += 1 ;
872- self . metrics
873- . successful_tx_gas_used
874- . record ( br_gas_used as f64 ) ;
875911 log_br_txn ( TxnExecutionResult :: Success ) ;
876912 info. cumulative_gas_used += br_gas_used;
877913 info. cumulative_da_bytes_used += br_tx_da_size;
@@ -908,10 +944,15 @@ impl OpPayloadJobCtx {
908944 self . metrics . set_payload_builder_metrics (
909945 payload_transaction_simulation_time,
910946 num_txs_considered,
911- num_txs_simulated,
912- num_txs_simulated_success,
913- num_txs_simulated_fail,
914- num_bundles_reverted,
947+ num_mempool_txs_simulated_success,
948+ num_mempool_txs_simulated_revert,
949+ num_mempool_txs_simulated_halt,
950+ num_bundle_txs_simulated_success,
951+ num_bundle_txs_simulated_revert,
952+ num_bundle_txs_simulated_halt,
953+ num_backrun_txs_simulated_success,
954+ num_backrun_txs_simulated_revert,
955+ num_backrun_txs_simulated_halt,
915956 reverted_gas_used,
916957 num_backruns_considered as f64 ,
917958 num_backruns_successful as f64 ,
@@ -924,7 +965,10 @@ impl OpPayloadJobCtx {
924965 txs_executed = num_txs_considered,
925966 txs_applied = num_txs_simulated_success,
926967 txs_rejected = num_txs_simulated_fail,
927- bundles_reverted = num_bundles_reverted,
968+ bundle_txs_reverted = num_bundle_txs_simulated_revert,
969+ bundle_txs_halted = num_bundle_txs_simulated_halt,
970+ backrun_txs_reverted = num_backrun_txs_simulated_revert,
971+ backrun_txs_halted = num_backrun_txs_simulated_halt,
928972 backruns_considered = num_backruns_considered,
929973 backruns_successful = num_backruns_successful,
930974 "Completed executing best transactions" ,
0 commit comments