removes pubkey references (#15050)

This commit is contained in:
behzad nouri
2021-02-03 23:02:11 +00:00
committed by GitHub
parent 2970b59853
commit 86467d825a
4 changed files with 24 additions and 172 deletions

View File

@ -1,7 +1,4 @@
use crate::{ use crate::progress_map::{LockoutIntervals, ProgressMap};
progress_map::{LockoutIntervals, ProgressMap},
pubkey_references::PubkeyReferences,
};
use chrono::prelude::*; use chrono::prelude::*;
use solana_ledger::{ancestor_iterator::AncestorIterator, blockstore::Blockstore, blockstore_db}; use solana_ledger::{ancestor_iterator::AncestorIterator, blockstore::Blockstore, blockstore_db};
use solana_measure::measure::Measure; use solana_measure::measure::Measure;
@ -214,7 +211,6 @@ impl Tower {
bank_slot: Slot, bank_slot: Slot,
vote_accounts: F, vote_accounts: F,
ancestors: &HashMap<Slot, HashSet<Slot>>, ancestors: &HashMap<Slot, HashSet<Slot>>,
all_pubkeys: &mut PubkeyReferences,
) -> ComputedBankState ) -> ComputedBankState
where where
F: IntoIterator<Item = (Pubkey, (u64, ArcVoteAccount))>, F: IntoIterator<Item = (Pubkey, (u64, ArcVoteAccount))>,
@ -247,7 +243,6 @@ impl Tower {
Ok(vote_state) => vote_state.clone(), Ok(vote_state) => vote_state.clone(),
}; };
for vote in &vote_state.votes { for vote in &vote_state.votes {
let key = all_pubkeys.get_or_insert(&key);
lockout_intervals lockout_intervals
.entry(vote.expiration_slot()) .entry(vote.expiration_slot())
.or_insert_with(Vec::new) .or_insert_with(Vec::new)
@ -1270,7 +1265,6 @@ pub mod test {
collections::HashMap, collections::HashMap,
fs::{remove_file, OpenOptions}, fs::{remove_file, OpenOptions},
io::{Read, Seek, SeekFrom, Write}, io::{Read, Seek, SeekFrom, Write},
rc::Rc,
sync::RwLock, sync::RwLock,
}; };
use tempfile::TempDir; use tempfile::TempDir;
@ -1380,7 +1374,6 @@ pub mod test {
&VoteTracker::default(), &VoteTracker::default(),
&ClusterSlots::default(), &ClusterSlots::default(),
&self.bank_forks, &self.bank_forks,
&mut PubkeyReferences::default(),
&mut self.heaviest_subtree_fork_choice, &mut self.heaviest_subtree_fork_choice,
); );
@ -1425,7 +1418,6 @@ pub mod test {
&self.bank_forks, &self.bank_forks,
&mut self.progress, &mut self.progress,
&ABSRequestSender::default(), &ABSRequestSender::default(),
&mut PubkeyReferences::default(),
None, None,
&mut self.heaviest_subtree_fork_choice, &mut self.heaviest_subtree_fork_choice,
) )
@ -1467,7 +1459,7 @@ pub mod test {
.lockout_intervals .lockout_intervals
.entry(lockout_interval.1) .entry(lockout_interval.1)
.or_default() .or_default()
.push((lockout_interval.0, Rc::new(*vote_account_pubkey))); .push((lockout_interval.0, *vote_account_pubkey));
} }
fn can_progress_on_fork( fn can_progress_on_fork(
@ -1993,13 +1985,7 @@ pub mod test {
bank_weight, bank_weight,
pubkey_votes, pubkey_votes,
.. ..
} = Tower::collect_vote_lockouts( } = Tower::collect_vote_lockouts(&Pubkey::default(), 1, accounts.into_iter(), &ancestors);
&Pubkey::default(),
1,
accounts.into_iter(),
&ancestors,
&mut PubkeyReferences::default(),
);
assert_eq!(voted_stakes[&0], 2); assert_eq!(voted_stakes[&0], 2);
assert_eq!(total_stake, 2); assert_eq!(total_stake, 2);
let mut pubkey_votes = Arc::try_unwrap(pubkey_votes).unwrap(); let mut pubkey_votes = Arc::try_unwrap(pubkey_votes).unwrap();
@ -2051,7 +2037,6 @@ pub mod test {
MAX_LOCKOUT_HISTORY as u64, MAX_LOCKOUT_HISTORY as u64,
accounts.into_iter(), accounts.into_iter(),
&ancestors, &ancestors,
&mut PubkeyReferences::default(),
); );
for i in 0..MAX_LOCKOUT_HISTORY { for i in 0..MAX_LOCKOUT_HISTORY {
assert_eq!(voted_stakes[&(i as u64)], 2); assert_eq!(voted_stakes[&(i as u64)], 2);
@ -2358,7 +2343,6 @@ pub mod test {
vote_to_evaluate, vote_to_evaluate,
accounts.clone().into_iter(), accounts.clone().into_iter(),
&ancestors, &ancestors,
&mut PubkeyReferences::default(),
); );
assert!(tower.check_vote_stake_threshold(vote_to_evaluate, &voted_stakes, total_stake,)); assert!(tower.check_vote_stake_threshold(vote_to_evaluate, &voted_stakes, total_stake,));
@ -2375,7 +2359,6 @@ pub mod test {
vote_to_evaluate, vote_to_evaluate,
accounts.into_iter(), accounts.into_iter(),
&ancestors, &ancestors,
&mut PubkeyReferences::default(),
); );
assert!(!tower.check_vote_stake_threshold(vote_to_evaluate, &voted_stakes, total_stake,)); assert!(!tower.check_vote_stake_threshold(vote_to_evaluate, &voted_stakes, total_stake,));
} }

