Skip to content

Commit

Permalink
Cleanup (solana-labs#13728)
Browse files Browse the repository at this point in the history
Co-authored-by: Carl Lin <[email protected]>
  • Loading branch information
carllin and carllin authored Nov 20, 2020
1 parent 87d907d commit 9bb11a2
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 58 deletions.
2 changes: 1 addition & 1 deletion bench-exchange/tests/bench_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn test_exchange_local_cluster() {
} = config;
let accounts_in_groups = batch_size * account_groups;

let cluster = LocalCluster::new(&ClusterConfig {
let cluster = LocalCluster::new(&mut ClusterConfig {
node_stakes: vec![100_000; NUM_NODES],
cluster_lamports: 100_000_000_000_000,
validator_configs: vec![ValidatorConfig::default(); 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 @@ -15,7 +15,7 @@ fn test_bench_tps_local_cluster(config: Config) {

solana_logger::setup();
const NUM_NODES: usize = 1;
let cluster = LocalCluster::new(&ClusterConfig {
let cluster = LocalCluster::new(&mut ClusterConfig {
node_stakes: vec![999_990; NUM_NODES],
cluster_lamports: 200_000_000,
validator_configs: vec![ValidatorConfig::default(); NUM_NODES],
Expand Down
16 changes: 11 additions & 5 deletions local-cluster/src/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use solana_runtime::genesis_utils::{
ValidatorVoteKeypairs,
};
use solana_sdk::{
account::Account,
client::SyncClient,
clock::{DEFAULT_DEV_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT},
commitment_config::CommitmentConfig,
Expand Down Expand Up @@ -67,6 +68,7 @@ pub struct ClusterConfig {
pub native_instruction_processors: Vec<(String, Pubkey)>,
pub cluster_type: ClusterType,
pub poh_config: PohConfig,
pub additional_accounts: Vec<(Pubkey, Account)>,
}

impl Default for ClusterConfig {
Expand All @@ -84,6 +86,7 @@ impl Default for ClusterConfig {
cluster_type: ClusterType::Development,
poh_config: PohConfig::default(),
skip_warmup_slots: false,
additional_accounts: vec![],
}
}
}
Expand All @@ -104,16 +107,16 @@ impl LocalCluster {
lamports_per_node: u64,
) -> Self {
let stakes: Vec<_> = (0..num_nodes).map(|_| lamports_per_node).collect();
let config = ClusterConfig {
let mut config = ClusterConfig {
node_stakes: stakes,
cluster_lamports,
validator_configs: vec![ValidatorConfig::default(); num_nodes],
..ClusterConfig::default()
};
Self::new(&config)
Self::new(&mut config)
}

pub fn new(config: &ClusterConfig) -> Self {
pub fn new(config: &mut ClusterConfig) -> Self {
assert_eq!(config.validator_configs.len(), config.node_stakes.len());
let mut validator_keys = {
if let Some(ref keys) = config.validator_keys {
Expand Down Expand Up @@ -162,6 +165,9 @@ impl LocalCluster {
stakes_in_genesis,
config.cluster_type,
);
genesis_config
.accounts
.extend(config.additional_accounts.drain(..));
genesis_config.ticks_per_slot = config.ticks_per_slot;
genesis_config.epoch_schedule = EpochSchedule::custom(
config.slots_per_epoch,
Expand Down Expand Up @@ -706,7 +712,7 @@ mod test {
let mut validator_config = ValidatorConfig::default();
validator_config.rpc_config.enable_validator_exit = true;
const NUM_NODES: usize = 1;
let config = ClusterConfig {
let mut config = ClusterConfig {
validator_configs: vec![ValidatorConfig::default(); NUM_NODES],
node_stakes: vec![3; NUM_NODES],
cluster_lamports: 100,
Expand All @@ -715,7 +721,7 @@ mod test {
stakers_slot_offset: MINIMUM_SLOTS_PER_EPOCH as u64,
..ClusterConfig::default()
};
let cluster = LocalCluster::new(&config);
let cluster = LocalCluster::new(&mut config);
assert_eq!(cluster.validators.len(), NUM_NODES);
}
}
Loading

0 comments on commit 9bb11a2

Please sign in to comment.