From 8ddce4b566d36691ecb1a1e3462dd2e4afbabf2d Mon Sep 17 00:00:00 2001 From: Brennan Date: Tue, 27 Jun 2023 12:43:10 -0700 Subject: [PATCH] report last slot vote send metrics (#32258) * report last slot vote send metrics * push conditional checking down * fix up unit tests --- core/src/cluster_info_vote_listener.rs | 35 ++++++++++++++++---------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/core/src/cluster_info_vote_listener.rs b/core/src/cluster_info_vote_listener.rs index bf66e93828e6e6..ed9094b392ae70 100644 --- a/core/src/cluster_info_vote_listener.rs +++ b/core/src/cluster_info_vote_listener.rs @@ -422,15 +422,12 @@ impl ClusterInfoVoteListener { // Always set this to avoid taking the poh lock too often time_since_lock = Instant::now(); // We will take this lock at most once every `BANK_SEND_VOTES_LOOP_SLEEP_MS` - let current_working_bank = poh_recorder.read().unwrap().bank(); - if let Some(current_working_bank) = current_working_bank { - Self::check_for_leader_bank_and_send_votes( - &mut bank_vote_sender_state_option, - current_working_bank, - verified_packets_sender, - &verified_vote_packets, - )?; - } + Self::check_for_leader_bank_and_send_votes( + &mut bank_vote_sender_state_option, + poh_recorder.read().unwrap().bank(), + verified_packets_sender, + &verified_vote_packets, + )?; // Check if we've crossed the feature boundary if !is_tower_full_vote_enabled { is_tower_full_vote_enabled = bank_forks @@ -446,10 +443,22 @@ impl ClusterInfoVoteListener { fn check_for_leader_bank_and_send_votes( bank_vote_sender_state_option: &mut Option, - current_working_bank: Arc, + current_working_bank: Option>, verified_packets_sender: &BankingPacketSender, verified_vote_packets: &VerifiedVotePackets, ) -> Result<()> { + let current_working_bank = match current_working_bank { + Some(current_working_bank) => current_working_bank, + None => { + // We are not the leader! + if let Some(bank_vote_sender_state) = bank_vote_sender_state_option { + // This ensures we report the last slot's metrics + bank_vote_sender_state.report_metrics(); + *bank_vote_sender_state_option = None; + } + return Ok(()); + } + }; // We will take this lock at most once every `BANK_SEND_VOTES_LOOP_SLEEP_MS` if let Some(bank_vote_sender_state) = bank_vote_sender_state_option { if bank_vote_sender_state.bank.slot() != current_working_bank.slot() { @@ -1713,7 +1722,7 @@ mod tests { // 1) If we hand over a `current_leader_bank`, vote sender state should be updated ClusterInfoVoteListener::check_for_leader_bank_and_send_votes( &mut bank_vote_sender_state_option, - current_leader_bank.clone(), + Some(current_leader_bank.clone()), &verified_packets_sender, &verified_vote_packets, ) @@ -1732,7 +1741,7 @@ mod tests { // 2) Handing over the same leader bank again should not update the state ClusterInfoVoteListener::check_for_leader_bank_and_send_votes( &mut bank_vote_sender_state_option, - current_leader_bank.clone(), + Some(current_leader_bank.clone()), &verified_packets_sender, &verified_vote_packets, ) @@ -1758,7 +1767,7 @@ mod tests { )); ClusterInfoVoteListener::check_for_leader_bank_and_send_votes( &mut bank_vote_sender_state_option, - current_leader_bank.clone(), + Some(current_leader_bank.clone()), &verified_packets_sender, &verified_vote_packets, )