Serde snapshot uses own types (#30391)
This commit is contained in:
parent
a8e07c41fe
commit
ec288ded9b
|
@ -54,6 +54,7 @@ use {
|
||||||
read_only_accounts_cache::ReadOnlyAccountsCache,
|
read_only_accounts_cache::ReadOnlyAccountsCache,
|
||||||
rent_collector::RentCollector,
|
rent_collector::RentCollector,
|
||||||
rent_paying_accounts_by_partition::RentPayingAccountsByPartition,
|
rent_paying_accounts_by_partition::RentPayingAccountsByPartition,
|
||||||
|
serde_snapshot::{SerdeAccountsDeltaHash, SerdeAccountsHash},
|
||||||
snapshot_utils::create_accounts_run_and_snapshot_dirs,
|
snapshot_utils::create_accounts_run_and_snapshot_dirs,
|
||||||
sorted_storages::SortedStorages,
|
sorted_storages::SortedStorages,
|
||||||
storable_accounts::StorableAccounts,
|
storable_accounts::StorableAccounts,
|
||||||
|
@ -7325,12 +7326,13 @@ impl AccountsDb {
|
||||||
.insert(slot, accounts_hash)
|
.insert(slot, accounts_hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// After deserializing a snapshot, set the accounts hash for the new AccountsDb
|
||||||
pub fn set_accounts_hash_from_snapshot(
|
pub fn set_accounts_hash_from_snapshot(
|
||||||
&self,
|
&mut self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
accounts_hash: AccountsHash,
|
accounts_hash: SerdeAccountsHash,
|
||||||
) -> Option<AccountsHash> {
|
) -> Option<AccountsHash> {
|
||||||
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
|
/// Get the accounts hash for `slot` in the `accounts_hashes` map
|
||||||
|
@ -7729,12 +7731,13 @@ impl AccountsDb {
|
||||||
.insert(slot, accounts_delta_hash)
|
.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(
|
pub fn set_accounts_delta_hash_from_snapshot(
|
||||||
&self,
|
&mut self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
accounts_delta_hash: AccountsDeltaHash,
|
accounts_delta_hash: SerdeAccountsDeltaHash,
|
||||||
) -> Option<AccountsDeltaHash> {
|
) -> Option<AccountsDeltaHash> {
|
||||||
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
|
/// 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
|
/// 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`.
|
/// default entry at slot 0, and then insert the new value at `slot`.
|
||||||
pub fn update_bank_hash_stats_from_snapshot(
|
pub fn update_bank_hash_stats_from_snapshot(
|
||||||
&self,
|
&mut self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
stats: BankHashStats,
|
stats: BankHashStats,
|
||||||
) -> Option<BankHashStats> {
|
) -> Option<BankHashStats> {
|
||||||
|
|
|
@ -83,11 +83,40 @@ pub struct AccountsDbFields<T>(
|
||||||
|
|
||||||
#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)]
|
#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)]
|
||||||
struct BankHashInfo {
|
struct BankHashInfo {
|
||||||
accounts_delta_hash: AccountsDeltaHash,
|
accounts_delta_hash: SerdeAccountsDeltaHash,
|
||||||
accounts_hash: AccountsHash,
|
accounts_hash: SerdeAccountsHash,
|
||||||
stats: BankHashStats,
|
stats: BankHashStats,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Snapshot serde-safe accounts delta hash
|
||||||
|
#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)]
|
||||||
|
pub struct SerdeAccountsDeltaHash(pub Hash);
|
||||||
|
|
||||||
|
impl From<SerdeAccountsDeltaHash> for AccountsDeltaHash {
|
||||||
|
fn from(accounts_delta_hash: SerdeAccountsDeltaHash) -> Self {
|
||||||
|
Self(accounts_delta_hash.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<AccountsDeltaHash> 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<SerdeAccountsHash> for AccountsHash {
|
||||||
|
fn from(accounts_hash: SerdeAccountsHash) -> Self {
|
||||||
|
Self(accounts_hash.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<AccountsHash> 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
|
/// Helper type to wrap BufReader streams when deserializing and reconstructing from either just a
|
||||||
/// full snapshot, or both a full and incremental snapshot
|
/// full snapshot, or both a full and incremental snapshot
|
||||||
pub struct SnapshotStreams<'a, R> {
|
pub struct SnapshotStreams<'a, R> {
|
||||||
|
|
|
@ -273,6 +273,7 @@ impl<'a> TypeContext<'a> for Context {
|
||||||
let accounts_delta_hash = serializable_db
|
let accounts_delta_hash = serializable_db
|
||||||
.accounts_db
|
.accounts_db
|
||||||
.get_accounts_delta_hash(slot)
|
.get_accounts_delta_hash(slot)
|
||||||
|
.map(Into::into)
|
||||||
.unwrap_or_else(|| panic!("Missing accounts delta hash entry for slot {slot}"));
|
.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
|
// 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
|
// (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
|
let accounts_hash = serializable_db
|
||||||
.accounts_db
|
.accounts_db
|
||||||
.get_accounts_hash(slot)
|
.get_accounts_hash(slot)
|
||||||
|
.map(Into::into)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let stats = serializable_db
|
let stats = serializable_db
|
||||||
.accounts_db
|
.accounts_db
|
||||||
|
@ -369,7 +371,7 @@ impl<'a> TypeContext<'a> for Context {
|
||||||
{
|
{
|
||||||
let (bank_fields, mut accounts_db_fields) =
|
let (bank_fields, mut accounts_db_fields) =
|
||||||
Self::deserialize_bank_fields(stream_reader).unwrap();
|
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 mut rhs = bank_fields;
|
||||||
let blockhash_queue = RwLock::new(std::mem::take(&mut rhs.blockhash_queue));
|
let blockhash_queue = RwLock::new(std::mem::take(&mut rhs.blockhash_queue));
|
||||||
let hard_forks = RwLock::new(std::mem::take(&mut rhs.hard_forks));
|
let hard_forks = RwLock::new(std::mem::take(&mut rhs.hard_forks));
|
||||||
|
|
|
@ -719,7 +719,7 @@ mod test_bank_serialize {
|
||||||
|
|
||||||
// This some what long test harness is required to freeze the ABI of
|
// This some what long test harness is required to freeze the ABI of
|
||||||
// Bank's serialization due to versioned nature
|
// Bank's serialization due to versioned nature
|
||||||
#[frozen_abi(digest = "Eg6gt9thiY8Sn6gDKvpyyHADtWpSt6ur9Z4Zwh1BrCgv")]
|
#[frozen_abi(digest = "FeRj6jpfB3n6FvX2edAhdwYhnBkYZgsqHufd7weFWTfx")]
|
||||||
#[derive(Serialize, AbiExample)]
|
#[derive(Serialize, AbiExample)]
|
||||||
pub struct BankAbiTestWrapperNewer {
|
pub struct BankAbiTestWrapperNewer {
|
||||||
#[serde(serialize_with = "wrapper_newer")]
|
#[serde(serialize_with = "wrapper_newer")]
|
||||||
|
|
Loading…
Reference in New Issue