Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions runtime/src/serde_snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg(RUSTC_WITH_SPECIALIZATION)]
use solana_frozen_abi::abi_example::IgnoreAsHelper;
use {
crate::{
accounts::Accounts,
Expand All @@ -16,7 +14,7 @@ use {
epoch_stakes::EpochStakes,
hardened_unpack::UnpackedAppendVecMap,
rent_collector::RentCollector,
serde_snapshot::future::SerializableStorage,
serde_snapshot::newer::SerializableStorage,
stakes::Stakes,
},
bincode::{self, config::Options, Error},
Expand Down Expand Up @@ -48,15 +46,14 @@ use {
};

mod common;
mod future;
mod newer;
mod tests;
mod utils;

// a number of test cases in accounts_db use this
#[cfg(test)]
pub(crate) use self::tests::reconstruct_accounts_db_via_serialization;
pub(crate) use crate::accounts_db::{SnapshotStorage, SnapshotStorages};
use future::Context as TypeContextFuture;
#[allow(unused_imports)]
use utils::{serialize_iter_as_map, serialize_iter_as_seq, serialize_iter_as_tuple};

Expand Down Expand Up @@ -204,15 +201,15 @@ where
R: Read,
{
macro_rules! INTO {
($x:ident) => {{
($style:ident) => {{
let (full_snapshot_bank_fields, full_snapshot_accounts_db_fields) =
$x::deserialize_bank_fields(snapshot_streams.full_snapshot_stream)?;
$style::Context::deserialize_bank_fields(snapshot_streams.full_snapshot_stream)?;
let (incremental_snapshot_bank_fields, incremental_snapshot_accounts_db_fields) =
if let Some(ref mut incremental_snapshot_stream) =
snapshot_streams.incremental_snapshot_stream
{
let (bank_fields, accounts_db_fields) =
$x::deserialize_bank_fields(incremental_snapshot_stream)?;
$style::Context::deserialize_bank_fields(incremental_snapshot_stream)?;
(Some(bank_fields), Some(accounts_db_fields))
} else {
(None, None)
Expand Down Expand Up @@ -242,7 +239,7 @@ where
}};
}
match serde_style {
SerdeStyle::Newer => INTO!(TypeContextFuture),
SerdeStyle::Newer => INTO!(newer),
}
.map_err(|err| {
warn!("bankrc_from_stream error: {:?}", err);
Expand All @@ -260,10 +257,10 @@ where
W: Write,
{
macro_rules! INTO {
($x:ident) => {
($style:ident) => {
bincode::serialize_into(
stream,
&SerializableBankAndStorage::<$x> {
&SerializableBankAndStorage::<$style::Context> {
bank,
snapshot_storages,
phantom: std::marker::PhantomData::default(),
Expand All @@ -272,7 +269,7 @@ where
};
}
match serde_style {
SerdeStyle::Newer => INTO!(TypeContextFuture),
SerdeStyle::Newer => INTO!(newer),
}
.map_err(|err| {
warn!("bankrc_to_stream error: {:?}", err);
Expand Down Expand Up @@ -312,7 +309,7 @@ impl<'a, C: TypeContext<'a>> Serialize for SerializableAccountsDb<'a, C> {
}

#[cfg(RUSTC_WITH_SPECIALIZATION)]
impl<'a, C> IgnoreAsHelper for SerializableAccountsDb<'a, C> {}
impl<'a, C> solana_frozen_abi::abi_example::IgnoreAsHelper for SerializableAccountsDb<'a, C> {}

#[allow(clippy::too_many_arguments)]
fn reconstruct_bank_from_fields<E>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg(all(test, RUSTC_WITH_SPECIALIZATION))]
use solana_frozen_abi::abi_example::IgnoreAsHelper;
use {
super::{common::UnusedAccounts, *},
crate::{ancestors::AncestorsForSerialization, stakes::StakesCache},
Expand Down Expand Up @@ -30,7 +28,7 @@ impl SerializableStorage for SerializableAccountStorageEntry {
}
}

#[cfg(all(test, RUSTC_WITH_SPECIALIZATION))]
#[cfg(RUSTC_WITH_SPECIALIZATION)]
impl solana_frozen_abi::abi_example::IgnoreAsHelper for SerializableAccountStorageEntry {}

impl From<&AccountStorageEntry> for SerializableAccountStorageEntry {
Expand Down Expand Up @@ -198,7 +196,7 @@ impl<'a> From<crate::bank::BankFieldsToSerialize<'a>> for SerializableVersionedB
}

#[cfg(RUSTC_WITH_SPECIALIZATION)]
impl<'a> IgnoreAsHelper for SerializableVersionedBank<'a> {}
impl<'a> solana_frozen_abi::abi_example::IgnoreAsHelper for SerializableVersionedBank<'a> {}

pub(super) struct Context {}
impl<'a> TypeContext<'a> for Context {
Expand Down
26 changes: 9 additions & 17 deletions runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(test)]
#![cfg(test)]
use {
super::*,
crate::{
Expand All @@ -23,7 +23,6 @@ use {
tempfile::TempDir,
};

#[cfg(test)]
fn copy_append_vecs<P: AsRef<Path>>(
accounts_db: &AccountsDb,
output_dir: P,
Expand All @@ -43,7 +42,6 @@ fn copy_append_vecs<P: AsRef<Path>>(
Ok(unpacked_append_vec_map)
}

#[cfg(test)]
fn check_accounts(accounts: &Accounts, pubkeys: &[Pubkey], num: usize) {
for _ in 1..num {
let idx = thread_rng().gen_range(0, num - 1);
Expand All @@ -57,7 +55,6 @@ fn check_accounts(accounts: &Accounts, pubkeys: &[Pubkey], num: usize) {
}
}

#[cfg(test)]
fn context_accountsdb_from_stream<'a, C, R>(
stream: &mut BufReader<R>,
account_paths: &[PathBuf],
Expand Down Expand Up @@ -92,7 +89,6 @@ where
.map(|(accounts_db, _)| accounts_db)
}

#[cfg(test)]
fn accountsdb_from_stream<R>(
serde_style: SerdeStyle,
stream: &mut BufReader<R>,
Expand All @@ -103,15 +99,14 @@ where
R: Read,
{
match serde_style {
SerdeStyle::Newer => context_accountsdb_from_stream::<TypeContextFuture, R>(
SerdeStyle::Newer => context_accountsdb_from_stream::<newer::Context, R>(
stream,
account_paths,
unpacked_append_vec_map,
),
}
}

#[cfg(test)]
fn accountsdb_to_stream<W>(
serde_style: SerdeStyle,
stream: &mut W,
Expand All @@ -125,7 +120,7 @@ where
match serde_style {
SerdeStyle::Newer => serialize_into(
stream,
&SerializableAccountsDb::<TypeContextFuture> {
&SerializableAccountsDb::<newer::Context> {
accounts_db,
slot,
account_storage_entries,
Expand All @@ -135,7 +130,6 @@ where
}
}

#[cfg(test)]
fn test_accounts_serialize_style(serde_style: SerdeStyle) {
solana_logger::setup();
let (_accounts_dir, paths) = get_temp_accounts_paths(4).unwrap();
Expand Down Expand Up @@ -184,7 +178,6 @@ fn test_accounts_serialize_style(serde_style: SerdeStyle) {
assert_eq!(accounts.bank_hash_at(0), daccounts.bank_hash_at(0));
}

#[cfg(test)]
fn test_bank_serialize_style(serde_style: SerdeStyle) {
solana_logger::setup();
let (genesis_config, _) = create_genesis_config(500);
Expand Down Expand Up @@ -260,7 +253,6 @@ fn test_bank_serialize_style(serde_style: SerdeStyle) {
assert!(bank2 == dbank);
}

#[cfg(test)]
pub(crate) fn reconstruct_accounts_db_via_serialization(
accounts: &AccountsDb,
slot: Slot,
Expand Down Expand Up @@ -307,20 +299,20 @@ fn test_bank_serialize_newer() {
test_bank_serialize_style(SerdeStyle::Newer)
}

#[cfg(all(test, RUSTC_WITH_SPECIALIZATION))]
#[cfg(RUSTC_WITH_SPECIALIZATION)]
mod test_bank_serialize {
use super::*;

// This some what long test harness is required to freeze the ABI of
// Bank's serialization due to versioned nature
#[frozen_abi(digest = "EuYcD3JCEWRnQaFHW1CAy2bBqLkakc88iLJtZH6kYeVF")]
#[frozen_abi(digest = "4xi75P1M48JwDjxf5k8y43r2w57AjYmgjMB1BmX6hXKK")]
#[derive(Serialize, AbiExample)]
pub struct BankAbiTestWrapperFuture {
#[serde(serialize_with = "wrapper_future")]
pub struct BankAbiTestWrapperNewer {
#[serde(serialize_with = "wrapper_newer")]
bank: Bank,
}

pub fn wrapper_future<S>(bank: &Bank, s: S) -> std::result::Result<S::Ok, S::Error>
pub fn wrapper_newer<S>(bank: &Bank, s: S) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
Expand All @@ -333,7 +325,7 @@ mod test_bank_serialize {
// ensure there is a single snapshot storage example for ABI digesting
assert_eq!(snapshot_storages.len(), 1);

(SerializableBankAndStorage::<future::Context> {
(SerializableBankAndStorage::<newer::Context> {
bank,
snapshot_storages: &snapshot_storages,
phantom: std::marker::PhantomData::default(),
Expand Down