From ffe2d309b28a5bc82311fbd37318f33e78fdbbf2 Mon Sep 17 00:00:00 2001 From: Brooks Date: Fri, 24 Feb 2023 15:27:12 -0500 Subject: [PATCH] Adds serde_snapshot::types module (#30501) --- runtime/src/serde_snapshot.rs | 37 ++++----------------- runtime/src/serde_snapshot/tests.rs | 2 +- runtime/src/serde_snapshot/types.rs | 51 +++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 32 deletions(-) create mode 100644 runtime/src/serde_snapshot/types.rs diff --git a/runtime/src/serde_snapshot.rs b/runtime/src/serde_snapshot.rs index ca1b581e70..1837a138e2 100644 --- a/runtime/src/serde_snapshot.rs +++ b/runtime/src/serde_snapshot.rs @@ -7,7 +7,7 @@ use { AtomicAppendVecId, BankHashStats, IndexGenerationInfo, }, accounts_file::AccountsFile, - accounts_hash::{AccountsDeltaHash, AccountsHash}, + accounts_hash::AccountsHash, accounts_index::AccountSecondaryIndexes, accounts_update_notifier_interface::AccountsUpdateNotifier, append_vec::AppendVec, @@ -54,12 +54,16 @@ use { mod newer; mod storage; mod tests; +mod types; mod utils; -pub(crate) use storage::SerializedAppendVecId; // a number of test cases in accounts_db use this #[cfg(test)] pub(crate) use tests::reconstruct_accounts_db_via_serialization; +pub(crate) use { + storage::SerializedAppendVecId, + types::{SerdeAccountsDeltaHash, SerdeAccountsHash}, +}; #[derive(Copy, Clone, Eq, PartialEq)] pub(crate) enum SerdeStyle { @@ -89,35 +93,6 @@ struct BankHashInfo { 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/tests.rs b/runtime/src/serde_snapshot/tests.rs index 9b6b1399f3..b874f571b3 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 = "FeRj6jpfB3n6FvX2edAhdwYhnBkYZgsqHufd7weFWTfx")] + #[frozen_abi(digest = "2TmCWJdi5zt6Y46PiNcfStrmW8ogqKut2ttRahD3SzMG")] #[derive(Serialize, AbiExample)] pub struct BankAbiTestWrapperNewer { #[serde(serialize_with = "wrapper_newer")] diff --git a/runtime/src/serde_snapshot/types.rs b/runtime/src/serde_snapshot/types.rs new file mode 100644 index 0000000000..ee739a3c61 --- /dev/null +++ b/runtime/src/serde_snapshot/types.rs @@ -0,0 +1,51 @@ +//! Types used by snapshots for safe serialization/deserialization +use { + crate::accounts_hash::{AccountsDeltaHash, AccountsHash, IncrementalAccountsHash}, + serde::{Deserialize, Serialize}, + solana_sdk::hash::Hash, +}; + +/// 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) + } +} + +/// Snapshot serde-safe incremental accounts hash +#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)] +pub struct SerdeIncrementalAccountsHash(pub Hash); + +impl From for IncrementalAccountsHash { + fn from(incremental_accounts_hash: SerdeIncrementalAccountsHash) -> Self { + Self(incremental_accounts_hash.0) + } +} +impl From for SerdeIncrementalAccountsHash { + fn from(incremental_accounts_hash: IncrementalAccountsHash) -> Self { + Self(incremental_accounts_hash.0) + } +}