Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Add full snapshot archive test, enable features in previous tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AshwinSekar committed Jun 1, 2022
1 parent 8e699a9 commit 3aa6098
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 30 deletions.
24 changes: 15 additions & 9 deletions runtime/src/genesis_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,24 @@ pub fn create_genesis_config_with_leader(
pub fn activate_all_features(genesis_config: &mut GenesisConfig) {
// Activate all features at genesis in development mode
for feature_id in FeatureSet::default().inactive {
genesis_config.accounts.insert(
feature_id,
Account::from(feature::create_account(
&Feature {
activated_at: Some(0),
},
std::cmp::max(genesis_config.rent.minimum_balance(Feature::size_of()), 1),
)),
);
activate_feature(genesis_config, feature_id);
}
}

pub fn activate_feature(genesis_config: &mut GenesisConfig, feature_id: Pubkey) {
genesis_config.accounts.insert(
feature_id,
Account::from(feature::create_account(
&Feature {
activated_at: Some(0),
},
std::cmp::max(genesis_config.rent.minimum_balance(Feature::size_of()), 1),
)),
);
}



#[allow(clippy::too_many_arguments)]
pub fn create_genesis_config_with_leader_ex(
mint_lamports: u64,
Expand Down
107 changes: 86 additions & 21 deletions runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ use {
accounts::{test_utils::create_test_accounts, Accounts},
accounts_db::{get_temp_accounts_paths, AccountShrinkThreshold},
bank::{Bank, Rewrites, StatusCacheRc},
genesis_utils::{activate_all_features, activate_feature},
hardened_unpack::UnpackedAppendVecMap,
snapshot_utils::ArchiveFormat,
},
bincode::serialize_into,
rand::{thread_rng, Rng},
solana_sdk::{
account::{AccountSharedData, ReadableAccount},
clock::Slot,
feature_set::disable_fee_calculator,
genesis_config::{create_genesis_config, ClusterType},
pubkey::Pubkey,
signature::{Keypair, Signer},
Expand Down Expand Up @@ -364,23 +367,24 @@ fn test_bank_serialize_newer() {
#[test]
fn test_extra_fields_eof() {
solana_logger::setup();
let (genesis_config, _) = create_genesis_config(500);
let (mut genesis_config, _) = create_genesis_config(500);
activate_feature(&mut genesis_config, disable_fee_calculator::id());

let bank0 = Arc::new(Bank::new_for_tests(&genesis_config));
let mut bank1 = Bank::new_from_parent(&bank0, &Pubkey::default(), 1);
bank0.squash();
let mut bank = Bank::new_from_parent(&bank0, &Pubkey::default(), 1);

// Set extra fields
bank1.fee_calculator.lamports_per_signature = 7000;
bank1.fee_rate_governor.lamports_per_signature = 7000;
bank.fee_rate_governor.lamports_per_signature = 7000;

// Serialize
let snapshot_storages = bank1.get_snapshot_storages(None);
let snapshot_storages = bank.get_snapshot_storages(None);
let mut buf = vec![];
let mut writer = Cursor::new(&mut buf);
crate::serde_snapshot::bank_to_stream(
SerdeStyle::Newer,
&mut std::io::BufWriter::new(&mut writer),
&bank1,
&bank,
&snapshot_storages,
)
.unwrap();
Expand All @@ -395,7 +399,7 @@ fn test_extra_fields_eof() {
let (_accounts_dir, dbank_paths) = get_temp_accounts_paths(4).unwrap();
let copied_accounts = TempDir::new().unwrap();
let unpacked_append_vec_map =
copy_append_vecs(&bank1.rc.accounts.accounts_db, copied_accounts.path()).unwrap();
copy_append_vecs(&bank.rc.accounts.accounts_db, copied_accounts.path()).unwrap();
let dbank = crate::serde_snapshot::bank_from_streams(
SerdeStyle::Newer,
&mut snapshot_streams,
Expand All @@ -414,31 +418,94 @@ fn test_extra_fields_eof() {
)
.unwrap();

assert_eq!(7000, dbank.fee_rate_governor.lamports_per_signature);
assert_eq!(
bank.fee_rate_governor.lamports_per_signature,
dbank.fee_rate_governor.lamports_per_signature
);
}

#[test]
fn test_extra_fields_full_snapshot_archive() {
solana_logger::setup();

let (mut genesis_config, _) = create_genesis_config(500);
activate_all_features(&mut genesis_config);

let bank0 = Arc::new(Bank::new_for_tests(&genesis_config));
let mut bank = Bank::new_from_parent(&bank0, &Pubkey::default(), 1);
while !bank.is_complete() {
bank.fill_bank_with_ticks_for_tests();
}

// Set extra field
bank.fee_rate_governor.lamports_per_signature = 7000;

let accounts_dir = TempDir::new().unwrap();
let bank_snapshots_dir = TempDir::new().unwrap();
let full_snapshot_archives_dir = TempDir::new().unwrap();
let incremental_snapshot_archives_dir = TempDir::new().unwrap();

// Serialize
let snapshot_archive_info = snapshot_utils::bank_to_full_snapshot_archive(
&bank_snapshots_dir,
&bank,
None,
full_snapshot_archives_dir.path(),
incremental_snapshot_archives_dir.path(),
ArchiveFormat::TarBzip2,
1,
0,
)
.unwrap();

// Deserialize
let (dbank, _) = snapshot_utils::bank_from_snapshot_archives(
&[PathBuf::from(accounts_dir.path())],
bank_snapshots_dir.path(),
&snapshot_archive_info,
None,
&genesis_config,
None,
None,
AccountSecondaryIndexes::default(),
false,
None,
AccountShrinkThreshold::default(),
false,
false,
false,
Some(crate::accounts_db::ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
)
.unwrap();

assert_eq!(
bank.fee_rate_governor.lamports_per_signature,
dbank.fee_rate_governor.lamports_per_signature
);
}

#[test]
fn test_blank_extra_fields() {
solana_logger::setup();
let (genesis_config, _) = create_genesis_config(500);
let (mut genesis_config, _) = create_genesis_config(500);
activate_feature(&mut genesis_config, disable_fee_calculator::id());

let bank0 = Arc::new(Bank::new_for_tests(&genesis_config));
let mut bank1 = Bank::new_from_parent(&bank0, &Pubkey::default(), 1);
bank0.squash();
let mut bank = Bank::new_from_parent(&bank0, &Pubkey::default(), 1);

// Set extra fields
bank1.fee_rate_governor.lamports_per_signature = 7000;

// On default it falls back to this value
bank1.fee_calculator.lamports_per_signature = 600;
bank.fee_rate_governor.lamports_per_signature = 7000;

// Serialize, but don't serialize the extra fields
let snapshot_storages = bank1.get_snapshot_storages(None);
let snapshot_storages = bank.get_snapshot_storages(None);
let mut buf = vec![];
let mut writer = Cursor::new(&mut buf);
crate::serde_snapshot::bank_to_stream_no_extra_fields(
SerdeStyle::Newer,
&mut std::io::BufWriter::new(&mut writer),
&bank1,
&bank,
&snapshot_storages,
)
.unwrap();
Expand All @@ -453,7 +520,7 @@ fn test_blank_extra_fields() {
let (_accounts_dir, dbank_paths) = get_temp_accounts_paths(4).unwrap();
let copied_accounts = TempDir::new().unwrap();
let unpacked_append_vec_map =
copy_append_vecs(&bank1.rc.accounts.accounts_db, copied_accounts.path()).unwrap();
copy_append_vecs(&bank.rc.accounts.accounts_db, copied_accounts.path()).unwrap();
let dbank = crate::serde_snapshot::bank_from_streams(
SerdeStyle::Newer,
&mut snapshot_streams,
Expand All @@ -472,10 +539,8 @@ fn test_blank_extra_fields() {
)
.unwrap();

assert_eq!(
bank1.fee_calculator.lamports_per_signature,
dbank.fee_rate_governor.lamports_per_signature
);
// Defaults to 0
assert_eq!(0, dbank.fee_rate_governor.lamports_per_signature);
}

#[cfg(RUSTC_WITH_SPECIALIZATION)]
Expand Down

0 comments on commit 3aa6098

Please sign in to comment.