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:
@ -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);
|
||||
|
Reference in New Issue
Block a user