Use BankForks on tests - Part 3 (#34248)
* Add BankForks to core tests * Refactor functions under DCOU
This commit is contained in:
parent
2294801954
commit
b97b3dd4ab
|
@ -34,6 +34,7 @@ spl-token = { workspace = true, features = ["no-entrypoint"] }
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
solana-core = { workspace = true }
|
solana-core = { workspace = true }
|
||||||
solana-local-cluster = { workspace = true }
|
solana-local-cluster = { workspace = true }
|
||||||
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
solana-test-validator = { workspace = true }
|
solana-test-validator = { workspace = true }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
|
|
|
@ -22,7 +22,7 @@ solana-logger = { workspace = true }
|
||||||
solana-measure = { workspace = true }
|
solana-measure = { workspace = true }
|
||||||
solana-perf = { workspace = true }
|
solana-perf = { workspace = true }
|
||||||
solana-poh = { workspace = true, features = ["dev-context-only-utils"] }
|
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-sdk = { workspace = true }
|
||||||
solana-streamer = { workspace = true }
|
solana-streamer = { workspace = true }
|
||||||
solana-tpu-client = { workspace = true }
|
solana-tpu-client = { workspace = true }
|
||||||
|
|
|
@ -22,7 +22,7 @@ tokio-serde = { workspace = true, features = ["bincode"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
solana-banks-server = { workspace = true }
|
solana-banks-server = { workspace = true }
|
||||||
solana-runtime = { workspace = true }
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["lib"]
|
crate-type = ["lib"]
|
||||||
|
|
|
@ -44,6 +44,7 @@ thiserror = { workspace = true }
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serial_test = { workspace = true }
|
serial_test = { workspace = true }
|
||||||
solana-local-cluster = { workspace = true }
|
solana-local-cluster = { workspace = true }
|
||||||
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
solana-test-validator = { workspace = true }
|
solana-test-validator = { workspace = true }
|
||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ tungstenite = { workspace = true, features = ["rustls-tls-webpki-roots"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
solana-logger = { workspace = true }
|
solana-logger = { workspace = true }
|
||||||
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
|
|
@ -801,9 +801,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
poh_service::PohService,
|
poh_service::PohService,
|
||||||
},
|
},
|
||||||
solana_runtime::{
|
solana_runtime::{bank::Bank, genesis_utils::bootstrap_validator_stake_lamports},
|
||||||
bank::Bank, bank_forks::BankForks, genesis_utils::bootstrap_validator_stake_lamports,
|
|
||||||
},
|
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
poh_config::PohConfig,
|
poh_config::PohConfig,
|
||||||
|
@ -839,9 +837,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_banking_stage_shutdown1() {
|
fn test_banking_stage_shutdown1() {
|
||||||
let genesis_config = create_genesis_config(2).genesis_config;
|
let genesis_config = create_genesis_config(2).genesis_config;
|
||||||
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
|
let (bank, bank_forks) = 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 banking_tracer = BankingTracer::new_disabled();
|
let banking_tracer = BankingTracer::new_disabled();
|
||||||
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();
|
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();
|
let (tpu_vote_sender, tpu_vote_receiver) = banking_tracer.create_channel_tpu_vote();
|
||||||
|
@ -891,9 +887,7 @@ mod tests {
|
||||||
} = create_genesis_config(2);
|
} = create_genesis_config(2);
|
||||||
genesis_config.ticks_per_slot = 4;
|
genesis_config.ticks_per_slot = 4;
|
||||||
let num_extra_ticks = 2;
|
let num_extra_ticks = 2;
|
||||||
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
|
let (bank, bank_forks) = 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 start_hash = bank.last_blockhash();
|
let start_hash = bank.last_blockhash();
|
||||||
let banking_tracer = BankingTracer::new_disabled();
|
let banking_tracer = BankingTracer::new_disabled();
|
||||||
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();
|
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();
|
||||||
|
@ -970,9 +964,7 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_slow_genesis_config(10);
|
} = create_slow_genesis_config(10);
|
||||||
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
|
let (bank, bank_forks) = 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 start_hash = bank.last_blockhash();
|
let start_hash = bank.last_blockhash();
|
||||||
let banking_tracer = BankingTracer::new_disabled();
|
let banking_tracer = BankingTracer::new_disabled();
|
||||||
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();
|
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();
|
||||||
|
@ -1057,7 +1049,7 @@ mod tests {
|
||||||
drop(poh_recorder);
|
drop(poh_recorder);
|
||||||
|
|
||||||
let mut blockhash = start_hash;
|
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();
|
bank.process_transaction(&fund_tx).unwrap();
|
||||||
//receive entries + ticks
|
//receive entries + ticks
|
||||||
loop {
|
loop {
|
||||||
|
@ -1152,9 +1144,7 @@ mod tests {
|
||||||
|
|
||||||
let entry_receiver = {
|
let entry_receiver = {
|
||||||
// start a banking_stage to eat verified receiver
|
// start a banking_stage to eat verified receiver
|
||||||
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
|
let (bank, bank_forks) = 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 blockstore = Arc::new(
|
let blockstore = Arc::new(
|
||||||
Blockstore::open(ledger_path.path())
|
Blockstore::open(ledger_path.path())
|
||||||
.expect("Expected to be able to open database ledger"),
|
.expect("Expected to be able to open database ledger"),
|
||||||
|
@ -1203,7 +1193,7 @@ mod tests {
|
||||||
.map(|(_bank, (entry, _tick_height))| entry)
|
.map(|(_bank, (entry, _tick_height))| entry)
|
||||||
.collect();
|
.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 {
|
for entry in entries {
|
||||||
bank.process_entry_transactions(entry.transactions)
|
bank.process_entry_transactions(entry.transactions)
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1227,7 +1217,7 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_genesis_config(10_000);
|
} = 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 ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
{
|
{
|
||||||
let blockstore = Blockstore::open(ledger_path.path())
|
let blockstore = Blockstore::open(ledger_path.path())
|
||||||
|
@ -1336,9 +1326,7 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_slow_genesis_config(10000);
|
} = create_slow_genesis_config(10000);
|
||||||
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
|
let (bank, bank_forks) = 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 start_hash = bank.last_blockhash();
|
let start_hash = bank.last_blockhash();
|
||||||
let banking_tracer = BankingTracer::new_disabled();
|
let banking_tracer = BankingTracer::new_disabled();
|
||||||
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();
|
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();
|
||||||
|
|
|
@ -616,7 +616,7 @@ mod tests {
|
||||||
get_tmp_ledger_path_auto_delete, leader_schedule_cache::LeaderScheduleCache,
|
get_tmp_ledger_path_auto_delete, leader_schedule_cache::LeaderScheduleCache,
|
||||||
},
|
},
|
||||||
solana_poh::poh_recorder::{PohRecorder, WorkingBankEntry},
|
solana_poh::poh_recorder::{PohRecorder, WorkingBankEntry},
|
||||||
solana_runtime::{bank_forks::BankForks, prioritization_fee_cache::PrioritizationFeeCache},
|
solana_runtime::prioritization_fee_cache::PrioritizationFeeCache,
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
genesis_config::GenesisConfig, poh_config::PohConfig, pubkey::Pubkey,
|
genesis_config::GenesisConfig, poh_config::PohConfig, pubkey::Pubkey,
|
||||||
signature::Keypair, system_transaction,
|
signature::Keypair, system_transaction,
|
||||||
|
@ -651,9 +651,7 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_slow_genesis_config(10_000);
|
} = create_slow_genesis_config(10_000);
|
||||||
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
|
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config).0;
|
||||||
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!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
let blockstore = Blockstore::open(ledger_path.path())
|
let blockstore = Blockstore::open(ledger_path.path())
|
||||||
|
|
|
@ -881,7 +881,7 @@ mod tests {
|
||||||
} = &genesis_config_info;
|
} = &genesis_config_info;
|
||||||
let blockstore =
|
let blockstore =
|
||||||
Blockstore::open(ledger_path).expect("Expected to be able to open database ledger");
|
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 exit = Arc::new(AtomicBool::default());
|
||||||
let (poh_recorder, entry_receiver, record_receiver) = PohRecorder::new(
|
let (poh_recorder, entry_receiver, record_receiver) = PohRecorder::new(
|
||||||
bank.tick_height(),
|
bank.tick_height(),
|
||||||
|
@ -938,7 +938,7 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_slow_genesis_config(10_000);
|
} = 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 pubkey = solana_sdk::pubkey::new_rand();
|
||||||
|
|
||||||
let transactions = sanitize_transactions(vec![system_transaction::transfer(
|
let transactions = sanitize_transactions(vec![system_transaction::transfer(
|
||||||
|
@ -1067,7 +1067,7 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_slow_genesis_config(10_000);
|
} = 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 pubkey = solana_sdk::pubkey::new_rand();
|
||||||
|
|
||||||
let transactions = {
|
let transactions = {
|
||||||
|
@ -1160,11 +1160,12 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_slow_genesis_config(10_000);
|
} = 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 {
|
if !apply_cost_tracker_during_replay_enabled {
|
||||||
bank.deactivate_feature(&feature_set::apply_cost_tracker_during_replay::id());
|
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 pubkey = solana_sdk::pubkey::new_rand();
|
||||||
|
|
||||||
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
|
@ -1312,7 +1313,7 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_slow_genesis_config(10_000);
|
} = 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 pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let pubkey1 = solana_sdk::pubkey::new_rand();
|
let pubkey1 = solana_sdk::pubkey::new_rand();
|
||||||
|
|
||||||
|
@ -1390,7 +1391,7 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_slow_genesis_config(lamports);
|
} = 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
|
// set cost tracker limits to MAX so it will not filter out TXs
|
||||||
bank.write_cost_tracker()
|
bank.write_cost_tracker()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -1451,7 +1452,7 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_slow_genesis_config(10_000);
|
} = 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
|
// set cost tracker limits to MAX so it will not filter out TXs
|
||||||
bank.write_cost_tracker()
|
bank.write_cost_tracker()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -1510,7 +1511,7 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_slow_genesis_config(10_000);
|
} = 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 pubkey = solana_sdk::pubkey::new_rand();
|
||||||
|
|
||||||
|
@ -1592,7 +1593,7 @@ mod tests {
|
||||||
} = create_slow_genesis_config(solana_sdk::native_token::sol_to_lamports(1000.0));
|
} = create_slow_genesis_config(solana_sdk::native_token::sol_to_lamports(1000.0));
|
||||||
genesis_config.rent.lamports_per_byte_year = 50;
|
genesis_config.rent.lamports_per_byte_year = 50;
|
||||||
genesis_config.rent.exemption_threshold = 2.0;
|
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 pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let pubkey1 = solana_sdk::pubkey::new_rand();
|
let pubkey1 = solana_sdk::pubkey::new_rand();
|
||||||
let keypair1 = Keypair::new();
|
let keypair1 = Keypair::new();
|
||||||
|
@ -1723,7 +1724,7 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_slow_genesis_config(10_000);
|
} = 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 keypair = Keypair::new();
|
||||||
|
|
||||||
let address_table_key = Pubkey::new_unique();
|
let address_table_key = Pubkey::new_unique();
|
||||||
|
|
|
@ -148,7 +148,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_make_consume_or_forward_decision() {
|
fn test_make_consume_or_forward_decision() {
|
||||||
let genesis_config = create_genesis_config(2).genesis_config;
|
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 ledger_path = temp_dir();
|
||||||
let blockstore = Arc::new(Blockstore::open(ledger_path.as_path()).unwrap());
|
let blockstore = Arc::new(Blockstore::open(ledger_path.as_path()).unwrap());
|
||||||
let (exit, poh_recorder, poh_service, _entry_receiver) =
|
let (exit, poh_recorder, poh_service, _entry_receiver) =
|
||||||
|
|
|
@ -97,7 +97,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
solana_perf::packet::to_packet_batches,
|
solana_perf::packet::to_packet_batches,
|
||||||
solana_poh::poh_recorder::{PohRecorder, WorkingBankEntry},
|
solana_poh::poh_recorder::{PohRecorder, WorkingBankEntry},
|
||||||
solana_runtime::{bank::Bank, bank_forks::BankForks},
|
solana_runtime::bank::Bank,
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
genesis_config::GenesisConfig, poh_config::PohConfig, pubkey::Pubkey,
|
genesis_config::GenesisConfig, poh_config::PohConfig, pubkey::Pubkey,
|
||||||
signature::Keypair, system_transaction,
|
signature::Keypair, system_transaction,
|
||||||
|
@ -128,9 +128,7 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_slow_genesis_config(10_000);
|
} = create_slow_genesis_config(10_000);
|
||||||
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
|
let (bank, bank_forks) = 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 ledger_path = get_tmp_ledger_path_auto_delete!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
let blockstore = Blockstore::open(ledger_path.path())
|
let blockstore = Blockstore::open(ledger_path.path())
|
||||||
|
|
|
@ -306,9 +306,7 @@ mod tests {
|
||||||
create_slow_genesis_config_with_leader(10_000, &validator_keypair.pubkey());
|
create_slow_genesis_config_with_leader(10_000, &validator_keypair.pubkey());
|
||||||
let GenesisConfigInfo { genesis_config, .. } = &genesis_config_info;
|
let GenesisConfigInfo { genesis_config, .. } = &genesis_config_info;
|
||||||
|
|
||||||
let bank: Bank = Bank::new_no_wallclock_throttle_for_tests(genesis_config);
|
let (bank, bank_forks) = 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 ledger_path = TempDir::new().unwrap();
|
let ledger_path = TempDir::new().unwrap();
|
||||||
let blockstore = Arc::new(
|
let blockstore = Arc::new(
|
||||||
|
|
|
@ -173,7 +173,7 @@ mod tests {
|
||||||
|
|
||||||
fn create_test_bank() -> Arc<Bank> {
|
fn create_test_bank() -> Arc<Bank> {
|
||||||
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
|
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).
|
// Helper function (could potentially use test_case in future).
|
||||||
|
|
|
@ -529,7 +529,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
solana_perf::packet::{to_packet_batches, PacketBatch, NUM_PACKETS},
|
solana_perf::packet::{to_packet_batches, PacketBatch, NUM_PACKETS},
|
||||||
solana_poh::poh_recorder::{PohRecorder, Record, WorkingBankEntry},
|
solana_poh::poh_recorder::{PohRecorder, Record, WorkingBankEntry},
|
||||||
solana_runtime::{bank::Bank, bank_forks::BankForks},
|
solana_runtime::bank::Bank,
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
compute_budget::ComputeBudgetInstruction, hash::Hash, message::Message,
|
compute_budget::ComputeBudgetInstruction, hash::Hash, message::Message,
|
||||||
poh_config::PohConfig, pubkey::Pubkey, signature::Keypair, signer::Signer,
|
poh_config::PohConfig, pubkey::Pubkey, signature::Keypair, signer::Signer,
|
||||||
|
@ -561,9 +561,7 @@ mod tests {
|
||||||
|
|
||||||
fn create_test_frame(num_threads: usize) -> (TestFrame, SchedulerController) {
|
fn create_test_frame(num_threads: usize) -> (TestFrame, SchedulerController) {
|
||||||
let GenesisConfigInfo { genesis_config, .. } = create_slow_genesis_config(10_000);
|
let GenesisConfigInfo { genesis_config, .. } = create_slow_genesis_config(10_000);
|
||||||
let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
|
let (bank, bank_forks) = 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 ledger_path = get_tmp_ledger_path_auto_delete!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
let blockstore = Blockstore::open(ledger_path.path())
|
let blockstore = Blockstore::open(ledger_path.path())
|
||||||
|
|
|
@ -1014,7 +1014,7 @@ mod tests {
|
||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_genesis_config(10);
|
} = 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)
|
let simple_transactions: Vec<Transaction> = (0..256)
|
||||||
.map(|_id| {
|
.map(|_id| {
|
||||||
|
|
|
@ -5018,7 +5018,7 @@ pub(crate) mod tests {
|
||||||
let keypair2 = Keypair::new();
|
let keypair2 = Keypair::new();
|
||||||
let keypair3 = 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
|
bank0
|
||||||
.transfer(
|
.transfer(
|
||||||
bank0.get_minimum_balance_for_rent_exemption(0),
|
bank0.get_minimum_balance_for_rent_exemption(0),
|
||||||
|
@ -5027,7 +5027,11 @@ pub(crate) mod tests {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.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 slot = bank1.slot();
|
||||||
|
|
||||||
let (entries, test_signatures) = create_test_transaction_entries(
|
let (entries, test_signatures) = create_test_transaction_entries(
|
||||||
|
|
|
@ -357,7 +357,7 @@ pub fn initialize_state(
|
||||||
);
|
);
|
||||||
|
|
||||||
genesis_config.poh_config.hashes_per_tick = Some(2);
|
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() {
|
for pubkey in validator_keypairs_map.keys() {
|
||||||
bank0.transfer(10_000, &mint_keypair, pubkey).unwrap();
|
bank0.transfer(10_000, &mint_keypair, pubkey).unwrap();
|
||||||
|
@ -372,7 +372,6 @@ pub fn initialize_state(
|
||||||
0,
|
0,
|
||||||
ForkProgress::new_from_bank(&bank0, bank0.collector_id(), &Pubkey::default(), None, 0, 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 =
|
let heaviest_subtree_fork_choice =
|
||||||
HeaviestSubtreeForkChoice::new_from_bank_forks(bank_forks.clone());
|
HeaviestSubtreeForkChoice::new_from_bank_forks(bank_forks.clone());
|
||||||
(bank_forks, progress, heaviest_subtree_fork_choice)
|
(bank_forks, progress, heaviest_subtree_fork_choice)
|
||||||
|
|
|
@ -17,6 +17,9 @@ reqwest = { workspace = true, features = ["blocking", "brotli", "deflate", "gzip
|
||||||
solana-runtime = { workspace = true }
|
solana-runtime = { workspace = true }
|
||||||
solana-sdk = { workspace = true }
|
solana-sdk = { workspace = true }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["lib"]
|
crate-type = ["lib"]
|
||||||
name = "solana_download_utils"
|
name = "solana_download_utils"
|
||||||
|
|
|
@ -30,6 +30,9 @@ solana-version = { workspace = true }
|
||||||
solana-vote-program = { workspace = true }
|
solana-vote-program = { workspace = true }
|
||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "solana-genesis"
|
name = "solana-genesis"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
|
@ -55,6 +55,7 @@ thiserror = { workspace = true }
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
num_cpus = { workspace = true }
|
num_cpus = { workspace = true }
|
||||||
serial_test = { workspace = true }
|
serial_test = { workspace = true }
|
||||||
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
test-case = { workspace = true }
|
test-case = { workspace = true }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|
|
@ -28,6 +28,7 @@ rand = { workspace = true }
|
||||||
solana-logger = { workspace = true }
|
solana-logger = { workspace = true }
|
||||||
solana-perf = { workspace = true }
|
solana-perf = { workspace = true }
|
||||||
solana-poh = { path = ".", features = ["dev-context-only-utils"] }
|
solana-poh = { path = ".", features = ["dev-context-only-utils"] }
|
||||||
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
dev-context-only-utils = []
|
dev-context-only-utils = []
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
//! For Entries:
|
//! For Entries:
|
||||||
//! * recorded entry must be >= WorkingBank::min_tick_height && entry must be < WorkingBank::max_tick_height
|
//! * recorded entry must be >= WorkingBank::min_tick_height && entry must be < WorkingBank::max_tick_height
|
||||||
//!
|
//!
|
||||||
|
#[cfg(feature = "dev-context-only-utils")]
|
||||||
|
use solana_ledger::genesis_utils::{create_genesis_config, GenesisConfigInfo};
|
||||||
use {
|
use {
|
||||||
crate::{leader_bank_notifier::LeaderBankNotifier, poh_service::PohService},
|
crate::{leader_bank_notifier::LeaderBankNotifier, poh_service::PohService},
|
||||||
crossbeam_channel::{unbounded, Receiver, RecvTimeoutError, SendError, Sender, TrySendError},
|
crossbeam_channel::{unbounded, Receiver, RecvTimeoutError, SendError, Sender, TrySendError},
|
||||||
|
@ -18,11 +20,7 @@ use {
|
||||||
entry::{hash_transactions, Entry},
|
entry::{hash_transactions, Entry},
|
||||||
poh::Poh,
|
poh::Poh,
|
||||||
},
|
},
|
||||||
solana_ledger::{
|
solana_ledger::{blockstore::Blockstore, leader_schedule_cache::LeaderScheduleCache},
|
||||||
blockstore::Blockstore,
|
|
||||||
genesis_utils::{create_genesis_config, GenesisConfigInfo},
|
|
||||||
leader_schedule_cache::LeaderScheduleCache,
|
|
||||||
},
|
|
||||||
solana_measure::{measure, measure_us},
|
solana_measure::{measure, measure_us},
|
||||||
solana_metrics::poh_timing_point::{send_poh_timing_point, PohTimingSender, SlotPohTimingInfo},
|
solana_metrics::poh_timing_point::{send_poh_timing_point, PohTimingSender, SlotPohTimingInfo},
|
||||||
solana_runtime::{bank::Bank, installed_scheduler_pool::BankWithScheduler},
|
solana_runtime::{bank::Bank, installed_scheduler_pool::BankWithScheduler},
|
||||||
|
@ -1053,6 +1051,7 @@ impl PohRecorder {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used in tests
|
// Used in tests
|
||||||
|
#[cfg(feature = "dev-context-only-utils")]
|
||||||
pub fn schedule_dummy_max_height_reached_failure(&mut self) {
|
pub fn schedule_dummy_max_height_reached_failure(&mut self) {
|
||||||
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2);
|
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2);
|
||||||
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
|
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
|
||||||
|
|
|
@ -402,7 +402,7 @@ mod tests {
|
||||||
fn test_poh_service() {
|
fn test_poh_service() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2);
|
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2);
|
||||||
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 prev_hash = bank.last_blockhash();
|
let prev_hash = bank.last_blockhash();
|
||||||
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
let blockstore = Blockstore::open(ledger_path.path())
|
let blockstore = Blockstore::open(ledger_path.path())
|
||||||
|
|
|
@ -91,7 +91,7 @@ solana-cli-output = { workspace = true }
|
||||||
solana-logger = { workspace = true }
|
solana-logger = { workspace = true }
|
||||||
solana-measure = { workspace = true }
|
solana-measure = { workspace = true }
|
||||||
solana-program-runtime = { workspace = true }
|
solana-program-runtime = { workspace = true }
|
||||||
solana-runtime = { workspace = true }
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
solana-sbf-rust-invoke = { workspace = true }
|
solana-sbf-rust-invoke = { workspace = true }
|
||||||
solana-sbf-rust-realloc = { workspace = true, features = ["default"] }
|
solana-sbf-rust-realloc = { workspace = true, features = ["default"] }
|
||||||
solana-sbf-rust-realloc-invoke = { workspace = true }
|
solana-sbf-rust-realloc-invoke = { workspace = true }
|
||||||
|
|
|
@ -63,6 +63,7 @@ tokio-util = { workspace = true, features = ["codec", "compat"] }
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serial_test = { workspace = true }
|
serial_test = { workspace = true }
|
||||||
solana-net-utils = { workspace = true }
|
solana-net-utils = { workspace = true }
|
||||||
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
solana-stake-program = { workspace = true }
|
solana-stake-program = { workspace = true }
|
||||||
spl-pod = { workspace = true }
|
spl-pod = { workspace = true }
|
||||||
symlink = { workspace = true }
|
symlink = { workspace = true }
|
||||||
|
|
|
@ -336,7 +336,7 @@ pub(crate) mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_notify_transaction() {
|
fn test_notify_transaction() {
|
||||||
let genesis_config = create_genesis_config(2).genesis_config;
|
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 (transaction_status_sender, transaction_status_receiver) = unbounded();
|
let (transaction_status_sender, transaction_status_receiver) = unbounded();
|
||||||
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
|
|
|
@ -966,57 +966,10 @@ pub(super) enum RewardInterval {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bank {
|
impl Bank {
|
||||||
pub(super) fn wrap_with_bank_forks_for_tests(self) -> (Arc<Self>, Arc<RwLock<BankForks>>) {
|
|
||||||
let bank_fork = BankForks::new_rw_arc(self);
|
|
||||||
let bank_arc = bank_fork.read().unwrap().root_bank();
|
|
||||||
bank_arc
|
|
||||||
.loaded_programs_cache
|
|
||||||
.write()
|
|
||||||
.unwrap()
|
|
||||||
.set_fork_graph(bank_fork.clone());
|
|
||||||
(bank_arc, bank_fork)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn default_for_tests() -> Self {
|
|
||||||
Self::default_with_accounts(Accounts::default_for_tests())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_for_benches(genesis_config: &GenesisConfig) -> Self {
|
pub fn new_for_benches(genesis_config: &GenesisConfig) -> Self {
|
||||||
Self::new_with_paths_for_benches(genesis_config, Vec::new())
|
Self::new_with_paths_for_benches(genesis_config, Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_for_tests(genesis_config: &GenesisConfig) -> Self {
|
|
||||||
Self::new_for_tests_with_config(genesis_config, BankTestConfig::default())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_with_bank_forks_for_tests(
|
|
||||||
genesis_config: &GenesisConfig,
|
|
||||||
) -> (Arc<Self>, Arc<RwLock<BankForks>>) {
|
|
||||||
let bank = Self::new_for_tests(genesis_config);
|
|
||||||
bank.wrap_with_bank_forks_for_tests()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_with_mockup_builtin_for_tests(
|
|
||||||
genesis_config: &GenesisConfig,
|
|
||||||
program_id: Pubkey,
|
|
||||||
builtin_function: BuiltinFunctionWithContext,
|
|
||||||
) -> (Arc<Self>, Arc<RwLock<BankForks>>) {
|
|
||||||
let mut bank = Self::new_for_tests(genesis_config);
|
|
||||||
bank.add_mockup_builtin(program_id, builtin_function);
|
|
||||||
bank.wrap_with_bank_forks_for_tests()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_for_tests_with_config(
|
|
||||||
genesis_config: &GenesisConfig,
|
|
||||||
test_config: BankTestConfig,
|
|
||||||
) -> Self {
|
|
||||||
Self::new_with_config_for_tests(
|
|
||||||
genesis_config,
|
|
||||||
test_config.secondary_indexes,
|
|
||||||
AccountShrinkThreshold::default(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Intended for use by tests only.
|
/// Intended for use by tests only.
|
||||||
/// create new bank with the given configs.
|
/// create new bank with the given configs.
|
||||||
pub fn new_with_runtime_config_for_tests(
|
pub fn new_with_runtime_config_for_tests(
|
||||||
|
@ -1032,27 +985,6 @@ impl Bank {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_no_wallclock_throttle_for_tests(genesis_config: &GenesisConfig) -> Self {
|
|
||||||
let mut bank = Self::new_for_tests(genesis_config);
|
|
||||||
|
|
||||||
bank.ns_per_slot = std::u128::MAX;
|
|
||||||
bank
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn new_with_config_for_tests(
|
|
||||||
genesis_config: &GenesisConfig,
|
|
||||||
account_indexes: AccountSecondaryIndexes,
|
|
||||||
shrink_ratio: AccountShrinkThreshold,
|
|
||||||
) -> Self {
|
|
||||||
Self::new_with_paths_for_tests(
|
|
||||||
genesis_config,
|
|
||||||
Arc::new(RuntimeConfig::default()),
|
|
||||||
Vec::new(),
|
|
||||||
account_indexes,
|
|
||||||
shrink_ratio,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn default_with_accounts(accounts: Accounts) -> Self {
|
fn default_with_accounts(accounts: Accounts) -> Self {
|
||||||
let mut bank = Self {
|
let mut bank = Self {
|
||||||
skipped_rewrites: Mutex::default(),
|
skipped_rewrites: Mutex::default(),
|
||||||
|
@ -4314,20 +4246,6 @@ impl Bank {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prepare a transaction batch from a list of legacy transactions. Used for tests only.
|
|
||||||
pub fn prepare_batch_for_tests(&self, txs: Vec<Transaction>) -> TransactionBatch {
|
|
||||||
let transaction_account_lock_limit = self.get_transaction_account_lock_limit();
|
|
||||||
let sanitized_txs = txs
|
|
||||||
.into_iter()
|
|
||||||
.map(SanitizedTransaction::from_transaction_for_tests)
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
let lock_results = self
|
|
||||||
.rc
|
|
||||||
.accounts
|
|
||||||
.lock_accounts(sanitized_txs.iter(), transaction_account_lock_limit);
|
|
||||||
TransactionBatch::new(lock_results, self, Cow::Owned(sanitized_txs))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Prepare a transaction batch from a list of versioned transactions from
|
/// Prepare a transaction batch from a list of versioned transactions from
|
||||||
/// an entry. Used for tests only.
|
/// an entry. Used for tests only.
|
||||||
pub fn prepare_entry_batch(&self, txs: Vec<VersionedTransaction>) -> Result<TransactionBatch> {
|
pub fn prepare_entry_batch(&self, txs: Vec<VersionedTransaction>) -> Result<TransactionBatch> {
|
||||||
|
@ -5561,18 +5479,6 @@ impl Bank {
|
||||||
self.update_accounts_data_size_delta_off_chain(data_size_delta);
|
self.update_accounts_data_size_delta_off_chain(data_size_delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the initial accounts data size
|
|
||||||
/// NOTE: This fn is *ONLY FOR TESTS*
|
|
||||||
pub fn set_accounts_data_size_initial_for_tests(&mut self, amount: u64) {
|
|
||||||
self.accounts_data_size_initial = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Update the accounts data size off-chain delta
|
|
||||||
/// NOTE: This fn is *ONLY FOR TESTS*
|
|
||||||
pub fn update_accounts_data_size_delta_off_chain_for_tests(&self, amount: i64) {
|
|
||||||
self.update_accounts_data_size_delta_off_chain(amount)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn filter_program_errors_and_collect_fee(
|
fn filter_program_errors_and_collect_fee(
|
||||||
&self,
|
&self,
|
||||||
txs: &[SanitizedTransaction],
|
txs: &[SanitizedTransaction],
|
||||||
|
@ -5880,11 +5786,6 @@ impl Bank {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
fn restore_old_behavior_for_fragile_tests(&self) {
|
|
||||||
self.lazy_rent_collection.store(true, Relaxed);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rent_collection_partitions(&self) -> Vec<Partition> {
|
fn rent_collection_partitions(&self) -> Vec<Partition> {
|
||||||
if !self.use_fixed_collection_cycle() {
|
if !self.use_fixed_collection_cycle() {
|
||||||
// This mode is for production/development/testing.
|
// This mode is for production/development/testing.
|
||||||
|
@ -6447,19 +6348,6 @@ impl Bank {
|
||||||
execution_results.remove(0)
|
execution_results.remove(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process multiple transaction in a single batch. This is used for benches and unit tests.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// Panics if any of the transactions do not pass sanitization checks.
|
|
||||||
#[must_use]
|
|
||||||
pub fn process_transactions<'a>(
|
|
||||||
&self,
|
|
||||||
txs: impl Iterator<Item = &'a Transaction>,
|
|
||||||
) -> Vec<Result<()>> {
|
|
||||||
self.try_process_transactions(txs).unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Process multiple transaction in a single batch. This is used for benches and unit tests.
|
/// Process multiple transaction in a single batch. This is used for benches and unit tests.
|
||||||
/// Short circuits if any of the transactions do not pass sanitization checks.
|
/// Short circuits if any of the transactions do not pass sanitization checks.
|
||||||
pub fn try_process_transactions<'a>(
|
pub fn try_process_transactions<'a>(
|
||||||
|
@ -6472,16 +6360,6 @@ impl Bank {
|
||||||
self.try_process_entry_transactions(txs)
|
self.try_process_entry_transactions(txs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process entry transactions in a single batch. This is used for benches and unit tests.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// Panics if any of the transactions do not pass sanitization checks.
|
|
||||||
#[must_use]
|
|
||||||
pub fn process_entry_transactions(&self, txs: Vec<VersionedTransaction>) -> Vec<Result<()>> {
|
|
||||||
self.try_process_entry_transactions(txs).unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Process multiple transaction in a single batch. This is used for benches and unit tests.
|
/// Process multiple transaction in a single batch. This is used for benches and unit tests.
|
||||||
/// Short circuits if any of the transactions do not pass sanitization checks.
|
/// Short circuits if any of the transactions do not pass sanitization checks.
|
||||||
pub fn try_process_entry_transactions(
|
pub fn try_process_entry_transactions(
|
||||||
|
@ -6594,14 +6472,6 @@ impl Bank {
|
||||||
.flush_accounts_cache(false, Some(self.slot()))
|
.flush_accounts_cache(false, Some(self.slot()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub fn flush_accounts_cache_slot_for_tests(&self) {
|
|
||||||
self.rc
|
|
||||||
.accounts
|
|
||||||
.accounts_db
|
|
||||||
.flush_accounts_cache_slot_for_tests(self.slot())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn expire_old_recycle_stores(&self) {
|
pub fn expire_old_recycle_stores(&self) {
|
||||||
self.rc.accounts.accounts_db.expire_old_recycle_stores()
|
self.rc.accounts.accounts_db.expire_old_recycle_stores()
|
||||||
}
|
}
|
||||||
|
@ -7258,16 +7128,6 @@ impl Bank {
|
||||||
.check_complete()
|
.check_complete()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is only valid to call from tests.
|
|
||||||
/// block until initial accounts hash verification has completed
|
|
||||||
pub fn wait_for_initial_accounts_hash_verification_completed_for_tests(&self) {
|
|
||||||
self.rc
|
|
||||||
.accounts
|
|
||||||
.accounts_db
|
|
||||||
.verify_accounts_hash_in_bg
|
|
||||||
.wait_for_complete()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get this bank's storages to use for snapshots.
|
/// Get this bank's storages to use for snapshots.
|
||||||
///
|
///
|
||||||
/// If a base slot is provided, return only the storages that are *higher* than this slot.
|
/// If a base slot is provided, return only the storages that are *higher* than this slot.
|
||||||
|
@ -7507,10 +7367,6 @@ impl Bank {
|
||||||
accounts_hash
|
accounts_hash
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_accounts_hash_for_tests(&self) -> AccountsHash {
|
|
||||||
self.update_accounts_hash(CalcAccountsHashDataSource::IndexForTests, false, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Calculate the incremental accounts hash from `base_slot` to `self`
|
/// Calculate the incremental accounts hash from `base_slot` to `self`
|
||||||
pub fn update_incremental_accounts_hash(&self, base_slot: Slot) -> IncrementalAccountsHash {
|
pub fn update_incremental_accounts_hash(&self, base_slot: Slot) -> IncrementalAccountsHash {
|
||||||
let config = CalcAccountsHashConfig {
|
let config = CalcAccountsHashConfig {
|
||||||
|
@ -8278,6 +8134,155 @@ impl Bank {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "dev-context-only-utils")]
|
||||||
|
impl Bank {
|
||||||
|
pub fn wrap_with_bank_forks_for_tests(self) -> (Arc<Self>, Arc<RwLock<BankForks>>) {
|
||||||
|
let bank_fork = BankForks::new_rw_arc(self);
|
||||||
|
let bank_arc = bank_fork.read().unwrap().root_bank();
|
||||||
|
bank_arc
|
||||||
|
.loaded_programs_cache
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.set_fork_graph(bank_fork.clone());
|
||||||
|
(bank_arc, bank_fork)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn default_for_tests() -> Self {
|
||||||
|
Self::default_with_accounts(Accounts::default_for_tests())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_with_bank_forks_for_tests(
|
||||||
|
genesis_config: &GenesisConfig,
|
||||||
|
) -> (Arc<Self>, Arc<RwLock<BankForks>>) {
|
||||||
|
let bank = Self::new_for_tests(genesis_config);
|
||||||
|
bank.wrap_with_bank_forks_for_tests()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_for_tests(genesis_config: &GenesisConfig) -> Self {
|
||||||
|
Self::new_for_tests_with_config(genesis_config, BankTestConfig::default())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_with_mockup_builtin_for_tests(
|
||||||
|
genesis_config: &GenesisConfig,
|
||||||
|
program_id: Pubkey,
|
||||||
|
builtin_function: BuiltinFunctionWithContext,
|
||||||
|
) -> (Arc<Self>, Arc<RwLock<BankForks>>) {
|
||||||
|
let mut bank = Self::new_for_tests(genesis_config);
|
||||||
|
bank.add_mockup_builtin(program_id, builtin_function);
|
||||||
|
bank.wrap_with_bank_forks_for_tests()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_for_tests_with_config(
|
||||||
|
genesis_config: &GenesisConfig,
|
||||||
|
test_config: BankTestConfig,
|
||||||
|
) -> Self {
|
||||||
|
Self::new_with_config_for_tests(
|
||||||
|
genesis_config,
|
||||||
|
test_config.secondary_indexes,
|
||||||
|
AccountShrinkThreshold::default(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_no_wallclock_throttle_for_tests(
|
||||||
|
genesis_config: &GenesisConfig,
|
||||||
|
) -> (Arc<Self>, Arc<RwLock<BankForks>>) {
|
||||||
|
let mut bank = Self::new_for_tests(genesis_config);
|
||||||
|
|
||||||
|
bank.ns_per_slot = std::u128::MAX;
|
||||||
|
bank.wrap_with_bank_forks_for_tests()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn new_with_config_for_tests(
|
||||||
|
genesis_config: &GenesisConfig,
|
||||||
|
account_indexes: AccountSecondaryIndexes,
|
||||||
|
shrink_ratio: AccountShrinkThreshold,
|
||||||
|
) -> Self {
|
||||||
|
Self::new_with_paths_for_tests(
|
||||||
|
genesis_config,
|
||||||
|
Arc::new(RuntimeConfig::default()),
|
||||||
|
Vec::new(),
|
||||||
|
account_indexes,
|
||||||
|
shrink_ratio,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Prepare a transaction batch from a list of legacy transactions. Used for tests only.
|
||||||
|
pub fn prepare_batch_for_tests(&self, txs: Vec<Transaction>) -> TransactionBatch {
|
||||||
|
let transaction_account_lock_limit = self.get_transaction_account_lock_limit();
|
||||||
|
let sanitized_txs = txs
|
||||||
|
.into_iter()
|
||||||
|
.map(SanitizedTransaction::from_transaction_for_tests)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let lock_results = self
|
||||||
|
.rc
|
||||||
|
.accounts
|
||||||
|
.lock_accounts(sanitized_txs.iter(), transaction_account_lock_limit);
|
||||||
|
TransactionBatch::new(lock_results, self, Cow::Owned(sanitized_txs))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the initial accounts data size
|
||||||
|
/// NOTE: This fn is *ONLY FOR TESTS*
|
||||||
|
pub fn set_accounts_data_size_initial_for_tests(&mut self, amount: u64) {
|
||||||
|
self.accounts_data_size_initial = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the accounts data size off-chain delta
|
||||||
|
/// NOTE: This fn is *ONLY FOR TESTS*
|
||||||
|
pub fn update_accounts_data_size_delta_off_chain_for_tests(&self, amount: i64) {
|
||||||
|
self.update_accounts_data_size_delta_off_chain(amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
fn restore_old_behavior_for_fragile_tests(&self) {
|
||||||
|
self.lazy_rent_collection.store(true, Relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Process multiple transaction in a single batch. This is used for benches and unit tests.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if any of the transactions do not pass sanitization checks.
|
||||||
|
#[must_use]
|
||||||
|
pub fn process_transactions<'a>(
|
||||||
|
&self,
|
||||||
|
txs: impl Iterator<Item = &'a Transaction>,
|
||||||
|
) -> Vec<Result<()>> {
|
||||||
|
self.try_process_transactions(txs).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Process entry transactions in a single batch. This is used for benches and unit tests.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if any of the transactions do not pass sanitization checks.
|
||||||
|
#[must_use]
|
||||||
|
pub fn process_entry_transactions(&self, txs: Vec<VersionedTransaction>) -> Vec<Result<()>> {
|
||||||
|
self.try_process_entry_transactions(txs).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn flush_accounts_cache_slot_for_tests(&self) {
|
||||||
|
self.rc
|
||||||
|
.accounts
|
||||||
|
.accounts_db
|
||||||
|
.flush_accounts_cache_slot_for_tests(self.slot())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This is only valid to call from tests.
|
||||||
|
/// block until initial accounts hash verification has completed
|
||||||
|
pub fn wait_for_initial_accounts_hash_verification_completed_for_tests(&self) {
|
||||||
|
self.rc
|
||||||
|
.accounts
|
||||||
|
.accounts_db
|
||||||
|
.verify_accounts_hash_in_bg
|
||||||
|
.wait_for_complete()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_accounts_hash_for_tests(&self) -> AccountsHash {
|
||||||
|
self.update_accounts_hash(CalcAccountsHashDataSource::IndexForTests, false, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Compute how much an account has changed size. This function is useful when the data size delta
|
/// Compute how much an account has changed size. This function is useful when the data size delta
|
||||||
/// needs to be computed and passed to an `update_accounts_data_size_delta` function.
|
/// needs to be computed and passed to an `update_accounts_data_size_delta` function.
|
||||||
fn calculate_data_size_delta(old_data_size: usize, new_data_size: usize) -> i64 {
|
fn calculate_data_size_delta(old_data_size: usize, new_data_size: usize) -> i64 {
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
|
#[cfg(feature = "dev-context-only-utils")]
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
bank::Bank,
|
bank::Bank,
|
||||||
genesis_utils::{self, GenesisConfigInfo, ValidatorVoteKeypairs},
|
genesis_utils::{self, GenesisConfigInfo, ValidatorVoteKeypairs},
|
||||||
},
|
},
|
||||||
|
solana_sdk::{pubkey::Pubkey, signature::Signer},
|
||||||
|
};
|
||||||
|
use {
|
||||||
solana_accounts_db::transaction_results::TransactionResults,
|
solana_accounts_db::transaction_results::TransactionResults,
|
||||||
solana_sdk::{pubkey::Pubkey, signature::Signer, transaction::SanitizedTransaction},
|
solana_sdk::transaction::SanitizedTransaction,
|
||||||
solana_vote::{vote_parser, vote_sender_types::ReplayVoteSender},
|
solana_vote::{vote_parser, vote_sender_types::ReplayVoteSender},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "dev-context-only-utils")]
|
||||||
pub fn setup_bank_and_vote_pubkeys_for_tests(
|
pub fn setup_bank_and_vote_pubkeys_for_tests(
|
||||||
num_vote_accounts: usize,
|
num_vote_accounts: usize,
|
||||||
stake: u64,
|
stake: u64,
|
||||||
|
|
|
@ -259,6 +259,7 @@ impl BankWithScheduler {
|
||||||
self.inner.bank.register_tick(hash, &self.inner.scheduler);
|
self.inner.bank.register_tick(hash, &self.inner.scheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "dev-context-only-utils")]
|
||||||
pub fn fill_bank_with_ticks_for_tests(&self) {
|
pub fn fill_bank_with_ticks_for_tests(&self) {
|
||||||
self.do_fill_bank_with_ticks_for_tests(&self.inner.scheduler);
|
self.do_fill_bank_with_ticks_for_tests(&self.inner.scheduler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1193,6 +1193,7 @@ pub fn package_and_archive_incremental_snapshot(
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "dev-context-only-utils")]
|
||||||
pub fn create_snapshot_dirs_for_tests(
|
pub fn create_snapshot_dirs_for_tests(
|
||||||
genesis_config: &GenesisConfig,
|
genesis_config: &GenesisConfig,
|
||||||
bank_snapshots_dir: impl AsRef<Path>,
|
bank_snapshots_dir: impl AsRef<Path>,
|
||||||
|
|
|
@ -27,6 +27,7 @@ tar = { workspace = true }
|
||||||
assert_cmd = { workspace = true }
|
assert_cmd = { workspace = true }
|
||||||
predicates = { workspace = true }
|
predicates = { workspace = true }
|
||||||
serial_test = { workspace = true }
|
serial_test = { workspace = true }
|
||||||
|
solana-sdk = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
program = []
|
program = []
|
||||||
|
|
|
@ -21,6 +21,7 @@ solana-tpu-client = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
solana-logger = { workspace = true }
|
solana-logger = { workspace = true }
|
||||||
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
|
|
@ -21,7 +21,7 @@ solana-stake-program = { workspace = true }
|
||||||
solana-version = { workspace = true }
|
solana-version = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
solana-runtime = { workspace = true }
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
|
|
@ -43,6 +43,7 @@ tokio = { workspace = true }
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_matches = { workspace = true }
|
assert_matches = { workspace = true }
|
||||||
solana-logger = { workspace = true }
|
solana-logger = { workspace = true }
|
||||||
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "cluster_info"
|
name = "cluster_info"
|
||||||
|
|
|
@ -67,6 +67,7 @@ thiserror = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
solana-account-decoder = { workspace = true }
|
solana-account-decoder = { workspace = true }
|
||||||
|
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
spl-token-2022 = { workspace = true, features = ["no-entrypoint"] }
|
spl-token-2022 = { workspace = true, features = ["no-entrypoint"] }
|
||||||
|
|
||||||
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
||||||
|
|
Loading…
Reference in New Issue