Adopt heaviest subtree fork choice rule (#10441)

* Add HeaviestSubtreeForkChoice

* Make replay stage switch between two fork choice rules

Co-authored-by: Carl <carl@solana.com>
This commit is contained in:
carllin
2020-06-11 12:16:04 -07:00
committed by GitHub
parent 0510b6e336
commit 2e1d59ff85
10 changed files with 1700 additions and 635 deletions

View File

@ -2411,6 +2411,10 @@ impl Bank {
self.epoch_stakes.get(&epoch)
}
pub fn epoch_stakes_map(&self) -> &HashMap<Epoch, EpochStakes> {
&self.epoch_stakes
}
/// vote accounts for the specific epoch along with the stake
/// attributed to each account
pub fn epoch_vote_accounts(&self, epoch: Epoch) -> Option<&HashMap<Pubkey, (u64, Account)>> {
@ -2448,11 +2452,11 @@ impl Bank {
}
/// Get the fixed stake of the given vote account for the current epoch
pub fn epoch_vote_account_stake(&self, voting_pubkey: &Pubkey) -> u64 {
pub fn epoch_vote_account_stake(&self, vote_account: &Pubkey) -> u64 {
*self
.epoch_vote_accounts(self.epoch())
.expect("Bank epoch vote accounts must contain entry for the bank's own epoch")
.get(voting_pubkey)
.get(vote_account)
.map(|(stake, _)| stake)
.unwrap_or(&0)
}

View File

@ -50,6 +50,13 @@ impl EpochStakes {
&self.epoch_authorized_voters
}
pub fn vote_account_stake(&self, vote_account: &Pubkey) -> u64 {
Stakes::vote_accounts(&self.stakes)
.get(vote_account)
.map(|(stake, _)| *stake)
.unwrap_or(0)
}
fn parse_epoch_vote_accounts(
epoch_vote_accounts: &HashMap<Pubkey, (u64, Account)>,
leader_schedule_epoch: Epoch,