Skip to content

Commit

Permalink
serialize incremental_snapshot_persistence with bank
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Jul 29, 2022
1 parent bc1227e commit 32bebc0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/src/accounts_hash_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ impl AccountsHashVerifier {
accounts_package.snapshot_links.path(),
accounts_package.slot,
&accounts_hash,
None,
);
datapoint_info!(
"accounts_hash_verifier",
Expand Down
3 changes: 3 additions & 0 deletions core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ fn run_bank_forks_snapshot_n<F>(
accounts_package.snapshot_links.path(),
accounts_package.slot,
&last_bank.get_accounts_hash(),
None,
);
let snapshot_package = SnapshotPackage::new(accounts_package, last_bank.get_accounts_hash());
snapshot_utils::archive_snapshot_package(
Expand Down Expand Up @@ -492,6 +493,7 @@ fn test_concurrent_snapshot_packaging(
accounts_package.snapshot_links.path(),
accounts_package.slot,
&Hash::default(),
None,
);
let snapshot_package = SnapshotPackage::new(accounts_package, Hash::default());
pending_snapshot_package
Expand Down Expand Up @@ -535,6 +537,7 @@ fn test_concurrent_snapshot_packaging(
saved_snapshots_dir.path(),
saved_slot,
&Hash::default(),
None,
);

snapshot_utils::verify_snapshot_archive(
Expand Down
13 changes: 11 additions & 2 deletions runtime/src/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
accounts_index::AccountSecondaryIndexes,
accounts_update_notifier_interface::AccountsUpdateNotifier,
append_vec::{AppendVec, StoredMetaWriteVersion},
bank::{Bank, BankFieldsToDeserialize, BankRc},
bank::{Bank, BankFieldsToDeserialize, BankIncrementalSnapshotPersistence, BankRc},
blockhash_queue::BlockhashQueue,
builtins::Builtins,
epoch_stakes::EpochStakes,
Expand Down Expand Up @@ -192,6 +192,7 @@ trait TypeContext<'a>: PartialEq {
stream_reader: &mut BufReader<R>,
stream_writer: &mut BufWriter<W>,
accounts_hash: &Hash,
incremental_snapshot_persistence: Option<BankIncrementalSnapshotPersistence>,
) -> std::result::Result<(), Box<bincode::ErrorKind>>
where
R: Read,
Expand Down Expand Up @@ -367,12 +368,18 @@ fn reserialize_bank_fields_with_new_hash<W, R>(
stream_reader: &mut BufReader<R>,
stream_writer: &mut BufWriter<W>,
accounts_hash: &Hash,
incremental_snapshot_persistence: Option<BankIncrementalSnapshotPersistence>,
) -> Result<(), Error>
where
W: Write,
R: Read,
{
newer::Context::reserialize_bank_fields_with_hash(stream_reader, stream_writer, accounts_hash)
newer::Context::reserialize_bank_fields_with_hash(
stream_reader,
stream_writer,
accounts_hash,
incremental_snapshot_persistence,
)
}

/// effectively updates the accounts hash in the serialized bank file on disk
Expand All @@ -384,6 +391,7 @@ pub fn reserialize_bank_with_new_accounts_hash(
bank_snapshots_dir: impl AsRef<Path>,
slot: Slot,
accounts_hash: &Hash,
incremental_snapshot_persistence: Option<BankIncrementalSnapshotPersistence>,
) -> bool {
let bank_post = snapshot_utils::get_bank_snapshots_dir(bank_snapshots_dir, slot);
let bank_post = bank_post.join(snapshot_utils::get_snapshot_file_name(slot));
Expand All @@ -401,6 +409,7 @@ pub fn reserialize_bank_with_new_accounts_hash(
&mut BufReader::new(file),
&mut BufWriter::new(file_out),
accounts_hash,
incremental_snapshot_persistence,
)
.unwrap();
}
Expand Down
15 changes: 12 additions & 3 deletions runtime/src/serde_snapshot/newer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ impl<'a> TypeContext<'a> for Context {
// we can grab it on restart.
// TODO: if we do a snapshot version bump, consider moving this out.
lamports_per_signature,
None::<BankIncrementalSnapshotPersistence>,
)
.serialize(serializer)
}
Expand Down Expand Up @@ -315,9 +316,10 @@ impl<'a> TypeContext<'a> for Context {
bank_fields.fee_rate_governor = bank_fields
.fee_rate_governor
.clone_with_lamports_per_signature(lamports_per_signature);
let incremental_snapshot_hash =
ignore_eof_error(deserialize_from(stream))?;

let incremental_snapshot_hash = ignore_eof_error(deserialize_from(stream))?;
bank_fields.incremental_snapshot_hash = incremental_snapshot_hash;

Ok((bank_fields, accounts_db_fields))
}

Expand All @@ -337,6 +339,7 @@ impl<'a> TypeContext<'a> for Context {
stream_reader: &mut BufReader<R>,
stream_writer: &mut BufWriter<W>,
accounts_hash: &Hash,
incremental_snapshot_persistence: Option<BankIncrementalSnapshotPersistence>,
) -> std::result::Result<(), Box<bincode::ErrorKind>>
where
R: Read,
Expand All @@ -349,6 +352,7 @@ impl<'a> TypeContext<'a> for Context {
let blockhash_queue = RwLock::new(rhs.blockhash_queue.clone());
let hard_forks = RwLock::new(rhs.hard_forks.clone());
let lamports_per_signature = rhs.fee_rate_governor.lamports_per_signature;

let bank = SerializableVersionedBank {
blockhash_queue: &blockhash_queue,
ancestors: &rhs.ancestors,
Expand Down Expand Up @@ -386,7 +390,12 @@ impl<'a> TypeContext<'a> for Context {

bincode::serialize_into(
stream_writer,
&(bank, accounts_db_fields, lamports_per_signature),
&(
bank,
accounts_db_fields,
lamports_per_signature,
incremental_snapshot_persistence,
),
)
}
}
3 changes: 2 additions & 1 deletion runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ fn test_bank_serialize_style(
assert!(reserialize_bank_with_new_accounts_hash(
temp_dir.path(),
slot,
&accounts_hash
&accounts_hash,
None,
));
let previous_len = buf.len();
// larger buffer than expected to make sure the file isn't larger than expected
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2036,6 +2036,7 @@ pub fn package_and_archive_full_snapshot(
accounts_package.snapshot_links.path(),
accounts_package.slot,
&bank.get_accounts_hash(),
None,
);

let snapshot_package = SnapshotPackage::new(accounts_package, bank.get_accounts_hash());
Expand Down Expand Up @@ -2088,6 +2089,7 @@ pub fn package_and_archive_incremental_snapshot(
accounts_package.snapshot_links.path(),
accounts_package.slot,
&bank.get_accounts_hash(),
None,
);

let snapshot_package = SnapshotPackage::new(accounts_package, bank.get_accounts_hash());
Expand Down

0 comments on commit 32bebc0

Please sign in to comment.