Skip to content

Commit

Permalink
v1.17: Initialize fork graph in program cache during bank_forks creat…
Browse files Browse the repository at this point in the history
…ion (backport of #33810) (#33817)

* Initialize fork graph in program cache during bank_forks creation (#33810)

* Initialize fork graph in program cache during bank_forks creation

* rename BankForks::new to BankForks::new_rw_arc

* fix compilation

* no need to set fork_graph on insert()

* fix partition tests

(cherry picked from commit 9d42cd7)

# Conflicts:
#	core/src/repair/repair_service.rs
#	core/tests/epoch_accounts_hash.rs
#	ledger/src/blockstore_processor.rs
#	rpc/src/rpc_service.rs
#	runtime/src/bank/tests.rs

* fix merge conflicts

---------

Co-authored-by: Pankaj Garg <pankaj@solana.com>
  • Loading branch information
mergify[bot] and pgarg66 authored Oct 23, 2023
1 parent a186c5c commit 22f44d0
Show file tree
Hide file tree
Showing 50 changed files with 501 additions and 444 deletions.
377 changes: 189 additions & 188 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion banking-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fn main() {

let (replay_vote_sender, _replay_vote_receiver) = unbounded();
let bank0 = Bank::new_for_benches(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank0)));
let bank_forks = BankForks::new_rw_arc(bank0);
let mut bank = bank_forks.read().unwrap().working_bank();

// set cost tracker limits to MAX so it will not filter out TXs
Expand Down
4 changes: 2 additions & 2 deletions banks-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ mod tests {
let block_commitment_cache = Arc::new(RwLock::new(
BlockCommitmentCache::new_for_tests_with_slots(slot, slot),
));
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);

let bob_pubkey = solana_sdk::pubkey::new_rand();
let mint_pubkey = genesis.mint_keypair.pubkey();
Expand Down Expand Up @@ -626,7 +626,7 @@ mod tests {
let block_commitment_cache = Arc::new(RwLock::new(
BlockCommitmentCache::new_for_tests_with_slots(slot, slot),
));
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);

let mint_pubkey = &genesis.mint_keypair.pubkey();
let bob_pubkey = solana_sdk::pubkey::new_rand();
Expand Down
12 changes: 6 additions & 6 deletions client-test/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn test_account_subscription() {
} = create_genesis_config(10_000);
let bank = Bank::new_for_tests(&genesis_config);
let blockhash = bank.last_blockhash();
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank0 = bank_forks.read().unwrap().get(0).unwrap();
let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1);
bank_forks.write().unwrap().insert(bank1);
Expand Down Expand Up @@ -230,7 +230,7 @@ fn test_block_subscription() {
} = create_genesis_config(10_000);
let bank = Bank::new_for_tests(&genesis_config);
let rent_exempt_amount = bank.get_minimum_balance_for_rent_exemption(0);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);

