Track a Bank's parent slot independently from parent bank (#7131)

This commit is contained in:
Sagar Dhawan
2019-11-25 15:34:51 -08:00
committed by GitHub
parent ef64f00cbb
commit 76a68c26c9
2 changed files with 8 additions and 7 deletions

View File

@ -141,13 +141,7 @@ impl StandardBroadcastRun {
{ {
self.slot_broadcast_start = Some(Instant::now()); self.slot_broadcast_start = Some(Instant::now());
let slot = bank.slot(); let slot = bank.slot();
let parent_slot = { let parent_slot = bank.parent_slot();
if let Some(parent_bank) = bank.parent() {
parent_bank.slot()
} else {
0
}
};
self.current_slot_and_parent = Some((slot, parent_slot)); self.current_slot_and_parent = Some((slot, parent_slot));
receive_elapsed = Duration::new(0, 0); receive_elapsed = Duration::new(0, 0);

View File

@ -180,6 +180,8 @@ pub struct Bank {
/// Hash of this Bank's parent's state /// Hash of this Bank's parent's state
parent_hash: Hash, parent_hash: Hash,
parent_slot: u64,
/// The number of transactions processed without error /// The number of transactions processed without error
#[serde(serialize_with = "serialize_atomicu64")] #[serde(serialize_with = "serialize_atomicu64")]
#[serde(deserialize_with = "deserialize_atomicu64")] #[serde(deserialize_with = "deserialize_atomicu64")]
@ -358,6 +360,7 @@ impl Bank {
epoch_stakes: parent.epoch_stakes.clone(), epoch_stakes: parent.epoch_stakes.clone(),
storage_accounts: RwLock::new(parent.storage_accounts.read().unwrap().clone()), storage_accounts: RwLock::new(parent.storage_accounts.read().unwrap().clone()),
parent_hash: parent.hash(), parent_hash: parent.hash(),
parent_slot: parent.slot(),
collector_id: *collector_id, collector_id: *collector_id,
collector_fees: AtomicU64::new(0), collector_fees: AtomicU64::new(0),
ancestors: HashMap::new(), ancestors: HashMap::new(),
@ -662,6 +665,10 @@ impl Bank {
self.rc.parent.read().unwrap().clone() self.rc.parent.read().unwrap().clone()
} }
pub fn parent_slot(&self) -> u64 {
self.parent_slot
}
fn process_genesis_config(&mut self, genesis_config: &GenesisConfig) { fn process_genesis_config(&mut self, genesis_config: &GenesisConfig) {
// Bootstrap leader collects fees until `new_from_parent` is called. // Bootstrap leader collects fees until `new_from_parent` is called.
self.fee_calculator = genesis_config.fee_calculator.clone(); self.fee_calculator = genesis_config.fee_calculator.clone();