Cache banks in BankForks until optional largest_confirmed_root (#9678)

automerge
This commit is contained in:
Tyera Eulberg
2020-04-24 16:49:57 -06:00
committed by GitHub
parent d7f37a703e
commit a7f33b5014
6 changed files with 106 additions and 22 deletions

View File

@ -186,6 +186,7 @@ impl BankForks {
&mut self,
root: Slot,
accounts_package_sender: &Option<AccountsPackageSender>,
largest_confirmed_root: Option<Slot>,
) {
let old_epoch = self.root_bank().epoch();
self.root = root;
@ -263,7 +264,7 @@ impl BankForks {
}
let new_tx_count = root_bank.transaction_count();
self.prune_non_root(root);
self.prune_non_root(root, largest_confirmed_root);
inc_new_counter_info!(
"bank-forks_set_root_ms",
@ -334,10 +335,19 @@ impl BankForks {
Ok(())
}
fn prune_non_root(&mut self, root: Slot) {
fn prune_non_root(&mut self, root: Slot, largest_confirmed_root: Option<Slot>) {
let descendants = self.descendants();
self.banks
.retain(|slot, _| slot == &root || descendants[&root].contains(slot));
self.banks.retain(|slot, _| {
*slot == root
|| descendants[&root].contains(slot)
|| (*slot < root
&& *slot >= largest_confirmed_root.unwrap_or(root)
&& descendants[slot].contains(&root))
});
datapoint_debug!(
"bank_forks_purge_non_root",
("num_banks_retained", self.banks.len(), i64),
);
}
pub fn set_snapshot_config(&mut self, snapshot_config: Option<SnapshotConfig>) {