Skip to content

Commit

Permalink
local-cluster: Custom genesis size (#2427)
Browse files Browse the repository at this point in the history
Some local-cluster tests may require larger than the default genesis, in
order to speed up the initial test setup.
  • Loading branch information
ilya-bobyr authored Aug 7, 2024
1 parent 15dbe7f commit 6668685
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
35 changes: 29 additions & 6 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ use {
rand::Rng,
rayon::iter::{IntoParallelIterator, ParallelIterator},
rocksdb::{DBRawIterator, LiveFile},
solana_accounts_db::hardened_unpack::{
unpack_genesis_archive, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
},
solana_accounts_db::hardened_unpack::unpack_genesis_archive,
solana_entry::entry::{create_ticks, Entry},
solana_measure::measure::Measure,
solana_metrics::{
Expand Down Expand Up @@ -4963,6 +4961,22 @@ macro_rules! create_new_tmp_ledger {
$crate::blockstore::create_new_ledger_from_name(
$crate::tmp_ledger_name!(),
$genesis_config,
$crate::macro_reexports::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
$crate::blockstore_options::LedgerColumnOptions::default(),
)
};
}

#[macro_export]
macro_rules! create_new_tmp_ledger_with_size {
(
$genesis_config:expr,
$max_genesis_archive_unpacked_size:expr $(,)?
) => {
$crate::blockstore::create_new_ledger_from_name(
$crate::tmp_ledger_name!(),
$genesis_config,
$max_genesis_archive_unpacked_size,
$crate::blockstore_options::LedgerColumnOptions::default(),
)
};
Expand All @@ -4974,6 +4988,7 @@ macro_rules! create_new_tmp_ledger_fifo {
$crate::blockstore::create_new_ledger_from_name(
$crate::tmp_ledger_name!(),
$genesis_config,
$crate::macro_reexports::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
$crate::blockstore_options::LedgerColumnOptions {
shred_storage_type: $crate::blockstore_options::ShredStorageType::RocksFifo(
$crate::blockstore_options::BlockstoreRocksFifoOptions::new_for_tests(),
Expand All @@ -4990,6 +5005,7 @@ macro_rules! create_new_tmp_ledger_auto_delete {
$crate::blockstore::create_new_ledger_from_name_auto_delete(
$crate::tmp_ledger_name!(),
$genesis_config,
$crate::macro_reexports::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
$crate::blockstore_options::LedgerColumnOptions::default(),
)
};
Expand All @@ -5001,6 +5017,7 @@ macro_rules! create_new_tmp_ledger_fifo_auto_delete {
$crate::blockstore::create_new_ledger_from_name_auto_delete(
$crate::tmp_ledger_name!(),
$genesis_config,
$crate::macro_reexports::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
$crate::blockstore_options::LedgerColumnOptions {
shred_storage_type: $crate::blockstore_options::ShredStorageType::RocksFifo(
$crate::blockstore_options::BlockstoreRocksFifoOptions::new_for_tests(),
Expand All @@ -5027,10 +5044,15 @@ pub(crate) fn verify_shred_slots(slot: Slot, parent: Slot, root: Slot) -> bool {
pub fn create_new_ledger_from_name(
name: &str,
genesis_config: &GenesisConfig,
max_genesis_archive_unpacked_size: u64,
column_options: LedgerColumnOptions,
) -> (PathBuf, Hash) {
let (ledger_path, blockhash) =
create_new_ledger_from_name_auto_delete(name, genesis_config, column_options);
let (ledger_path, blockhash) = create_new_ledger_from_name_auto_delete(
name,
genesis_config,
max_genesis_archive_unpacked_size,
column_options,
);
(ledger_path.into_path(), blockhash)
}

Expand All @@ -5041,13 +5063,14 @@ pub fn create_new_ledger_from_name(
pub fn create_new_ledger_from_name_auto_delete(
name: &str,
genesis_config: &GenesisConfig,
max_genesis_archive_unpacked_size: u64,
column_options: LedgerColumnOptions,
) -> (TempDir, Hash) {
let ledger_path = get_ledger_path_from_name_auto_delete(name);
let blockhash = create_new_ledger(
ledger_path.path(),
genesis_config,
MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
max_genesis_archive_unpacked_size,
column_options,
)
.unwrap();
Expand Down
5 changes: 5 additions & 0 deletions ledger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ extern crate log;
#[cfg_attr(feature = "frozen-abi", macro_use)]
#[cfg(feature = "frozen-abi")]
extern crate solana_frozen_abi_macro;

#[doc(hidden)]
pub mod macro_reexports {
pub use solana_accounts_db::hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE;
}
15 changes: 11 additions & 4 deletions local-cluster/src/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use {
contact_info::{ContactInfo, Protocol},
gossip_service::discover_cluster,
},
solana_ledger::{create_new_tmp_ledger, shred::Shred},
solana_ledger::{create_new_tmp_ledger_with_size, shred::Shred},
solana_rpc_client::rpc_client::RpcClient,
solana_runtime::{
genesis_utils::{
Expand Down Expand Up @@ -312,9 +312,13 @@ impl LocalCluster {
.native_instruction_processors
.extend_from_slice(&config.native_instruction_processors);

let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
let leader_contact_info = leader_node.info.clone();
let mut leader_config = safe_clone_config(&config.validator_configs[0]);
let (leader_ledger_path, _blockhash) = create_new_tmp_ledger_with_size!(
&genesis_config,
leader_config.max_genesis_archive_unpacked_size,
);

let leader_contact_info = leader_node.info.clone();
leader_config.rpc_addrs = Some((
leader_node.info.rpc().unwrap(),
leader_node.info.rpc_pubsub().unwrap(),
Expand Down Expand Up @@ -494,7 +498,10 @@ impl LocalCluster {
let validator_pubkey = validator_keypair.pubkey();
let validator_node = Node::new_localhost_with_pubkey(&validator_keypair.pubkey());
let contact_info = validator_node.info.clone();
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&self.genesis_config);
let (ledger_path, _blockhash) = create_new_tmp_ledger_with_size!(
&self.genesis_config,
validator_config.max_genesis_archive_unpacked_size,
);

// Give the validator some lamports to setup vote accounts
if is_listener {
Expand Down

0 comments on commit 6668685

Please sign in to comment.