Adds serde_snapshot::types module (#30501)

This commit is contained in:
Brooks 2023-02-24 15:27:12 -05:00 committed by GitHub
parent 31573beb2d
commit ffe2d309b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 32 deletions

View File

@ -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<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
/// full snapshot, or both a full and incremental snapshot
pub struct SnapshotStreams<'a, R> {

View File

@ -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")]

View File

@ -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<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)
}
}
/// Snapshot serde-safe incremental accounts hash
#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)]
pub struct SerdeIncrementalAccountsHash(pub Hash);
impl From<SerdeIncrementalAccountsHash> for IncrementalAccountsHash {
fn from(incremental_accounts_hash: SerdeIncrementalAccountsHash) -> Self {
Self(incremental_accounts_hash.0)
}
}
impl From<IncrementalAccountsHash> for SerdeIncrementalAccountsHash {
fn from(incremental_accounts_hash: IncrementalAccountsHash) -> Self {
Self(incremental_accounts_hash.0)
}
}