-
Notifications
You must be signed in to change notification settings - Fork 64
feat(metrics): Add labels to tx simulation metrics #492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
avalonche
wants to merge
2
commits into
main
Choose a base branch
from
feat/tx-simulation-metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,9 @@ use crate::{ | |
| evm::OpBlockEvmFactory, | ||
| gas_limiter::AddressGasLimiter, | ||
| hardforks::ActiveHardforks, | ||
| metrics::OpRBuilderMetrics, | ||
| metrics::{ | ||
| OpRBuilderMetrics, TxResult, TxSource, record_tx_gas_used, record_tx_simulation_duration, | ||
| }, | ||
| primitives::reth::{ExecutionInfo, TxnExecutionResult}, | ||
| traits::PayloadTxsBounds, | ||
| }; | ||
|
|
@@ -387,10 +389,17 @@ impl OpPayloadJobCtx { | |
| ) -> Result<Option<()>, PayloadBuilderError> { | ||
| let execute_txs_start_time = Instant::now(); | ||
| let mut num_txs_considered = 0; | ||
| let mut num_txs_simulated = 0; | ||
| let mut num_txs_simulated_success = 0; | ||
| let mut num_txs_simulated_fail = 0; | ||
| let mut num_bundles_reverted = 0; | ||
| let mut num_mempool_txs_simulated_success = 0; | ||
| let mut num_mempool_txs_simulated_revert = 0; | ||
| let mut num_mempool_txs_simulated_halt = 0; | ||
| let mut num_bundle_txs_simulated_success = 0; | ||
| let mut num_bundle_txs_simulated_revert = 0; | ||
| let mut num_bundle_txs_simulated_halt = 0; | ||
| let mut num_backrun_txs_simulated_success = 0; | ||
| let mut num_backrun_txs_simulated_revert = 0; | ||
| let mut num_backrun_txs_simulated_halt = 0; | ||
| let mut reverted_gas_used: u64 = 0; | ||
| let mut num_backruns_considered = 0usize; | ||
| let mut num_backruns_successful = 0usize; | ||
|
|
@@ -420,7 +429,12 @@ impl OpPayloadJobCtx { | |
| let tx_da_size = tx.estimated_da_size(); | ||
|
|
||
| let is_bundle_tx = tx.is_bundle(); | ||
| let exclude_reverting_txs = tx.revert_protected(); | ||
| let revert_protected = tx.revert_protected(); | ||
| let tx_source = if is_bundle_tx { | ||
| TxSource::Bundle | ||
| } else { | ||
| TxSource::Mempool | ||
| }; | ||
|
|
||
| let tx = tx.into_consensus(); | ||
| let tx_hash = tx.tx_hash(); | ||
|
|
@@ -443,7 +457,7 @@ impl OpPayloadJobCtx { | |
| id = %self.payload_id(), | ||
| tx_hash = %tx_hash, | ||
| tx_da_size, | ||
| exclude_reverting_txs, | ||
| revert_protected, | ||
| result = %result, | ||
| "Considering transaction", | ||
| ); | ||
|
|
@@ -528,11 +542,15 @@ impl OpPayloadJobCtx { | |
| } | ||
| }; | ||
|
|
||
| self.metrics | ||
| .tx_simulation_duration | ||
| .record(tx_simulation_start_time.elapsed()); | ||
| let tx_simulation_elapsed = tx_simulation_start_time.elapsed(); | ||
| let tx_result = TxResult::from_execution_result(&result); | ||
| record_tx_simulation_duration( | ||
| tx_simulation_elapsed, | ||
| tx_source, | ||
| tx_result, | ||
| revert_protected, | ||
| ); | ||
| self.metrics.tx_byte_size.record(tx.inner().size() as f64); | ||
| num_txs_simulated += 1; | ||
|
|
||
| // Run the per-address gas limiting before checking if the tx has | ||
| // reverted or not, as this is a check against maliciously searchers | ||
|
|
@@ -546,7 +564,7 @@ impl OpPayloadJobCtx { | |
| flashblock_index, | ||
| gas_used, | ||
| success = result.is_success(), | ||
| evm_duration_us = tx_simulation_start_time.elapsed().as_micros() as u64, | ||
| evm_duration_us = tx_simulation_elapsed.as_micros() as u64, | ||
| stage = "evm_executed" | ||
| ); | ||
| } | ||
|
|
@@ -561,18 +579,36 @@ impl OpPayloadJobCtx { | |
| continue; | ||
| } | ||
|
|
||
| record_tx_gas_used(gas_used, tx_source, tx_result, revert_protected); | ||
| if result.is_success() { | ||
| log_txn(TxnExecutionResult::Success); | ||
| num_txs_simulated_success += 1; | ||
| self.metrics.successful_tx_gas_used.record(gas_used as f64); | ||
| match tx_source { | ||
| TxSource::Mempool => num_mempool_txs_simulated_success += 1, | ||
| TxSource::Bundle => num_bundle_txs_simulated_success += 1, | ||
| TxSource::Backrun => unreachable!("backruns are handled in the backrun loop"), | ||
| } | ||
| } else { | ||
| num_txs_simulated_fail += 1; | ||
| reverted_gas_used += gas_used; | ||
| self.metrics.reverted_tx_gas_used.record(gas_used as f64); | ||
| if is_bundle_tx { | ||
| num_bundles_reverted += 1; | ||
| match tx_source { | ||
| TxSource::Mempool => match tx_result { | ||
| TxResult::Revert => num_mempool_txs_simulated_revert += 1, | ||
| TxResult::Halt => num_mempool_txs_simulated_halt += 1, | ||
| TxResult::Success => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think you can avoid the |
||
| unreachable!("successes are handled in the success branch") | ||
| } | ||
| }, | ||
| TxSource::Bundle => match tx_result { | ||
| TxResult::Revert => num_bundle_txs_simulated_revert += 1, | ||
| TxResult::Halt => num_bundle_txs_simulated_halt += 1, | ||
| TxResult::Success => { | ||
| unreachable!("successes are handled in the success branch") | ||
| } | ||
| }, | ||
| TxSource::Backrun => unreachable!("backruns are handled in the backrun loop"), | ||
| } | ||
| if exclude_reverting_txs { | ||
| if revert_protected { | ||
| log_txn(TxnExecutionResult::RevertedAndExcluded); | ||
| trace!( | ||
| target: "payload_builder", | ||
|
|
@@ -699,8 +735,8 @@ impl OpPayloadJobCtx { | |
| // - [x] log when tx execution fails | ||
| // - [x] inc num_txs_simulated_success or num_txs_simulated_fail | ||
| // - [x] inc reverted_gas_used | ||
| // - [x] metrics use successful_tx_gas_used and reverted_tx_gas_used | ||
| // - [x] inc num_bundles_reverted | ||
| // - [x] meter tx_gas_used | ||
| // - [x] meter payload simulated counts by source/result | ||
| // - [x] enforce self.max_gas_per_txn | ||
| // - [x] increase info.{cumulative_gas_used, cumulative_da_bytes_used} | ||
| // - [x] push receipt to info.receipts | ||
|
|
@@ -809,13 +845,16 @@ impl OpPayloadJobCtx { | |
| continue; | ||
| } | ||
| }; | ||
| self.metrics | ||
| .tx_simulation_duration | ||
| .record(br_simulation_start.elapsed()); | ||
| let br_tx_result = TxResult::from_execution_result(&br_result); | ||
| record_tx_simulation_duration( | ||
| br_simulation_start.elapsed(), | ||
| TxSource::Backrun, | ||
| br_tx_result, | ||
| true, | ||
| ); | ||
| self.metrics | ||
| .tx_byte_size | ||
| .record(bundle.backrun_tx.inner().size() as f64); | ||
| num_txs_simulated += 1; | ||
|
|
||
| let br_gas_used = br_result.gas_used(); | ||
|
|
||
|
|
@@ -828,11 +867,17 @@ impl OpPayloadJobCtx { | |
| continue; | ||
| } | ||
|
|
||
| record_tx_gas_used(br_gas_used, TxSource::Backrun, br_tx_result, true); | ||
| if !br_result.is_success() { | ||
| num_txs_simulated_fail += 1; | ||
| num_bundles_reverted += 1; | ||
| reverted_gas_used += br_gas_used; | ||
| self.metrics.reverted_tx_gas_used.record(br_gas_used as f64); | ||
| match br_tx_result { | ||
| TxResult::Revert => num_backrun_txs_simulated_revert += 1, | ||
| TxResult::Halt => num_backrun_txs_simulated_halt += 1, | ||
| TxResult::Success => { | ||
| unreachable!("successes are handled in the success branch") | ||
| } | ||
| } | ||
| log_br_txn(TxnExecutionResult::RevertedAndExcluded); | ||
| continue; | ||
| } | ||
|
|
@@ -861,10 +906,8 @@ impl OpPayloadJobCtx { | |
| } | ||
|
|
||
| num_txs_simulated_success += 1; | ||
| num_backrun_txs_simulated_success += 1; | ||
| num_backruns_successful += 1; | ||
| self.metrics | ||
| .successful_tx_gas_used | ||
| .record(br_gas_used as f64); | ||
| log_br_txn(TxnExecutionResult::Success); | ||
| info.cumulative_gas_used += br_gas_used; | ||
| info.cumulative_da_bytes_used += br_tx_da_size; | ||
|
|
@@ -901,10 +944,15 @@ impl OpPayloadJobCtx { | |
| self.metrics.set_payload_builder_metrics( | ||
| payload_transaction_simulation_time, | ||
| num_txs_considered, | ||
| num_txs_simulated, | ||
| num_txs_simulated_success, | ||
| num_txs_simulated_fail, | ||
| num_bundles_reverted, | ||
| num_mempool_txs_simulated_success, | ||
| num_mempool_txs_simulated_revert, | ||
| num_mempool_txs_simulated_halt, | ||
| num_bundle_txs_simulated_success, | ||
| num_bundle_txs_simulated_revert, | ||
| num_bundle_txs_simulated_halt, | ||
| num_backrun_txs_simulated_success, | ||
| num_backrun_txs_simulated_revert, | ||
| num_backrun_txs_simulated_halt, | ||
| reverted_gas_used, | ||
| num_backruns_considered as f64, | ||
| num_backruns_successful as f64, | ||
|
|
@@ -917,7 +965,10 @@ impl OpPayloadJobCtx { | |
| txs_executed = num_txs_considered, | ||
| txs_applied = num_txs_simulated_success, | ||
| txs_rejected = num_txs_simulated_fail, | ||
| bundles_reverted = num_bundles_reverted, | ||
| bundle_txs_reverted = num_bundle_txs_simulated_revert, | ||
| bundle_txs_halted = num_bundle_txs_simulated_halt, | ||
| backrun_txs_reverted = num_backrun_txs_simulated_revert, | ||
| backrun_txs_halted = num_backrun_txs_simulated_halt, | ||
| backruns_considered = num_backruns_considered, | ||
| backruns_successful = num_backruns_successful, | ||
| "Completed executing best transactions", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just store all these in a hashmap or something so you just have one mutable variable for recording metrics. you wouldn't have so much repetitive code in
set_payload_builder_metricsthen either