Skip to content

Commit

Permalink
Handle validators with multiple staked vote accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Mar 31, 2021
1 parent 041f589 commit 0bffd04
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,9 +948,23 @@ fn main() -> Result<(), Box<dyn error::Error>> {
delinquent,
} = rpc_client.get_vote_accounts()?;

current
.into_iter()
.chain(delinquent.into_iter())
let mut latest_vote_account_info = HashMap::<String, _>::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::<Vec<_>>()
};

Expand Down

0 comments on commit 0bffd04

Please sign in to comment.