Use BankForks on tests - Part 3 (#34248)

* Add BankForks to core tests

* Refactor functions under DCOU
This commit is contained in:
Lucas Steuernagel 2023-12-01 13:47:22 -03:00 committed by GitHub
parent 2294801954
commit b97b3dd4ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 221 additions and 210 deletions

View File

@ -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]

View File

@ -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 }

View File

@ -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"]

View File

@ -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 }

View File

@ -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"]

View File

@ -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,
@ -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();
@ -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();
@ -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();
@ -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 {
@ -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"),
@ -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()
@ -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())
@ -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();

View File

@ -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,
@ -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())

View File

@ -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(),
@ -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(
@ -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 = {
@ -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!();
@ -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();
@ -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()
@ -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()
@ -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();
@ -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();
@ -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();

View File

@ -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) =

View File

@ -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,
@ -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())

View File

@ -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(

View File

@ -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).

View File

@ -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,
@ -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())

View File

@ -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| {

View File

@ -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),
@ -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(

View File

@ -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();
@ -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)

View File

@ -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"

View File

@ -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"

View File

@ -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]

View File

@ -28,6 +28,7 @@ rand = { workspace = true }
solana-logger = { workspace = true }
solana-perf = { workspace = true }
solana-poh = { path = ".", features = ["dev-context-only-utils"] }
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
[features]
dev-context-only-utils = []

View File

@ -10,6 +10,8 @@
//! For Entries:
//! * 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 {
crate::{leader_bank_notifier::LeaderBankNotifier, poh_service::PohService},
crossbeam_channel::{unbounded, Receiver, RecvTimeoutError, SendError, Sender, TrySendError},
@ -18,11 +20,7 @@ use {
entry::{hash_transactions, Entry},
poh::Poh,
},
solana_ledger::{
blockstore::Blockstore,
genesis_utils::{create_genesis_config, GenesisConfigInfo},
leader_schedule_cache::LeaderScheduleCache,
},
solana_ledger::{blockstore::Blockstore, leader_schedule_cache::LeaderScheduleCache},
solana_measure::{measure, measure_us},
solana_metrics::poh_timing_point::{send_poh_timing_point, PohTimingSender, SlotPohTimingInfo},
solana_runtime::{bank::Bank, installed_scheduler_pool::BankWithScheduler},
@ -1053,6 +1051,7 @@ impl PohRecorder {
}
// Used in tests
#[cfg(feature = "dev-context-only-utils")]
pub fn schedule_dummy_max_height_reached_failure(&mut self) {
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2);
let bank = Arc::new(Bank::new_for_tests(&genesis_config));

View File

@ -402,7 +402,7 @@ mod tests {
fn test_poh_service() {
solana_logger::setup();
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 ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore = Blockstore::open(ledger_path.path())

View File

@ -91,7 +91,7 @@ solana-cli-output = { workspace = true }
solana-logger = { workspace = true }
solana-measure = { 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-realloc = { workspace = true, features = ["default"] }
solana-sbf-rust-realloc-invoke = { workspace = true }

View File

@ -63,6 +63,7 @@ tokio-util = { workspace = true, features = ["codec", "compat"] }
[dev-dependencies]
serial_test = { workspace = true }
solana-net-utils = { workspace = true }
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
solana-stake-program = { workspace = true }
spl-pod = { workspace = true }
symlink = { workspace = true }

View File

@ -336,7 +336,7 @@ pub(crate) mod tests {
#[test]
fn test_notify_transaction() {
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 ledger_path = get_tmp_ledger_path_auto_delete!();

View File

@ -966,57 +966,10 @@ pub(super) enum RewardInterval {
}
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 {
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.
/// create new bank with the given configs.
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 {
let mut bank = Self {
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
/// an entry. Used for tests only.
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);
}
/// 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(
&self,
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> {
if !self.use_fixed_collection_cycle() {
// This mode is for production/development/testing.
@ -6447,19 +6348,6 @@ impl Bank {
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.
/// Short circuits if any of the transactions do not pass sanitization checks.
pub fn try_process_transactions<'a>(
@ -6472,16 +6360,6 @@ impl Bank {
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.
/// Short circuits if any of the transactions do not pass sanitization checks.
pub fn try_process_entry_transactions(
@ -6594,14 +6472,6 @@ impl Bank {
.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) {
self.rc.accounts.accounts_db.expire_old_recycle_stores()
}
@ -7258,16 +7128,6 @@ impl Bank {
.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.
///
/// If a base slot is provided, return only the storages that are *higher* than this slot.
@ -7507,10 +7367,6 @@ impl Bank {
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`
pub fn update_incremental_accounts_hash(&self, base_slot: Slot) -> IncrementalAccountsHash {
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
/// 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 {

View File

@ -1,13 +1,18 @@
#[cfg(feature = "dev-context-only-utils")]
use {
crate::{
bank::Bank,
genesis_utils::{self, GenesisConfigInfo, ValidatorVoteKeypairs},
},
solana_sdk::{pubkey::Pubkey, signature::Signer},
};
use {
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},
};
#[cfg(feature = "dev-context-only-utils")]
pub fn setup_bank_and_vote_pubkeys_for_tests(
num_vote_accounts: usize,
stake: u64,

View File

@ -259,6 +259,7 @@ impl BankWithScheduler {
self.inner.bank.register_tick(hash, &self.inner.scheduler);
}
#[cfg(feature = "dev-context-only-utils")]
pub fn fill_bank_with_ticks_for_tests(&self) {
self.do_fill_bank_with_ticks_for_tests(&self.inner.scheduler);
}

View File

@ -1193,6 +1193,7 @@ pub fn package_and_archive_incremental_snapshot(
))
}
#[cfg(feature = "dev-context-only-utils")]
pub fn create_snapshot_dirs_for_tests(
genesis_config: &GenesisConfig,
bank_snapshots_dir: impl AsRef<Path>,

View File

@ -27,6 +27,7 @@ tar = { workspace = true }
assert_cmd = { workspace = true }
predicates = { workspace = true }
serial_test = { workspace = true }
solana-sdk = { workspace = true, features = ["dev-context-only-utils"] }
[features]
program = []

View File

@ -21,6 +21,7 @@ solana-tpu-client = { workspace = true }
[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"]

View File

@ -21,7 +21,7 @@ solana-stake-program = { workspace = true }
solana-version = { workspace = true }
[dev-dependencies]
solana-runtime = { workspace = true }
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

View File

@ -43,6 +43,7 @@ tokio = { workspace = true }
[dev-dependencies]
assert_matches = { workspace = true }
solana-logger = { workspace = true }
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
[[bench]]
name = "cluster_info"

View File

@ -67,6 +67,7 @@ thiserror = { workspace = true }
[dev-dependencies]
solana-account-decoder = { workspace = true }
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
spl-token-2022 = { workspace = true, features = ["no-entrypoint"] }
[target.'cfg(not(target_env = "msvc"))'.dependencies]