Avoid holding the entire rooted path while loading bank forks (#9885)
This commit is contained in:
parent
3442f36f8a
commit
72312ad615
|
@ -2528,7 +2528,7 @@ pub(crate) mod tests {
|
||||||
let arc_bank0 = Arc::new(bank0);
|
let arc_bank0 = Arc::new(bank0);
|
||||||
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(
|
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(
|
||||||
&[arc_bank0.clone()],
|
&[arc_bank0.clone()],
|
||||||
vec![0],
|
0,
|
||||||
)));
|
)));
|
||||||
|
|
||||||
assert!(block_commitment_cache
|
assert!(block_commitment_cache
|
||||||
|
|
|
@ -689,10 +689,7 @@ mod tests {
|
||||||
let cluster_info = test_cluster_info(&keypair.pubkey());
|
let cluster_info = test_cluster_info(&keypair.pubkey());
|
||||||
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(1000);
|
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(1000);
|
||||||
let bank = Arc::new(Bank::new(&genesis_config));
|
let bank = Arc::new(Bank::new(&genesis_config));
|
||||||
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(
|
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(&[bank.clone()], 0)));
|
||||||
&[bank.clone()],
|
|
||||||
vec![0],
|
|
||||||
)));
|
|
||||||
let ledger_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path!();
|
||||||
let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap());
|
let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap());
|
||||||
let block_commitment_cache = Arc::new(RwLock::new(
|
let block_commitment_cache = Arc::new(RwLock::new(
|
||||||
|
|
|
@ -56,10 +56,7 @@ mod tests {
|
||||||
|
|
||||||
let bank = Bank::new(&genesis_config);
|
let bank = Bank::new(&genesis_config);
|
||||||
let bank = Arc::new(bank);
|
let bank = Arc::new(bank);
|
||||||
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(
|
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(&[bank.clone()], 0)));
|
||||||
&[bank.clone()],
|
|
||||||
vec![0],
|
|
||||||
)));
|
|
||||||
let block_commitment_cache = Arc::new(RwLock::new(
|
let block_commitment_cache = Arc::new(RwLock::new(
|
||||||
BlockCommitmentCache::default_with_blockstore(blockstore.clone()),
|
BlockCommitmentCache::default_with_blockstore(blockstore.clone()),
|
||||||
));
|
));
|
||||||
|
@ -179,10 +176,7 @@ mod tests {
|
||||||
let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap());
|
let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap());
|
||||||
let slot = 1;
|
let slot = 1;
|
||||||
let bank = Arc::new(Bank::new(&genesis_config));
|
let bank = Arc::new(Bank::new(&genesis_config));
|
||||||
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(
|
let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(&[bank.clone()], 0)));
|
||||||
&[bank.clone()],
|
|
||||||
vec![0],
|
|
||||||
)));
|
|
||||||
let block_commitment_cache = Arc::new(RwLock::new(
|
let block_commitment_cache = Arc::new(RwLock::new(
|
||||||
BlockCommitmentCache::default_with_blockstore(blockstore.clone()),
|
BlockCommitmentCache::default_with_blockstore(blockstore.clone()),
|
||||||
));
|
));
|
||||||
|
|
|
@ -141,7 +141,7 @@ impl BankForks {
|
||||||
self.banks.get(&self.root()).expect("Root bank must exist")
|
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 mut banks = HashMap::new();
|
||||||
let working_bank = initial_forks[0].clone();
|
let working_bank = initial_forks[0].clone();
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ impl BankForks {
|
||||||
banks.insert(parent.slot(), parent.clone());
|
banks.insert(parent.slot(), parent.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let root = *rooted_path.last().unwrap();
|
|
||||||
Self {
|
Self {
|
||||||
root,
|
root,
|
||||||
banks,
|
banks,
|
||||||
|
|
|
@ -318,7 +318,7 @@ pub fn process_blockstore_from_root(
|
||||||
assert!(bank.parent().is_none());
|
assert!(bank.parent().is_none());
|
||||||
let start_slot = bank.slot();
|
let start_slot = bank.slot();
|
||||||
let now = Instant::now();
|
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(
|
bank.set_entered_epoch_callback(solana_genesis_programs::get_entered_epoch_callback(
|
||||||
genesis_config.operating_mode,
|
genesis_config.operating_mode,
|
||||||
|
@ -366,7 +366,7 @@ pub fn process_blockstore_from_root(
|
||||||
&meta,
|
&meta,
|
||||||
blockstore,
|
blockstore,
|
||||||
&mut leader_schedule_cache,
|
&mut leader_schedule_cache,
|
||||||
&mut rooted_path,
|
&mut root,
|
||||||
opts,
|
opts,
|
||||||
recyclers,
|
recyclers,
|
||||||
)?;
|
)?;
|
||||||
|
@ -375,7 +375,7 @@ pub fn process_blockstore_from_root(
|
||||||
if banks.is_empty() {
|
if banks.is_empty() {
|
||||||
return Err(BlockstoreProcessorError::NoValidForksFound);
|
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)
|
(bank_forks, bank_forks_info, leader_schedule_cache)
|
||||||
} else {
|
} else {
|
||||||
// If there's no meta for the input `start_slot`, then we started from a snapshot
|
// 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,
|
bank_slot: start_slot,
|
||||||
};
|
};
|
||||||
let leader_schedule_cache = LeaderScheduleCache::new_from_bank(&bank);
|
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)
|
(bank_forks, vec![bfi], leader_schedule_cache)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -704,7 +704,7 @@ fn process_pending_slots(
|
||||||
root_meta: &SlotMeta,
|
root_meta: &SlotMeta,
|
||||||
blockstore: &Blockstore,
|
blockstore: &Blockstore,
|
||||||
leader_schedule_cache: &mut LeaderScheduleCache,
|
leader_schedule_cache: &mut LeaderScheduleCache,
|
||||||
rooted_path: &mut Vec<u64>,
|
root: &mut Slot,
|
||||||
opts: &ProcessOptions,
|
opts: &ProcessOptions,
|
||||||
recyclers: &VerifyRecyclers,
|
recyclers: &VerifyRecyclers,
|
||||||
) -> result::Result<HashMap<u64, (Arc<Bank>, BankForksInfo)>, BlockstoreProcessorError> {
|
) -> result::Result<HashMap<u64, (Arc<Bank>, BankForksInfo)>, BlockstoreProcessorError> {
|
||||||
|
@ -752,10 +752,7 @@ fn process_pending_slots(
|
||||||
txs += progress.num_txs;
|
txs += progress.num_txs;
|
||||||
|
|
||||||
if blockstore.is_root(slot) {
|
if blockstore.is_root(slot) {
|
||||||
let parents = bank.parents().into_iter().map(|b| b.slot()).rev().skip(1);
|
*root = slot;
|
||||||
let parents: Vec<_> = parents.collect();
|
|
||||||
rooted_path.extend(parents);
|
|
||||||
rooted_path.push(slot);
|
|
||||||
leader_schedule_cache.set_root(&bank);
|
leader_schedule_cache.set_root(&bank);
|
||||||
bank.squash();
|
bank.squash();
|
||||||
pending_slots.clear();
|
pending_slots.clear();
|
||||||
|
|
Loading…
Reference in New Issue