From 0bffd046a3ab330f90bc18a60f7a282a711add1d Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Tue, 30 Mar 2021 23:52:22 -0700 Subject: [PATCH] Handle validators with multiple staked vote accounts --- src/main.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index af7d9116..9fe4470f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -948,9 +948,23 @@ fn main() -> Result<(), Box> { delinquent, } = rpc_client.get_vote_accounts()?; - current - .into_iter() - .chain(delinquent.into_iter()) + let mut latest_vote_account_info = HashMap::::new(); + + for vote_account_info in current.into_iter().chain(delinquent.into_iter()) { + let entry = latest_vote_account_info + .entry(vote_account_info.node_pubkey.clone()) + .or_insert_with(|| vote_account_info.clone()); + + // If the validator has multiple staked vote accounts then select the vote account that + // voted most recently + if entry.last_vote < vote_account_info.last_vote { + *entry = vote_account_info.clone(); + } + } + + latest_vote_account_info + .values() + .cloned() .collect::>() };