Skip to content

Commit

Permalink
Remove now-erroneous snapshot test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
CriesofCarrots committed May 3, 2024
1 parent 76159de commit a547820
Showing 1 changed file with 112 additions and 174 deletions.
286 changes: 112 additions & 174 deletions runtime/src/bank/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ mod tests {
use {
crate::{
bank::{
epoch_accounts_hash_utils, partitioned_epoch_rewards::StartBlockHeightAndRewards,
test_utils as bank_test_utils, Bank, EpochRewardStatus,
epoch_accounts_hash_utils, test_utils as bank_test_utils, Bank, EpochRewardStatus,
},
genesis_utils::activate_all_features,
runtime_config::RuntimeConfig,
Expand All @@ -30,7 +29,6 @@ mod tests {
accounts_hash::{AccountsDeltaHash, AccountsHash},
accounts_index::AccountSecondaryIndexes,
epoch_accounts_hash::EpochAccountsHash,
stake_rewards::StakeReward,
},
solana_sdk::{
epoch_schedule::EpochSchedule,
Expand Down Expand Up @@ -335,195 +333,135 @@ mod tests {
#[test]
fn test_extra_fields_eof() {
solana_logger::setup();
let sample_rewards = (0..2)
.map(|_| StakeReward::new_random())
.collect::<Vec<_>>();
for epoch_reward_status_active in [None, Some(vec![]), Some(vec![sample_rewards])] {
let (genesis_config, _) = create_genesis_config(500);

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

add_root_and_flush_write_cache(&bank0);
bank.rc
.accounts
.accounts_db
.set_accounts_delta_hash(bank.slot(), AccountsDeltaHash(Hash::new_unique()));
bank.rc.accounts.accounts_db.set_accounts_hash(
bank.slot(),
(AccountsHash(Hash::new_unique()), u64::default()),
);
let bank0 = Arc::new(Bank::new_for_tests(&genesis_config));
bank0.squash();
let mut bank = Bank::new_from_parent(bank0.clone(), &Pubkey::default(), 1);

// Set extra fields
bank.fee_rate_governor.lamports_per_signature = 7000;
add_root_and_flush_write_cache(&bank0);
bank.rc
.accounts
.accounts_db
.set_accounts_delta_hash(bank.slot(), AccountsDeltaHash(Hash::new_unique()));
bank.rc.accounts.accounts_db.set_accounts_hash(
bank.slot(),
(AccountsHash(Hash::new_unique()), u64::default()),
);

if let Some(rewards) = epoch_reward_status_active.as_ref() {
assert_eq!(bank.block_height(), 1);
bank.set_epoch_reward_status_active(bank.block_height(), rewards.clone());
}
// Set extra fields
bank.fee_rate_governor.lamports_per_signature = 7000;

// Serialize
let snapshot_storages = bank.get_snapshot_storages(None);
let mut buf = vec![];
let mut writer = Cursor::new(&mut buf);
// Serialize
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),
&bank,
&get_storages_to_serialize(&snapshot_storages),
)
.unwrap();

// Deserialize
let rdr = Cursor::new(&buf[..]);
let mut reader = std::io::BufReader::new(&buf[rdr.position() as usize..]);
let mut snapshot_streams = SnapshotStreams {
full_snapshot_stream: &mut reader,
incremental_snapshot_stream: None,
};
let (_accounts_dir, dbank_paths) = get_temp_accounts_paths(4).unwrap();
let copied_accounts = TempDir::new().unwrap();
let storage_and_next_append_vec_id =
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,
&dbank_paths,
storage_and_next_append_vec_id,
&genesis_config,
&RuntimeConfig::default(),
None,
None,
AccountSecondaryIndexes::default(),
None,
AccountShrinkThreshold::default(),
false,
Some(solana_accounts_db::accounts_db::ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
Arc::default(),
)
.unwrap();
crate::serde_snapshot::bank_to_stream(
SerdeStyle::Newer,
&mut std::io::BufWriter::new(&mut writer),
&bank,
&get_storages_to_serialize(&snapshot_storages),
)
.unwrap();

assert_eq!(
bank.fee_rate_governor.lamports_per_signature,
dbank.fee_rate_governor.lamports_per_signature
);
// Deserialize
let rdr = Cursor::new(&buf[..]);
let mut reader = std::io::BufReader::new(&buf[rdr.position() as usize..]);
let mut snapshot_streams = SnapshotStreams {
full_snapshot_stream: &mut reader,
incremental_snapshot_stream: None,
};
let (_accounts_dir, dbank_paths) = get_temp_accounts_paths(4).unwrap();
let copied_accounts = TempDir::new().unwrap();
let storage_and_next_append_vec_id =
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,
&dbank_paths,
storage_and_next_append_vec_id,
&genesis_config,
&RuntimeConfig::default(),
None,
None,
AccountSecondaryIndexes::default(),
None,
AccountShrinkThreshold::default(),
false,
Some(solana_accounts_db::accounts_db::ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
Arc::default(),
)
.unwrap();

// assert epoch_reward_status is the same as the set epoch reward status
let epoch_reward_status = dbank
.get_epoch_reward_status_to_serialize()
.unwrap_or(&EpochRewardStatus::Inactive);
if let Some(rewards) = epoch_reward_status_active {
assert_matches!(epoch_reward_status, EpochRewardStatus::Active(_));
if let EpochRewardStatus::Active(StartBlockHeightAndRewards {
start_block_height,
ref stake_rewards_by_partition,
}) = epoch_reward_status
{
assert_eq!(*start_block_height, 1);
assert_eq!(&rewards[..], &stake_rewards_by_partition[..]);
} else {
unreachable!("Epoch reward status should NOT be inactive.");
}
} else {
assert_matches!(epoch_reward_status, EpochRewardStatus::Inactive);
}
}
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 sample_rewards = (0..2)
.map(|_| StakeReward::new_random())
.collect::<Vec<_>>();
for epoch_reward_status_active in [None, Some(vec![]), Some(vec![sample_rewards])] {
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();
}
let (mut genesis_config, _) = create_genesis_config(500);
activate_all_features(&mut genesis_config);

// Set extra field
bank.fee_rate_governor.lamports_per_signature = 7000;
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();
}

if let Some(rewards) = epoch_reward_status_active.as_ref() {
assert_eq!(bank.block_height(), 1);
bank.set_epoch_reward_status_active(bank.block_height(), rewards.clone());
}
// Set extra field
bank.fee_rate_governor.lamports_per_signature = 7000;

let (_tmp_dir, accounts_dir) = create_tmp_accounts_dir_for_tests();
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_bank_utils::bank_to_full_snapshot_archive(
&bank_snapshots_dir,
&bank,
None,
full_snapshot_archives_dir.path(),
incremental_snapshot_archives_dir.path(),
ArchiveFormat::Tar,
NonZeroUsize::new(1).unwrap(),
NonZeroUsize::new(1).unwrap(),
)
.unwrap();

// Deserialize
let (dbank, _) = snapshot_bank_utils::bank_from_snapshot_archives(
&[accounts_dir],
bank_snapshots_dir.path(),
&snapshot_archive_info,
None,
&genesis_config,
&RuntimeConfig::default(),
None,
None,
AccountSecondaryIndexes::default(),
None,
AccountShrinkThreshold::default(),
false,
false,
false,
false,
Some(solana_accounts_db::accounts_db::ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
Arc::default(),
)
.unwrap();
let (_tmp_dir, accounts_dir) = create_tmp_accounts_dir_for_tests();
let bank_snapshots_dir = TempDir::new().unwrap();
let full_snapshot_archives_dir = TempDir::new().unwrap();
let incremental_snapshot_archives_dir = TempDir::new().unwrap();

assert_eq!(
bank.fee_rate_governor.lamports_per_signature,
dbank.fee_rate_governor.lamports_per_signature
);
// Serialize
let snapshot_archive_info = snapshot_bank_utils::bank_to_full_snapshot_archive(
&bank_snapshots_dir,
&bank,
None,
full_snapshot_archives_dir.path(),
incremental_snapshot_archives_dir.path(),
ArchiveFormat::Tar,
NonZeroUsize::new(1).unwrap(),
NonZeroUsize::new(1).unwrap(),
)
.unwrap();

// assert epoch_reward_status is the same as the set epoch reward status
let epoch_reward_status = dbank
.get_epoch_reward_status_to_serialize()
.unwrap_or(&EpochRewardStatus::Inactive);
if let Some(rewards) = epoch_reward_status_active {
assert_matches!(epoch_reward_status, EpochRewardStatus::Active(_));
if let EpochRewardStatus::Active(StartBlockHeightAndRewards {
start_block_height,
ref stake_rewards_by_partition,
}) = epoch_reward_status
{
assert_eq!(*start_block_height, 1);
assert_eq!(&rewards[..], &stake_rewards_by_partition[..]);
} else {
unreachable!("Epoch reward status should NOT be inactive.");
}
} else {
assert_matches!(epoch_reward_status, EpochRewardStatus::Inactive);
}
}
// Deserialize
let (dbank, _) = snapshot_bank_utils::bank_from_snapshot_archives(
&[accounts_dir],
bank_snapshots_dir.path(),
&snapshot_archive_info,
None,
&genesis_config,
&RuntimeConfig::default(),
None,
None,
AccountSecondaryIndexes::default(),
None,
AccountShrinkThreshold::default(),
false,
false,
false,
false,
Some(solana_accounts_db::accounts_db::ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
Arc::default(),
)
.unwrap();

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

#[test]
Expand Down

0 comments on commit a547820

Please sign in to comment.