Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion crates/op-rbuilder/src/builders/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,21 +517,37 @@ impl OpPayloadBuilderCtx {
info.executed_transactions.push(tx.into_inner());
}

let payload_tx_simulation_time = execute_txs_start_time.elapsed();
self.metrics
.payload_tx_simulation_duration
.record(execute_txs_start_time.elapsed());
.record(payload_tx_simulation_time);
self.metrics
.payload_tx_simulation_gauge
.set(payload_tx_simulation_time);
self.metrics
.payload_num_tx_considered
.record(num_txs_considered as f64);
self.metrics
.payload_num_tx_considered_gauge
.set(num_txs_considered as f64);
self.metrics
.payload_num_tx_simulated
.record(num_txs_simulated as f64);
self.metrics
.payload_num_tx_simulated_gauge
.set(num_txs_simulated as f64);
self.metrics
.payload_num_tx_simulated_success
.record(num_txs_simulated_success as f64);
self.metrics
.payload_num_tx_simulated_success_gauge
.set(num_txs_simulated_success as f64);
self.metrics
.payload_num_tx_simulated_fail
.record(num_txs_simulated_fail as f64);
self.metrics
.payload_num_tx_simulated_fail_gauge
.set(num_txs_simulated_fail as f64);
self.metrics
.bundles_reverted
.record(num_bundles_reverted as f64);
Expand Down
52 changes: 38 additions & 14 deletions crates/op-rbuilder/src/builders/flashblocks/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ where
.unwrap_or(0);

let mut info = execute_pre_steps(&mut db, &ctx)?;
ctx.metrics
.sequencer_tx_duration
.record(sequencer_tx_start_time.elapsed());
let sequencer_tx_time = sequencer_tx_start_time.elapsed();
ctx.metrics.sequencer_tx_duration.record(sequencer_tx_time);
ctx.metrics.sequencer_tx_gauge.set(sequencer_tx_time);

// If we have payload with txpool we add first builder tx right after deposits
if !ctx.attributes().no_tx_pool {
Expand All @@ -257,16 +257,23 @@ where
ctx.metrics
.payload_num_tx
.record(info.executed_transactions.len() as f64);
ctx.metrics
.payload_num_tx_gauge
.set(info.executed_transactions.len() as f64);

if ctx.attributes().no_tx_pool {
info!(
target: "payload_builder",
"No transaction pool, skipping transaction pool processing",
);

let total_block_building_time = block_build_start_time.elapsed();
ctx.metrics
.total_block_built_duration
.record(block_build_start_time.elapsed());
.record(total_block_building_time);
ctx.metrics
.total_block_built_gauge
.set(total_block_building_time);

// return early since we don't need to build a block with transactions from the pool
return Ok(());
Expand Down Expand Up @@ -389,9 +396,13 @@ where
self.pool
.best_transactions_with_attributes(ctx.best_transaction_attributes()),
);
let transaction_pool_fetch_time = best_txs_start_time.elapsed();
ctx.metrics
.transaction_pool_fetch_duration
.record(best_txs_start_time.elapsed());
.record(transaction_pool_fetch_time);
ctx.metrics
.transaction_pool_fetch_gauge
.set(transaction_pool_fetch_time);

let tx_execution_start_time = Instant::now();
ctx.execute_best_transactions(
Expand All @@ -413,13 +424,14 @@ where
span.record("flashblock_count", flashblock_count);
return Ok(());
}
ctx.metrics
.payload_tx_simulation_duration
.record(tx_execution_start_time.elapsed());

let payload_tx_simulation_time = tx_execution_start_time.elapsed();
ctx.metrics
.payload_tx_simulation_duration
.record(tx_execution_start_time.elapsed());
.record(payload_tx_simulation_time);
ctx.metrics
.payload_tx_simulation_gauge
.set(payload_tx_simulation_time);

// If it is the last flashblocks, add the builder txn to the block if enabled
invoke_on_last_flashblock(flashblock_count, last_flashblock, || {
Expand All @@ -428,9 +440,13 @@ where

let total_block_built_duration = Instant::now();
let build_result = build_block(db, &ctx, &mut info);
let total_block_built_duration = total_block_built_duration.elapsed();
ctx.metrics
.total_block_built_duration
.record(total_block_built_duration.elapsed());
.record(total_block_built_duration);
ctx.metrics
.total_block_built_gauge
.set(total_block_built_duration);

// Handle build errors with match pattern
match build_result {
Expand Down Expand Up @@ -460,10 +476,10 @@ where
.flashblock_build_duration
.record(flashblock_build_start_time.elapsed());
ctx.metrics
.payload_byte_size
.flashblock_byte_size_histogram
.record(new_payload.block().size() as f64);
ctx.metrics
.payload_num_tx
.flashblock_num_tx_histogram
.record(info.executed_transactions.len() as f64);

best_payload.set(new_payload.clone());
Expand Down Expand Up @@ -677,9 +693,13 @@ where
// and 4788 contract call
let state_merge_start_time = Instant::now();
state.merge_transitions(BundleRetention::Reverts);
let state_transition_merge_time = state_merge_start_time.elapsed();
ctx.metrics
.state_transition_merge_duration
.record(state_merge_start_time.elapsed());
.record(state_transition_merge_time);
ctx.metrics
.state_transition_merge_gauge
.set(state_transition_merge_time);

let new_bundle = state.take_bundle();

Expand Down Expand Up @@ -723,9 +743,13 @@ where
);
})?
};
let state_root_calculation_time = state_root_start_time.elapsed();
ctx.metrics
.state_root_calculation_duration
.record(state_root_start_time.elapsed());
.record(state_root_calculation_time);
ctx.metrics
.state_root_calculation_gauge
.set(state_root_calculation_time);

