From c8d0dc02e3e27d5b71ba70d459d0010b0c745910 Mon Sep 17 00:00:00 2001 From: Anatoly Yakovenko Date: Tue, 4 Feb 2020 11:14:27 -0800 Subject: [PATCH] fixing #8113 --- core/src/consensus.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/core/src/consensus.rs b/core/src/consensus.rs index b68722f4dc54e2..51527e9522ba86 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -83,6 +83,40 @@ impl Tower { } } + pub fn observed_vote_distribution( + vote_accounts: &HashMap, + ) -> HashMap> { + let mut votes = HashMap::new(); + for (key, (lamports, account)) in vote_accounts.iter() { + let vote_state = VoteState::from(&account); + if vote_state.is_none() { + datapoint_warn!( + "tower_warn", + ( + "warn", + format!("Unable to get vote_state from account {}", key), + String + ), + ); + continue; + } + let mut vote_state = vote_state.unwrap(); + for vote in &vote_state.votes { + votes + .entry(vote.slot()) + .or_default() + .insert(key, vote.lockout()); + } + if let Some(slot) = vote_state.root_slot { + votes + .entry(slot) + .or_default() + .insert(key, MAX_LOCKOUT_HISTORY); + } + } + votes + } + pub fn collect_vote_lockouts( &self, bank_slot: u64,