Skip to content

Commit 8b83c3b

Browse files
apollo_batcher: use metrics helper function (#9937)
1 parent 3c013fc commit 8b83c3b

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

crates/apollo_batcher/src/block_builder.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ use tracing::{debug, error, info, trace, warn};
5151

5252
use crate::block_builder::FailOnErrorCause::L1HandlerTransactionValidationFailed;
5353
use crate::cende_client_types::{StarknetClientStateDiff, StarknetClientTransactionReceipt};
54-
use crate::metrics::{PROPOSER_DEFERRED_TXS, VALIDATOR_WASTED_TXS};
54+
use crate::metrics::{
55+
record_block_close_reason,
56+
BlockCloseReason,
57+
PROPOSER_DEFERRED_TXS,
58+
VALIDATOR_WASTED_TXS,
59+
};
5560
use crate::pre_confirmed_block_writer::{CandidateTxSender, PreconfirmedTxSender};
5661
use crate::transaction_executor::TransactionExecutorTrait;
5762
use crate::transaction_provider::{TransactionProvider, TransactionProviderError};
@@ -244,14 +249,7 @@ impl BlockBuilder {
244249
if self.execution_params.is_validator {
245250
return Err(BlockBuilderError::FailOnError(FailOnErrorCause::DeadlineReached));
246251
}
247-
// TODO(Dan): extract to a function (as in record_validate_proposal_failure).
248-
crate::metrics::BLOCK_CLOSE_REASON.increment(
249-
1,
250-
&[(
251-
crate::metrics::LABEL_NAME_BLOCK_CLOSE_REASON,
252-
crate::metrics::BlockCloseReason::Deadline.into(),
253-
)],
254-
);
252+
record_block_close_reason(BlockCloseReason::Deadline);
255253
break;
256254
}
257255

@@ -263,14 +261,7 @@ impl BlockBuilder {
263261
started (timeout is set to {:?}), finishing block building.",
264262
time_since_start, self.execution_params.proposer_idle_detection_delay,
265263
);
266-
// TODO(Dan): extract to a function (as in record_validate_proposal_failure).
267-
crate::metrics::BLOCK_CLOSE_REASON.increment(
268-
1,
269-
&[(
270-
crate::metrics::LABEL_NAME_BLOCK_CLOSE_REASON,
271-
crate::metrics::BlockCloseReason::IdleExecutionTimeout.into(),
272-
)],
273-
);
264+
record_block_close_reason(BlockCloseReason::IdleExecutionTimeout);
274265
break;
275266
}
276267
if final_n_executed_txs.is_none() {
@@ -293,14 +284,7 @@ impl BlockBuilder {
293284
// Call `handle_executed_txs()` once more to get the last results.
294285
self.handle_executed_txs().await?;
295286
info!("Block is full.");
296-
// TODO(Dan): extract to a function (as in record_validate_proposal_failure).
297-
crate::metrics::BLOCK_CLOSE_REASON.increment(
298-
1,
299-
&[(
300-
crate::metrics::LABEL_NAME_BLOCK_CLOSE_REASON,
301-
crate::metrics::BlockCloseReason::FullBlock.into(),
302-
)],
303-
);
287+
record_block_close_reason(BlockCloseReason::FullBlock);
304288
break;
305289
}
306290

crates/apollo_batcher/src/metrics.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ generate_permutation_labels! {
7171
(LABEL_NAME_BLOCK_CLOSE_REASON, BlockCloseReason),
7272
}
7373

74+
pub(crate) fn record_block_close_reason(reason: BlockCloseReason) {
75+
BLOCK_CLOSE_REASON.increment(1, &[(LABEL_NAME_BLOCK_CLOSE_REASON, reason.into())]);
76+
}
77+
7478
pub fn register_metrics(storage_height: BlockNumber) {
7579
STORAGE_HEIGHT.register();
7680
STORAGE_HEIGHT.set_lossy(storage_height.0);

0 commit comments

Comments
 (0)