// setup Blockstore
let ledger_path = get_tmp_ledger_path!();
Expand Down Expand Up @@ -338,7 +338,7 @@ fn test_program_subscription() {
} = create_genesis_config(10_000);
let bank = Bank::new_for_tests(&genesis_config);
let blockhash = bank.last_blockhash();
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank0 = bank_forks.read().unwrap().get(0).unwrap();
let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1);
bank_forks.write().unwrap().insert(bank1);
Expand Down Expand Up @@ -425,7 +425,7 @@ fn test_root_subscription() {

let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
let bank = Bank::new_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank0 = bank_forks.read().unwrap().get(0).unwrap();
let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1);
bank_forks.write().unwrap().insert(bank1);
Expand Down Expand Up @@ -477,7 +477,7 @@ fn test_slot_subscription() {
let exit = Arc::new(AtomicBool::new(false));
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
let bank = Bank::new_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let optimistically_confirmed_bank =
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks);
let max_complete_transaction_status_slot = Arc::new(AtomicU64::default());
Expand Down Expand Up @@ -553,7 +553,7 @@ async fn test_slot_subscription_async() {
let exit = Arc::new(AtomicBool::new(false));
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
let bank = Bank::new_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let optimistically_confirmed_bank =
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks);
let max_complete_transaction_status_slot = Arc::new(AtomicU64::default());
Expand Down
4 changes: 2 additions & 2 deletions core/benches/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use {
},
std::{
iter::repeat_with,
sync::{atomic::Ordering, Arc, RwLock},
sync::{atomic::Ordering, Arc},
time::{Duration, Instant},
},
test::Bencher,
Expand Down Expand Up @@ -219,7 +219,7 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {
let mut bank = Bank::new_for_benches(&genesis_config);
// Allow arbitrary transaction processing time for the purposes of this bench
bank.ns_per_slot = u128::MAX;
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().get(0).unwrap();

// set cost tracker limits to MAX so it will not filter out TXs
Expand Down
10 changes: 8 additions & 2 deletions core/benches/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ fn bench_save_tower(bench: &mut Bencher) {

let vote_account_pubkey = &Pubkey::default();
let node_keypair = Arc::new(Keypair::new());
let heaviest_bank = BankForks::new(Bank::default_for_tests()).working_bank();
let heaviest_bank = BankForks::new_rw_arc(Bank::default_for_tests())
.read()
.unwrap()
.working_bank();
let tower_storage = FileTowerStorage::new(dir.path().to_path_buf());
let tower = Tower::new(
&node_keypair.pubkey(),
Expand All @@ -47,7 +50,10 @@ fn bench_save_tower(bench: &mut Bencher) {
fn bench_generate_ancestors_descendants(bench: &mut Bencher) {
let vote_account_pubkey = &Pubkey::default();
let node_keypair = Arc::new(Keypair::new());
let heaviest_bank = BankForks::new(Bank::default_for_tests()).working_bank();
let heaviest_bank = BankForks::new_rw_arc(Bank::default_for_tests())
.read()
.unwrap()
.working_bank();
let mut tower = Tower::new(
&node_keypair.pubkey(),
vote_account_pubkey,
Expand Down
10 changes: 5 additions & 5 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ mod tests {
fn test_banking_stage_shutdown1() {
let genesis_config = create_genesis_config(2).genesis_config;
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().get(0).unwrap();
let banking_tracer = BankingTracer::new_disabled();
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();
Expand Down Expand Up @@ -722,7 +722,7 @@ mod tests {
genesis_config.ticks_per_slot = 4;
let num_extra_ticks = 2;
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().get(0).unwrap();
let start_hash = bank.last_blockhash();
let banking_tracer = BankingTracer::new_disabled();
Expand Down Expand Up @@ -802,7 +802,7 @@ mod tests {
..
} = create_slow_genesis_config(10);
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().get(0).unwrap();
let start_hash = bank.last_blockhash();
let banking_tracer = BankingTracer::new_disabled();
Expand Down Expand Up @@ -974,7 +974,7 @@ mod tests {
let entry_receiver = {
// start a banking_stage to eat verified receiver
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().get(0).unwrap();
let blockstore = Arc::new(
Blockstore::open(ledger_path.path())
Expand Down Expand Up @@ -1155,7 +1155,7 @@ mod tests {
..
} = create_slow_genesis_config(10000);
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().get(0).unwrap();
let start_hash = bank.last_blockhash();
let banking_tracer = BankingTracer::new_disabled();
Expand Down
2 changes: 1 addition & 1 deletion core/src/banking_stage/consume_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ mod tests {
..
} = create_slow_genesis_config(10_000);
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().working_bank();

let ledger_path = get_tmp_ledger_path_auto_delete!();
Expand Down
2 changes: 1 addition & 1 deletion core/src/banking_stage/forward_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ mod tests {
..
} = create_slow_genesis_config(10_000);
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().working_bank();

let ledger_path = get_tmp_ledger_path_auto_delete!();
Expand Down
2 changes: 1 addition & 1 deletion core/src/banking_stage/forwarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ mod tests {
let GenesisConfigInfo { genesis_config, .. } = &genesis_config_info;

let bank: Bank = Bank::new_no_wallclock_throttle_for_tests(genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().working_bank();

let ledger_path = TempDir::new().unwrap();
Expand Down
10 changes: 5 additions & 5 deletions core/src/cluster_info_vote_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ mod tests {
);
let bank = Bank::new_for_tests(&genesis_config);
let exit = Arc::new(AtomicBool::new(false));
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().get(0).unwrap();
let vote_tracker = VoteTracker::default();
let optimistically_confirmed_bank =
Expand Down Expand Up @@ -1556,7 +1556,7 @@ mod tests {
let bank = Bank::new_for_tests(&genesis_config);
let vote_tracker = VoteTracker::default();
let exit = Arc::new(AtomicBool::new(false));
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().get(0).unwrap();
let optimistically_confirmed_bank =
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks);
Expand Down Expand Up @@ -1584,7 +1584,7 @@ mod tests {
solana_logger::setup();
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
let bank = Bank::new_for_tests(&genesis_config);
let bank_forks = RwLock::new(BankForks::new(bank));
let bank_forks = BankForks::new_rw_arc(bank);
let votes = vec![];
let (vote_txs, packets) = ClusterInfoVoteListener::verify_votes(votes, &bank_forks);
assert!(vote_txs.is_empty());
Expand Down Expand Up @@ -1629,7 +1629,7 @@ mod tests {
vec![100; voting_keypairs.len()], // stakes
);
let bank = Bank::new_for_tests(&genesis_config);
let bank_forks = RwLock::new(BankForks::new(bank));
let bank_forks = BankForks::new_rw_arc(bank);
let vote_tx = test_vote_tx(voting_keypairs.first(), hash);
let votes = vec![vote_tx];
let (vote_txs, packets) = ClusterInfoVoteListener::verify_votes(votes, &bank_forks);
Expand All @@ -1654,7 +1654,7 @@ mod tests {
vec![100; voting_keypairs.len()], // stakes
);
let bank = Bank::new_for_tests(&genesis_config);
let bank_forks = RwLock::new(BankForks::new(bank));
let bank_forks = BankForks::new_rw_arc(bank);
let vote_tx = test_vote_tx(voting_keypairs.first(), hash);
let mut bad_vote = vote_tx.clone();
bad_vote.signatures[0] = Signature::default();
Expand Down
3 changes: 2 additions & 1 deletion core/src/commitment_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ mod tests {
);

let bank0 = Bank::new_for_tests(&genesis_config);
let mut bank_forks = BankForks::new(bank0);
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
Expand Down
3 changes: 2 additions & 1 deletion core/src/consensus/heaviest_subtree_fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ impl HeaviestSubtreeForkChoice {
heaviest_subtree_fork_choice
}

pub fn new_from_bank_forks(bank_forks: &BankForks) -> Self {
pub fn new_from_bank_forks(bank_forks: Arc<RwLock<BankForks>>) -> Self {
let bank_forks = bank_forks.read().unwrap();
let mut frozen_banks: Vec<_> = bank_forks.frozen_banks().values().cloned().collect();

frozen_banks.sort_by_key(|bank| bank.slot());
Expand Down
2 changes: 1 addition & 1 deletion core/src/repair/ancestor_hashes_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ mod test {
#[test]
fn test_verify_and_process_ancestor_responses_invalid_packet() {
let bank0 = Bank::default_for_tests();
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank0)));
let bank_forks = BankForks::new_rw_arc(bank0);

let ManageAncestorHashesState {
ancestor_hashes_request_statuses,
Expand Down
2 changes: 1 addition & 1 deletion core/src/repair/quic_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ mod tests {
let GenesisConfigInfo { genesis_config, .. } =
create_genesis_config(/*mint_lamports:*/ 100_000);
let bank = Bank::new_for_tests(&genesis_config);
Arc::new(RwLock::new(BankForks::new(bank)))
BankForks::new_rw_arc(bank)
};
let (endpoints, senders, tasks): (Vec<_>, Vec<_>, Vec<_>) = multiunzip(
keypairs
Expand Down
4 changes: 2 additions & 2 deletions core/src/repair/repair_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ mod test {
pub fn test_generate_and_send_duplicate_repairs() {
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
let bank = Bank::new_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let blockstore_path = get_tmp_ledger_path!();
let blockstore = Blockstore::open(&blockstore_path).unwrap();
let cluster_slots = ClusterSlots::default();
Expand Down Expand Up @@ -1301,7 +1301,7 @@ mod test {
pub fn test_update_duplicate_slot_repair_addr() {
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
let bank = Bank::new_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let dummy_addr = Some((
Pubkey::default(),
UdpSocket::bind("0.0.0.0:0").unwrap().local_addr().unwrap(),
Expand Down
10 changes: 5 additions & 5 deletions core/src/repair/serve_repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ mod tests {
fn test_serialize_deserialize_signed_request() {
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
let bank = Bank::new_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let cluster_info = Arc::new(new_test_cluster_info());
let serve_repair = ServeRepair::new(
cluster_info.clone(),
Expand Down Expand Up @@ -1611,7 +1611,7 @@ mod tests {

let mut bank = Bank::new_for_tests(&genesis_config);
bank.feature_set = Arc::new(FeatureSet::all_enabled());
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let serve_repair = ServeRepair::new(
cluster_info,
bank_forks,
Expand Down Expand Up @@ -1647,7 +1647,7 @@ mod tests {
fn test_map_requests_signed() {
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
let bank = Bank::new_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let cluster_info = Arc::new(new_test_cluster_info());
let serve_repair = ServeRepair::new(
cluster_info.clone(),
Expand Down Expand Up @@ -1976,7 +1976,7 @@ mod tests {
fn window_index_request() {
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
let bank = Bank::new_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let cluster_slots = ClusterSlots::default();
let cluster_info = Arc::new(new_test_cluster_info());
let serve_repair = ServeRepair::new(
Expand Down Expand Up @@ -2318,7 +2318,7 @@ mod tests {
fn test_repair_with_repair_validators() {
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
let bank = Bank::new_for_tests(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
let bank_forks = BankForks::new_rw_arc(bank);
let cluster_slots = ClusterSlots::default();
let cluster_info = Arc::new(new_test_cluster_info());
let me = cluster_info.my_contact_info();
Expand Down
Loading

0 comments on commit 22f44d0

Please sign in to comment.