From 42872bf61ffb3a4ed00af38ec38e30483677261e Mon Sep 17 00:00:00 2001 From: zhoujunma Date: Thu, 22 Feb 2024 16:43:34 -0800 Subject: [PATCH] vtxn proposal metrics (#12164) --- consensus/src/counters.rs | 18 ++++++++++++++++++ consensus/src/round_manager.rs | 24 ++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/consensus/src/counters.rs b/consensus/src/counters.rs index 542d4eeb43578..7e2d31f1a462c 100644 --- a/consensus/src/counters.rs +++ b/consensus/src/counters.rs @@ -905,3 +905,21 @@ pub static EPOCH_MANAGER_ISSUES_DETAILS: Lazy = Lazy::new(|| { ) .unwrap() }); + +pub static PROPOSED_VTXN_COUNT: Lazy = Lazy::new(|| { + register_int_counter_vec!( + "aptos_proposed_vtxn_count", + "Number of validator transactions proposed", + &["proposer"] + ) + .unwrap() +}); + +pub static PROPOSED_VTXN_BYTES: Lazy = Lazy::new(|| { + register_int_counter_vec!( + "aptos_proposed_vtxn_bytes", + "The total size in bytes of validator transactions proposed", + &["proposer"] + ) + .unwrap() +}); diff --git a/consensus/src/round_manager.rs b/consensus/src/round_manager.rs index b7f47e224edf0..78d445bfd4992 100644 --- a/consensus/src/round_manager.rs +++ b/consensus/src/round_manager.rs @@ -8,6 +8,7 @@ use crate::{ BlockReader, BlockRetriever, BlockStore, }, counters, + counters::{PROPOSED_VTXN_BYTES, PROPOSED_VTXN_COUNT}, error::{error_kind, VerifyError}, liveness::{ proposal_generator::ProposalGenerator, @@ -678,16 +679,35 @@ impl RoundManager { (count_acc + 1, size_acc + txn.size_in_bytes()) }) }); + let num_validator_txns = num_validator_txns as u64; let validator_txns_total_bytes = validator_txns_total_bytes as u64; + let vtxn_count_limit = self.vtxn_config.per_block_limit_txn_count(); + let vtxn_bytes_limit = self.vtxn_config.per_block_limit_total_bytes(); + let author_hex = author.to_hex(); + PROPOSED_VTXN_COUNT + .with_label_values(&[&author_hex]) + .inc_by(num_validator_txns); + PROPOSED_VTXN_BYTES + .with_label_values(&[&author_hex]) + .inc_by(validator_txns_total_bytes); + info!( + vtxn_count_limit = vtxn_count_limit, + vtxn_count_proposed = num_validator_txns, + vtxn_bytes_limit = vtxn_bytes_limit, + vtxn_bytes_proposed = validator_txns_total_bytes, + proposer = author_hex, + "Summarizing proposed validator txns." + ); + ensure!( - num_validator_txns <= self.vtxn_config.per_block_limit_txn_count(), + num_validator_txns <= vtxn_count_limit, "process_proposal failed with per-block vtxn count limit exceeded: limit={}, actual={}", self.vtxn_config.per_block_limit_txn_count(), num_validator_txns ); ensure!( - validator_txns_total_bytes <= self.vtxn_config.per_block_limit_total_bytes(), + validator_txns_total_bytes <= vtxn_bytes_limit, "process_proposal failed with per-block vtxn bytes limit exceeded: limit={}, actual={}", self.vtxn_config.per_block_limit_total_bytes(), validator_txns_total_bytes