Rename to ClusterType and restore devnet compat. (#12068)
* Rename to ClusterType and restore devnet compat. * De-duplicate parse code and add comments * Adjust default Devnet genesis & reduce it in tests
This commit is contained in:
parent
c67f8bd821
commit
53b8ea4464
|
@ -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;
|
||||
|
||||
|
@ -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)
|
||||
|
|
|
@ -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},
|
||||
|
@ -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(),
|
||||
|
|
|
@ -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};
|
||||
|
@ -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));
|
||||
|
|
|
@ -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},
|
||||
|
@ -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();
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
@ -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)))
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -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},
|
||||
|
@ -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,
|
||||
|
@ -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()],
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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(
|
||||
|
|
|
@ -12,18 +12,22 @@ use solana_runtime::bank::{Bank, EnteredEpochCallback};
|
|||
use solana_sdk::{
|
||||
clock::{Epoch, GENESIS_EPOCH},
|
||||
entrypoint_native::{ErasedProcessInstructionWithContext, ProcessInstructionWithContext},
|
||||
genesis_config::OperatingMode,
|
||||
genesis_config::ClusterType,
|
||||
inflation::Inflation,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
||||
pub fn get_inflation(operating_mode: OperatingMode, epoch: Epoch) -> Option<Inflation> {
|
||||
match operating_mode {
|
||||
OperatingMode::Development => match epoch {
|
||||
pub fn get_inflation(cluster_type: ClusterType, epoch: Epoch) -> Option<Inflation> {
|
||||
match cluster_type {
|
||||
ClusterType::Development => match epoch {
|
||||
0 => Some(Inflation::default()),
|
||||
_ => None,
|
||||
},
|
||||
OperatingMode::Preview => match epoch {
|
||||
ClusterType::Devnet => match epoch {
|
||||
0 => Some(Inflation::default()),
|
||||
_ => None,
|
||||
},
|
||||
ClusterType::Testnet => match epoch {
|
||||
// No inflation at epoch 0
|
||||
0 => Some(Inflation::new_disabled()),
|
||||
// testnet enabled inflation at epoch 44:
|
||||
|
@ -36,7 +40,7 @@ pub fn get_inflation(operating_mode: OperatingMode, epoch: Epoch) -> Option<Infl
|
|||
74 => Some(Inflation::default()),
|
||||
_ => None,
|
||||
},
|
||||
OperatingMode::Stable => match epoch {
|
||||
ClusterType::MainnetBeta => match epoch {
|
||||
// No inflation at epoch 0
|
||||
0 => Some(Inflation::new_disabled()),
|
||||
// Inflation starts The epoch of Epoch::MAX is a placeholder and is
|
||||
|
@ -70,10 +74,10 @@ impl std::fmt::Debug for Program {
|
|||
}
|
||||
}
|
||||
|
||||
// given operating_mode, return the entire set of enabled programs
|
||||
fn get_programs(operating_mode: OperatingMode) -> Vec<(Program, Epoch)> {
|
||||
match operating_mode {
|
||||
OperatingMode::Development => vec![
|
||||
// given cluster type, return the entire set of enabled programs
|
||||
fn get_programs(cluster_type: ClusterType) -> Vec<(Program, Epoch)> {
|
||||
match cluster_type {
|
||||
ClusterType::Development => vec![
|
||||
// Programs used for testing
|
||||
Program::BuiltinLoader(solana_bpf_loader_program!()),
|
||||
Program::BuiltinLoader(solana_bpf_loader_deprecated_program!()),
|
||||
|
@ -84,8 +88,18 @@ fn get_programs(operating_mode: OperatingMode) -> Vec<(Program, Epoch)> {
|
|||
.into_iter()
|
||||
.map(|program| (program, GENESIS_EPOCH))
|
||||
.collect::<Vec<_>>(),
|
||||
ClusterType::Devnet => vec![
|
||||
// Programs used for testing
|
||||
Program::BuiltinLoader(solana_bpf_loader_deprecated_program!()),
|
||||
Program::Native(solana_vest_program!()),
|
||||
Program::Native(solana_budget_program!()),
|
||||
Program::Native(solana_exchange_program!()),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|program| (program, GENESIS_EPOCH))
|
||||
.collect::<Vec<_>>(),
|
||||
|
||||
OperatingMode::Preview => vec![
|
||||
ClusterType::Testnet => vec![
|
||||
(
|
||||
Program::BuiltinLoader(solana_bpf_loader_deprecated_program!()),
|
||||
GENESIS_EPOCH,
|
||||
|
@ -93,7 +107,7 @@ fn get_programs(operating_mode: OperatingMode) -> Vec<(Program, Epoch)> {
|
|||
(Program::BuiltinLoader(solana_bpf_loader_program!()), 89),
|
||||
],
|
||||
|
||||
OperatingMode::Stable => vec![
|
||||
ClusterType::MainnetBeta => vec![
|
||||
(
|
||||
Program::BuiltinLoader(solana_bpf_loader_deprecated_program!()),
|
||||
34,
|
||||
|
@ -108,9 +122,9 @@ fn get_programs(operating_mode: OperatingMode) -> Vec<(Program, Epoch)> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_native_programs_for_genesis(operating_mode: OperatingMode) -> Vec<(String, Pubkey)> {
|
||||
pub fn get_native_programs_for_genesis(cluster_type: ClusterType) -> Vec<(String, Pubkey)> {
|
||||
let mut native_programs = vec![];
|
||||
for (program, start_epoch) in get_programs(operating_mode) {
|
||||
for (program, start_epoch) in get_programs(cluster_type) {
|
||||
if let Program::Native((string, key)) = program {
|
||||
if start_epoch == GENESIS_EPOCH {
|
||||
native_programs.push((string, key));
|
||||
|
@ -120,7 +134,7 @@ pub fn get_native_programs_for_genesis(operating_mode: OperatingMode) -> Vec<(St
|
|||
native_programs
|
||||
}
|
||||
|
||||
pub fn get_entered_epoch_callback(operating_mode: OperatingMode) -> EnteredEpochCallback {
|
||||
pub fn get_entered_epoch_callback(cluster_type: ClusterType) -> EnteredEpochCallback {
|
||||
Box::new(move |bank: &mut Bank, initial: bool| {
|
||||
// Be careful to add arbitrary logic here; this should be idempotent and can be called
|
||||
// at arbitrary point in an epoch not only epoch boundaries.
|
||||
|
@ -129,11 +143,11 @@ pub fn get_entered_epoch_callback(operating_mode: OperatingMode) -> EnteredEpoch
|
|||
// In other words, this callback initializes some skip(serde) fields, regardless
|
||||
// frozen or not
|
||||
|
||||
if let Some(inflation) = get_inflation(operating_mode, bank.epoch()) {
|
||||
if let Some(inflation) = get_inflation(cluster_type, bank.epoch()) {
|
||||
info!("Entering new epoch with inflation {:?}", inflation);
|
||||
bank.set_inflation(inflation);
|
||||
}
|
||||
for (program, start_epoch) in get_programs(operating_mode) {
|
||||
for (program, start_epoch) in get_programs(cluster_type) {
|
||||
let should_populate =
|
||||
initial && bank.epoch() >= start_epoch || !initial && bank.epoch() == start_epoch;
|
||||
if should_populate {
|
||||
|
@ -185,29 +199,30 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_uniqueness() {
|
||||
do_test_uniqueness(get_programs(OperatingMode::Development));
|
||||
do_test_uniqueness(get_programs(OperatingMode::Preview));
|
||||
do_test_uniqueness(get_programs(OperatingMode::Stable));
|
||||
do_test_uniqueness(get_programs(ClusterType::Development));
|
||||
do_test_uniqueness(get_programs(ClusterType::Devnet));
|
||||
do_test_uniqueness(get_programs(ClusterType::Testnet));
|
||||
do_test_uniqueness(get_programs(ClusterType::MainnetBeta));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_development_inflation() {
|
||||
assert_eq!(
|
||||
get_inflation(OperatingMode::Development, 0).unwrap(),
|
||||
get_inflation(ClusterType::Development, 0).unwrap(),
|
||||
Inflation::default()
|
||||
);
|
||||
assert_eq!(get_inflation(OperatingMode::Development, 1), None);
|
||||
assert_eq!(get_inflation(ClusterType::Development, 1), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_development_programs() {
|
||||
assert_eq!(get_programs(OperatingMode::Development).len(), 5);
|
||||
assert_eq!(get_programs(ClusterType::Development).len(), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_native_development_programs() {
|
||||
assert_eq!(
|
||||
get_native_programs_for_genesis(OperatingMode::Development).len(),
|
||||
get_native_programs_for_genesis(ClusterType::Development).len(),
|
||||
3
|
||||
);
|
||||
}
|
||||
|
@ -215,23 +230,23 @@ mod tests {
|
|||
#[test]
|
||||
fn test_softlaunch_inflation() {
|
||||
assert_eq!(
|
||||
get_inflation(OperatingMode::Stable, 0).unwrap(),
|
||||
get_inflation(ClusterType::MainnetBeta, 0).unwrap(),
|
||||
Inflation::new_disabled()
|
||||
);
|
||||
assert_eq!(get_inflation(OperatingMode::Stable, 1), None);
|
||||
assert_eq!(get_inflation(ClusterType::MainnetBeta, 1), None);
|
||||
assert_eq!(
|
||||
get_inflation(OperatingMode::Stable, std::u64::MAX).unwrap(),
|
||||
get_inflation(ClusterType::MainnetBeta, std::u64::MAX).unwrap(),
|
||||
Inflation::default()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_softlaunch_programs() {
|
||||
assert!(!get_programs(OperatingMode::Stable).is_empty());
|
||||
assert!(!get_programs(ClusterType::MainnetBeta).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_debug() {
|
||||
assert!(!format!("{:?}", get_programs(OperatingMode::Development)).is_empty());
|
||||
assert!(!format!("{:?}", get_programs(ClusterType::Development)).is_empty());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg, ArgMatches};
|
||||
use solana_clap_utils::{
|
||||
input_parsers::{pubkey_of, pubkeys_of, unix_timestamp_from_rfc3339_datetime},
|
||||
input_parsers::{cluster_type_of, pubkey_of, pubkeys_of, unix_timestamp_from_rfc3339_datetime},
|
||||
input_validators::{is_pubkey_or_keypair, is_rfc3339_datetime, is_valid_percentage},
|
||||
};
|
||||
use solana_genesis::{genesis_accounts::add_genesis_accounts, Base64Account};
|
||||
|
@ -15,7 +15,7 @@ use solana_sdk::{
|
|||
clock,
|
||||
epoch_schedule::EpochSchedule,
|
||||
fee_calculator::FeeRateGovernor,
|
||||
genesis_config::{GenesisConfig, OperatingMode},
|
||||
genesis_config::{ClusterType, GenesisConfig},
|
||||
native_token::sol_to_lamports,
|
||||
poh_config::PohConfig,
|
||||
pubkey::Pubkey,
|
||||
|
@ -130,7 +130,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
let default_target_tick_duration =
|
||||
timing::duration_as_us(&PohConfig::default().target_tick_duration);
|
||||
let default_ticks_per_slot = &clock::DEFAULT_TICKS_PER_SLOT.to_string();
|
||||
let default_operating_mode = "stable";
|
||||
let default_cluster_type = "mainnet-beta";
|
||||
let default_genesis_archive_unpacked_size = MAX_GENESIS_ARCHIVE_UNPACKED_SIZE.to_string();
|
||||
|
||||
let matches = App::new(crate_name!())
|
||||
|
@ -327,13 +327,11 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
.help("The location of pubkey for primordial accounts and balance"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("operating_mode")
|
||||
.long("operating-mode")
|
||||
.possible_value("development")
|
||||
.possible_value("preview")
|
||||
.possible_value("stable")
|
||||
Arg::with_name("cluster_type")
|
||||
.long("cluster-type")
|
||||
.possible_values(&ClusterType::STRINGS)
|
||||
.takes_value(true)
|
||||
.default_value(default_operating_mode)
|
||||
.default_value(default_cluster_type)
|
||||
.help(
|
||||
"Selects the features that will be enabled for the cluster"
|
||||
),
|
||||
|
@ -426,21 +424,16 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
Duration::from_micros(default_target_tick_duration)
|
||||
};
|
||||
|
||||
let operating_mode = match matches.value_of("operating_mode").unwrap() {
|
||||
"development" => OperatingMode::Development,
|
||||
"stable" => OperatingMode::Stable,
|
||||
"preview" => OperatingMode::Preview,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let cluster_type = cluster_type_of(&matches, "cluster_type").unwrap();
|
||||
|
||||
match matches.value_of("hashes_per_tick").unwrap() {
|
||||
"auto" => match operating_mode {
|
||||
OperatingMode::Development => {
|
||||
"auto" => match cluster_type {
|
||||
ClusterType::Development => {
|
||||
let hashes_per_tick =
|
||||
compute_hashes_per_tick(poh_config.target_tick_duration, 1_000_000);
|
||||
poh_config.hashes_per_tick = Some(hashes_per_tick);
|
||||
}
|
||||
OperatingMode::Stable | OperatingMode::Preview => {
|
||||
ClusterType::Devnet | ClusterType::Testnet | ClusterType::MainnetBeta => {
|
||||
poh_config.hashes_per_tick =
|
||||
Some(clock::DEFAULT_HASHES_PER_SECOND / clock::DEFAULT_TICKS_PER_SECOND);
|
||||
}
|
||||
|
@ -456,9 +449,11 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
let slots_per_epoch = if matches.value_of("slots_per_epoch").is_some() {
|
||||
value_t_or_exit!(matches, "slots_per_epoch", u64)
|
||||
} else {
|
||||
match operating_mode {
|
||||
OperatingMode::Development => clock::DEFAULT_DEV_SLOTS_PER_EPOCH,
|
||||
OperatingMode::Stable | OperatingMode::Preview => clock::DEFAULT_SLOTS_PER_EPOCH,
|
||||
match cluster_type {
|
||||
ClusterType::Development => clock::DEFAULT_DEV_SLOTS_PER_EPOCH,
|
||||
ClusterType::Devnet | ClusterType::Testnet | ClusterType::MainnetBeta => {
|
||||
clock::DEFAULT_SLOTS_PER_EPOCH
|
||||
}
|
||||
}
|
||||
};
|
||||
let epoch_schedule = EpochSchedule::custom(
|
||||
|
@ -468,8 +463,8 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
);
|
||||
|
||||
let native_instruction_processors =
|
||||
solana_genesis_programs::get_native_programs_for_genesis(operating_mode);
|
||||
let inflation = solana_genesis_programs::get_inflation(operating_mode, 0).unwrap();
|
||||
solana_genesis_programs::get_native_programs_for_genesis(cluster_type);
|
||||
let inflation = solana_genesis_programs::get_inflation(cluster_type, 0).unwrap();
|
||||
|
||||
let mut genesis_config = GenesisConfig {
|
||||
native_instruction_processors,
|
||||
|
@ -479,7 +474,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
fee_rate_governor,
|
||||
rent,
|
||||
poh_config,
|
||||
operating_mode,
|
||||
cluster_type,
|
||||
..GenesisConfig::default()
|
||||
};
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use log::*;
|
|||
use regex::Regex;
|
||||
use serde_json::json;
|
||||
use solana_clap_utils::{
|
||||
input_parsers::{pubkey_of, pubkeys_of},
|
||||
input_parsers::{cluster_type_of, pubkey_of, pubkeys_of},
|
||||
input_validators::{is_parsable, is_pubkey_or_keypair, is_slot, is_valid_percentage},
|
||||
};
|
||||
use solana_ledger::entry::Entry;
|
||||
|
@ -28,7 +28,7 @@ use solana_runtime::{
|
|||
use solana_sdk::{
|
||||
account::Account,
|
||||
clock::{Epoch, Slot},
|
||||
genesis_config::{GenesisConfig, OperatingMode},
|
||||
genesis_config::{ClusterType, GenesisConfig},
|
||||
hash::Hash,
|
||||
inflation::Inflation,
|
||||
native_token::{lamports_to_sol, sol_to_lamports, Sol},
|
||||
|
@ -947,11 +947,9 @@ fn main() {
|
|||
.arg(&max_genesis_archive_unpacked_size_arg)
|
||||
.arg(&hashes_per_tick)
|
||||
.arg(
|
||||
Arg::with_name("operating_mode")
|
||||
.long("operating-mode")
|
||||
.possible_value("development")
|
||||
.possible_value("preview")
|
||||
.possible_value("stable")
|
||||
Arg::with_name("cluster_type")
|
||||
.long("cluster-type")
|
||||
.possible_values(&ClusterType::STRINGS)
|
||||
.takes_value(true)
|
||||
.help(
|
||||
"Selects the features that will be enabled for the cluster"
|
||||
|
@ -1333,13 +1331,8 @@ fn main() {
|
|||
let mut genesis_config = open_genesis_config_by(&ledger_path, arg_matches);
|
||||
let output_directory = PathBuf::from(arg_matches.value_of("output_directory").unwrap());
|
||||
|
||||
if let Some(operating_mode) = arg_matches.value_of("operating_mode") {
|
||||
genesis_config.operating_mode = match operating_mode {
|
||||
"development" => OperatingMode::Development,
|
||||
"stable" => OperatingMode::Stable,
|
||||
"preview" => OperatingMode::Preview,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
if let Some(cluster_type) = cluster_type_of(arg_matches, "cluster_type") {
|
||||
genesis_config.cluster_type = cluster_type;
|
||||
}
|
||||
|
||||
if let Some(hashes_per_tick) = arg_matches.value_of("hashes_per_tick") {
|
||||
|
|
|
@ -313,7 +313,7 @@ fn initiate_callback(mut bank: &mut Arc<Bank>, genesis_config: &GenesisConfig) {
|
|||
Arc::get_mut(&mut bank)
|
||||
.unwrap()
|
||||
.initiate_entered_epoch_callback(solana_genesis_programs::get_entered_epoch_callback(
|
||||
genesis_config.operating_mode,
|
||||
genesis_config.cluster_type,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -3173,7 +3173,7 @@ pub mod tests {
|
|||
mut genesis_config, ..
|
||||
} = create_genesis_config(123);
|
||||
|
||||
genesis_config.operating_mode = solana_sdk::genesis_config::OperatingMode::Stable;
|
||||
genesis_config.cluster_type = solana_sdk::genesis_config::ClusterType::MainnetBeta;
|
||||
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
|
||||
let blockstore = Blockstore::open(&ledger_path).unwrap();
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use solana_sdk::{
|
|||
clock::{DEFAULT_DEV_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT},
|
||||
commitment_config::CommitmentConfig,
|
||||
epoch_schedule::EpochSchedule,
|
||||
genesis_config::{GenesisConfig, OperatingMode},
|
||||
genesis_config::{ClusterType, GenesisConfig},
|
||||
message::Message,
|
||||
poh_config::PohConfig,
|
||||
pubkey::Pubkey,
|
||||
|
@ -64,7 +64,7 @@ pub struct ClusterConfig {
|
|||
pub stakers_slot_offset: u64,
|
||||
pub skip_warmup_slots: bool,
|
||||
pub native_instruction_processors: Vec<(String, Pubkey)>,
|
||||
pub operating_mode: OperatingMode,
|
||||
pub cluster_type: ClusterType,
|
||||
pub poh_config: PohConfig,
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ impl Default for ClusterConfig {
|
|||
slots_per_epoch: DEFAULT_DEV_SLOTS_PER_EPOCH,
|
||||
stakers_slot_offset: DEFAULT_DEV_SLOTS_PER_EPOCH,
|
||||
native_instruction_processors: vec![],
|
||||
operating_mode: OperatingMode::Development,
|
||||
cluster_type: ClusterType::Development,
|
||||
poh_config: PohConfig::default(),
|
||||
skip_warmup_slots: false,
|
||||
}
|
||||
|
@ -166,21 +166,21 @@ impl LocalCluster {
|
|||
config.stakers_slot_offset,
|
||||
!config.skip_warmup_slots,
|
||||
);
|
||||
genesis_config.operating_mode = config.operating_mode;
|
||||
genesis_config.cluster_type = config.cluster_type;
|
||||
genesis_config.poh_config = config.poh_config.clone();
|
||||
|
||||
match genesis_config.operating_mode {
|
||||
OperatingMode::Stable | OperatingMode::Preview => {
|
||||
match genesis_config.cluster_type {
|
||||
ClusterType::MainnetBeta | ClusterType::Testnet => {
|
||||
genesis_config.native_instruction_processors =
|
||||
solana_genesis_programs::get_native_programs_for_genesis(
|
||||
genesis_config.operating_mode,
|
||||
genesis_config.cluster_type,
|
||||
)
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
genesis_config.inflation =
|
||||
solana_genesis_programs::get_inflation(genesis_config.operating_mode, 0).unwrap();
|
||||
solana_genesis_programs::get_inflation(genesis_config.cluster_type, 0).unwrap();
|
||||
|
||||
genesis_config
|
||||
.native_instruction_processors
|
||||
|
|
|
@ -32,7 +32,7 @@ use solana_sdk::{
|
|||
clock::{self, Slot},
|
||||
commitment_config::CommitmentConfig,
|
||||
epoch_schedule::MINIMUM_SLOTS_PER_EPOCH,
|
||||
genesis_config::OperatingMode,
|
||||
genesis_config::ClusterType,
|
||||
hash::Hash,
|
||||
poh_config::PohConfig,
|
||||
pubkey::Pubkey,
|
||||
|
@ -734,11 +734,11 @@ fn test_listener_startup() {
|
|||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn test_stable_operating_mode() {
|
||||
fn test_mainnet_beta_cluster_type() {
|
||||
solana_logger::setup();
|
||||
|
||||
let config = ClusterConfig {
|
||||
operating_mode: OperatingMode::Stable,
|
||||
cluster_type: ClusterType::MainnetBeta,
|
||||
node_stakes: vec![100; 1],
|
||||
cluster_lamports: 1_000,
|
||||
validator_configs: vec![ValidatorConfig::default(); 1],
|
||||
|
|
|
@ -46,6 +46,6 @@ default_arg --ledger "$SOLANA_CONFIG_DIR"/bootstrap-validator
|
|||
default_arg --faucet-pubkey "$SOLANA_CONFIG_DIR"/faucet.json
|
||||
default_arg --faucet-lamports 500000000000000000
|
||||
default_arg --hashes-per-tick auto
|
||||
default_arg --operating-mode development
|
||||
default_arg --cluster-type development
|
||||
|
||||
$solana_genesis "${args[@]}"
|
||||
|
|
10
net/net.sh
10
net/net.sh
|
@ -94,9 +94,9 @@ Operate a configured testnet
|
|||
--deploy-if-newer - Only deploy if newer software is
|
||||
available (requires -t or -T)
|
||||
|
||||
--operating-mode development|softlaunch
|
||||
--cluster-type development|devnet|testnet|mainnet-beta
|
||||
- Specify whether or not to launch the cluster in "development" mode with all features enabled at epoch 0,
|
||||
or "softlaunch" mode with some features disabled at epoch 0 (default: development)
|
||||
or various other live clusters' feature set (default: development)
|
||||
--warp-slot WARP_SLOT - Boot from a snapshot that has warped ahead to WARP_SLOT rather than a slot 0 genesis.
|
||||
sanity/start-specific options:
|
||||
-F - Discard validator nodes that didn't bootup successfully
|
||||
|
@ -779,12 +779,12 @@ while [[ -n $1 ]]; do
|
|||
elif [[ $1 = --faucet-lamports ]]; then
|
||||
genesisOptions="$genesisOptions $1 $2"
|
||||
shift 2
|
||||
elif [[ $1 = --operating-mode ]]; then
|
||||
elif [[ $1 = --cluster-type ]]; then
|
||||
case "$2" in
|
||||
development|softlaunch)
|
||||
development|devnet|testnet|mainnet-beta)
|
||||
;;
|
||||
*)
|
||||
echo "Unexpected operating mode: \"$2\""
|
||||
echo "Unexpected cluster type: \"$2\""
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
|
2
run.sh
2
run.sh
|
@ -78,7 +78,7 @@ else
|
|||
"$dataDir"/validator-vote-account.json \
|
||||
"$dataDir"/validator-stake-account.json \
|
||||
--ledger "$ledgerDir" \
|
||||
--operating-mode development \
|
||||
--cluster-type development \
|
||||
$SPL_GENESIS_ARGS \
|
||||
$SOLANA_RUN_SH_GENESIS_ARGS
|
||||
fi
|
||||
|
|
|
@ -8,7 +8,7 @@ use solana_runtime::{
|
|||
};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
genesis_config::{create_genesis_config, OperatingMode},
|
||||
genesis_config::{create_genesis_config, ClusterType},
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
@ -71,7 +71,7 @@ fn test_accounts_squash(bencher: &mut Bencher) {
|
|||
fn test_accounts_hash_bank_hash(bencher: &mut Bencher) {
|
||||
let accounts = Accounts::new(
|
||||
vec![PathBuf::from("bench_accounts_hash_internal")],
|
||||
&OperatingMode::Development,
|
||||
&ClusterType::Development,
|
||||
);
|
||||
let mut pubkeys: Vec<Pubkey> = vec![];
|
||||
create_test_accounts(&accounts, &mut pubkeys, 60000, 0);
|
||||
|
@ -85,7 +85,7 @@ fn test_update_accounts_hash(bencher: &mut Bencher) {
|
|||
solana_logger::setup();
|
||||
let accounts = Accounts::new(
|
||||
vec![PathBuf::from("update_accounts_hash")],
|
||||
&OperatingMode::Development,
|
||||
&ClusterType::Development,
|
||||
);
|
||||
let mut pubkeys: Vec<Pubkey> = vec![];
|
||||
create_test_accounts(&accounts, &mut pubkeys, 50_000, 0);
|
||||
|
@ -100,7 +100,7 @@ fn test_accounts_delta_hash(bencher: &mut Bencher) {
|
|||
solana_logger::setup();
|
||||
let accounts = Accounts::new(
|
||||
vec![PathBuf::from("accounts_delta_hash")],
|
||||
&OperatingMode::Development,
|
||||
&ClusterType::Development,
|
||||
);
|
||||
let mut pubkeys: Vec<Pubkey> = vec![];
|
||||
create_test_accounts(&accounts, &mut pubkeys, 100_000, 0);
|
||||
|
@ -114,7 +114,7 @@ fn bench_delete_dependencies(bencher: &mut Bencher) {
|
|||
solana_logger::setup();
|
||||
let accounts = Accounts::new(
|
||||
vec![PathBuf::from("accounts_delete_deps")],
|
||||
&OperatingMode::Development,
|
||||
&ClusterType::Development,
|
||||
);
|
||||
let mut old_pubkey = Pubkey::default();
|
||||
let zero_account = Account::new(0, 0, &Account::default().owner);
|
||||
|
|
|
@ -18,7 +18,7 @@ use solana_sdk::{
|
|||
account::Account,
|
||||
clock::Slot,
|
||||
fee_calculator::FeeCalculator,
|
||||
genesis_config::OperatingMode,
|
||||
genesis_config::ClusterType,
|
||||
hash::Hash,
|
||||
message::Message,
|
||||
native_loader, nonce,
|
||||
|
@ -67,10 +67,10 @@ pub enum AccountAddressFilter {
|
|||
}
|
||||
|
||||
impl Accounts {
|
||||
pub fn new(paths: Vec<PathBuf>, operating_mode: &OperatingMode) -> Self {
|
||||
pub fn new(paths: Vec<PathBuf>, cluster_type: &ClusterType) -> Self {
|
||||
Self {
|
||||
slot: 0,
|
||||
accounts_db: Arc::new(AccountsDB::new(paths, operating_mode)),
|
||||
accounts_db: Arc::new(AccountsDB::new(paths, cluster_type)),
|
||||
account_locks: Mutex::new(HashSet::new()),
|
||||
readonly_locks: Arc::new(RwLock::new(Some(HashMap::new()))),
|
||||
}
|
||||
|
@ -796,7 +796,7 @@ mod tests {
|
|||
account::Account,
|
||||
epoch_schedule::EpochSchedule,
|
||||
fee_calculator::FeeCalculator,
|
||||
genesis_config::OperatingMode,
|
||||
genesis_config::ClusterType,
|
||||
hash::Hash,
|
||||
instruction::CompiledInstruction,
|
||||
message::Message,
|
||||
|
@ -820,7 +820,7 @@ mod tests {
|
|||
) -> Vec<(Result<TransactionLoadResult>, Option<HashAgeKind>)> {
|
||||
let mut hash_queue = BlockhashQueue::new(100);
|
||||
hash_queue.register_hash(&tx.message().recent_blockhash, &fee_calculator);
|
||||
let accounts = Accounts::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = Accounts::new(Vec::new(), &ClusterType::Development);
|
||||
for ka in ka.iter() {
|
||||
accounts.store_slow(0, &ka.0, &ka.1);
|
||||
}
|
||||
|
@ -1030,7 +1030,7 @@ mod tests {
|
|||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
},
|
||||
OperatingMode::Development,
|
||||
ClusterType::Development,
|
||||
);
|
||||
let min_balance = rent_collector.rent.minimum_balance(nonce::State::size());
|
||||
let fee_calculator = FeeCalculator::new(min_balance);
|
||||
|
@ -1386,7 +1386,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_load_by_program_slot() {
|
||||
let accounts = Accounts::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = Accounts::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
// Load accounts owned by various programs into AccountsDB
|
||||
let pubkey0 = Pubkey::new_rand();
|
||||
|
@ -1409,7 +1409,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_accounts_account_not_found() {
|
||||
let accounts = Accounts::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = Accounts::new(Vec::new(), &ClusterType::Development);
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
let ancestors = vec![(0, 0)].into_iter().collect();
|
||||
|
||||
|
@ -1431,7 +1431,7 @@ mod tests {
|
|||
#[test]
|
||||
#[should_panic]
|
||||
fn test_accounts_empty_bank_hash() {
|
||||
let accounts = Accounts::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = Accounts::new(Vec::new(), &ClusterType::Development);
|
||||
accounts.bank_hash_at(1);
|
||||
}
|
||||
|
||||
|
@ -1447,7 +1447,7 @@ mod tests {
|
|||
let account2 = Account::new(3, 0, &Pubkey::default());
|
||||
let account3 = Account::new(4, 0, &Pubkey::default());
|
||||
|
||||
let accounts = Accounts::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = Accounts::new(Vec::new(), &ClusterType::Development);
|
||||
accounts.store_slow(0, &keypair0.pubkey(), &account0);
|
||||
accounts.store_slow(0, &keypair1.pubkey(), &account1);
|
||||
accounts.store_slow(0, &keypair2.pubkey(), &account2);
|
||||
|
@ -1559,7 +1559,7 @@ mod tests {
|
|||
let account1 = Account::new(2, 0, &Pubkey::default());
|
||||
let account2 = Account::new(3, 0, &Pubkey::default());
|
||||
|
||||
let accounts = Accounts::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = Accounts::new(Vec::new(), &ClusterType::Development);
|
||||
accounts.store_slow(0, &keypair0.pubkey(), &account0);
|
||||
accounts.store_slow(0, &keypair1.pubkey(), &account1);
|
||||
accounts.store_slow(0, &keypair2.pubkey(), &account2);
|
||||
|
@ -1689,7 +1689,7 @@ mod tests {
|
|||
|
||||
let mut loaded = vec![loaded0, loaded1];
|
||||
|
||||
let accounts = Accounts::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = Accounts::new(Vec::new(), &ClusterType::Development);
|
||||
{
|
||||
let mut readonly_locks = accounts.readonly_locks.write().unwrap();
|
||||
let readonly_locks = readonly_locks.as_mut().unwrap();
|
||||
|
@ -1740,7 +1740,7 @@ mod tests {
|
|||
#[test]
|
||||
fn huge_clean() {
|
||||
solana_logger::setup();
|
||||
let accounts = Accounts::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = Accounts::new(Vec::new(), &ClusterType::Development);
|
||||
let mut old_pubkey = Pubkey::default();
|
||||
let zero_account = Account::new(0, 0, &Account::default().owner);
|
||||
info!("storing..");
|
||||
|
|
|
@ -33,7 +33,7 @@ use solana_rayon_threadlimit::get_thread_count;
|
|||
use solana_sdk::{
|
||||
account::Account,
|
||||
clock::{Epoch, Slot},
|
||||
genesis_config::OperatingMode,
|
||||
genesis_config::ClusterType,
|
||||
hash::{Hash, Hasher},
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
@ -416,7 +416,7 @@ pub struct AccountsDB {
|
|||
|
||||
stats: AccountsStats,
|
||||
|
||||
operating_mode: Option<OperatingMode>,
|
||||
cluster_type: Option<ClusterType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
@ -478,18 +478,18 @@ impl Default for AccountsDB {
|
|||
frozen_accounts: HashMap::new(),
|
||||
dead_slots: RwLock::new(HashSet::new()),
|
||||
stats: AccountsStats::default(),
|
||||
operating_mode: None,
|
||||
cluster_type: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AccountsDB {
|
||||
pub fn new(paths: Vec<PathBuf>, operating_mode: &OperatingMode) -> Self {
|
||||
pub fn new(paths: Vec<PathBuf>, cluster_type: &ClusterType) -> Self {
|
||||
let new = if !paths.is_empty() {
|
||||
Self {
|
||||
paths,
|
||||
temp_paths: None,
|
||||
operating_mode: Some(*operating_mode),
|
||||
cluster_type: Some(*cluster_type),
|
||||
..Self::default()
|
||||
}
|
||||
} else {
|
||||
|
@ -499,7 +499,7 @@ impl AccountsDB {
|
|||
Self {
|
||||
paths,
|
||||
temp_paths: Some(temp_dirs),
|
||||
operating_mode: Some(*operating_mode),
|
||||
cluster_type: Some(*cluster_type),
|
||||
..Self::default()
|
||||
}
|
||||
};
|
||||
|
@ -515,14 +515,14 @@ impl AccountsDB {
|
|||
pub fn new_single() -> Self {
|
||||
AccountsDB {
|
||||
min_num_stores: 0,
|
||||
..AccountsDB::new(Vec::new(), &OperatingMode::Development)
|
||||
..AccountsDB::new(Vec::new(), &ClusterType::Development)
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
pub fn new_sized(paths: Vec<PathBuf>, file_size: u64) -> Self {
|
||||
AccountsDB {
|
||||
file_size,
|
||||
..AccountsDB::new(paths, &OperatingMode::Development)
|
||||
..AccountsDB::new(paths, &ClusterType::Development)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1280,12 +1280,24 @@ impl AccountsDB {
|
|||
assert!(self.storage.read().unwrap().0.get(&remove_slot).is_none());
|
||||
}
|
||||
|
||||
fn include_owner(cluster_type: &ClusterType, slot: Slot) -> bool {
|
||||
// When devnet was moved to stable release channel, it was done without
|
||||
// hashing account.owner. That's because devnet's slot was lower than
|
||||
// 5_800_000 and the release channel's gating lacked ClusterType at the time...
|
||||
match cluster_type {
|
||||
ClusterType::Devnet => slot >= 5_800_000,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hash_stored_account(
|
||||
slot: Slot,
|
||||
account: &StoredAccount,
|
||||
operating_mode: &OperatingMode,
|
||||
cluster_type: &ClusterType,
|
||||
) -> Hash {
|
||||
if slot > Self::get_blake3_slot(operating_mode) {
|
||||
let include_owner = Self::include_owner(cluster_type, slot);
|
||||
|
||||
if slot > Self::get_blake3_slot(cluster_type) {
|
||||
Self::blake3_hash_account_data(
|
||||
slot,
|
||||
account.account_meta.lamports,
|
||||
|
@ -1294,6 +1306,7 @@ impl AccountsDB {
|
|||
account.account_meta.rent_epoch,
|
||||
account.data,
|
||||
&account.meta.pubkey,
|
||||
include_owner,
|
||||
)
|
||||
} else {
|
||||
Self::hash_account_data(
|
||||
|
@ -1304,6 +1317,7 @@ impl AccountsDB {
|
|||
account.account_meta.rent_epoch,
|
||||
account.data,
|
||||
&account.meta.pubkey,
|
||||
include_owner,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1312,9 +1326,11 @@ impl AccountsDB {
|
|||
slot: Slot,
|
||||
account: &Account,
|
||||
pubkey: &Pubkey,
|
||||
operating_mode: &OperatingMode,
|
||||
cluster_type: &ClusterType,
|
||||
) -> Hash {
|
||||
if slot > Self::get_blake3_slot(operating_mode) {
|
||||
let include_owner = Self::include_owner(cluster_type, slot);
|
||||
|
||||
if slot > Self::get_blake3_slot(cluster_type) {
|
||||
Self::blake3_hash_account_data(
|
||||
slot,
|
||||
account.lamports,
|
||||
|
@ -1323,6 +1339,7 @@ impl AccountsDB {
|
|||
account.rent_epoch,
|
||||
&account.data,
|
||||
pubkey,
|
||||
include_owner,
|
||||
)
|
||||
} else {
|
||||
Self::hash_account_data(
|
||||
|
@ -1333,6 +1350,7 @@ impl AccountsDB {
|
|||
account.rent_epoch,
|
||||
&account.data,
|
||||
pubkey,
|
||||
include_owner,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1360,6 +1378,7 @@ impl AccountsDB {
|
|||
rent_epoch: Epoch,
|
||||
data: &[u8],
|
||||
pubkey: &Pubkey,
|
||||
include_owner: bool,
|
||||
) -> Hash {
|
||||
if lamports == 0 {
|
||||
return Hash::default();
|
||||
|
@ -1381,7 +1400,9 @@ impl AccountsDB {
|
|||
hasher.hash(&[0u8; 1]);
|
||||
}
|
||||
|
||||
hasher.hash(&owner.as_ref());
|
||||
if include_owner {
|
||||
hasher.hash(&owner.as_ref());
|
||||
}
|
||||
hasher.hash(&pubkey.as_ref());
|
||||
|
||||
hasher.result()
|
||||
|
@ -1395,6 +1416,7 @@ impl AccountsDB {
|
|||
rent_epoch: Epoch,
|
||||
data: &[u8],
|
||||
pubkey: &Pubkey,
|
||||
include_owner: bool,
|
||||
) -> Hash {
|
||||
if lamports == 0 {
|
||||
return Hash::default();
|
||||
|
@ -1416,20 +1438,23 @@ impl AccountsDB {
|
|||
hasher.update(&[0u8; 1]);
|
||||
}
|
||||
|
||||
hasher.update(&owner.as_ref());
|
||||
if include_owner {
|
||||
hasher.update(&owner.as_ref());
|
||||
}
|
||||
hasher.update(&pubkey.as_ref());
|
||||
|
||||
Hash(<[u8; solana_sdk::hash::HASH_BYTES]>::try_from(hasher.finalize().as_slice()).unwrap())
|
||||
}
|
||||
|
||||
fn get_blake3_slot(operating_mode: &OperatingMode) -> Slot {
|
||||
match operating_mode {
|
||||
fn get_blake3_slot(cluster_type: &ClusterType) -> Slot {
|
||||
match cluster_type {
|
||||
ClusterType::Development => 0,
|
||||
// Epoch 400
|
||||
OperatingMode::Development => 3_276_800,
|
||||
ClusterType::Devnet => 3_276_800,
|
||||
// Epoch 78
|
||||
OperatingMode::Stable => 33_696_000,
|
||||
ClusterType::MainnetBeta => 33_696_000,
|
||||
// Epoch 95
|
||||
OperatingMode::Preview => 35_516_256,
|
||||
ClusterType::Testnet => 35_516_256,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1652,8 +1677,8 @@ impl AccountsDB {
|
|||
*slot,
|
||||
&account,
|
||||
&self
|
||||
.operating_mode
|
||||
.expect("Operating mode must be set at initialization"),
|
||||
.cluster_type
|
||||
.expect("Cluster type must be set at initialization"),
|
||||
);
|
||||
if hash != *account.hash {
|
||||
mismatch_found.fetch_add(1, Ordering::Relaxed);
|
||||
|
@ -1893,14 +1918,14 @@ impl AccountsDB {
|
|||
&self,
|
||||
slot: Slot,
|
||||
accounts: &[(&Pubkey, &Account)],
|
||||
operating_mode: &OperatingMode,
|
||||
cluster_type: &ClusterType,
|
||||
) -> Vec<Hash> {
|
||||
let mut stats = BankHashStats::default();
|
||||
let hashes: Vec<_> = accounts
|
||||
.iter()
|
||||
.map(|(pubkey, account)| {
|
||||
stats.update(account);
|
||||
Self::hash_account(slot, account, pubkey, operating_mode)
|
||||
Self::hash_account(slot, account, pubkey, cluster_type)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
@ -1969,8 +1994,8 @@ impl AccountsDB {
|
|||
slot,
|
||||
accounts,
|
||||
&self
|
||||
.operating_mode
|
||||
.expect("Operating mode must be set at initialization"),
|
||||
.cluster_type
|
||||
.expect("Cluster type must be set at initialization"),
|
||||
);
|
||||
self.store_with_hashes(slot, accounts, &hashes);
|
||||
}
|
||||
|
@ -2182,7 +2207,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_accountsdb_add_root() {
|
||||
solana_logger::setup();
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let key = Pubkey::default();
|
||||
let account0 = Account::new(1, 0, &key);
|
||||
|
||||
|
@ -2195,7 +2220,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_accountsdb_latest_ancestor() {
|
||||
solana_logger::setup();
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let key = Pubkey::default();
|
||||
let account0 = Account::new(1, 0, &key);
|
||||
|
||||
|
@ -2222,7 +2247,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_accountsdb_latest_ancestor_with_root() {
|
||||
solana_logger::setup();
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let key = Pubkey::default();
|
||||
let account0 = Account::new(1, 0, &key);
|
||||
|
||||
|
@ -2242,7 +2267,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_accountsdb_root_one_slot() {
|
||||
solana_logger::setup();
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let key = Pubkey::default();
|
||||
let account0 = Account::new(1, 0, &key);
|
||||
|
@ -2283,7 +2308,7 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_accountsdb_add_root_many() {
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let mut pubkeys: Vec<Pubkey> = vec![];
|
||||
create_account(&db, &mut pubkeys, 0, 100, 0, 0);
|
||||
|
@ -2372,7 +2397,7 @@ pub mod tests {
|
|||
let key = Pubkey::default();
|
||||
|
||||
// 1 token in the "root", i.e. db zero
|
||||
let db0 = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db0 = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let account0 = Account::new(1, 0, &key);
|
||||
db0.store(0, &[(&key, &account0)]);
|
||||
|
||||
|
@ -2391,7 +2416,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_remove_unrooted_slot() {
|
||||
let unrooted_slot = 9;
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let key = Pubkey::default();
|
||||
let account0 = Account::new(1, 0, &key);
|
||||
let ancestors: HashMap<_, _> = vec![(unrooted_slot, 1)].into_iter().collect();
|
||||
|
@ -2437,7 +2462,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_remove_unrooted_slot_snapshot() {
|
||||
let unrooted_slot = 9;
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let key = Pubkey::new_rand();
|
||||
let account0 = Account::new(1, 0, &key);
|
||||
db.store(unrooted_slot, &[(&key, &account0)]);
|
||||
|
@ -2564,7 +2589,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_account_one() {
|
||||
let (_accounts_dirs, paths) = get_temp_accounts_paths(1).unwrap();
|
||||
let db = AccountsDB::new(paths, &OperatingMode::Development);
|
||||
let db = AccountsDB::new(paths, &ClusterType::Development);
|
||||
let mut pubkeys: Vec<Pubkey> = vec![];
|
||||
create_account(&db, &mut pubkeys, 0, 1, 0, 0);
|
||||
let ancestors = vec![(0, 0)].into_iter().collect();
|
||||
|
@ -2577,7 +2602,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_account_many() {
|
||||
let (_accounts_dirs, paths) = get_temp_accounts_paths(2).unwrap();
|
||||
let db = AccountsDB::new(paths, &OperatingMode::Development);
|
||||
let db = AccountsDB::new(paths, &ClusterType::Development);
|
||||
let mut pubkeys: Vec<Pubkey> = vec![];
|
||||
create_account(&db, &mut pubkeys, 0, 100, 0, 0);
|
||||
check_accounts(&db, &pubkeys, 0, 100, 1);
|
||||
|
@ -2695,7 +2720,7 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_purge_slot_not_root() {
|
||||
let accounts = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let mut pubkeys: Vec<Pubkey> = vec![];
|
||||
create_account(&accounts, &mut pubkeys, 0, 1, 0, 0);
|
||||
let ancestors = vec![(0, 0)].into_iter().collect();
|
||||
|
@ -2706,7 +2731,7 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_purge_slot_after_root() {
|
||||
let accounts = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let mut pubkeys: Vec<Pubkey> = vec![];
|
||||
create_account(&accounts, &mut pubkeys, 0, 1, 0, 0);
|
||||
let ancestors = vec![(0, 0)].into_iter().collect();
|
||||
|
@ -2721,7 +2746,7 @@ pub mod tests {
|
|||
//This test is pedantic
|
||||
//A slot is purged when a non root bank is cleaned up. If a slot is behind root but it is
|
||||
//not root, it means we are retaining dead banks.
|
||||
let accounts = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let pubkey = Pubkey::new_rand();
|
||||
let account = Account::new(1, 0, &Account::default().owner);
|
||||
//store an account
|
||||
|
@ -2799,7 +2824,7 @@ pub mod tests {
|
|||
fn test_clean_old_with_normal_account() {
|
||||
solana_logger::setup();
|
||||
|
||||
let accounts = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let pubkey = Pubkey::new_rand();
|
||||
let account = Account::new(1, 0, &Account::default().owner);
|
||||
//store an account
|
||||
|
@ -2825,7 +2850,7 @@ pub mod tests {
|
|||
fn test_clean_old_with_zero_lamport_account() {
|
||||
solana_logger::setup();
|
||||
|
||||
let accounts = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let pubkey1 = Pubkey::new_rand();
|
||||
let pubkey2 = Pubkey::new_rand();
|
||||
let normal_account = Account::new(1, 0, &Account::default().owner);
|
||||
|
@ -2855,7 +2880,7 @@ pub mod tests {
|
|||
fn test_clean_old_with_both_normal_and_zero_lamport_accounts() {
|
||||
solana_logger::setup();
|
||||
|
||||
let accounts = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let pubkey1 = Pubkey::new_rand();
|
||||
let pubkey2 = Pubkey::new_rand();
|
||||
let normal_account = Account::new(1, 0, &Account::default().owner);
|
||||
|
@ -2888,7 +2913,7 @@ pub mod tests {
|
|||
fn test_uncleaned_roots_with_account() {
|
||||
solana_logger::setup();
|
||||
|
||||
let accounts = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let pubkey = Pubkey::new_rand();
|
||||
let account = Account::new(1, 0, &Account::default().owner);
|
||||
//store an account
|
||||
|
@ -2908,7 +2933,7 @@ pub mod tests {
|
|||
fn test_uncleaned_roots_with_no_account() {
|
||||
solana_logger::setup();
|
||||
|
||||
let accounts = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
assert_eq!(accounts.uncleaned_root_count(), 0);
|
||||
|
||||
|
@ -3342,7 +3367,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_accountsdb_scan_accounts() {
|
||||
solana_logger::setup();
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let key = Pubkey::default();
|
||||
let key0 = Pubkey::new_rand();
|
||||
let account0 = Account::new(1, 0, &key);
|
||||
|
@ -3406,7 +3431,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_store_large_account() {
|
||||
solana_logger::setup();
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let key = Pubkey::default();
|
||||
let data_len = DEFAULT_FILE_SIZE as usize + 7;
|
||||
|
@ -3491,7 +3516,7 @@ pub mod tests {
|
|||
fn test_frozen_account_lamport_increase() {
|
||||
let frozen_pubkey =
|
||||
Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
|
||||
let mut db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let mut db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let mut account = Account::new(1, 42, &frozen_pubkey);
|
||||
db.store(0, &[(&frozen_pubkey, &account)]);
|
||||
|
@ -3526,7 +3551,7 @@ pub mod tests {
|
|||
fn test_frozen_account_lamport_decrease() {
|
||||
let frozen_pubkey =
|
||||
Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
|
||||
let mut db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let mut db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let mut account = Account::new(1, 42, &frozen_pubkey);
|
||||
db.store(0, &[(&frozen_pubkey, &account)]);
|
||||
|
@ -3546,7 +3571,7 @@ pub mod tests {
|
|||
fn test_frozen_account_nonexistent() {
|
||||
let frozen_pubkey =
|
||||
Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
|
||||
let mut db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let mut db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let ancestors = vec![(0, 0)].into_iter().collect();
|
||||
db.freeze_accounts(&ancestors, &[frozen_pubkey]);
|
||||
|
@ -3559,7 +3584,7 @@ pub mod tests {
|
|||
fn test_frozen_account_data_modified() {
|
||||
let frozen_pubkey =
|
||||
Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
|
||||
let mut db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let mut db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let mut account = Account::new(1, 42, &frozen_pubkey);
|
||||
db.store(0, &[(&frozen_pubkey, &account)]);
|
||||
|
@ -3612,7 +3637,7 @@ pub mod tests {
|
|||
Hash::from_str("4StuvYHFd7xuShVXB94uHHvpqGMCaacdZnYB74QQkPA1").unwrap();
|
||||
|
||||
assert_eq!(
|
||||
AccountsDB::hash_stored_account(slot, &stored_account, &OperatingMode::Development),
|
||||
AccountsDB::hash_stored_account(slot, &stored_account, &ClusterType::Development),
|
||||
expected_account_hash,
|
||||
"StoredAccount's data layout might be changed; update hashing if needed."
|
||||
);
|
||||
|
@ -3621,7 +3646,7 @@ pub mod tests {
|
|||
slot,
|
||||
&account,
|
||||
&stored_account.meta.pubkey,
|
||||
&OperatingMode::Development
|
||||
&ClusterType::Development
|
||||
),
|
||||
expected_account_hash,
|
||||
"Account-based hashing must be consistent with StoredAccount-based one."
|
||||
|
@ -3631,7 +3656,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_bank_hash_stats() {
|
||||
solana_logger::setup();
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let key = Pubkey::default();
|
||||
let some_data_len = 5;
|
||||
|
@ -3659,7 +3684,7 @@ pub mod tests {
|
|||
fn test_verify_bank_hash() {
|
||||
use BankHashVerificationError::*;
|
||||
solana_logger::setup();
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let key = Pubkey::default();
|
||||
let some_data_len = 0;
|
||||
|
@ -3697,7 +3722,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_verify_bank_hash_no_account() {
|
||||
solana_logger::setup();
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let some_slot: Slot = 0;
|
||||
let ancestors = vec![(some_slot, 0)].into_iter().collect();
|
||||
|
@ -3715,7 +3740,7 @@ pub mod tests {
|
|||
fn test_verify_bank_hash_bad_account_hash() {
|
||||
use BankHashVerificationError::*;
|
||||
solana_logger::setup();
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let key = Pubkey::default();
|
||||
let some_data_len = 0;
|
||||
|
@ -3725,7 +3750,7 @@ pub mod tests {
|
|||
|
||||
let accounts = &[(&key, &account)];
|
||||
// update AccountsDB's bank hash but discard real account hashes
|
||||
db.hash_accounts(some_slot, accounts, &OperatingMode::Development);
|
||||
db.hash_accounts(some_slot, accounts, &ClusterType::Development);
|
||||
// provide bogus account hashes
|
||||
let some_hash = Hash::new(&[0xca; HASH_BYTES]);
|
||||
db.store_with_hashes(some_slot, accounts, &[some_hash]);
|
||||
|
@ -3739,7 +3764,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_bad_bank_hash() {
|
||||
use solana_sdk::signature::{Keypair, Signer};
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let some_slot: Slot = 0;
|
||||
let ancestors: Ancestors = [(some_slot, 0)].iter().copied().collect();
|
||||
|
@ -3764,12 +3789,7 @@ pub mod tests {
|
|||
for (key, account) in &accounts_keys {
|
||||
assert_eq!(
|
||||
db.load_account_hash(&ancestors, key),
|
||||
AccountsDB::hash_account(
|
||||
some_slot,
|
||||
&account,
|
||||
&key,
|
||||
&OperatingMode::Development
|
||||
)
|
||||
AccountsDB::hash_account(some_slot, &account, &key, &ClusterType::Development)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3777,13 +3797,13 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_get_snapshot_storages_empty() {
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
assert!(db.get_snapshot_storages(0).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_snapshot_storages_only_older_than_or_equal_to_snapshot_slot() {
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let key = Pubkey::default();
|
||||
let account = Account::new(1, 0, &key);
|
||||
|
@ -3801,7 +3821,7 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_get_snapshot_storages_only_non_empty() {
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let key = Pubkey::default();
|
||||
let account = Account::new(1, 0, &key);
|
||||
|
@ -3825,7 +3845,7 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_get_snapshot_storages_only_roots() {
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let key = Pubkey::default();
|
||||
let account = Account::new(1, 0, &key);
|
||||
|
@ -3841,7 +3861,7 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_get_snapshot_storages_exclude_empty() {
|
||||
let db = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
|
||||
let key = Pubkey::default();
|
||||
let account = Account::new(1, 0, &key);
|
||||
|
@ -3860,7 +3880,7 @@ pub mod tests {
|
|||
#[test]
|
||||
#[should_panic(expected = "double remove of account in slot: 0/store: 0!!")]
|
||||
fn test_storage_remove_account_double_remove() {
|
||||
let accounts = AccountsDB::new(Vec::new(), &OperatingMode::Development);
|
||||
let accounts = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||
let pubkey = Pubkey::new_rand();
|
||||
let account = Account::new(1, 0, &Account::default().owner);
|
||||
accounts.store(0, &[(&pubkey, &account)]);
|
||||
|
|
|
@ -39,7 +39,7 @@ use solana_sdk::{
|
|||
epoch_info::EpochInfo,
|
||||
epoch_schedule::EpochSchedule,
|
||||
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
||||
genesis_config::{GenesisConfig, OperatingMode},
|
||||
genesis_config::{ClusterType, GenesisConfig},
|
||||
hard_forks::HardForks,
|
||||
hash::{extend_and_hash, hashv, Hash},
|
||||
incinerator,
|
||||
|
@ -452,7 +452,7 @@ pub struct Bank {
|
|||
|
||||
pub skip_drop: AtomicBool,
|
||||
|
||||
pub operating_mode: Option<OperatingMode>,
|
||||
pub cluster_type: Option<ClusterType>,
|
||||
|
||||
pub lazy_rent_collection: AtomicBool,
|
||||
|
||||
|
@ -477,10 +477,10 @@ impl Bank {
|
|||
frozen_account_pubkeys: &[Pubkey],
|
||||
) -> Self {
|
||||
let mut bank = Self::default();
|
||||
bank.operating_mode = Some(genesis_config.operating_mode);
|
||||
bank.cluster_type = Some(genesis_config.cluster_type);
|
||||
bank.ancestors.insert(bank.slot(), 0);
|
||||
|
||||
bank.rc.accounts = Arc::new(Accounts::new(paths, &genesis_config.operating_mode));
|
||||
bank.rc.accounts = Arc::new(Accounts::new(paths, &genesis_config.cluster_type));
|
||||
bank.process_genesis_config(genesis_config);
|
||||
bank.finish_init(genesis_config);
|
||||
|
||||
|
@ -547,7 +547,7 @@ impl Bank {
|
|||
collected_rent: AtomicU64::new(0),
|
||||
rent_collector: parent
|
||||
.rent_collector
|
||||
.clone_with_epoch(epoch, parent.operating_mode()),
|
||||
.clone_with_epoch(epoch, parent.cluster_type()),
|
||||
max_tick_height: (slot + 1) * parent.ticks_per_slot,
|
||||
block_height: parent.block_height + 1,
|
||||
fee_calculator: fee_rate_governor.create_fee_calculator(),
|
||||
|
@ -572,7 +572,7 @@ impl Bank {
|
|||
last_vote_sync: AtomicU64::new(parent.last_vote_sync.load(Ordering::Relaxed)),
|
||||
rewards: None,
|
||||
skip_drop: AtomicBool::new(false),
|
||||
operating_mode: parent.operating_mode,
|
||||
cluster_type: parent.cluster_type,
|
||||
lazy_rent_collection: AtomicBool::new(
|
||||
parent.lazy_rent_collection.load(Ordering::Relaxed),
|
||||
),
|
||||
|
@ -665,7 +665,7 @@ impl Bank {
|
|||
// clone()-ing is needed to consider a gated behavior in rent_collector
|
||||
rent_collector: fields
|
||||
.rent_collector
|
||||
.clone_with_epoch(fields.epoch, genesis_config.operating_mode),
|
||||
.clone_with_epoch(fields.epoch, genesis_config.cluster_type),
|
||||
epoch_schedule: fields.epoch_schedule,
|
||||
inflation: Arc::new(RwLock::new(fields.inflation)),
|
||||
stakes: RwLock::new(fields.stakes),
|
||||
|
@ -676,7 +676,7 @@ impl Bank {
|
|||
last_vote_sync: new(),
|
||||
rewards: new(),
|
||||
skip_drop: new(),
|
||||
operating_mode: Some(genesis_config.operating_mode),
|
||||
cluster_type: Some(genesis_config.cluster_type),
|
||||
lazy_rent_collection: new(),
|
||||
rewards_pool_pubkeys: new(),
|
||||
};
|
||||
|
@ -1218,7 +1218,7 @@ impl Bank {
|
|||
&self.epoch_schedule,
|
||||
self.slots_per_year,
|
||||
&genesis_config.rent,
|
||||
self.operating_mode(),
|
||||
self.cluster_type(),
|
||||
);
|
||||
|
||||
// Add additional native programs specified in the genesis config
|
||||
|
@ -1619,13 +1619,14 @@ impl Bank {
|
|||
|
||||
// Determine if the bank is currently in an upgrade epoch, where only votes are permitted
|
||||
fn upgrade_epoch(&self) -> bool {
|
||||
match self.operating_mode() {
|
||||
match self.cluster_type() {
|
||||
#[cfg(test)]
|
||||
OperatingMode::Development => self.epoch == 0xdead, // Value assumed by `test_upgrade_epoch()`
|
||||
ClusterType::Development => self.epoch == 0xdead, // Value assumed by `test_upgrade_epoch()`
|
||||
#[cfg(not(test))]
|
||||
OperatingMode::Development => false,
|
||||
OperatingMode::Preview => false,
|
||||
OperatingMode::Stable => self.epoch == 61,
|
||||
ClusterType::Development => false,
|
||||
ClusterType::Devnet => false,
|
||||
ClusterType::Testnet => false,
|
||||
ClusterType::MainnetBeta => self.epoch == 61,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2303,15 +2304,16 @@ impl Bank {
|
|||
let (parent_epoch, mut parent_slot_index) =
|
||||
self.get_epoch_and_slot_index(self.parent_slot());
|
||||
|
||||
let should_enable = match self.operating_mode() {
|
||||
OperatingMode::Development => true,
|
||||
OperatingMode::Preview => current_epoch >= Epoch::max_value(),
|
||||
OperatingMode::Stable => {
|
||||
let should_enable = match self.cluster_type() {
|
||||
ClusterType::Development => true,
|
||||
ClusterType::Devnet => true,
|
||||
ClusterType::Testnet => current_epoch >= Epoch::max_value(),
|
||||
ClusterType::MainnetBeta => {
|
||||
#[cfg(not(test))]
|
||||
let should_enable = current_epoch >= Epoch::max_value();
|
||||
|
||||
// needed for test_rent_eager_across_epoch_with_gap_under_multi_epoch_cycle,
|
||||
// which depends on OperatingMode::Stable
|
||||
// which depends on ClusterType::MainnetBeta
|
||||
#[cfg(test)]
|
||||
let should_enable = true;
|
||||
|
||||
|
@ -2488,14 +2490,14 @@ impl Bank {
|
|||
// within an epoch, so lower the frequency of it.
|
||||
// These logic isn't strictly eager anymore and should only be used
|
||||
// for development/performance purpose.
|
||||
// Absolutely not under OperationMode::Stable!!!!
|
||||
// Absolutely not under ClusterType::MainnetBeta!!!!
|
||||
fn use_multi_epoch_collection_cycle(&self, epoch: Epoch) -> bool {
|
||||
epoch >= self.first_normal_epoch()
|
||||
&& self.slot_count_per_normal_epoch() < self.slot_count_in_two_day()
|
||||
}
|
||||
|
||||
fn use_fixed_collection_cycle(&self) -> bool {
|
||||
self.operating_mode() != OperatingMode::Stable
|
||||
self.cluster_type() != ClusterType::MainnetBeta
|
||||
&& self.slot_count_per_normal_epoch() < self.slot_count_in_two_day()
|
||||
}
|
||||
|
||||
|
@ -2510,10 +2512,10 @@ impl Bank {
|
|||
self.get_slots_in_epoch(self.first_normal_epoch())
|
||||
}
|
||||
|
||||
pub fn operating_mode(&self) -> OperatingMode {
|
||||
// unwrap is safe; self.operating_mode is ensured to be Some() always...
|
||||
pub fn cluster_type(&self) -> ClusterType {
|
||||
// unwrap is safe; self.cluster_type is ensured to be Some() always...
|
||||
// we only using Option here for ABI compatibility...
|
||||
self.operating_mode.unwrap()
|
||||
self.cluster_type.unwrap()
|
||||
}
|
||||
|
||||
/// Process a batch of transactions.
|
||||
|
@ -2624,10 +2626,11 @@ impl Bank {
|
|||
pub fn deposit(&self, pubkey: &Pubkey, lamports: u64) {
|
||||
let mut account = self.get_account(pubkey).unwrap_or_default();
|
||||
|
||||
let should_be_in_new_behavior = match self.operating_mode() {
|
||||
OperatingMode::Development => true,
|
||||
OperatingMode::Preview => self.epoch() >= Epoch::max_value(),
|
||||
OperatingMode::Stable => self.epoch() >= Epoch::max_value(),
|
||||
let should_be_in_new_behavior = match self.cluster_type() {
|
||||
ClusterType::Development => true,
|
||||
ClusterType::Devnet => true,
|
||||
ClusterType::Testnet => self.epoch() >= Epoch::max_value(),
|
||||
ClusterType::MainnetBeta => self.epoch() >= Epoch::max_value(),
|
||||
};
|
||||
|
||||
// don't collect rents if we're in the new behavior;
|
||||
|
@ -3247,7 +3250,7 @@ impl Bank {
|
|||
}
|
||||
|
||||
fn ensure_builtins(&mut self, init_or_warp: bool) {
|
||||
for (program, start_epoch) in get_builtins(self.operating_mode()) {
|
||||
for (program, start_epoch) in get_builtins(self.cluster_type()) {
|
||||
let should_populate = init_or_warp && self.epoch() >= start_epoch
|
||||
|| !init_or_warp && self.epoch() == start_epoch;
|
||||
if should_populate {
|
||||
|
@ -3265,7 +3268,7 @@ impl Bank {
|
|||
}
|
||||
|
||||
fn recheck_cross_program_support(&mut self) {
|
||||
if OperatingMode::Stable == self.operating_mode() {
|
||||
if ClusterType::MainnetBeta == self.cluster_type() {
|
||||
self.set_cross_program_support(self.epoch() >= 63);
|
||||
} else {
|
||||
self.set_cross_program_support(true);
|
||||
|
@ -3273,7 +3276,7 @@ impl Bank {
|
|||
}
|
||||
|
||||
fn recheck_compute_budget(&mut self) {
|
||||
let compute_budget = if OperatingMode::Stable == self.operating_mode() {
|
||||
let compute_budget = if ClusterType::MainnetBeta == self.cluster_type() {
|
||||
if self.epoch() >= u64::MAX - 1 {
|
||||
ComputeBudget::default()
|
||||
} else {
|
||||
|
@ -3294,10 +3297,11 @@ impl Bank {
|
|||
}
|
||||
|
||||
fn reconfigure_token2_native_mint(&mut self) {
|
||||
let reconfigure_token2_native_mint = match self.operating_mode() {
|
||||
OperatingMode::Development => true,
|
||||
OperatingMode::Preview => self.epoch() == 93,
|
||||
OperatingMode::Stable => self.epoch() == 75,
|
||||
let reconfigure_token2_native_mint = match self.cluster_type() {
|
||||
ClusterType::Development => true,
|
||||
ClusterType::Devnet => true,
|
||||
ClusterType::Testnet => self.epoch() == 93,
|
||||
ClusterType::MainnetBeta => self.epoch() == 75,
|
||||
};
|
||||
|
||||
if reconfigure_token2_native_mint {
|
||||
|
@ -3337,13 +3341,14 @@ impl Bank {
|
|||
}
|
||||
|
||||
fn ensure_no_storage_rewards_pool(&mut self) {
|
||||
let purge_window_epoch = match self.operating_mode() {
|
||||
// never do this for testnet; we're pristine here. :)
|
||||
OperatingMode::Development => false,
|
||||
let purge_window_epoch = match self.cluster_type() {
|
||||
ClusterType::Development => false,
|
||||
// never do this for devnet; we're pristine here. :)
|
||||
ClusterType::Devnet => false,
|
||||
// schedule to remove at testnet/tds
|
||||
OperatingMode::Preview => self.epoch() == 93,
|
||||
ClusterType::Testnet => self.epoch() == 93,
|
||||
// never do this for stable; we're pristine here. :)
|
||||
OperatingMode::Stable => false,
|
||||
ClusterType::MainnetBeta => false,
|
||||
};
|
||||
|
||||
if purge_window_epoch {
|
||||
|
@ -3366,10 +3371,11 @@ impl Bank {
|
|||
}
|
||||
|
||||
fn fix_recent_blockhashes_sysvar_delay(&self) -> bool {
|
||||
let activation_slot = match self.operating_mode() {
|
||||
OperatingMode::Development => 0,
|
||||
OperatingMode::Preview => 27_740_256, // Epoch 76
|
||||
OperatingMode::Stable => Slot::MAX / 2,
|
||||
let activation_slot = match self.cluster_type() {
|
||||
ClusterType::Development => 0,
|
||||
ClusterType::Devnet => 0,
|
||||
ClusterType::Testnet => 27_740_256, // Epoch 76
|
||||
ClusterType::MainnetBeta => Slot::MAX / 2,
|
||||
};
|
||||
|
||||
self.slot() >= activation_slot
|
||||
|
@ -3591,7 +3597,7 @@ mod tests {
|
|||
accounts: (0..42)
|
||||
.map(|_| (Pubkey::new_rand(), Account::new(42, 0, &Pubkey::default())))
|
||||
.collect(),
|
||||
operating_mode: OperatingMode::Stable,
|
||||
cluster_type: ClusterType::MainnetBeta,
|
||||
..GenesisConfig::default()
|
||||
}));
|
||||
assert_eq!(bank.capitalization(), 42 * 42);
|
||||
|
@ -4370,7 +4376,7 @@ mod tests {
|
|||
let leader_lamports = 3;
|
||||
let mut genesis_config =
|
||||
create_genesis_config_with_leader(5, &leader_pubkey, leader_lamports).genesis_config;
|
||||
genesis_config.operating_mode = OperatingMode::Stable;
|
||||
genesis_config.cluster_type = ClusterType::MainnetBeta;
|
||||
|
||||
const SLOTS_PER_EPOCH: u64 = MINIMUM_SLOTS_PER_EPOCH as u64;
|
||||
const LEADER_SCHEDULE_SLOT_OFFSET: u64 = SLOTS_PER_EPOCH * 3 - 3;
|
||||
|
@ -4440,7 +4446,7 @@ mod tests {
|
|||
let leader_lamports = 3;
|
||||
let mut genesis_config =
|
||||
create_genesis_config_with_leader(5, &leader_pubkey, leader_lamports).genesis_config;
|
||||
genesis_config.operating_mode = OperatingMode::Stable;
|
||||
genesis_config.cluster_type = ClusterType::MainnetBeta;
|
||||
|
||||
const SLOTS_PER_EPOCH: u64 = MINIMUM_SLOTS_PER_EPOCH as u64;
|
||||
const LEADER_SCHEDULE_SLOT_OFFSET: u64 = SLOTS_PER_EPOCH * 3 - 3;
|
||||
|
@ -4498,7 +4504,7 @@ mod tests {
|
|||
let leader_lamports = 3;
|
||||
let mut genesis_config =
|
||||
create_genesis_config_with_leader(5, &leader_pubkey, leader_lamports).genesis_config;
|
||||
genesis_config.operating_mode = OperatingMode::Stable;
|
||||
genesis_config.cluster_type = ClusterType::MainnetBeta;
|
||||
|
||||
const SLOTS_PER_EPOCH: u64 = MINIMUM_SLOTS_PER_EPOCH as u64 * 8;
|
||||
const LEADER_SCHEDULE_SLOT_OFFSET: u64 = SLOTS_PER_EPOCH * 3 - 3;
|
||||
|
@ -5057,7 +5063,7 @@ mod tests {
|
|||
hashes_per_tick: None,
|
||||
target_tick_count: None,
|
||||
},
|
||||
operating_mode: OperatingMode::Stable,
|
||||
cluster_type: ClusterType::MainnetBeta,
|
||||
|
||||
..GenesisConfig::default()
|
||||
}));
|
||||
|
@ -5169,7 +5175,7 @@ mod tests {
|
|||
hashes_per_tick: None,
|
||||
target_tick_count: None,
|
||||
},
|
||||
operating_mode: OperatingMode::Stable,
|
||||
cluster_type: ClusterType::MainnetBeta,
|
||||
|
||||
..GenesisConfig::default()
|
||||
}));
|
||||
|
@ -8119,7 +8125,7 @@ mod tests {
|
|||
&[],
|
||||
);
|
||||
genesis_config.creation_time = 0;
|
||||
genesis_config.operating_mode = OperatingMode::Stable;
|
||||
genesis_config.cluster_type = ClusterType::MainnetBeta;
|
||||
let mut bank = Arc::new(Bank::new(&genesis_config));
|
||||
// Check a few slots, cross an epoch boundary
|
||||
assert_eq!(bank.get_slots_in_epoch(0), 32);
|
||||
|
@ -8480,16 +8486,16 @@ mod tests {
|
|||
let mut genesis_config =
|
||||
create_genesis_config_with_leader(5, &Pubkey::new_rand(), 0).genesis_config;
|
||||
|
||||
// OperatingMode::Development - Native mint exists immediately
|
||||
assert_eq!(genesis_config.operating_mode, OperatingMode::Development);
|
||||
// ClusterType::Development - Native mint exists immediately
|
||||
assert_eq!(genesis_config.cluster_type, ClusterType::Development);
|
||||
let bank = Arc::new(Bank::new(&genesis_config));
|
||||
assert_eq!(
|
||||
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
|
||||
1000000000
|
||||
);
|
||||
|
||||
// OperatingMode::Preview - Native mint blinks into existence at epoch 93
|
||||
genesis_config.operating_mode = OperatingMode::Preview;
|
||||
// Testnet - Native mint blinks into existence at epoch 93
|
||||
genesis_config.cluster_type = ClusterType::Testnet;
|
||||
let bank = Arc::new(Bank::new(&genesis_config));
|
||||
assert_eq!(
|
||||
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
|
||||
|
@ -8513,8 +8519,8 @@ mod tests {
|
|||
);
|
||||
assert_eq!(native_mint_account.owner, inline_spl_token_v2_0::id());
|
||||
|
||||
// OperatingMode::Stable - Native mint blinks into existence at epoch 75
|
||||
genesis_config.operating_mode = OperatingMode::Stable;
|
||||
// MainnetBeta - Native mint blinks into existence at epoch 75
|
||||
genesis_config.cluster_type = ClusterType::MainnetBeta;
|
||||
let bank = Arc::new(Bank::new(&genesis_config));
|
||||
assert_eq!(
|
||||
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
|
||||
|
@ -8546,9 +8552,9 @@ mod tests {
|
|||
let mut genesis_config =
|
||||
create_genesis_config_with_leader(5, &Pubkey::new_rand(), 0).genesis_config;
|
||||
|
||||
// OperatingMode::Preview - Storage rewards pool is purged at epoch 93
|
||||
// Testnet - Storage rewards pool is purged at epoch 93
|
||||
// Also this is with bad capitalization
|
||||
genesis_config.operating_mode = OperatingMode::Preview;
|
||||
genesis_config.cluster_type = ClusterType::Testnet;
|
||||
genesis_config.inflation = Inflation::default();
|
||||
let reward_pubkey = Pubkey::new_rand();
|
||||
genesis_config.rewards_pools.insert(
|
||||
|
|
|
@ -4,15 +4,15 @@ use crate::{
|
|||
};
|
||||
use solana_sdk::{
|
||||
clock::{Epoch, GENESIS_EPOCH},
|
||||
genesis_config::OperatingMode,
|
||||
genesis_config::ClusterType,
|
||||
system_program,
|
||||
};
|
||||
|
||||
use log::*;
|
||||
|
||||
/// The entire set of available builtin programs that should be active at the given operating_mode
|
||||
pub fn get_builtins(operating_mode: OperatingMode) -> Vec<(Builtin, Epoch)> {
|
||||
trace!("get_builtins: {:?}", operating_mode);
|
||||
/// The entire set of available builtin programs that should be active at the given cluster_type
|
||||
pub fn get_builtins(cluster_type: ClusterType) -> Vec<(Builtin, Epoch)> {
|
||||
trace!("get_builtins: {:?}", cluster_type);
|
||||
let mut builtins = vec![];
|
||||
|
||||
builtins.extend(
|
||||
|
@ -43,9 +43,9 @@ pub fn get_builtins(operating_mode: OperatingMode) -> Vec<(Builtin, Epoch)> {
|
|||
.collect::<Vec<_>>(),
|
||||
);
|
||||
|
||||
// repurpose Preview for test_get_builtins because the Development is overloaded...
|
||||
// repurpose Testnet for test_get_builtins because the Development is overloaded...
|
||||
#[cfg(test)]
|
||||
if operating_mode == OperatingMode::Preview {
|
||||
if cluster_type == ClusterType::Testnet {
|
||||
use solana_sdk::instruction::InstructionError;
|
||||
use solana_sdk::{account::KeyedAccount, pubkey::Pubkey};
|
||||
use std::str::FromStr;
|
||||
|
@ -71,7 +71,7 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::bank::Bank;
|
||||
use solana_sdk::{
|
||||
genesis_config::{create_genesis_config, OperatingMode},
|
||||
genesis_config::{create_genesis_config, ClusterType},
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
||||
|
@ -93,15 +93,16 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_uniqueness() {
|
||||
do_test_uniqueness(get_builtins(OperatingMode::Development));
|
||||
do_test_uniqueness(get_builtins(OperatingMode::Preview));
|
||||
do_test_uniqueness(get_builtins(OperatingMode::Stable));
|
||||
do_test_uniqueness(get_builtins(ClusterType::Development));
|
||||
do_test_uniqueness(get_builtins(ClusterType::Devnet));
|
||||
do_test_uniqueness(get_builtins(ClusterType::Testnet));
|
||||
do_test_uniqueness(get_builtins(ClusterType::MainnetBeta));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_builtins() {
|
||||
let (mut genesis_config, _mint_keypair) = create_genesis_config(100_000);
|
||||
genesis_config.operating_mode = OperatingMode::Preview;
|
||||
genesis_config.cluster_type = ClusterType::Testnet;
|
||||
let bank0 = Arc::new(Bank::new(&genesis_config));
|
||||
|
||||
let restored_slot1 = genesis_config.epoch_schedule.get_first_slot_in_epoch(2);
|
||||
|
|
|
@ -3,7 +3,7 @@ use solana_sdk::{
|
|||
account::Account,
|
||||
clock::Epoch,
|
||||
epoch_schedule::EpochSchedule,
|
||||
genesis_config::{GenesisConfig, OperatingMode},
|
||||
genesis_config::{ClusterType, GenesisConfig},
|
||||
incinerator,
|
||||
pubkey::Pubkey,
|
||||
rent::Rent,
|
||||
|
@ -20,7 +20,7 @@ pub struct RentCollector {
|
|||
// Also, wrap this with Option so that we can spot any uninitialized codepath (like
|
||||
// snapshot restore)
|
||||
#[serde(skip)]
|
||||
pub operating_mode: Option<OperatingMode>,
|
||||
pub cluster_type: Option<ClusterType>,
|
||||
}
|
||||
|
||||
impl Default for RentCollector {
|
||||
|
@ -31,7 +31,7 @@ impl Default for RentCollector {
|
|||
// derive default value using GenesisConfig::default()
|
||||
slots_per_year: GenesisConfig::default().slots_per_year(),
|
||||
rent: Rent::default(),
|
||||
operating_mode: Option::default(),
|
||||
cluster_type: Option::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,30 +42,31 @@ impl RentCollector {
|
|||
epoch_schedule: &EpochSchedule,
|
||||
slots_per_year: f64,
|
||||
rent: &Rent,
|
||||
operating_mode: OperatingMode,
|
||||
cluster_type: ClusterType,
|
||||
) -> Self {
|
||||
Self {
|
||||
epoch,
|
||||
epoch_schedule: *epoch_schedule,
|
||||
slots_per_year,
|
||||
rent: *rent,
|
||||
operating_mode: Some(operating_mode),
|
||||
cluster_type: Some(cluster_type),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clone_with_epoch(&self, epoch: Epoch, operating_mode: OperatingMode) -> Self {
|
||||
pub fn clone_with_epoch(&self, epoch: Epoch, cluster_type: ClusterType) -> Self {
|
||||
Self {
|
||||
epoch,
|
||||
operating_mode: Some(operating_mode),
|
||||
cluster_type: Some(cluster_type),
|
||||
..self.clone()
|
||||
}
|
||||
}
|
||||
|
||||
fn enable_new_behavior(&self) -> bool {
|
||||
match self.operating_mode.unwrap() {
|
||||
OperatingMode::Development => true,
|
||||
OperatingMode::Preview => self.epoch >= Epoch::max_value(),
|
||||
OperatingMode::Stable => self.epoch >= Epoch::max_value(),
|
||||
match self.cluster_type.unwrap() {
|
||||
ClusterType::Development => true,
|
||||
ClusterType::Devnet => true,
|
||||
ClusterType::Testnet => self.epoch >= Epoch::max_value(),
|
||||
ClusterType::MainnetBeta => self.epoch >= Epoch::max_value(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,7 +149,7 @@ mod tests {
|
|||
};
|
||||
|
||||
let rent_collector =
|
||||
RentCollector::default().clone_with_epoch(new_epoch, OperatingMode::Development);
|
||||
RentCollector::default().clone_with_epoch(new_epoch, ClusterType::Development);
|
||||
|
||||
// collect rent on a newly-created account
|
||||
let collected =
|
||||
|
@ -183,7 +184,7 @@ mod tests {
|
|||
|
||||
// create a tested rent collector
|
||||
let rent_collector =
|
||||
RentCollector::default().clone_with_epoch(epoch, OperatingMode::Development);
|
||||
RentCollector::default().clone_with_epoch(epoch, ClusterType::Development);
|
||||
|
||||
// first mark account as being collected while being rent-exempt
|
||||
collected = rent_collector.collect_from_existing_account(&pubkey, &mut account);
|
||||
|
|
|
@ -21,8 +21,8 @@ use {
|
|||
clock::{Epoch, Slot, UnixTimestamp},
|
||||
epoch_schedule::EpochSchedule,
|
||||
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
||||
genesis_config::ClusterType,
|
||||
genesis_config::GenesisConfig,
|
||||
genesis_config::OperatingMode,
|
||||
hard_forks::HardForks,
|
||||
hash::Hash,
|
||||
inflation::Inflation,
|
||||
|
@ -233,7 +233,7 @@ where
|
|||
accounts_db_fields,
|
||||
account_paths,
|
||||
append_vecs_path,
|
||||
&genesis_config.operating_mode,
|
||||
&genesis_config.cluster_type,
|
||||
)?;
|
||||
accounts_db.freeze_accounts(&bank_fields.ancestors, frozen_account_pubkeys);
|
||||
|
||||
|
@ -247,13 +247,13 @@ fn reconstruct_accountsdb_from_fields<E, P>(
|
|||
accounts_db_fields: AccountsDbFields<E>,
|
||||
account_paths: &[PathBuf],
|
||||
stream_append_vecs_path: P,
|
||||
operating_mode: &OperatingMode,
|
||||
cluster_type: &ClusterType,
|
||||
) -> Result<AccountsDB, Error>
|
||||
where
|
||||
E: Into<AccountStorageEntry>,
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
let accounts_db = AccountsDB::new(account_paths.to_vec(), operating_mode);
|
||||
let accounts_db = AccountsDB::new(account_paths.to_vec(), cluster_type);
|
||||
|
||||
let AccountsDbFields(storage, version, slot, bank_hash_info) = accounts_db_fields;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ use {
|
|||
solana_sdk::{
|
||||
account::Account,
|
||||
clock::Slot,
|
||||
genesis_config::{create_genesis_config, OperatingMode},
|
||||
genesis_config::{create_genesis_config, ClusterType},
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
},
|
||||
|
@ -69,7 +69,7 @@ where
|
|||
C::deserialize_accounts_db_fields(stream)?,
|
||||
account_paths,
|
||||
stream_append_vecs_path,
|
||||
&OperatingMode::Development,
|
||||
&ClusterType::Development,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ where
|
|||
fn test_accounts_serialize_style(serde_style: SerdeStyle) {
|
||||
solana_logger::setup();
|
||||
let (_accounts_dir, paths) = get_temp_accounts_paths(4).unwrap();
|
||||
let accounts = Accounts::new(paths, &OperatingMode::Development);
|
||||
let accounts = Accounts::new(paths, &ClusterType::Development);
|
||||
|
||||
let mut pubkeys: Vec<Pubkey> = vec![];
|
||||
create_test_accounts(&accounts, &mut pubkeys, 100, 0);
|
||||
|
|
|
@ -25,20 +25,41 @@ use std::{
|
|||
fs::{File, OpenOptions},
|
||||
io::Write,
|
||||
path::{Path, PathBuf},
|
||||
str::FromStr,
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
// deprecated default that is no longer used
|
||||
pub const UNUSED_DEFAULT: u64 = 1024;
|
||||
|
||||
// The order can't align with release lifecycle only to remain ABI-compatible...
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, AbiEnumVisitor, AbiExample)]
|
||||
pub enum OperatingMode {
|
||||
Preview, // Next set of cluster features to be promoted to Stable
|
||||
Stable, // Stable cluster features
|
||||
Development, // All features (including experimental features)
|
||||
pub enum ClusterType {
|
||||
Testnet,
|
||||
MainnetBeta,
|
||||
Devnet,
|
||||
Development,
|
||||
}
|
||||
|
||||
#[frozen_abi(digest = "2KQs7m2DbLxkEx6pY9Z6qwYJAhN2Q4AdoNgUcULmscgB")]
|
||||
impl ClusterType {
|
||||
pub const STRINGS: [&'static str; 4] = ["development", "devnet", "testnet", "mainnet-beta"];
|
||||
}
|
||||
|
||||
impl FromStr for ClusterType {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"development" => Ok(ClusterType::Development),
|
||||
"devnet" => Ok(ClusterType::Devnet),
|
||||
"testnet" => Ok(ClusterType::Testnet),
|
||||
"mainnet-beta" => Ok(ClusterType::MainnetBeta),
|
||||
_ => Err(format!("{} is unrecognized for cluster type", s)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[frozen_abi(digest = "AM75NxYJj5s45rtkFV5S1RCHg2kNMgACjTu5HPfEt4Fp")]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, AbiExample)]
|
||||
pub struct GenesisConfig {
|
||||
/// when the network (bootstrap validator) was started relative to the UNIX Epoch
|
||||
|
@ -65,7 +86,7 @@ pub struct GenesisConfig {
|
|||
/// how slots map to epochs
|
||||
pub epoch_schedule: EpochSchedule,
|
||||
/// network runlevel
|
||||
pub operating_mode: OperatingMode,
|
||||
pub cluster_type: ClusterType,
|
||||
}
|
||||
|
||||
// useful for basic tests
|
||||
|
@ -101,7 +122,7 @@ impl Default for GenesisConfig {
|
|||
fee_rate_governor: FeeRateGovernor::default(),
|
||||
rent: Rent::default(),
|
||||
epoch_schedule: EpochSchedule::default(),
|
||||
operating_mode: OperatingMode::Development,
|
||||
cluster_type: ClusterType::Development,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -212,7 +233,7 @@ impl fmt::Display for GenesisConfig {
|
|||
f,
|
||||
"\
|
||||
Creation time: {}\n\
|
||||
Operating mode: {:?}\n\
|
||||
Cluster type: {:?}\n\
|
||||
Genesis hash: {}\n\
|
||||
Shred version: {}\n\
|
||||
Ticks per slot: {:?}\n\
|
||||
|
@ -225,7 +246,7 @@ impl fmt::Display for GenesisConfig {
|
|||
Capitalization: {} SOL in {} accounts\n\
|
||||
",
|
||||
Utc.timestamp(self.creation_time, 0).to_rfc3339(),
|
||||
self.operating_mode,
|
||||
self.cluster_type,
|
||||
self.hash(),
|
||||
compute_shred_version(&self.hash(), None),
|
||||
self.ticks_per_slot,
|
||||
|
|
|
@ -361,7 +361,7 @@ mod test {
|
|||
use solana_local_cluster::local_cluster::{ClusterConfig, LocalCluster};
|
||||
use solana_sdk::{
|
||||
commitment_config::CommitmentConfig,
|
||||
genesis_config::OperatingMode,
|
||||
genesis_config::ClusterType,
|
||||
message::Message,
|
||||
native_token::sol_to_lamports,
|
||||
signature::{Keypair, Signer},
|
||||
|
@ -378,7 +378,7 @@ mod test {
|
|||
|
||||
let one_sol = sol_to_lamports(1.0);
|
||||
let cluster = LocalCluster::new(&ClusterConfig {
|
||||
operating_mode: OperatingMode::Stable,
|
||||
cluster_type: ClusterType::MainnetBeta,
|
||||
node_stakes: vec![10; 1],
|
||||
cluster_lamports: sol_to_lamports(1_000_000_000.0),
|
||||
validator_configs: vec![ValidatorConfig {
|
||||
|
|
Loading…
Reference in New Issue