diff --git a/runtime/src/serde_snapshot.rs b/runtime/src/serde_snapshot.rs index adf59e00a6..3bec35ff6b 100644 --- a/runtime/src/serde_snapshot.rs +++ b/runtime/src/serde_snapshot.rs @@ -1,5 +1,3 @@ -#[cfg(RUSTC_WITH_SPECIALIZATION)] -use solana_frozen_abi::abi_example::IgnoreAsHelper; use { crate::{ accounts::Accounts, @@ -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}, @@ -48,7 +46,7 @@ use { }; mod common; -mod future; +mod newer; mod tests; mod utils; @@ -56,7 +54,6 @@ mod utils; #[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}; @@ -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) @@ -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); @@ -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(), @@ -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); @@ -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( diff --git a/runtime/src/serde_snapshot/future.rs b/runtime/src/serde_snapshot/newer.rs similarity index 98% rename from runtime/src/serde_snapshot/future.rs rename to runtime/src/serde_snapshot/newer.rs index 96960e0c1b..31aca58c3e 100644 --- a/runtime/src/serde_snapshot/future.rs +++ b/runtime/src/serde_snapshot/newer.rs @@ -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}, @@ -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 { @@ -198,7 +196,7 @@ impl<'a> From> 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 { diff --git a/runtime/src/serde_snapshot/tests.rs b/runtime/src/serde_snapshot/tests.rs index c4975827bd..0c11b3c86f 100644 --- a/runtime/src/serde_snapshot/tests.rs +++ b/runtime/src/serde_snapshot/tests.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +#![cfg(test)] use { super::*, crate::{ @@ -23,7 +23,6 @@ use { tempfile::TempDir, }; -#[cfg(test)] fn copy_append_vecs>( accounts_db: &AccountsDb, output_dir: P, @@ -43,7 +42,6 @@ fn copy_append_vecs>( 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); @@ -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, account_paths: &[PathBuf], @@ -92,7 +89,6 @@ where .map(|(accounts_db, _)| accounts_db) } -#[cfg(test)] fn accountsdb_from_stream( serde_style: SerdeStyle, stream: &mut BufReader, @@ -103,7 +99,7 @@ where R: Read, { match serde_style { - SerdeStyle::Newer => context_accountsdb_from_stream::( + SerdeStyle::Newer => context_accountsdb_from_stream::( stream, account_paths, unpacked_append_vec_map, @@ -111,7 +107,6 @@ where } } -#[cfg(test)] fn accountsdb_to_stream( serde_style: SerdeStyle, stream: &mut W, @@ -125,7 +120,7 @@ where match serde_style { SerdeStyle::Newer => serialize_into( stream, - &SerializableAccountsDb:: { + &SerializableAccountsDb:: { accounts_db, slot, account_storage_entries, @@ -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(); @@ -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); @@ -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, @@ -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(bank: &Bank, s: S) -> std::result::Result + pub fn wrapper_newer(bank: &Bank, s: S) -> std::result::Result where S: serde::Serializer, { @@ -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:: { + (SerializableBankAndStorage:: { bank, snapshot_storages: &snapshot_storages, phantom: std::marker::PhantomData::default(),