View File

@ -1,7 +1,6 @@
use crate::{ use crate::{
cluster_info_vote_listener::SlotVoteTracker, cluster_info_vote_listener::SlotVoteTracker,
cluster_slots::SlotPubkeys, cluster_slots::SlotPubkeys,
pubkey_references::PubkeyReferences,
replay_stage::SUPERMINORITY_THRESHOLD, replay_stage::SUPERMINORITY_THRESHOLD,
{consensus::Stake, consensus::VotedStakes}, {consensus::Stake, consensus::VotedStakes},
}; };
@ -10,13 +9,12 @@ use solana_runtime::{bank::Bank, bank_forks::BankForks, vote_account::ArcVoteAcc
use solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey}; use solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey};
use std::{ use std::{
collections::{BTreeMap, HashMap, HashSet}, collections::{BTreeMap, HashMap, HashSet},
rc::Rc,
sync::{Arc, RwLock}, sync::{Arc, RwLock},
}; };
type VotedSlot = Slot; type VotedSlot = Slot;
type ExpirationSlot = Slot; type ExpirationSlot = Slot;
pub(crate) type LockoutIntervals = BTreeMap<ExpirationSlot, Vec<(VotedSlot, Rc<Pubkey>)>>; pub(crate) type LockoutIntervals = BTreeMap<ExpirationSlot, Vec<(VotedSlot, Pubkey)>>;
#[derive(Default)] #[derive(Default)]
pub(crate) struct ReplaySlotStats(ConfirmationTiming); pub(crate) struct ReplaySlotStats(ConfirmationTiming);
@ -128,9 +126,7 @@ impl ForkProgress {
( (
true, true,
info.stake, info.stake,
vec![Rc::new(info.validator_vote_pubkey)] vec![info.validator_vote_pubkey].into_iter().collect(),
.into_iter()
.collect(),
{ {
if info.total_epoch_stake == 0 { if info.total_epoch_stake == 0 {
true true
@ -212,8 +208,8 @@ pub(crate) struct ForkStats {
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub(crate) struct PropagatedStats { pub(crate) struct PropagatedStats {
pub(crate) propagated_validators: HashSet<Rc<Pubkey>>, pub(crate) propagated_validators: HashSet<Pubkey>,
pub(crate) propagated_node_ids: HashSet<Rc<Pubkey>>, pub(crate) propagated_node_ids: HashSet<Pubkey>,
pub(crate) propagated_validators_stake: u64, pub(crate) propagated_validators_stake: u64,
pub(crate) is_propagated: bool, pub(crate) is_propagated: bool,
pub(crate) is_leader_slot: bool, pub(crate) is_leader_slot: bool,
@ -224,25 +220,13 @@ pub(crate) struct PropagatedStats {
} }
impl PropagatedStats { impl PropagatedStats {
pub fn add_vote_pubkey( pub fn add_vote_pubkey(&mut self, vote_pubkey: Pubkey, stake: u64) {
&mut self, if self.propagated_validators.insert(vote_pubkey) {
vote_pubkey: &Pubkey,
all_pubkeys: &mut PubkeyReferences,
stake: u64,
) {
if !self.propagated_validators.contains(vote_pubkey) {
let cached_pubkey = all_pubkeys.get_or_insert(vote_pubkey);
self.propagated_validators.insert(cached_pubkey);
self.propagated_validators_stake += stake; self.propagated_validators_stake += stake;
} }
} }
pub fn add_node_pubkey( pub fn add_node_pubkey(&mut self, node_pubkey: &Pubkey, bank: &Bank) {
&mut self,
node_pubkey: &Pubkey,
all_pubkeys: &mut PubkeyReferences,
bank: &Bank,
) {
if !self.propagated_node_ids.contains(node_pubkey) { if !self.propagated_node_ids.contains(node_pubkey) {
let node_vote_accounts = bank let node_vote_accounts = bank
.epoch_vote_accounts_for_node_id(&node_pubkey) .epoch_vote_accounts_for_node_id(&node_pubkey)
@ -251,7 +235,6 @@ impl PropagatedStats {
if let Some(node_vote_accounts) = node_vote_accounts { if let Some(node_vote_accounts) = node_vote_accounts {
self.add_node_pubkey_internal( self.add_node_pubkey_internal(
node_pubkey, node_pubkey,
all_pubkeys,
node_vote_accounts, node_vote_accounts,
bank.epoch_vote_accounts(bank.epoch()) bank.epoch_vote_accounts(bank.epoch())
.expect("Epoch stakes for bank's own epoch must exist"), .expect("Epoch stakes for bank's own epoch must exist"),
@ -263,18 +246,16 @@ impl PropagatedStats {
fn add_node_pubkey_internal( fn add_node_pubkey_internal(
&mut self, &mut self,
node_pubkey: &Pubkey, node_pubkey: &Pubkey,
all_pubkeys: &mut PubkeyReferences,
vote_account_pubkeys: &[Pubkey], vote_account_pubkeys: &[Pubkey],
epoch_vote_accounts: &HashMap<Pubkey, (u64, ArcVoteAccount)>, epoch_vote_accounts: &HashMap<Pubkey, (u64, ArcVoteAccount)>,
) { ) {
let cached_pubkey = all_pubkeys.get_or_insert(node_pubkey); self.propagated_node_ids.insert(*node_pubkey);
self.propagated_node_ids.insert(cached_pubkey);
for vote_account_pubkey in vote_account_pubkeys.iter() { for vote_account_pubkey in vote_account_pubkeys.iter() {
let stake = epoch_vote_accounts let stake = epoch_vote_accounts
.get(vote_account_pubkey) .get(vote_account_pubkey)
.map(|(stake, _)| *stake) .map(|(stake, _)| *stake)
.unwrap_or(0); .unwrap_or(0);
self.add_vote_pubkey(vote_account_pubkey, all_pubkeys, stake); self.add_vote_pubkey(*vote_account_pubkey, stake);
} }
} }
} }
@ -403,34 +384,24 @@ mod test {
#[test] #[test]
fn test_add_vote_pubkey() { fn test_add_vote_pubkey() {
let mut stats = PropagatedStats::default(); let mut stats = PropagatedStats::default();
let mut all_pubkeys = PubkeyReferences::default();
let mut vote_pubkey = solana_sdk::pubkey::new_rand(); let mut vote_pubkey = solana_sdk::pubkey::new_rand();
all_pubkeys.get_or_insert(&vote_pubkey);
// Add a vote pubkey, the number of references in all_pubkeys // Add a vote pubkey, the number of references in all_pubkeys
// should be 2 // should be 2
stats.add_vote_pubkey(&vote_pubkey, &mut all_pubkeys, 1); stats.add_vote_pubkey(vote_pubkey, 1);
assert!(stats.propagated_validators.contains(&vote_pubkey)); assert!(stats.propagated_validators.contains(&vote_pubkey));
assert_eq!(stats.propagated_validators_stake, 1); assert_eq!(stats.propagated_validators_stake, 1);
assert_eq!(
Rc::strong_count(&all_pubkeys.get_or_insert(&vote_pubkey)),
3
);
// Adding it again should change no state since the key already existed // Adding it again should change no state since the key already existed
stats.add_vote_pubkey(&vote_pubkey, &mut all_pubkeys, 1); stats.add_vote_pubkey(vote_pubkey, 1);
assert!(stats.propagated_validators.contains(&vote_pubkey)); assert!(stats.propagated_validators.contains(&vote_pubkey));
assert_eq!(stats.propagated_validators_stake, 1); assert_eq!(stats.propagated_validators_stake, 1);
// Adding another pubkey should succeed // Adding another pubkey should succeed
vote_pubkey = solana_sdk::pubkey::new_rand(); vote_pubkey = solana_sdk::pubkey::new_rand();
stats.add_vote_pubkey(&vote_pubkey, &mut all_pubkeys, 2); stats.add_vote_pubkey(vote_pubkey, 2);
assert!(stats.propagated_validators.contains(&vote_pubkey)); assert!(stats.propagated_validators.contains(&vote_pubkey));
assert_eq!(stats.propagated_validators_stake, 3); assert_eq!(stats.propagated_validators_stake, 3);
assert_eq!(
Rc::strong_count(&all_pubkeys.get_or_insert(&vote_pubkey)),
3
);
} }
#[test] #[test]
@ -447,35 +418,19 @@ mod test {
.collect(); .collect();
let mut stats = PropagatedStats::default(); let mut stats = PropagatedStats::default();
let mut all_pubkeys = PubkeyReferences::default();
let mut node_pubkey = solana_sdk::pubkey::new_rand(); let mut node_pubkey = solana_sdk::pubkey::new_rand();
all_pubkeys.get_or_insert(&node_pubkey);
// Add a vote pubkey, the number of references in all_pubkeys // Add a vote pubkey, the number of references in all_pubkeys
// should be 2 // should be 2
stats.add_node_pubkey_internal( stats.add_node_pubkey_internal(&node_pubkey, &vote_account_pubkeys, &epoch_vote_accounts);
&node_pubkey,
&mut all_pubkeys,
&vote_account_pubkeys,
&epoch_vote_accounts,
);
assert!(stats.propagated_node_ids.contains(&node_pubkey)); assert!(stats.propagated_node_ids.contains(&node_pubkey));
assert_eq!( assert_eq!(
stats.propagated_validators_stake, stats.propagated_validators_stake,
staked_vote_accounts as u64 staked_vote_accounts as u64
); );
assert_eq!(
Rc::strong_count(&all_pubkeys.get_or_insert(&node_pubkey)),
3
);
// Adding it again should not change any state // Adding it again should not change any state
stats.add_node_pubkey_internal( stats.add_node_pubkey_internal(&node_pubkey, &vote_account_pubkeys, &epoch_vote_accounts);
&node_pubkey,
&mut all_pubkeys,
&vote_account_pubkeys,
&epoch_vote_accounts,
);
assert!(stats.propagated_node_ids.contains(&node_pubkey)); assert!(stats.propagated_node_ids.contains(&node_pubkey));
assert_eq!( assert_eq!(
stats.propagated_validators_stake, stats.propagated_validators_stake,
@ -485,21 +440,12 @@ mod test {
// Adding another pubkey with same vote accounts should succeed, but stake // Adding another pubkey with same vote accounts should succeed, but stake
// shouldn't increase // shouldn't increase
node_pubkey = solana_sdk::pubkey::new_rand(); node_pubkey = solana_sdk::pubkey::new_rand();
stats.add_node_pubkey_internal( stats.add_node_pubkey_internal(&node_pubkey, &vote_account_pubkeys, &epoch_vote_accounts);
&node_pubkey,
&mut all_pubkeys,
&vote_account_pubkeys,
&epoch_vote_accounts,
);
assert!(stats.propagated_node_ids.contains(&node_pubkey)); assert!(stats.propagated_node_ids.contains(&node_pubkey));
assert_eq!( assert_eq!(
stats.propagated_validators_stake, stats.propagated_validators_stake,
staked_vote_accounts as u64 staked_vote_accounts as u64
); );
assert_eq!(
Rc::strong_count(&all_pubkeys.get_or_insert(&node_pubkey)),
3
);
// Adding another pubkey with different vote accounts should succeed // Adding another pubkey with different vote accounts should succeed
// and increase stake // and increase stake
@ -512,21 +458,12 @@ mod test {
.skip(num_vote_accounts - staked_vote_accounts) .skip(num_vote_accounts - staked_vote_accounts)
.map(|pubkey| (*pubkey, (1, ArcVoteAccount::default()))) .map(|pubkey| (*pubkey, (1, ArcVoteAccount::default())))
.collect(); .collect();
stats.add_node_pubkey_internal( stats.add_node_pubkey_internal(&node_pubkey, &vote_account_pubkeys, &epoch_vote_accounts);
&node_pubkey,
&mut all_pubkeys,
&vote_account_pubkeys,
&epoch_vote_accounts,
);
assert!(stats.propagated_node_ids.contains(&node_pubkey)); assert!(stats.propagated_node_ids.contains(&node_pubkey));
assert_eq!( assert_eq!(
stats.propagated_validators_stake, stats.propagated_validators_stake,
2 * staked_vote_accounts as u64 2 * staked_vote_accounts as u64
); );
assert_eq!(
Rc::strong_count(&all_pubkeys.get_or_insert(&node_pubkey)),
3
);
} }
#[test] #[test]

View File

@ -1,29 +1,9 @@
use solana_sdk::pubkey::Pubkey; use solana_sdk::pubkey::Pubkey;
use std::{ use std::{
collections::HashSet, collections::HashSet,
rc::Rc,
sync::{Arc, RwLock}, sync::{Arc, RwLock},
}; };
#[derive(Default)]
pub struct PubkeyReferences(HashSet<Rc<Pubkey>>);
impl PubkeyReferences {
pub fn get_or_insert(&mut self, pubkey: &Pubkey) -> Rc<Pubkey> {
let mut cached_pubkey: Option<Rc<Pubkey>> = self.0.get(pubkey).cloned();
if cached_pubkey.is_none() {
let new_pubkey = Rc::new(*pubkey);
self.0.insert(new_pubkey.clone());
cached_pubkey = Some(new_pubkey);
}
cached_pubkey.unwrap()
}
pub fn purge(&mut self) {
self.0.retain(|x| Rc::strong_count(x) > 1);
}
}
#[derive(Default)] #[derive(Default)]
pub struct LockedPubkeyReferences(pub RwLock<HashSet<Arc<Pubkey>>>); pub struct LockedPubkeyReferences(pub RwLock<HashSet<Arc<Pubkey>>>);

View File

@ -13,7 +13,6 @@ use crate::{
optimistically_confirmed_bank_tracker::{BankNotification, BankNotificationSender}, optimistically_confirmed_bank_tracker::{BankNotification, BankNotificationSender},
poh_recorder::{PohRecorder, GRACE_TICKS_FACTOR, MAX_GRACE_SLOTS}, poh_recorder::{PohRecorder, GRACE_TICKS_FACTOR, MAX_GRACE_SLOTS},
progress_map::{ForkProgress, ProgressMap, PropagatedStats}, progress_map::{ForkProgress, ProgressMap, PropagatedStats},
pubkey_references::PubkeyReferences,
repair_service::DuplicateSlotsResetReceiver, repair_service::DuplicateSlotsResetReceiver,
result::Result, result::Result,
rewards_recorder_service::RewardsRecorderSender, rewards_recorder_service::RewardsRecorderSender,
@ -280,7 +279,6 @@ impl ReplayStage {
let t_replay = Builder::new() let t_replay = Builder::new()
.name("solana-replay-stage".to_string()) .name("solana-replay-stage".to_string())
.spawn(move || { .spawn(move || {
let mut all_pubkeys = PubkeyReferences::default();
let verify_recyclers = VerifyRecyclers::default(); let verify_recyclers = VerifyRecyclers::default();
let _exit = Finalizer::new(exit.clone()); let _exit = Finalizer::new(exit.clone());
let ( let (
@ -314,7 +312,6 @@ impl ReplayStage {
&leader_schedule_cache, &leader_schedule_cache,
&subscriptions, &subscriptions,
&mut progress, &mut progress,
&mut all_pubkeys,
); );
generate_new_bank_forks_time.stop(); generate_new_bank_forks_time.stop();
Self::report_memory(&allocated, "generate_new_bank_forks", start); Self::report_memory(&allocated, "generate_new_bank_forks", start);
@ -378,7 +375,6 @@ impl ReplayStage {
&vote_tracker, &vote_tracker,
&cluster_slots, &cluster_slots,
&bank_forks, &bank_forks,
&mut all_pubkeys,
&mut heaviest_subtree_fork_choice, &mut heaviest_subtree_fork_choice,
); );
compute_bank_stats_time.stop(); compute_bank_stats_time.stop();
@ -479,7 +475,6 @@ impl ReplayStage {
&lockouts_sender, &lockouts_sender,
&accounts_background_request_sender, &accounts_background_request_sender,
&latest_root_senders, &latest_root_senders,
&mut all_pubkeys,
&subscriptions, &subscriptions,
&block_commitment_cache, &block_commitment_cache,
&mut heaviest_subtree_fork_choice, &mut heaviest_subtree_fork_choice,
@ -1077,7 +1072,6 @@ impl ReplayStage {
lockouts_sender: &Sender<CommitmentAggregationData>, lockouts_sender: &Sender<CommitmentAggregationData>,
accounts_background_request_sender: &ABSRequestSender, accounts_background_request_sender: &ABSRequestSender,
latest_root_senders: &[Sender<Slot>], latest_root_senders: &[Sender<Slot>],
all_pubkeys: &mut PubkeyReferences,
subscriptions: &Arc<RpcSubscriptions>, subscriptions: &Arc<RpcSubscriptions>,
block_commitment_cache: &Arc<RwLock<BlockCommitmentCache>>, block_commitment_cache: &Arc<RwLock<BlockCommitmentCache>>,
heaviest_subtree_fork_choice: &mut HeaviestSubtreeForkChoice, heaviest_subtree_fork_choice: &mut HeaviestSubtreeForkChoice,
@ -1133,7 +1127,6 @@ impl ReplayStage {
&bank_forks, &bank_forks,
progress, progress,
accounts_background_request_sender, accounts_background_request_sender,
all_pubkeys,
highest_confirmed_root, highest_confirmed_root,
heaviest_subtree_fork_choice, heaviest_subtree_fork_choice,
); );
@ -1429,7 +1422,6 @@ impl ReplayStage {
vote_tracker: &VoteTracker, vote_tracker: &VoteTracker,
cluster_slots: &ClusterSlots, cluster_slots: &ClusterSlots,
bank_forks: &RwLock<BankForks>, bank_forks: &RwLock<BankForks>,
all_pubkeys: &mut PubkeyReferences,
heaviest_subtree_fork_choice: &mut dyn ForkChoice, heaviest_subtree_fork_choice: &mut dyn ForkChoice,
) -> Vec<Slot> { ) -> Vec<Slot> {
frozen_banks.sort_by_key(|bank| bank.slot()); frozen_banks.sort_by_key(|bank| bank.slot());
@ -1450,7 +1442,6 @@ impl ReplayStage {
bank_slot, bank_slot,
bank.vote_accounts().into_iter(), bank.vote_accounts().into_iter(),
&ancestors, &ancestors,
all_pubkeys,
); );
// Notify any listeners of the votes found in this newly computed // Notify any listeners of the votes found in this newly computed
// bank // bank
@ -1495,7 +1486,6 @@ impl ReplayStage {
Self::update_propagation_status( Self::update_propagation_status(
progress, progress,
bank_slot, bank_slot,
all_pubkeys,
bank_forks, bank_forks,
vote_tracker, vote_tracker,
cluster_slots, cluster_slots,
@ -1517,7 +1507,6 @@ impl ReplayStage {
fn update_propagation_status( fn update_propagation_status(
progress: &mut ProgressMap, progress: &mut ProgressMap,
slot: Slot, slot: Slot,
all_pubkeys: &mut PubkeyReferences,
bank_forks: &RwLock<BankForks>, bank_forks: &RwLock<BankForks>,
vote_tracker: &VoteTracker, vote_tracker: &VoteTracker,
cluster_slots: &ClusterSlots, cluster_slots: &ClusterSlots,
@ -1571,7 +1560,6 @@ impl ReplayStage {
cluster_slot_pubkeys, cluster_slot_pubkeys,
slot, slot,
bank_forks, bank_forks,
all_pubkeys,
); );
} }
@ -1690,7 +1678,6 @@ impl ReplayStage {
mut cluster_slot_pubkeys: Vec<impl Deref<Target = Pubkey>>, mut cluster_slot_pubkeys: Vec<impl Deref<Target = Pubkey>>,
fork_tip: Slot, fork_tip: Slot,
bank_forks: &RwLock<BankForks>, bank_forks: &RwLock<BankForks>,
all_pubkeys: &mut PubkeyReferences,
) { ) {
let mut current_leader_slot = progress.get_latest_leader_slot(fork_tip); let mut current_leader_slot = progress.get_latest_leader_slot(fork_tip);
let mut did_newly_reach_threshold = false; let mut did_newly_reach_threshold = false;
@ -1736,7 +1723,6 @@ impl ReplayStage {
&mut cluster_slot_pubkeys, &mut cluster_slot_pubkeys,
&leader_bank, &leader_bank,
leader_propagated_stats, leader_propagated_stats,
all_pubkeys,
did_newly_reach_threshold, did_newly_reach_threshold,
) || did_newly_reach_threshold; ) || did_newly_reach_threshold;
@ -1750,7 +1736,6 @@ impl ReplayStage {
cluster_slot_pubkeys: &mut Vec<impl Deref<Target = Pubkey>>, cluster_slot_pubkeys: &mut Vec<impl Deref<Target = Pubkey>>,
leader_bank: &Bank, leader_bank: &Bank,
leader_propagated_stats: &mut PropagatedStats, leader_propagated_stats: &mut PropagatedStats,
all_pubkeys: &mut PubkeyReferences,
did_child_reach_threshold: bool, did_child_reach_threshold: bool,
) -> bool { ) -> bool {
// Track whether this slot newly confirm propagation // Track whether this slot newly confirm propagation
@ -1784,10 +1769,9 @@ impl ReplayStage {
newly_voted_pubkeys.retain(|vote_pubkey| { newly_voted_pubkeys.retain(|vote_pubkey| {
let exists = leader_propagated_stats let exists = leader_propagated_stats
.propagated_validators .propagated_validators
.contains(&**vote_pubkey); .contains(vote_pubkey);
leader_propagated_stats.add_vote_pubkey( leader_propagated_stats.add_vote_pubkey(
&*vote_pubkey, **vote_pubkey,
all_pubkeys,
leader_bank.epoch_vote_account_stake(&vote_pubkey), leader_bank.epoch_vote_account_stake(&vote_pubkey),
); );
!exists !exists
@ -1797,7 +1781,7 @@ impl ReplayStage {
let exists = leader_propagated_stats let exists = leader_propagated_stats
.propagated_node_ids .propagated_node_ids
.contains(&**node_pubkey); .contains(&**node_pubkey);
leader_propagated_stats.add_node_pubkey(&*node_pubkey, all_pubkeys, leader_bank); leader_propagated_stats.add_node_pubkey(&*node_pubkey, leader_bank);
!exists !exists
}); });
@ -1852,21 +1836,15 @@ impl ReplayStage {
bank_forks: &RwLock<BankForks>, bank_forks: &RwLock<BankForks>,
progress: &mut ProgressMap, progress: &mut ProgressMap,
accounts_background_request_sender: &ABSRequestSender, accounts_background_request_sender: &ABSRequestSender,
all_pubkeys: &mut PubkeyReferences,
highest_confirmed_root: Option<Slot>, highest_confirmed_root: Option<Slot>,
heaviest_subtree_fork_choice: &mut HeaviestSubtreeForkChoice, heaviest_subtree_fork_choice: &mut HeaviestSubtreeForkChoice,
) { ) {
let old_epoch = bank_forks.read().unwrap().root_bank().epoch();
bank_forks.write().unwrap().set_root( bank_forks.write().unwrap().set_root(
new_root, new_root,
accounts_background_request_sender, accounts_background_request_sender,
highest_confirmed_root, highest_confirmed_root,
); );
let r_bank_forks = bank_forks.read().unwrap(); let r_bank_forks = bank_forks.read().unwrap();
let new_epoch = bank_forks.read().unwrap().root_bank().epoch();
if old_epoch != new_epoch {
all_pubkeys.purge();
}
progress.handle_new_root(&r_bank_forks); progress.handle_new_root(&r_bank_forks);
heaviest_subtree_fork_choice.set_root(new_root); heaviest_subtree_fork_choice.set_root(new_root);
} }
@ -1877,7 +1855,6 @@ impl ReplayStage {
leader_schedule_cache: &Arc<LeaderScheduleCache>, leader_schedule_cache: &Arc<LeaderScheduleCache>,
subscriptions: &Arc<RpcSubscriptions>, subscriptions: &Arc<RpcSubscriptions>,
progress: &mut ProgressMap, progress: &mut ProgressMap,
all_pubkeys: &mut PubkeyReferences,
) { ) {
// Find the next slot that chains to the old slot // Find the next slot that chains to the old slot
let forks = bank_forks.read().unwrap(); let forks = bank_forks.read().unwrap();
@ -1930,7 +1907,6 @@ impl ReplayStage {
vec![&leader], vec![&leader],
parent_bank.slot(), parent_bank.slot(),
bank_forks, bank_forks,
all_pubkeys,
); );
new_banks.insert(child_slot, child_bank); new_banks.insert(child_slot, child_bank);
} }
@ -2059,7 +2035,6 @@ pub(crate) mod tests {
use std::{ use std::{
fs::remove_dir_all, fs::remove_dir_all,
iter, iter,
rc::Rc,
sync::{Arc, RwLock}, sync::{Arc, RwLock},
}; };
use trees::tr; use trees::tr;
@ -2200,7 +2175,6 @@ pub(crate) mod tests {
&leader_schedule_cache, &leader_schedule_cache,
&rpc_subscriptions, &rpc_subscriptions,
&mut progress, &mut progress,
&mut PubkeyReferences::default(),
); );
assert!(bank_forks assert!(bank_forks
.read() .read()
@ -2223,7 +2197,6 @@ pub(crate) mod tests {
&leader_schedule_cache, &leader_schedule_cache,
&rpc_subscriptions, &rpc_subscriptions,
&mut progress, &mut progress,
&mut PubkeyReferences::default(),
); );
assert!(bank_forks assert!(bank_forks
.read() .read()
@ -2277,7 +2250,6 @@ pub(crate) mod tests {
&bank_forks, &bank_forks,
&mut progress, &mut progress,
&ABSRequestSender::default(), &ABSRequestSender::default(),
&mut PubkeyReferences::default(),
None, None,
&mut heaviest_subtree_fork_choice, &mut heaviest_subtree_fork_choice,
); );
@ -2322,7 +2294,6 @@ pub(crate) mod tests {
&bank_forks, &bank_forks,
&mut progress, &mut progress,
&ABSRequestSender::default(), &ABSRequestSender::default(),
&mut PubkeyReferences::default(),
Some(confirmed_root), Some(confirmed_root),
&mut heaviest_subtree_fork_choice, &mut heaviest_subtree_fork_choice,
); );
@ -2860,7 +2831,6 @@ pub(crate) mod tests {
&VoteTracker::default(), &VoteTracker::default(),
&ClusterSlots::default(), &ClusterSlots::default(),
&bank_forks, &bank_forks,
&mut PubkeyReferences::default(),
&mut heaviest_subtree_fork_choice, &mut heaviest_subtree_fork_choice,
); );
@ -2905,7 +2875,6 @@ pub(crate) mod tests {
&VoteTracker::default(), &VoteTracker::default(),
&ClusterSlots::default(), &ClusterSlots::default(),
&bank_forks, &bank_forks,
&mut PubkeyReferences::default(),
&mut heaviest_subtree_fork_choice, &mut heaviest_subtree_fork_choice,
); );
@ -2940,7 +2909,6 @@ pub(crate) mod tests {
&VoteTracker::default(), &VoteTracker::default(),
&ClusterSlots::default(), &ClusterSlots::default(),
&bank_forks, &bank_forks,
&mut PubkeyReferences::default(),
&mut heaviest_subtree_fork_choice, &mut heaviest_subtree_fork_choice,
); );
// No new stats should have been computed // No new stats should have been computed
@ -2977,7 +2945,6 @@ pub(crate) mod tests {
&VoteTracker::default(), &VoteTracker::default(),
&ClusterSlots::default(), &ClusterSlots::default(),
&vote_simulator.bank_forks, &vote_simulator.bank_forks,
&mut PubkeyReferences::default(),
&mut heaviest_subtree_fork_choice, &mut heaviest_subtree_fork_choice,
); );
@ -3039,7 +3006,6 @@ pub(crate) mod tests {
&VoteTracker::default(), &VoteTracker::default(),
&ClusterSlots::default(), &ClusterSlots::default(),
&vote_simulator.bank_forks, &vote_simulator.bank_forks,
&mut PubkeyReferences::default(),
&mut vote_simulator.heaviest_subtree_fork_choice, &mut vote_simulator.heaviest_subtree_fork_choice,
); );
@ -3165,7 +3131,6 @@ pub(crate) mod tests {
..PropagatedStats::default() ..PropagatedStats::default()
}; };
let mut all_pubkeys = PubkeyReferences::default();
let child_reached_threshold = false; let child_reached_threshold = false;
for i in 0..std::cmp::max(new_vote_pubkeys.len(), new_node_pubkeys.len()) { for i in 0..std::cmp::max(new_vote_pubkeys.len(), new_node_pubkeys.len()) {
propagated_stats.is_propagated = false; propagated_stats.is_propagated = false;
@ -3187,7 +3152,6 @@ pub(crate) mod tests {
&mut node_pubkeys, &mut node_pubkeys,
&root_bank, &root_bank,
&mut propagated_stats, &mut propagated_stats,
&mut all_pubkeys,
child_reached_threshold, child_reached_threshold,
); );
@ -3238,7 +3202,6 @@ pub(crate) mod tests {
..PropagatedStats::default() ..PropagatedStats::default()
}; };
propagated_stats.total_epoch_stake = stake * 10; propagated_stats.total_epoch_stake = stake * 10;
let mut all_pubkeys = PubkeyReferences::default();
let child_reached_threshold = true; let child_reached_threshold = true;
let mut newly_voted_pubkeys: Vec<Arc<Pubkey>> = vec![]; let mut newly_voted_pubkeys: Vec<Arc<Pubkey>> = vec![];
@ -3247,7 +3210,6 @@ pub(crate) mod tests {
&mut empty, &mut empty,
&root_bank, &root_bank,
&mut propagated_stats, &mut propagated_stats,
&mut all_pubkeys,
child_reached_threshold, child_reached_threshold,
)); ));
@ -3258,14 +3220,12 @@ pub(crate) mod tests {
..PropagatedStats::default() ..PropagatedStats::default()
}; };
propagated_stats.is_propagated = true; propagated_stats.is_propagated = true;
all_pubkeys = PubkeyReferences::default();
newly_voted_pubkeys = vec![]; newly_voted_pubkeys = vec![];
assert!(!ReplayStage::update_slot_propagated_threshold_from_votes( assert!(!ReplayStage::update_slot_propagated_threshold_from_votes(
&mut newly_voted_pubkeys, &mut newly_voted_pubkeys,
&mut empty, &mut empty,
&root_bank, &root_bank,
&mut propagated_stats, &mut propagated_stats,
&mut all_pubkeys,
child_reached_threshold, child_reached_threshold,
)); ));
@ -3275,7 +3235,6 @@ pub(crate) mod tests {
&mut empty, &mut empty,
&root_bank, &root_bank,
&mut propagated_stats, &mut propagated_stats,
&mut all_pubkeys,
child_reached_threshold, child_reached_threshold,
)); ));
} }
@ -3335,7 +3294,6 @@ pub(crate) mod tests {
ReplayStage::update_propagation_status( ReplayStage::update_propagation_status(
&mut progress_map, &mut progress_map,
10, 10,
&mut PubkeyReferences::default(),
&RwLock::new(bank_forks), &RwLock::new(bank_forks),
&vote_tracker, &vote_tracker,
&ClusterSlots::default(), &ClusterSlots::default(),
@ -3427,7 +3385,6 @@ pub(crate) mod tests {
ReplayStage::update_propagation_status( ReplayStage::update_propagation_status(
&mut progress_map, &mut progress_map,
10, 10,
&mut PubkeyReferences::default(),
&RwLock::new(bank_forks), &RwLock::new(bank_forks),
&vote_tracker, &vote_tracker,
&ClusterSlots::default(), &ClusterSlots::default(),
@ -3497,11 +3454,8 @@ pub(crate) mod tests {
1 1
} }
}; };
fork_progress.propagated_stats.propagated_validators = vote_pubkeys[0..end_range] fork_progress.propagated_stats.propagated_validators =
.iter() vote_pubkeys[0..end_range].iter().copied().collect();
.cloned()
.map(Rc::new)
.collect();
fork_progress.propagated_stats.propagated_validators_stake = fork_progress.propagated_stats.propagated_validators_stake =
end_range as u64 * stake_per_validator; end_range as u64 * stake_per_validator;
progress_map.insert(i, fork_progress); progress_map.insert(i, fork_progress);
@ -3516,7 +3470,6 @@ pub(crate) mod tests {
ReplayStage::update_propagation_status( ReplayStage::update_propagation_status(
&mut progress_map, &mut progress_map,
10, 10,
&mut PubkeyReferences::default(),
&RwLock::new(bank_forks), &RwLock::new(bank_forks),
&vote_tracker, &vote_tracker,
&ClusterSlots::default(), &ClusterSlots::default(),
@ -3889,7 +3842,6 @@ pub(crate) mod tests {
&vote_tracker, &vote_tracker,
&ClusterSlots::default(), &ClusterSlots::default(),
&bank_forks, &bank_forks,
&mut PubkeyReferences::default(),
&mut HeaviestSubtreeForkChoice::new_from_bank_forks(&bank_forks.read().unwrap()), &mut HeaviestSubtreeForkChoice::new_from_bank_forks(&bank_forks.read().unwrap()),
); );