Avoid holding the entire rooted path while loading bank forks (#9885)

This commit is contained in:
Michael Vines 2020-05-05 19:45:41 -07:00 committed by GitHub
parent 3442f36f8a
commit 72312ad615
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 24 deletions

View File

@ -2528,7 +2528,7 @@ pub(crate) mod tests {
let arc_bank0 = Arc::new(bank0);
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(
&[arc_bank0.clone()],
vec![0],
0,
)));
assert!(block_commitment_cache

View File

@ -689,10 +689,7 @@ mod tests {
let cluster_info = test_cluster_info(&keypair.pubkey());
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(1000);
let bank = Arc::new(Bank::new(&genesis_config));
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(
&[bank.clone()],
vec![0],
)));
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(&[bank.clone()], 0)));
let ledger_path = get_tmp_ledger_path!();
let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap());
let block_commitment_cache = Arc::new(RwLock::new(

View File

@ -56,10 +56,7 @@ mod tests {
let bank = Bank::new(&genesis_config);
let bank = Arc::new(bank);
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(
&[bank.clone()],
vec![0],
)));
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(&[bank.clone()], 0)));
let block_commitment_cache = Arc::new(RwLock::new(
BlockCommitmentCache::default_with_blockstore(blockstore.clone()),
));
@ -179,10 +176,7 @@ mod tests {
let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap());
let slot = 1;
let bank = Arc::new(Bank::new(&genesis_config));
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(
&[bank.clone()],
vec![0],
)));
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(&[bank.clone()], 0)));
let block_commitment_cache = Arc::new(RwLock::new(
BlockCommitmentCache::default_with_blockstore(blockstore.clone()),
));

View File

@ -141,7 +141,7 @@ impl BankForks {
self.banks.get(&self.root()).expect("Root bank must exist")
}
pub fn new_from_banks(initial_forks: &[Arc<Bank>], rooted_path: Vec<Slot>) -> Self {
pub fn new_from_banks(initial_forks: &[Arc<Bank>], root: Slot) -> Self {
let mut banks = HashMap::new();
let working_bank = initial_forks[0].clone();
@ -157,7 +157,7 @@ impl BankForks {
banks.insert(parent.slot(), parent.clone());
}
}
let root = *rooted_path.last().unwrap();
Self {
root,
banks,

View File

@ -318,7 +318,7 @@ pub fn process_blockstore_from_root(
assert!(bank.parent().is_none());
let start_slot = bank.slot();
let now = Instant::now();
let mut rooted_path = vec![start_slot];
let mut root = start_slot;
bank.set_entered_epoch_callback(solana_genesis_programs::get_entered_epoch_callback(
genesis_config.operating_mode,
@ -366,7 +366,7 @@ pub fn process_blockstore_from_root(
&meta,
blockstore,
&mut leader_schedule_cache,
&mut rooted_path,
&mut root,
opts,
recyclers,
)?;
@ -375,7 +375,7 @@ pub fn process_blockstore_from_root(
if banks.is_empty() {
return Err(BlockstoreProcessorError::NoValidForksFound);
}
let bank_forks = BankForks::new_from_banks(&banks, rooted_path);
let bank_forks = BankForks::new_from_banks(&banks, root);
(bank_forks, bank_forks_info, leader_schedule_cache)
} else {
// If there's no meta for the input `start_slot`, then we started from a snapshot
@ -385,7 +385,7 @@ pub fn process_blockstore_from_root(
bank_slot: start_slot,
};
let leader_schedule_cache = LeaderScheduleCache::new_from_bank(&bank);
let bank_forks = BankForks::new_from_banks(&[bank], rooted_path);
let bank_forks = BankForks::new_from_banks(&[bank], root);
(bank_forks, vec![bfi], leader_schedule_cache)
}
};
@ -704,7 +704,7 @@ fn process_pending_slots(
root_meta: &SlotMeta,
blockstore: &Blockstore,
leader_schedule_cache: &mut LeaderScheduleCache,
rooted_path: &mut Vec<u64>,
root: &mut Slot,
opts: &ProcessOptions,
recyclers: &VerifyRecyclers,
) -> result::Result<HashMap<u64, (Arc<Bank>, BankForksInfo)>, BlockstoreProcessorError> {
@ -752,10 +752,7 @@ fn process_pending_slots(
txs += progress.num_txs;
if blockstore.is_root(slot) {
let parents = bank.parents().into_iter().map(|b| b.slot()).rev().skip(1);
let parents: Vec<_> = parents.collect();
rooted_path.extend(parents);
rooted_path.push(slot);
*root = slot;
leader_schedule_cache.set_root(&bank);
bank.squash();
pending_slots.clear();