Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LocalCluster - rename, refactor consts, verify initial transfers #4437

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions accounts-cluster-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ pub mod test {
initialize_and_add_secondary_indexes(&mut validator_config);
let num_nodes = 1;
let mut config = ClusterConfig {
cluster_lamports: 10_000_000,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could probably get rid of all these lower values as well...I can't imagine there's anything special about these that require lower mint lamports

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could either do them in this PR, or just up them if these tests fail once fees are added.

mint_lamports: 10_000_000,
poh_config: PohConfig::new_sleep(Duration::from_millis(50)),
node_stakes: vec![100; num_nodes],
validator_configs: make_identical_validator_configs(&validator_config, num_nodes),
Expand Down Expand Up @@ -1482,7 +1482,7 @@ pub mod test {
initialize_and_add_secondary_indexes(&mut validator_config);
let num_nodes = 1;
let mut config = ClusterConfig {
cluster_lamports: 10_000_000,
mint_lamports: 10_000_000,
poh_config: PohConfig::new_sleep(Duration::from_millis(50)),
node_stakes: vec![100; num_nodes],
validator_configs: make_identical_validator_configs(&validator_config, num_nodes),
Expand Down
2 changes: 1 addition & 1 deletion bench-tps/tests/bench_tps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn test_bench_tps_local_cluster(config: Config) {
let cluster = LocalCluster::new(
&mut ClusterConfig {
node_stakes: vec![999_990; NUM_NODES],
cluster_lamports: 200_000_000,
mint_lamports: 200_000_000,
validator_configs: make_identical_validator_configs(
&ValidatorConfig {
rpc_config: JsonRpcConfig {
Expand Down
2 changes: 1 addition & 1 deletion dos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ pub mod test {
let cluster = LocalCluster::new(
&mut ClusterConfig {
node_stakes: vec![999_990; num_nodes],
cluster_lamports: 200_000_000,
mint_lamports: 200_000_000,
validator_configs: make_identical_validator_configs(
&ValidatorConfig {
rpc_config: JsonRpcConfig {
Expand Down
7 changes: 3 additions & 4 deletions local-cluster/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ use {
pub const RUST_LOG_FILTER: &str =
"error,solana_core::replay_stage=warn,solana_local_cluster=info,local_cluster=info";

pub const DEFAULT_CLUSTER_LAMPORTS: u64 = 10_000_000 * LAMPORTS_PER_SOL;
pub const DEFAULT_NODE_STAKE: u64 = 10 * LAMPORTS_PER_SOL;

pub fn last_vote_in_tower(tower_path: &Path, node_pubkey: &Pubkey) -> Option<(Slot, Hash)> {
Expand Down Expand Up @@ -319,7 +318,7 @@ pub fn run_cluster_partition<C>(
.map(|stake_weight| 100 * *stake_weight as u64)
.collect();
assert_eq!(node_stakes.len(), num_nodes);
let cluster_lamports = node_stakes.iter().sum::<u64>() * 2;
let mint_lamports = node_stakes.iter().sum::<u64>() * 2;
let turbine_disabled = Arc::new(AtomicBool::new(false));
let mut validator_config = ValidatorConfig {
turbine_disabled: turbine_disabled.clone(),
Expand Down Expand Up @@ -351,7 +350,7 @@ pub fn run_cluster_partition<C>(

let slots_per_epoch = 2048;
let mut config = ClusterConfig {
cluster_lamports,
mint_lamports,
node_stakes,
validator_configs: make_identical_validator_configs(&validator_config, num_nodes),
validator_keys: Some(
Expand Down Expand Up @@ -490,7 +489,7 @@ pub fn test_faulty_node(
}

let mut cluster_config = ClusterConfig {
cluster_lamports: 10_000,
mint_lamports: 10_000,
node_stakes,
validator_configs,
validator_keys: Some(validator_keys.clone()),
Expand Down
40 changes: 27 additions & 13 deletions local-cluster/src/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use {
epoch_schedule::EpochSchedule,
genesis_config::{ClusterType, GenesisConfig},
message::Message,
native_token::LAMPORTS_PER_SOL,
poh_config::PohConfig,
pubkey::Pubkey,
signature::{Keypair, Signature, Signer},
Expand Down Expand Up @@ -68,6 +69,7 @@ use {
},
};

pub const DEFAULT_MINT_LAMPORTS: u64 = 10_000_000 * LAMPORTS_PER_SOL;
const DUMMY_SNAPSHOT_CONFIG_PATH_MARKER: &str = "dummy";

pub struct ClusterConfig {
Expand All @@ -85,8 +87,8 @@ pub struct ClusterConfig {
pub node_stakes: Vec<u64>,
/// Optional vote keypairs to use for each node
pub node_vote_keys: Option<Vec<Arc<Keypair>>>,
/// The total lamports available to the cluster
pub cluster_lamports: u64,
/// The number of lamports in the mint account
pub mint_lamports: u64,
pub ticks_per_slot: u64,
pub slots_per_epoch: u64,
pub stakers_slot_offset: u64,
Expand All @@ -103,12 +105,12 @@ pub struct ClusterConfig {
impl ClusterConfig {
pub fn new_with_equal_stakes(
num_nodes: usize,
cluster_lamports: u64,
mint_lamports: u64,
lamports_per_node: u64,
) -> Self {
Self {
node_stakes: vec![lamports_per_node; num_nodes],
cluster_lamports,
mint_lamports,
validator_configs: make_identical_validator_configs(
&ValidatorConfig::default_for_test(),
num_nodes,
Expand All @@ -126,7 +128,7 @@ impl Default for ClusterConfig {
validator_keys: None,
node_stakes: vec![],
node_vote_keys: None,
cluster_lamports: 0,
mint_lamports: DEFAULT_MINT_LAMPORTS,
ticks_per_slot: DEFAULT_TICKS_PER_SLOT,
slots_per_epoch: DEFAULT_DEV_SLOTS_PER_EPOCH,
stakers_slot_offset: DEFAULT_DEV_SLOTS_PER_EPOCH,
Expand Down Expand Up @@ -155,16 +157,12 @@ pub struct LocalCluster {
impl LocalCluster {
pub fn new_with_equal_stakes(
num_nodes: usize,
cluster_lamports: u64,
mint_lamports: u64,
lamports_per_node: u64,
socket_addr_space: SocketAddrSpace,
) -> Self {
Self::new(
&mut ClusterConfig::new_with_equal_stakes(
num_nodes,
cluster_lamports,
lamports_per_node,
),
&mut ClusterConfig::new_with_equal_stakes(num_nodes, mint_lamports, lamports_per_node),
socket_addr_space,
)
}
Expand Down Expand Up @@ -254,6 +252,10 @@ impl LocalCluster {
}
};

// Mint used to fund validator identities for non-genesis accounts.
// Verify we have enough lamports in the mint address to do those transfers.
let mut required_mint_lamports = 0;

// Bootstrap leader should always be in genesis block
validator_keys[0].1 = true;
let (keys_in_genesis, stakes_in_genesis): (Vec<ValidatorVoteKeypairs>, Vec<u64>) =
Expand All @@ -278,10 +280,18 @@ impl LocalCluster {
stake,
))
} else {
required_mint_lamports += Self::required_validator_funding(*stake);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

working on making local cluster tests (and all tests) have fees.
This line will change as we need to add additional lamports to pay for fees.

None
}
})
.unzip();

// Verify mint has enough lamports to fund all required validators.
assert!(
config.mint_lamports >= required_mint_lamports,
"mint requires additional lamports to fund validators"
);

let leader_keypair = &keys_in_genesis[0].node_keypair;
let leader_vote_keypair = &keys_in_genesis[0].vote_keypair;
let leader_pubkey = leader_keypair.pubkey();
Expand All @@ -292,7 +302,7 @@ impl LocalCluster {
mint_keypair,
..
} = create_genesis_config_with_vote_accounts_and_cluster_type(
config.cluster_lamports,
config.mint_lamports,
&keys_in_genesis,
stakes_in_genesis,
config.cluster_type,
Expand Down Expand Up @@ -519,7 +529,7 @@ impl LocalCluster {
&client,
&self.funding_keypair,
&validator_pubkey,
stake * 2 + 2,
Self::required_validator_funding(stake),
);
info!(
"validator {} balance {}",
Expand Down Expand Up @@ -972,6 +982,10 @@ impl LocalCluster {

Ok(tpu_client)
}

fn required_validator_funding(stake: u64) -> u64 {
stake.saturating_mul(2).saturating_add(2)
brooksprumo marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl Cluster for LocalCluster {
Expand Down
Loading
Loading