Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions core/src/staking_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions core/src/voting_keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down