let mut requests_hash = None;
let withdrawals_root = if ctx
Expand Down
38 changes: 31 additions & 7 deletions crates/op-rbuilder/src/builders/standard/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,13 @@ where
builder.build(db, ctx)
}
.map(|out| {
let total_block_building_time = block_build_start_time.elapsed();
metrics
.total_block_built_duration
.record(block_build_start_time.elapsed());
.record(total_block_building_time);
metrics
.total_block_built_gauge
.set(total_block_building_time);

out.with_cached_reads(cached_reads)
})
Expand Down Expand Up @@ -367,9 +371,9 @@ impl<Txs: PayloadTxsBounds> OpBuilder<'_, Txs> {
// 3. execute sequencer transactions
let mut info = ctx.execute_sequencer_transactions(state)?;

ctx.metrics
.sequencer_tx_duration
.record(sequencer_tx_start_time.elapsed());
let sequencer_tx_time = sequencer_tx_start_time.elapsed();
ctx.metrics.sequencer_tx_duration.record(sequencer_tx_time);
ctx.metrics.sequencer_tx_gauge.set(sequencer_tx_time);

// 4. if mem pool transactions are requested we execute them

Expand Down Expand Up @@ -399,9 +403,14 @@ impl<Txs: PayloadTxsBounds> OpBuilder<'_, Txs> {
if !ctx.attributes().no_tx_pool {
let best_txs_start_time = Instant::now();
let best_txs = best(ctx.best_transaction_attributes());
let transaction_pool_fetch_time = best_txs_start_time.elapsed();
ctx.metrics
.transaction_pool_fetch_duration
.record(best_txs_start_time.elapsed());
.record(transaction_pool_fetch_time);
ctx.metrics
.transaction_pool_fetch_gauge
.set(transaction_pool_fetch_time);

if ctx
.execute_best_transactions(
&mut info,
Expand All @@ -425,12 +434,20 @@ impl<Txs: PayloadTxsBounds> OpBuilder<'_, Txs> {
// and 4788 contract call
state.merge_transitions(BundleRetention::Reverts);

let state_transition_merge_time = state_merge_start_time.elapsed();
ctx.metrics
.state_transition_merge_duration
.record(state_merge_start_time.elapsed());
.record(state_transition_merge_time);
ctx.metrics
.state_transition_merge_gauge
.set(state_transition_merge_time);

ctx.metrics
.payload_num_tx
.record(info.executed_transactions.len() as f64);
ctx.metrics
.payload_num_tx_gauge
.set(info.executed_transactions.len() as f64);

let payload = ExecutedPayload { info };

Expand Down Expand Up @@ -493,9 +510,13 @@ impl<Txs: PayloadTxsBounds> OpBuilder<'_, Txs> {
})?
};

let state_root_calculation_time = state_root_start_time.elapsed();
ctx.metrics
.state_root_calculation_duration
.record(state_root_start_time.elapsed());
.record(state_root_calculation_time);
ctx.metrics
.state_root_calculation_gauge
.set(state_root_calculation_time);

