Skip to content

Commit

Permalink
Rename to ClusterType and restore devnet compat. (solana-labs#12068)
Browse files Browse the repository at this point in the history
* Rename to ClusterType and restore devnet compat.

* De-duplicate parse code and add comments

* Adjust default Devnet genesis & reduce it in tests
  • Loading branch information
ryoqun authored Sep 8, 2020
1 parent c67f8bd commit 53b8ea4
Show file tree
Hide file tree
Showing 25 changed files with 376 additions and 319 deletions.
4 changes: 2 additions & 2 deletions accounts-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use solana_runtime::{
accounts::{create_test_accounts, update_accounts, Accounts},
accounts_index::Ancestors,
};
use solana_sdk::{genesis_config::OperatingMode, pubkey::Pubkey};
use solana_sdk::{genesis_config::ClusterType, pubkey::Pubkey};
use std::fs;
use std::path::PathBuf;

Expand Down Expand Up @@ -54,7 +54,7 @@ fn main() {
if fs::remove_dir_all(path.clone()).is_err() {
println!("Warning: Couldn't remove {:?}", path);
}
let accounts = Accounts::new(vec![path], &OperatingMode::Preview);
let accounts = Accounts::new(vec![path], &ClusterType::Testnet);
println!("Creating {} accounts", num_accounts);
let mut create_time = Measure::start("create accounts");
let pubkeys: Vec<_> = (0..num_slots)
Expand Down
5 changes: 5 additions & 0 deletions clap-utils/src/input_parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use solana_remote_wallet::remote_wallet::RemoteWalletManager;
use solana_sdk::{
clock::UnixTimestamp,
commitment_config::CommitmentConfig,
genesis_config::ClusterType,
native_token::sol_to_lamports,
pubkey::Pubkey,
signature::{read_keypair_file, Keypair, Signature, Signer},
Expand Down Expand Up @@ -178,6 +179,10 @@ pub fn lamports_of_sol(matches: &ArgMatches<'_>, name: &str) -> Option<u64> {
value_of(matches, name).map(sol_to_lamports)
}

pub fn cluster_type_of(matches: &ArgMatches<'_>, name: &str) -> Option<ClusterType> {
value_of(matches, name)
}

pub fn commitment_of(matches: &ArgMatches<'_>, name: &str) -> Option<CommitmentConfig> {
matches.value_of(name).map(|value| match value {
"max" => CommitmentConfig::max(),
Expand Down
4 changes: 2 additions & 2 deletions core/src/non_circulating_supply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ mod tests {
use solana_sdk::{
account::Account,
epoch_schedule::EpochSchedule,
genesis_config::{GenesisConfig, OperatingMode},
genesis_config::{ClusterType, GenesisConfig},
};
use solana_stake_program::stake_state::{Authorized, Lockup, Meta, StakeState};
use std::{collections::BTreeMap, sync::Arc};
Expand Down Expand Up @@ -150,7 +150,7 @@ mod tests {
let genesis_config = GenesisConfig {
accounts,
epoch_schedule: EpochSchedule::new(slots_per_epoch),
operating_mode: OperatingMode::Stable,
cluster_type: ClusterType::MainnetBeta,
..GenesisConfig::default()
};
let mut bank = Arc::new(Bank::new(&genesis_config));
Expand Down
32 changes: 17 additions & 15 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use solana_runtime::{
};
use solana_sdk::{
clock::{Slot, NUM_CONSECUTIVE_LEADER_SLOTS},
genesis_config::OperatingMode,
genesis_config::ClusterType,
hash::Hash,
pubkey::Pubkey,
signature::{Keypair, Signer},
Expand Down Expand Up @@ -281,7 +281,7 @@ impl ReplayStage {
let root_bank = bank_forks.read().unwrap().root_bank().clone();
let root = root_bank.slot();
let unlock_heaviest_subtree_fork_choice_slot =
Self::get_unlock_heaviest_subtree_fork_choice(root_bank.operating_mode());
Self::get_unlock_heaviest_subtree_fork_choice(root_bank.cluster_type());
let mut heaviest_subtree_fork_choice =
HeaviestSubtreeForkChoice::new_from_frozen_banks(root, &frozen_banks);
let mut bank_weight_fork_choice = BankWeightForkChoice::default();
Expand Down Expand Up @@ -1129,7 +1129,7 @@ impl ReplayStage {
let node_keypair = cluster_info.keypair.clone();

// Send our last few votes along with the new one
let vote_ix = if bank.slot() > Self::get_unlock_switch_vote_slot(bank.operating_mode()) {
let vote_ix = if bank.slot() > Self::get_unlock_switch_vote_slot(bank.cluster_type()) {
switch_fork_decision
.to_vote_instruction(
vote,
Expand Down Expand Up @@ -1855,23 +1855,25 @@ impl ReplayStage {
}
}

pub fn get_unlock_switch_vote_slot(operating_mode: OperatingMode) -> Slot {
match operating_mode {
OperatingMode::Development => 0,
// 400_000 slots into epoch 61
OperatingMode::Stable => 26_752_000,
pub fn get_unlock_switch_vote_slot(cluster_type: ClusterType) -> Slot {
match cluster_type {
ClusterType::Development => 0,
ClusterType::Devnet => 0,
// Epoch 63
OperatingMode::Preview => 21_692_256,
ClusterType::Testnet => 21_692_256,
// 400_000 slots into epoch 61
ClusterType::MainnetBeta => 26_752_000,
}
}

pub fn get_unlock_heaviest_subtree_fork_choice(operating_mode: OperatingMode) -> Slot {
match operating_mode {
OperatingMode::Development => 0,
// 400_000 slots into epoch 61
OperatingMode::Stable => 26_752_000,
pub fn get_unlock_heaviest_subtree_fork_choice(cluster_type: ClusterType) -> Slot {
match cluster_type {
ClusterType::Development => 0,
ClusterType::Devnet => 0,
// Epoch 63
OperatingMode::Preview => 21_692_256,
ClusterType::Testnet => 21_692_256,
// 400_000 slots into epoch 61
ClusterType::MainnetBeta => 26_752_000,
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/rpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ mod tests {
use solana_runtime::{
bank::Bank, bank_forks::CompressionType, snapshot_utils::SnapshotVersion,
};
use solana_sdk::{genesis_config::OperatingMode, signature::Signer};
use solana_sdk::{genesis_config::ClusterType, signature::Signer};
use std::net::{IpAddr, Ipv4Addr};

#[test]
Expand Down Expand Up @@ -471,7 +471,7 @@ mod tests {
let GenesisConfigInfo {
mut genesis_config, ..
} = create_genesis_config(10_000);
genesis_config.operating_mode = OperatingMode::Stable;
genesis_config.cluster_type = ClusterType::MainnetBeta;
let bank = Bank::new(&genesis_config);
Arc::new(RwLock::new(BankForks::new(bank)))
}
Expand Down
44 changes: 21 additions & 23 deletions core/tests/bank_forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ macro_rules! DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS {
use super::*;

const SNAPSHOT_VERSION: SnapshotVersion = SnapshotVersion::$x;
const OPERATING_MODE: OperatingMode = OperatingMode::$y;
const CLUSTER_TYPE: ClusterType = ClusterType::$y;

#[test]
fn test_bank_forks_status_cache_snapshot_n() {
run_test_bank_forks_status_cache_snapshot_n(SNAPSHOT_VERSION, OPERATING_MODE)
run_test_bank_forks_status_cache_snapshot_n(SNAPSHOT_VERSION, CLUSTER_TYPE)
}

#[test]
fn test_bank_forks_snapshot_n() {
run_test_bank_forks_snapshot_n(SNAPSHOT_VERSION, OPERATING_MODE)
run_test_bank_forks_snapshot_n(SNAPSHOT_VERSION, CLUSTER_TYPE)
}

#[test]
fn test_concurrent_snapshot_packaging() {
run_test_concurrent_snapshot_packaging(SNAPSHOT_VERSION, OPERATING_MODE)
run_test_concurrent_snapshot_packaging(SNAPSHOT_VERSION, CLUSTER_TYPE)
}

#[test]
fn test_slots_to_snapshot() {
run_test_slots_to_snapshot(SNAPSHOT_VERSION, OPERATING_MODE)
run_test_slots_to_snapshot(SNAPSHOT_VERSION, CLUSTER_TYPE)
}
}
};
Expand All @@ -50,7 +50,7 @@ mod tests {
};
use solana_sdk::{
clock::Slot,
genesis_config::{GenesisConfig, OperatingMode},
genesis_config::{ClusterType, GenesisConfig},
hash::hashv,
pubkey::Pubkey,
signature::{Keypair, Signer},
Expand All @@ -60,8 +60,9 @@ mod tests {
use tempfile::TempDir;

DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, Development, V1_2_0_Development);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, Preview, V1_2_0_Preview);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, Stable, V1_2_0_Stable);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, Devnet, V1_2_0_Devnet);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, Testnet, V1_2_0_Testnet);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, MainnetBeta, V1_2_0_MainnetBeta);

struct SnapshotTestConfig {
accounts_dir: TempDir,
Expand All @@ -75,14 +76,14 @@ mod tests {
impl SnapshotTestConfig {
fn new(
snapshot_version: SnapshotVersion,
operating_mode: OperatingMode,
cluster_type: ClusterType,
snapshot_interval_slots: u64,
) -> SnapshotTestConfig {
let accounts_dir = TempDir::new().unwrap();
let snapshot_dir = TempDir::new().unwrap();
let snapshot_output_path = TempDir::new().unwrap();
let mut genesis_config_info = create_genesis_config(10_000);
genesis_config_info.genesis_config.operating_mode = operating_mode;
genesis_config_info.genesis_config.cluster_type = cluster_type;
let bank0 = Bank::new_with_paths(
&genesis_config_info.genesis_config,
vec![accounts_dir.path().to_path_buf()],
Expand Down Expand Up @@ -163,7 +164,7 @@ mod tests {
// `last_slot` bank
fn run_bank_forks_snapshot_n<F>(
snapshot_version: SnapshotVersion,
operating_mode: OperatingMode,
cluster_type: ClusterType,
last_slot: Slot,
f: F,
set_root_interval: u64,
Expand All @@ -172,7 +173,7 @@ mod tests {
{
solana_logger::setup();
// Set up snapshotting config
let mut snapshot_test_config = SnapshotTestConfig::new(snapshot_version, operating_mode, 1);
let mut snapshot_test_config = SnapshotTestConfig::new(snapshot_version, cluster_type, 1);

let bank_forks = &mut snapshot_test_config.bank_forks;
let mint_keypair = &snapshot_test_config.genesis_config_info.mint_keypair;
Expand Down Expand Up @@ -219,13 +220,13 @@ mod tests {

fn run_test_bank_forks_snapshot_n(
snapshot_version: SnapshotVersion,
operating_mode: OperatingMode,
cluster_type: ClusterType,
) {
// create banks up to slot 4 and create 1 new account in each bank. test that bank 4 snapshots
// and restores correctly
run_bank_forks_snapshot_n(
snapshot_version,
operating_mode,
cluster_type,
4,
|bank, mint_keypair| {
let key1 = Keypair::new().pubkey();
Expand Down Expand Up @@ -258,12 +259,12 @@ mod tests {

fn run_test_concurrent_snapshot_packaging(
snapshot_version: SnapshotVersion,
operating_mode: OperatingMode,
cluster_type: ClusterType,
) {
solana_logger::setup();

// Set up snapshotting config
let mut snapshot_test_config = SnapshotTestConfig::new(snapshot_version, operating_mode, 1);
let mut snapshot_test_config = SnapshotTestConfig::new(snapshot_version, cluster_type, 1);

let bank_forks = &mut snapshot_test_config.bank_forks;
let accounts_dir = &snapshot_test_config.accounts_dir;
Expand Down Expand Up @@ -408,10 +409,7 @@ mod tests {
);
}

fn run_test_slots_to_snapshot(
snapshot_version: SnapshotVersion,
operating_mode: OperatingMode,
) {
fn run_test_slots_to_snapshot(snapshot_version: SnapshotVersion, cluster_type: ClusterType) {
solana_logger::setup();
let num_set_roots = MAX_CACHE_ENTRIES * 2;

Expand All @@ -420,7 +418,7 @@ mod tests {
// Make sure this test never clears bank.slots_since_snapshot
let mut snapshot_test_config = SnapshotTestConfig::new(
snapshot_version,
operating_mode,
cluster_type,
(*add_root_interval * num_set_roots * 2) as u64,
);
let mut current_bank = snapshot_test_config.bank_forks[0].clone();
Expand Down Expand Up @@ -456,7 +454,7 @@ mod tests {

fn run_test_bank_forks_status_cache_snapshot_n(
snapshot_version: SnapshotVersion,
operating_mode: OperatingMode,
cluster_type: ClusterType,
) {
// create banks up to slot (MAX_CACHE_ENTRIES * 2) + 1 while transferring 1 lamport into 2 different accounts each time
// this is done to ensure the AccountStorageEntries keep getting cleaned up as the root moves
Expand All @@ -467,7 +465,7 @@ mod tests {
for set_root_interval in &[1, 4] {
run_bank_forks_snapshot_n(
snapshot_version,
operating_mode,
cluster_type,
(MAX_CACHE_ENTRIES * 2 + 1) as u64,
|bank, mint_keypair| {
let tx = system_transaction::transfer(
Expand Down
Loading

0 comments on commit 53b8ea4

Please sign in to comment.