Skip to content

Commit

Permalink
backport
Browse files Browse the repository at this point in the history
    only READ BankIncrementalSnapshotPersistence in 1.11 (solana-labs#27345)
    serialize incremental_snapshot_hash (backport solana-labs#26839) (solana-labs#27212)
  • Loading branch information
jeffwashington committed Sep 13, 2022
1 parent 884ba62 commit 4a056b9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
19 changes: 19 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,25 @@ impl RentDebit {
}
}

/// Incremental snapshots only calculate their accounts hash based on the account changes WITHIN the incremental slot range.
/// So, we need to keep track of the full snapshot expected accounts hash results.
/// We also need to keep track of the hash and capitalization specific to the incremental snapshot slot range.
/// The capitalization we calculate for the incremental slot will NOT be consistent with the bank's capitalization.
/// It is not feasible to calculate a capitalization delta that is correct given just incremental slots account data and the full snapshot's capitalization.
#[derive(Serialize, Deserialize, AbiExample, Clone, Debug, Default, PartialEq, Eq)]
pub struct BankIncrementalSnapshotPersistence {
/// slot of full snapshot
pub full_slot: Slot,
/// accounts hash from the full snapshot
pub full_hash: Hash,
/// capitalization from the full snapshot
pub full_capitalization: u64,
/// hash of the accounts in the incremental snapshot slot range, including zero-lamport accounts
pub incremental_hash: Hash,
/// capitalization of the accounts in the incremental snapshot slot range
pub incremental_capitalization: u64,
}

#[derive(Clone, Debug, Default, PartialEq)]
pub struct RentDebits(HashMap<Pubkey, RentDebit>);
impl RentDebits {
Expand Down
12 changes: 8 additions & 4 deletions runtime/src/serde_snapshot/newer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ use {
utils::{serialize_iter_as_map, serialize_iter_as_seq},
*,
},
crate::{ancestors::AncestorsForSerialization, stakes::StakesCache},
crate::{
ancestors::AncestorsForSerialization, bank::BankIncrementalSnapshotPersistence,
stakes::StakesCache,
},
solana_measure::measure::Measure,
solana_sdk::deserialize_utils::ignore_eof_error,
std::{cell::RefCell, collections::HashSet, sync::RwLock},
};

Expand Down Expand Up @@ -300,7 +304,7 @@ impl<'a> TypeContext<'a> for Context {
deserialize_from::<_, DeserializableVersionedBank>(&mut stream)?.into();
let accounts_db_fields = Self::deserialize_accounts_db_fields(stream)?;
// Process extra fields
let lamports_per_signature: u64 = match deserialize_from(stream) {
let lamports_per_signature: u64 = match deserialize_from(&mut stream) {
Err(err) if err.to_string() == "io error: unexpected end of file" => Ok(0),
Err(err) if err.to_string() == "io error: failed to fill whole buffer" => Ok(0),
result => result,
Expand All @@ -309,8 +313,8 @@ impl<'a> TypeContext<'a> for Context {
.fee_rate_governor
.clone_with_lamports_per_signature(lamports_per_signature);

let incremental_snapshot_persistence = ignore_eof_error(deserialize_from(stream))?;
bank_fields.incremental_snapshot_persistence = incremental_snapshot_persistence;
let _incremental_snapshot_persistence: Option<BankIncrementalSnapshotPersistence> =
ignore_eof_error(deserialize_from(stream))?;

Ok((bank_fields, accounts_db_fields))
}
Expand Down
9 changes: 9 additions & 0 deletions sdk/src/deserialize_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serde::{Deserialize, Deserializer};


/// This helper function enables successful deserialization of versioned structs; new structs may
/// include additional fields if they impl Default and are added to the end of the struct. Right
/// now, this function is targeted at `bincode` deserialization; the error match may need to be
Expand All @@ -10,6 +11,14 @@ where
T: Deserialize<'de> + Default,
{
let result = T::deserialize(d);
ignore_eof_error::<'de, T, D::Error>(result)
}

pub fn ignore_eof_error<'de, T, D>(result: Result<T, D>) -> Result<T, D>
where
T: Deserialize<'de> + Default,
D: std::fmt::Display,
{
match result {
Err(err) if err.to_string() == "io error: unexpected end of file" => Ok(T::default()),
Err(err) if err.to_string() == "io error: failed to fill whole buffer" => Ok(T::default()),
Expand Down

0 comments on commit 4a056b9

Please sign in to comment.