let (withdrawals_root, requests_hash) = if ctx.is_isthmus_active() {
// withdrawals root field in block header is used for storage root of L2 predeploy
Expand Down Expand Up @@ -585,6 +606,9 @@ impl<Txs: PayloadTxsBounds> OpBuilder<'_, Txs> {
ctx.metrics
.payload_byte_size
.record(payload.block().size() as f64);
ctx.metrics
.payload_byte_size_gauge
.set(payload.block().size() as f64);

if no_tx_pool {
// if `no_tx_pool` is set only transactions from the payload attributes will be included
Expand Down
56 changes: 42 additions & 14 deletions crates/op-rbuilder/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,63 @@ pub struct OpRBuilderMetrics {
pub flashblock_count: Histogram,
/// Number of messages sent
pub messages_sent_count: Counter,
/// Total duration of building a block
/// Histogram of the time taken to build a block
pub total_block_built_duration: Histogram,
/// Flashblock build duration
/// Latest time taken to build a block
pub total_block_built_gauge: Gauge,
/// Histogram of the time taken to build a Flashblock
pub flashblock_build_duration: Histogram,
/// Flashblock byte size histogram
pub flashblock_byte_size_histogram: Histogram,
/// Histogram of transactions in a Flashblock
pub flashblock_num_tx_histogram: Histogram,
/// Number of invalid blocks
pub invalid_blocks_count: Counter,
/// Duration of fetching transactions from the pool
/// Histogram of fetching transactions from the pool duration
pub transaction_pool_fetch_duration: Histogram,
/// Duration of state root calculation
/// Latest time taken to fetch tx from the pool
pub transaction_pool_fetch_gauge: Gauge,
/// Histogram of state root calculation duration
pub state_root_calculation_duration: Histogram,
/// Duration of sequencer transaction execution
/// Latest state root calculation duration
pub state_root_calculation_gauge: Gauge,
/// Histogram of sequencer transaction execution duration
pub sequencer_tx_duration: Histogram,
/// Duration of state merge transitions
/// Latest sequencer transaction execution duration
pub sequencer_tx_gauge: Gauge,
/// Histogram of state merge transitions duration
pub state_transition_merge_duration: Histogram,
/// Duration of payload simulation of all transactions
/// Latest state merge transitions duration
pub state_transition_merge_gauge: Gauge,
/// Histogram of the duration of payload simulation of all transactions
pub payload_tx_simulation_duration: Histogram,
/// Latest payload simulation of all transactions duration
pub payload_tx_simulation_gauge: Gauge,
/// Number of transaction considered for inclusion in the block
pub payload_num_tx_considered: Histogram,
/// Payload byte size
/// Latest number of transactions considered for inclusion in the block
pub payload_num_tx_considered_gauge: Gauge,
/// Payload byte size histogram
pub payload_byte_size: Histogram,
/// Number of transactions in the payload
/// Latest Payload byte size
pub payload_byte_size_gauge: Gauge,
/// Histogram of transactions in the payload
pub payload_num_tx: Histogram,
/// Number of transactions in the payload that were successfully simulated
/// Latest number of transactions in the payload
pub payload_num_tx_gauge: Gauge,
/// Histogram of transactions in the payload that were successfully simulated
pub payload_num_tx_simulated: Histogram,
/// Number of transactions in the payload that were successfully simulated
/// Latest number of transactions in the payload that were successfully simulated
pub payload_num_tx_simulated_gauge: Gauge,
/// Histogram of transactions in the payload that were successfully simulated
pub payload_num_tx_simulated_success: Histogram,
/// Number of transactions in the payload that failed simulation
/// Latest number of transactions in the payload that were successfully simulated
pub payload_num_tx_simulated_success_gauge: Gauge,
/// Histogram of transactions in the payload that failed simulation
pub payload_num_tx_simulated_fail: Histogram,
/// Duration of tx simulation
/// Latest number of transactions in the payload that failed simulation
pub payload_num_tx_simulated_fail_gauge: Gauge,
/// Histogram of tx simulation duration
pub tx_simulation_duration: Histogram,
/// Byte size of transactions
pub tx_byte_size: Histogram,
Expand All @@ -92,7 +120,7 @@ pub struct OpRBuilderMetrics {
pub failed_bundles: Counter,
/// Number of reverted bundles
pub bundles_reverted: Histogram,
/// Time taken to respond to a request to the eth_sendBundle endpoint
/// Histogram of eth_sendBundle request duration
pub bundle_receive_duration: Histogram,
}

Expand Down
Loading