Skip to content

Commit

Permalink
Use BankForks on tests - Part 3 (#34248)
Browse files Browse the repository at this point in the history
* Add BankForks to core tests

* Refactor functions under DCOU
  • Loading branch information
LucasSte authored Dec 1, 2023
1 parent 2294801 commit b97b3dd
Show file tree
Hide file tree
Showing 34 changed files with 221 additions and 210 deletions.
1 change: 1 addition & 0 deletions accounts-cluster-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ spl-token = { workspace = true, features = ["no-entrypoint"] }
[dev-dependencies]
solana-core = { workspace = true }
solana-local-cluster = { workspace = true }
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
solana-test-validator = { workspace = true }

[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion banking-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ solana-logger = { workspace = true }
solana-measure = { workspace = true }
solana-perf = { workspace = true }
solana-poh = { workspace = true, features = ["dev-context-only-utils"] }
solana-runtime = { workspace = true }
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
solana-sdk = { workspace = true }
solana-streamer = { workspace = true }
solana-tpu-client = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion banks-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tokio-serde = { workspace = true, features = ["bincode"] }

[dev-dependencies]
solana-banks-server = { workspace = true }
solana-runtime = { workspace = true }
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }

[lib]
crate-type = ["lib"]
Expand Down
1 change: 1 addition & 0 deletions bench-tps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ thiserror = { workspace = true }
[dev-dependencies]
serial_test = { workspace = true }
solana-local-cluster = { workspace = true }
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
solana-test-validator = { workspace = true }
tempfile = { workspace = true }

Expand Down
1 change: 1 addition & 0 deletions client-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ tungstenite = { workspace = true, features = ["rustls-tls-webpki-roots"] }

[dev-dependencies]
solana-logger = { workspace = true }
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
30 changes: 9 additions & 21 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,7 @@ mod tests {
},
poh_service::PohService,
},
solana_runtime::{
bank::Bank, bank_forks::BankForks, genesis_utils::bootstrap_validator_stake_lamports,
},
solana_runtime::{bank::Bank, genesis_utils::bootstrap_validator_stake_lamports},
solana_sdk::{
hash::Hash,
poh_config::PohConfig,
Expand Down Expand Up @@ -839,9 +837,7 @@ mod tests {
#[test]
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 = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().get(0).unwrap();
let (bank, bank_forks) = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let banking_tracer = BankingTracer::new_disabled();
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();
let (tpu_vote_sender, tpu_vote_receiver) = banking_tracer.create_channel_tpu_vote();
Expand Down Expand Up @@ -891,9 +887,7 @@ mod tests {
} = create_genesis_config(2);
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 = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().get(0).unwrap();
let (bank, bank_forks) = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let start_hash = bank.last_blockhash();
let banking_tracer = BankingTracer::new_disabled();
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();
Expand Down Expand Up @@ -970,9 +964,7 @@ mod tests {
mint_keypair,
..
} = create_slow_genesis_config(10);
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().get(0).unwrap();
let (bank, bank_forks) = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let start_hash = bank.last_blockhash();
let banking_tracer = BankingTracer::new_disabled();
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();
Expand Down Expand Up @@ -1057,7 +1049,7 @@ mod tests {
drop(poh_recorder);

let mut blockhash = start_hash;
let bank = Arc::new(Bank::new_no_wallclock_throttle_for_tests(&genesis_config));
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;
bank.process_transaction(&fund_tx).unwrap();
//receive entries + ticks
loop {
Expand Down Expand Up @@ -1152,9 +1144,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 = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().get(0).unwrap();
let (bank, bank_forks) = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let blockstore = Arc::new(
Blockstore::open(ledger_path.path())
.expect("Expected to be able to open database ledger"),
Expand Down Expand Up @@ -1203,7 +1193,7 @@ mod tests {
.map(|(_bank, (entry, _tick_height))| entry)
.collect();

let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;
for entry in entries {
bank.process_entry_transactions(entry.transactions)
.iter()
Expand All @@ -1227,7 +1217,7 @@ mod tests {
mint_keypair,
..
} = create_genesis_config(10_000);
let bank = Arc::new(Bank::new_no_wallclock_throttle_for_tests(&genesis_config));
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;
let ledger_path = get_tmp_ledger_path_auto_delete!();
{
let blockstore = Blockstore::open(ledger_path.path())
Expand Down Expand Up @@ -1336,9 +1326,7 @@ mod tests {
mint_keypair,
..
} = create_slow_genesis_config(10000);
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().get(0).unwrap();
let (bank, bank_forks) = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let start_hash = bank.last_blockhash();
let banking_tracer = BankingTracer::new_disabled();
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();
Expand Down
6 changes: 2 additions & 4 deletions core/src/banking_stage/consume_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ mod tests {
get_tmp_ledger_path_auto_delete, leader_schedule_cache::LeaderScheduleCache,
},
solana_poh::poh_recorder::{PohRecorder, WorkingBankEntry},
solana_runtime::{bank_forks::BankForks, prioritization_fee_cache::PrioritizationFeeCache},
solana_runtime::prioritization_fee_cache::PrioritizationFeeCache,
solana_sdk::{
genesis_config::GenesisConfig, poh_config::PohConfig, pubkey::Pubkey,
signature::Keypair, system_transaction,
Expand Down Expand Up @@ -651,9 +651,7 @@ mod tests {
mint_keypair,
..
} = create_slow_genesis_config(10_000);
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().working_bank();
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;

let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore = Blockstore::open(ledger_path.path())
Expand Down
23 changes: 12 additions & 11 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ mod tests {
} = &genesis_config_info;
let blockstore =
Blockstore::open(ledger_path).expect("Expected to be able to open database ledger");
let bank = Arc::new(Bank::new_no_wallclock_throttle_for_tests(genesis_config));
let bank = Bank::new_no_wallclock_throttle_for_tests(genesis_config).0;
let exit = Arc::new(AtomicBool::default());
let (poh_recorder, entry_receiver, record_receiver) = PohRecorder::new(
bank.tick_height(),
Expand Down Expand Up @@ -938,7 +938,7 @@ mod tests {
mint_keypair,
..
} = create_slow_genesis_config(10_000);
let bank = Arc::new(Bank::new_no_wallclock_throttle_for_tests(&genesis_config));
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;
let pubkey = solana_sdk::pubkey::new_rand();

let transactions = sanitize_transactions(vec![system_transaction::transfer(
Expand Down Expand Up @@ -1067,7 +1067,7 @@ mod tests {
mint_keypair,
..
} = create_slow_genesis_config(10_000);
let bank = Arc::new(Bank::new_no_wallclock_throttle_for_tests(&genesis_config));
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;
let pubkey = solana_sdk::pubkey::new_rand();

let transactions = {
Expand Down Expand Up @@ -1160,11 +1160,12 @@ mod tests {
mint_keypair,
..
} = create_slow_genesis_config(10_000);
let mut bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let mut bank = Bank::new_for_tests(&genesis_config);
bank.ns_per_slot = std::u128::MAX;
if !apply_cost_tracker_during_replay_enabled {
bank.deactivate_feature(&feature_set::apply_cost_tracker_during_replay::id());
}
let bank = Arc::new(bank);
let bank = bank.wrap_with_bank_forks_for_tests().0;
let pubkey = solana_sdk::pubkey::new_rand();

let ledger_path = get_tmp_ledger_path_auto_delete!();
Expand Down Expand Up @@ -1312,7 +1313,7 @@ mod tests {
mint_keypair,
..
} = create_slow_genesis_config(10_000);
let bank = Arc::new(Bank::new_no_wallclock_throttle_for_tests(&genesis_config));
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;
let pubkey = solana_sdk::pubkey::new_rand();
let pubkey1 = solana_sdk::pubkey::new_rand();

Expand Down Expand Up @@ -1390,7 +1391,7 @@ mod tests {
mint_keypair,
..
} = create_slow_genesis_config(lamports);
let bank = Arc::new(Bank::new_no_wallclock_throttle_for_tests(&genesis_config));
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;
// set cost tracker limits to MAX so it will not filter out TXs
bank.write_cost_tracker()
.unwrap()
Expand Down Expand Up @@ -1451,7 +1452,7 @@ mod tests {
mint_keypair,
..
} = create_slow_genesis_config(10_000);
let bank = Arc::new(Bank::new_no_wallclock_throttle_for_tests(&genesis_config));
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;
// set cost tracker limits to MAX so it will not filter out TXs
bank.write_cost_tracker()
.unwrap()
Expand Down Expand Up @@ -1510,7 +1511,7 @@ mod tests {
mint_keypair,
..
} = create_slow_genesis_config(10_000);
let bank = Arc::new(Bank::new_no_wallclock_throttle_for_tests(&genesis_config));
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;

let pubkey = solana_sdk::pubkey::new_rand();

Expand Down Expand Up @@ -1592,7 +1593,7 @@ mod tests {
} = create_slow_genesis_config(solana_sdk::native_token::sol_to_lamports(1000.0));
genesis_config.rent.lamports_per_byte_year = 50;
genesis_config.rent.exemption_threshold = 2.0;
let bank = Arc::new(Bank::new_no_wallclock_throttle_for_tests(&genesis_config));
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;
let pubkey = solana_sdk::pubkey::new_rand();
let pubkey1 = solana_sdk::pubkey::new_rand();
let keypair1 = Keypair::new();
Expand Down Expand Up @@ -1723,7 +1724,7 @@ mod tests {
mint_keypair,
..
} = create_slow_genesis_config(10_000);
let bank = Arc::new(Bank::new_no_wallclock_throttle_for_tests(&genesis_config));
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;
let keypair = Keypair::new();

let address_table_key = Pubkey::new_unique();
Expand Down
2 changes: 1 addition & 1 deletion core/src/banking_stage/decision_maker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ mod tests {
#[test]
fn test_make_consume_or_forward_decision() {
let genesis_config = create_genesis_config(2).genesis_config;
let bank = Arc::new(Bank::new_no_wallclock_throttle_for_tests(&genesis_config));
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;
let ledger_path = temp_dir();
let blockstore = Arc::new(Blockstore::open(ledger_path.as_path()).unwrap());
let (exit, poh_recorder, poh_service, _entry_receiver) =
Expand Down
6 changes: 2 additions & 4 deletions core/src/banking_stage/forward_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mod tests {
},
solana_perf::packet::to_packet_batches,
solana_poh::poh_recorder::{PohRecorder, WorkingBankEntry},
solana_runtime::{bank::Bank, bank_forks::BankForks},
solana_runtime::bank::Bank,
solana_sdk::{
genesis_config::GenesisConfig, poh_config::PohConfig, pubkey::Pubkey,
signature::Keypair, system_transaction,
Expand Down Expand Up @@ -128,9 +128,7 @@ mod tests {
mint_keypair,
..
} = create_slow_genesis_config(10_000);
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().working_bank();
let (bank, bank_forks) = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);

let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore = Blockstore::open(ledger_path.path())
Expand Down
4 changes: 1 addition & 3 deletions core/src/banking_stage/forwarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,7 @@ mod tests {
create_slow_genesis_config_with_leader(10_000, &validator_keypair.pubkey());
let GenesisConfigInfo { genesis_config, .. } = &genesis_config_info;

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

let ledger_path = TempDir::new().unwrap();
let blockstore = Arc::new(
Expand Down
2 changes: 1 addition & 1 deletion core/src/banking_stage/read_write_account_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ mod tests {

fn create_test_bank() -> Arc<Bank> {
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
Arc::new(Bank::new_no_wallclock_throttle_for_tests(&genesis_config))
Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0
}

// Helper function (could potentially use test_case in future).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ mod tests {
},
solana_perf::packet::{to_packet_batches, PacketBatch, NUM_PACKETS},
solana_poh::poh_recorder::{PohRecorder, Record, WorkingBankEntry},
solana_runtime::{bank::Bank, bank_forks::BankForks},
solana_runtime::bank::Bank,
solana_sdk::{
compute_budget::ComputeBudgetInstruction, hash::Hash, message::Message,
poh_config::PohConfig, pubkey::Pubkey, signature::Keypair, signer::Signer,
Expand Down Expand Up @@ -561,9 +561,7 @@ mod tests {

fn create_test_frame(num_threads: usize) -> (TestFrame, SchedulerController) {
let GenesisConfigInfo { genesis_config, .. } = create_slow_genesis_config(10_000);
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let bank_forks = BankForks::new_rw_arc(bank);
let bank = bank_forks.read().unwrap().working_bank();
let (bank, bank_forks) = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);

let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore = Blockstore::open(ledger_path.path())
Expand Down
2 changes: 1 addition & 1 deletion core/src/banking_stage/unprocessed_transaction_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ mod tests {
mint_keypair,
..
} = create_genesis_config(10);
let current_bank = Arc::new(Bank::new_for_tests(&genesis_config));
let current_bank = Bank::new_with_bank_forks_for_tests(&genesis_config).0;

let simple_transactions: Vec<Transaction> = (0..256)
.map(|_id| {
Expand Down
8 changes: 6 additions & 2 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5018,7 +5018,7 @@ pub(crate) mod tests {
let keypair2 = Keypair::new();
let keypair3 = Keypair::new();

let bank0 = Arc::new(Bank::new_for_tests(&genesis_config));
let (bank0, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config);
bank0
.transfer(
bank0.get_minimum_balance_for_rent_exemption(0),
Expand All @@ -5027,7 +5027,11 @@ pub(crate) mod tests {
)
.unwrap();

let bank1 = Arc::new(Bank::new_from_parent(bank0, &Pubkey::default(), 1));
let bank1 = bank_forks
.write()
.unwrap()
.insert(Bank::new_from_parent(bank0, &Pubkey::default(), 1))
.clone_without_scheduler();
let slot = bank1.slot();

let (entries, test_signatures) = create_test_transaction_entries(
Expand Down
3 changes: 1 addition & 2 deletions core/src/vote_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ pub fn initialize_state(
);

genesis_config.poh_config.hashes_per_tick = Some(2);
let bank0 = Bank::new_for_tests(&genesis_config);
let (bank0, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config);

for pubkey in validator_keypairs_map.keys() {
bank0.transfer(10_000, &mint_keypair, pubkey).unwrap();
Expand All @@ -372,7 +372,6 @@ pub fn initialize_state(
0,
ForkProgress::new_from_bank(&bank0, bank0.collector_id(), &Pubkey::default(), None, 0, 0),
);
let bank_forks = BankForks::new_rw_arc(bank0);
let heaviest_subtree_fork_choice =
HeaviestSubtreeForkChoice::new_from_bank_forks(bank_forks.clone());
(bank_forks, progress, heaviest_subtree_fork_choice)
Expand Down
3 changes: 3 additions & 0 deletions download-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ reqwest = { workspace = true, features = ["blocking", "brotli", "deflate", "gzip
solana-runtime = { workspace = true }
solana-sdk = { workspace = true }

[dev-dependencies]
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }

[lib]
crate-type = ["lib"]
name = "solana_download_utils"
Expand Down
3 changes: 3 additions & 0 deletions genesis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ solana-version = { workspace = true }
solana-vote-program = { workspace = true }
tempfile = { workspace = true }

[dev-dependencies]
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }

[[bin]]
name = "solana-genesis"
path = "src/main.rs"
Expand Down
1 change: 1 addition & 0 deletions gossip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ thiserror = { workspace = true }
[dev-dependencies]
num_cpus = { workspace = true }
serial_test = { workspace = true }
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
test-case = { workspace = true }

[build-dependencies]
Expand Down
Loading

0 comments on commit b97b3dd

Please sign in to comment.