Skip to content

Commit

Permalink
local-cluster: Custom genesis size
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 committed Aug 3, 2024
1 parent 3739f5a commit 7dffe72
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 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 @@ -4956,6 +4954,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 @@ -4967,6 +4981,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 @@ -4983,6 +4998,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 @@ -4994,6 +5010,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 @@ -5020,10 +5037,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 @@ -5034,13 +5056,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;
}
12 changes: 9 additions & 3 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,7 +312,10 @@ 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_ledger_path, _blockhash) = create_new_tmp_ledger_with_size!(
&genesis_config,
config.validator_configs[0].max_genesis_archive_unpacked_size,
);
let leader_contact_info = leader_node.info.clone();
let mut leader_config = safe_clone_config(&config.validator_configs[0]);
leader_config.rpc_addrs = Some((
Expand Down Expand Up @@ -494,7 +497,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 7dffe72

Please sign in to comment.