Filter vote accounts with no delegate from being selected in Rotation (#3224)

This commit is contained in:
Sagar Dhawan 2019-03-11 17:58:21 -07:00 committed by GitHub
parent b418525464
commit 7b35114c0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 4 deletions

View File

@ -63,12 +63,21 @@ fn node_staked_accounts_at_epoch(
epoch_height: u64,
) -> Option<impl Iterator<Item = (&Pubkey, u64, &Account)>> {
bank.epoch_vote_accounts(epoch_height).map(|epoch_state| {
epoch_state.into_iter().filter_map(|(account_id, account)| {
filter_zero_balances(account).map(|stake| (account_id, stake, account))
})
epoch_state
.into_iter()
.filter_map(|(account_id, account)| {
filter_zero_balances(account).map(|stake| (account_id, stake, account))
})
.filter(|(account_id, _, account)| filter_no_delegate(account_id, account))
})
}
fn filter_no_delegate(account_id: &Pubkey, account: &Account) -> bool {
VoteState::deserialize(&account.userdata)
.map(|vote_state| vote_state.delegate_id != *account_id)
.unwrap_or(false)
}
fn filter_zero_balances(account: &Account) -> Option<u64> {
let balance = Bank::read_balance(&account);
if balance > 0 {
@ -189,7 +198,13 @@ mod tests {
// Make a mint vote account. Because the mint has nonzero stake, this
// should show up in the active set
voting_keypair_tests::new_vote_account_with_vote(&mint_keypair, &bank_voter, &bank, 499, 0);
voting_keypair_tests::new_vote_account_with_delegate(
&mint_keypair,
&bank_voter,
&mint_keypair.pubkey(),
&bank,
499,
);
// soonest slot that could be a new epoch is 1
let mut slot = 1;

View File

@ -120,6 +120,25 @@ pub mod tests {
bank.process_transaction(&tx).unwrap();
}
pub fn new_vote_account_with_delegate(
from_keypair: &Keypair,
voting_keypair: &Keypair,
delegate: &Pubkey,
bank: &Bank,
lamports: u64,
) {
let blockhash = bank.last_blockhash();
let tx = VoteTransaction::new_account_with_delegate(
from_keypair,
voting_keypair,
delegate,
blockhash,
lamports,
0,
);
bank.process_transaction(&tx).unwrap();
}
pub fn push_vote<T: KeypairUtil>(voting_keypair: &T, bank: &Bank, slot: u64) {
let blockhash = bank.last_blockhash();
let tx =