diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 18e188e491..0655cd36d0 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -54,6 +54,7 @@ use { read_only_accounts_cache::ReadOnlyAccountsCache, rent_collector::RentCollector, rent_paying_accounts_by_partition::RentPayingAccountsByPartition, + serde_snapshot::{SerdeAccountsDeltaHash, SerdeAccountsHash}, snapshot_utils::create_accounts_run_and_snapshot_dirs, sorted_storages::SortedStorages, storable_accounts::StorableAccounts, @@ -7325,12 +7326,13 @@ impl AccountsDb { .insert(slot, accounts_hash) } + /// After deserializing a snapshot, set the accounts hash for the new AccountsDb pub fn set_accounts_hash_from_snapshot( - &self, + &mut self, slot: Slot, - accounts_hash: AccountsHash, + accounts_hash: SerdeAccountsHash, ) -> Option { - self.set_accounts_hash(slot, accounts_hash) + self.set_accounts_hash(slot, accounts_hash.into()) } /// Get the accounts hash for `slot` in the `accounts_hashes` map @@ -7729,12 +7731,13 @@ impl AccountsDb { .insert(slot, accounts_delta_hash) } + /// After deserializing a snapshot, set the accounts delta hash for the new AccountsDb pub fn set_accounts_delta_hash_from_snapshot( - &self, + &mut self, slot: Slot, - accounts_delta_hash: AccountsDeltaHash, + accounts_delta_hash: SerdeAccountsDeltaHash, ) -> Option { - self.set_accounts_delta_hash(slot, accounts_delta_hash) + self.set_accounts_delta_hash(slot, accounts_delta_hash.into()) } /// Get the accounts delta hash for `slot` in the `accounts_delta_hashes` map @@ -7756,7 +7759,7 @@ impl AccountsDb { /// snapshot--the bank hash stats map is populated with a default entry at slot 0. Remove the /// default entry at slot 0, and then insert the new value at `slot`. pub fn update_bank_hash_stats_from_snapshot( - &self, + &mut self, slot: Slot, stats: BankHashStats, ) -> Option { diff --git a/runtime/src/serde_snapshot.rs b/runtime/src/serde_snapshot.rs index 3c5fe8e59a..66be2f0119 100644 --- a/runtime/src/serde_snapshot.rs +++ b/runtime/src/serde_snapshot.rs @@ -83,11 +83,40 @@ pub struct AccountsDbFields( #[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)] struct BankHashInfo { - accounts_delta_hash: AccountsDeltaHash, - accounts_hash: AccountsHash, + accounts_delta_hash: SerdeAccountsDeltaHash, + accounts_hash: SerdeAccountsHash, stats: BankHashStats, } +/// Snapshot serde-safe accounts delta hash +#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)] +pub struct SerdeAccountsDeltaHash(pub Hash); + +impl From for AccountsDeltaHash { + fn from(accounts_delta_hash: SerdeAccountsDeltaHash) -> Self { + Self(accounts_delta_hash.0) + } +} +impl From for SerdeAccountsDeltaHash { + fn from(accounts_delta_hash: AccountsDeltaHash) -> Self { + Self(accounts_delta_hash.0) + } +} + +/// Snapshot serde-safe accounts hash +#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)] +pub struct SerdeAccountsHash(pub Hash); +impl From for AccountsHash { + fn from(accounts_hash: SerdeAccountsHash) -> Self { + Self(accounts_hash.0) + } +} +impl From for SerdeAccountsHash { + fn from(accounts_hash: AccountsHash) -> Self { + Self(accounts_hash.0) + } +} + /// Helper type to wrap BufReader streams when deserializing and reconstructing from either just a /// full snapshot, or both a full and incremental snapshot pub struct SnapshotStreams<'a, R> { diff --git a/runtime/src/serde_snapshot/newer.rs b/runtime/src/serde_snapshot/newer.rs index 104e1909cd..9ae32f98a3 100644 --- a/runtime/src/serde_snapshot/newer.rs +++ b/runtime/src/serde_snapshot/newer.rs @@ -273,6 +273,7 @@ impl<'a> TypeContext<'a> for Context { let accounts_delta_hash = serializable_db .accounts_db .get_accounts_delta_hash(slot) + .map(Into::into) .unwrap_or_else(|| panic!("Missing accounts delta hash entry for slot {slot}")); // NOTE: The accounts hash is calculated in AHV, which is *after* a bank snapshot is taken // (and serialized here). Thus it is expected that an accounts hash is *not* found for @@ -281,6 +282,7 @@ impl<'a> TypeContext<'a> for Context { let accounts_hash = serializable_db .accounts_db .get_accounts_hash(slot) + .map(Into::into) .unwrap_or_default(); let stats = serializable_db .accounts_db @@ -369,7 +371,7 @@ impl<'a> TypeContext<'a> for Context { { let (bank_fields, mut accounts_db_fields) = Self::deserialize_bank_fields(stream_reader).unwrap(); - accounts_db_fields.3.accounts_hash = *accounts_hash; + accounts_db_fields.3.accounts_hash = (*accounts_hash).into(); let mut rhs = bank_fields; let blockhash_queue = RwLock::new(std::mem::take(&mut rhs.blockhash_queue)); let hard_forks = RwLock::new(std::mem::take(&mut rhs.hard_forks)); diff --git a/runtime/src/serde_snapshot/tests.rs b/runtime/src/serde_snapshot/tests.rs index 564dc05d54..9b6b1399f3 100644 --- a/runtime/src/serde_snapshot/tests.rs +++ b/runtime/src/serde_snapshot/tests.rs @@ -719,7 +719,7 @@ mod test_bank_serialize { // This some what long test harness is required to freeze the ABI of // Bank's serialization due to versioned nature - #[frozen_abi(digest = "Eg6gt9thiY8Sn6gDKvpyyHADtWpSt6ur9Z4Zwh1BrCgv")] + #[frozen_abi(digest = "FeRj6jpfB3n6FvX2edAhdwYhnBkYZgsqHufd7weFWTfx")] #[derive(Serialize, AbiExample)] pub struct BankAbiTestWrapperNewer { #[serde(serialize_with = "wrapper_newer")]