Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Use program cache fork graph in extract() (#33806)
Browse files Browse the repository at this point in the history
* Use program cache fork graph instead of WorkingSlot trait

* Fix deadlocked tests

* keep WorkingSlot trait for now
  • Loading branch information
pgarg66 authored Oct 25, 2023
1 parent a3b0348 commit 78c31aa
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 146 deletions.
4 changes: 2 additions & 2 deletions client-test/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn test_account_subscription() {
// Transfer 100 lamports from alice to bob
let tx = system_transaction::transfer(&alice, &bob.pubkey(), 100, blockhash);
bank_forks
.write()
.read()
.unwrap()
.get(1)
.unwrap()
Expand Down Expand Up @@ -373,7 +373,7 @@ fn test_program_subscription() {
// Create new program account at bob's address
let tx = system_transaction::create_account(&alice, &bob, blockhash, 100, 0, &program_id);
bank_forks
.write()
.read()
.unwrap()
.get(1)
.unwrap()
Expand Down
43 changes: 24 additions & 19 deletions core/src/commitment_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,11 @@ mod tests {

let bank0 = Bank::new_for_tests(&genesis_config);
let bank_forks = BankForks::new_rw_arc(bank0);
let mut bank_forks = bank_forks.write().unwrap();

// Fill bank_forks with banks with votes landing in the next slot
// Create enough banks such that vote account will root slots 0 and 1
for x in 0..33 {
let previous_bank = bank_forks.get(x).unwrap();
let previous_bank = bank_forks.read().unwrap().get(x).unwrap();
let bank = Bank::new_from_parent(previous_bank.clone(), &Pubkey::default(), x + 1);
let vote = vote_transaction::new_vote_transaction(
vec![x],
Expand All @@ -527,20 +526,23 @@ mod tests {
None,
);
bank.process_transaction(&vote).unwrap();
bank_forks.insert(bank);
bank_forks.write().unwrap().insert(bank);
}

let working_bank = bank_forks.working_bank();
let working_bank = bank_forks.read().unwrap().working_bank();
let root = get_vote_account_root_slot(
validator_vote_keypairs.vote_keypair.pubkey(),
&working_bank,
);
for x in 0..root {
bank_forks.set_root(x, &AbsRequestSender::default(), None);
bank_forks
.write()
.unwrap()
.set_root(x, &AbsRequestSender::default(), None);
}

// Add an additional bank/vote that will root slot 2
let bank33 = bank_forks.get(33).unwrap();
let bank33 = bank_forks.read().unwrap().get(33).unwrap();
let bank34 = Bank::new_from_parent(bank33.clone(), &Pubkey::default(), 34);
let vote33 = vote_transaction::new_vote_transaction(
vec![33],
Expand All @@ -552,9 +554,9 @@ mod tests {
None,
);
bank34.process_transaction(&vote33).unwrap();
bank_forks.insert(bank34);
bank_forks.write().unwrap().insert(bank34);

let working_bank = bank_forks.working_bank();
let working_bank = bank_forks.read().unwrap().working_bank();
let root = get_vote_account_root_slot(
validator_vote_keypairs.vote_keypair.pubkey(),
&working_bank,
Expand All @@ -573,21 +575,22 @@ mod tests {
.read()
.unwrap()
.highest_super_majority_root();
bank_forks.set_root(
bank_forks.write().unwrap().set_root(
root,
&AbsRequestSender::default(),
Some(highest_super_majority_root),
);
let highest_super_majority_root_bank = bank_forks.get(highest_super_majority_root);
let highest_super_majority_root_bank =
bank_forks.read().unwrap().get(highest_super_majority_root);
assert!(highest_super_majority_root_bank.is_some());

// Add a forked bank. Because the vote for bank 33 landed in the non-ancestor, the vote
// account's root (and thus the highest_super_majority_root) rolls back to slot 1
let bank33 = bank_forks.get(33).unwrap();
let bank33 = bank_forks.read().unwrap().get(33).unwrap();
let bank35 = Bank::new_from_parent(bank33, &Pubkey::default(), 35);
bank_forks.insert(bank35);
bank_forks.write().unwrap().insert(bank35);

let working_bank = bank_forks.working_bank();
let working_bank = bank_forks.read().unwrap().working_bank();
let ancestors = working_bank.status_cache_ancestors();
let _ = AggregateCommitmentService::update_commitment_cache(
&block_commitment_cache,
Expand All @@ -602,13 +605,14 @@ mod tests {
.read()
.unwrap()
.highest_super_majority_root();
let highest_super_majority_root_bank = bank_forks.get(highest_super_majority_root);
let highest_super_majority_root_bank =
bank_forks.read().unwrap().get(highest_super_majority_root);
assert!(highest_super_majority_root_bank.is_some());

// Add additional banks beyond lockout built on the new fork to ensure that behavior
// continues normally
for x in 35..=37 {
let previous_bank = bank_forks.get(x).unwrap();
let previous_bank = bank_forks.read().unwrap().get(x).unwrap();
let bank = Bank::new_from_parent(previous_bank.clone(), &Pubkey::default(), x + 1);
let vote = vote_transaction::new_vote_transaction(
vec![x],
Expand All @@ -620,10 +624,10 @@ mod tests {
None,
);
bank.process_transaction(&vote).unwrap();
bank_forks.insert(bank);
bank_forks.write().unwrap().insert(bank);
}

let working_bank = bank_forks.working_bank();
let working_bank = bank_forks.read().unwrap().working_bank();
let root = get_vote_account_root_slot(
validator_vote_keypairs.vote_keypair.pubkey(),
&working_bank,
Expand All @@ -642,12 +646,13 @@ mod tests {
.read()
.unwrap()
.highest_super_majority_root();
bank_forks.set_root(
bank_forks.write().unwrap().set_root(
root,
&AbsRequestSender::default(),
Some(highest_super_majority_root),
);
let highest_super_majority_root_bank = bank_forks.get(highest_super_majority_root);
let highest_super_majority_root_bank =
bank_forks.read().unwrap().get(highest_super_majority_root);
assert!(highest_super_majority_root_bank.is_some());
}
}
25 changes: 15 additions & 10 deletions core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,13 @@ fn run_bank_forks_snapshot_n<F>(
accounts_package_sender,
};
for slot in 1..=last_slot {
let mut bank_forks_w = bank_forks.write().unwrap();
let mut bank =
Bank::new_from_parent(bank_forks_w[slot - 1].clone(), &Pubkey::default(), slot);
let mut bank = Bank::new_from_parent(
bank_forks.read().unwrap().get(slot - 1).unwrap().clone(),
&Pubkey::default(),
slot,
);
f(&mut bank, mint_keypair);
let bank = bank_forks_w.insert(bank);
drop(bank_forks_w);
let bank = bank_forks.write().unwrap().insert(bank);
// Set root to make sure we don't end up with too many account storage entries
// and to allow snapshotting of bank and the purging logic on status_cache to
// kick in
Expand Down Expand Up @@ -352,7 +353,7 @@ fn test_concurrent_snapshot_packaging(
DISABLED_SNAPSHOT_ARCHIVE_INTERVAL,
);

let mut bank_forks = snapshot_test_config.bank_forks.write().unwrap();
let bank_forks = snapshot_test_config.bank_forks.clone();
let snapshot_config = &snapshot_test_config.snapshot_config;
let bank_snapshots_dir = &snapshot_config.bank_snapshots_dir;
let full_snapshot_archives_dir = &snapshot_config.full_snapshot_archives_dir;
Expand All @@ -361,7 +362,7 @@ fn test_concurrent_snapshot_packaging(
let genesis_config = &snapshot_test_config.genesis_config_info.genesis_config;

// Take snapshot of zeroth bank
let bank0 = bank_forks.get(0).unwrap();
let bank0 = bank_forks.read().unwrap().get(0).unwrap();
let storages = bank0.get_snapshot_storages(None);
let slot_deltas = bank0.status_cache.read().unwrap().root_slot_deltas();
snapshot_bank_utils::add_bank_snapshot(
Expand Down Expand Up @@ -394,7 +395,7 @@ fn test_concurrent_snapshot_packaging(
for i in 0..MAX_BANK_SNAPSHOTS_TO_RETAIN + 2 {
let parent_slot = i as Slot;
let bank = Bank::new_from_parent(
bank_forks[parent_slot].clone(),
bank_forks.read().unwrap().get(parent_slot).unwrap().clone(),
&Pubkey::default(),
parent_slot + 1,
);
Expand Down Expand Up @@ -438,10 +439,14 @@ fn test_concurrent_snapshot_packaging(
);
accounts_package_sender.send(accounts_package).unwrap();

bank_forks.insert(bank);
bank_forks.write().unwrap().insert(bank);
if slot == saved_slot {
// Find the relevant snapshot storages
let snapshot_storage_files: HashSet<_> = bank_forks[slot]
let snapshot_storage_files: HashSet<_> = bank_forks
.read()
.unwrap()
.get(slot)
.unwrap()
.get_snapshot_storages(None)
.into_iter()
.map(|s| s.get_path())
Expand Down
Loading

0 comments on commit 78c31aa

Please sign in to comment.