updates cluster-slots with root-bank instead of root-slot + bank-forks
ClusterSlots::update is taking both root-slot and bank-forks only to later lookup root-bank from bank-forks, which is redundant. Also potentially by the time bank-forks is locked to obtain root-bank, root-slot may have already changed and so be inconsistent with the root-slot passed in as the argument. https://github.com/solana-labs/solana/blob/6d95d679c/core/src/cluster_slots.rs#L32-L39 https://github.com/solana-labs/solana/blob/6d95d679c/core/src/cluster_slots.rs#L122
This commit is contained in:
parent
2fc112edcf
commit
40914de811
|
@ -3,7 +3,7 @@ use {
|
||||||
solana_gossip::{
|
solana_gossip::{
|
||||||
cluster_info::ClusterInfo, contact_info::ContactInfo, crds::Cursor, epoch_slots::EpochSlots,
|
cluster_info::ClusterInfo, contact_info::ContactInfo, crds::Cursor, epoch_slots::EpochSlots,
|
||||||
},
|
},
|
||||||
solana_runtime::{bank_forks::BankForks, epoch_stakes::NodeIdToVoteAccounts},
|
solana_runtime::{bank::Bank, epoch_stakes::NodeIdToVoteAccounts},
|
||||||
solana_sdk::{clock::Slot, pubkey::Pubkey},
|
solana_sdk::{clock::Slot, pubkey::Pubkey},
|
||||||
std::{
|
std::{
|
||||||
collections::{BTreeMap, HashMap},
|
collections::{BTreeMap, HashMap},
|
||||||
|
@ -30,18 +30,13 @@ impl ClusterSlots {
|
||||||
self.cluster_slots.read().unwrap().get(&slot).cloned()
|
self.cluster_slots.read().unwrap().get(&slot).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn update(
|
pub(crate) fn update(&self, root_bank: &Bank, cluster_info: &ClusterInfo) {
|
||||||
&self,
|
self.update_peers(root_bank);
|
||||||
root: Slot,
|
|
||||||
cluster_info: &ClusterInfo,
|
|
||||||
bank_forks: &RwLock<BankForks>,
|
|
||||||
) {
|
|
||||||
self.update_peers(bank_forks);
|
|
||||||
let epoch_slots = {
|
let epoch_slots = {
|
||||||
let mut cursor = self.cursor.lock().unwrap();
|
let mut cursor = self.cursor.lock().unwrap();
|
||||||
cluster_info.get_epoch_slots(&mut cursor)
|
cluster_info.get_epoch_slots(&mut cursor)
|
||||||
};
|
};
|
||||||
self.update_internal(root, epoch_slots);
|
self.update_internal(root_bank.slot(), epoch_slots);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_internal(&self, root: Slot, epoch_slots_list: Vec<EpochSlots>) {
|
fn update_internal(&self, root: Slot, epoch_slots_list: Vec<EpochSlots>) {
|
||||||
|
@ -114,8 +109,7 @@ impl ClusterSlots {
|
||||||
slot_pubkeys.write().unwrap().insert(node_id, balance);
|
slot_pubkeys.write().unwrap().insert(node_id, balance);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_peers(&self, bank_forks: &RwLock<BankForks>) {
|
fn update_peers(&self, root_bank: &Bank) {
|
||||||
let root_bank = bank_forks.read().unwrap().root_bank();
|
|
||||||
let root_epoch = root_bank.epoch();
|
let root_epoch = root_bank.epoch();
|
||||||
let my_epoch = *self.epoch.read().unwrap();
|
let my_epoch = *self.epoch.read().unwrap();
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,6 @@ impl ClusterSlotsService {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let new_root = bank_forks.read().unwrap().root();
|
|
||||||
let mut lowest_slot_elapsed = Measure::start("lowest_slot_elapsed");
|
let mut lowest_slot_elapsed = Measure::start("lowest_slot_elapsed");
|
||||||
let lowest_slot = blockstore.lowest_slot();
|
let lowest_slot = blockstore.lowest_slot();
|
||||||
Self::update_lowest_slot(lowest_slot, &cluster_info);
|
Self::update_lowest_slot(lowest_slot, &cluster_info);
|
||||||
|
@ -105,7 +104,8 @@ impl ClusterSlotsService {
|
||||||
&cluster_info,
|
&cluster_info,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
cluster_slots.update(new_root, &cluster_info, &bank_forks);
|
let root_bank = bank_forks.read().unwrap().root_bank();
|
||||||
|
cluster_slots.update(&root_bank, &cluster_info);
|
||||||
process_cluster_slots_updates_elapsed.stop();
|
process_cluster_slots_updates_elapsed.stop();
|
||||||
|
|
||||||
cluster_slots_service_timing.update(
|
cluster_slots_service_timing.update(
|
||||||
|
|
Loading…
Reference in New Issue