Cleanup serde snapshot's "future" to "newer" (backport #22431) (#22870)

* Refactor serde snapshot's "future" to "newer" (#22431)

(cherry picked from commit 9c3144e2863ffd3215f6c6e6e5475044f380ac3e)

# Conflicts:
#	runtime/src/serde_snapshot.rs

* fixup conflicts

* fixup remove unused use

Co-authored-by: Brooks Prumo <brooks@solana.com>
This commit is contained in:
mergify[bot] 2022-02-01 19:03:02 +00:00 committed by GitHub
parent c715bc93cf
commit 12e40a40f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 34 deletions

View File

@ -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<E>(

View File

@ -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<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 {

View File

@ -1,4 +1,4 @@
#[cfg(test)]
#![cfg(test)]
use {
super::*,
crate::{
@ -23,7 +23,6 @@ use {
tempfile::TempDir,
};
#[cfg(test)]
fn copy_append_vecs<P: AsRef<Path>>(
accounts_db: &AccountsDb,
output_dir: P,
@ -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);
@ -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],
@ -92,7 +89,6 @@ where
.map(|(accounts_db, _)| accounts_db)
}
#[cfg(test)]
fn accountsdb_from_stream<R>(
serde_style: SerdeStyle,
stream: &mut BufReader<R>,
@ -103,7 +99,7 @@ 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,
@ -111,7 +107,6 @@ where
}
}
#[cfg(test)]
fn accountsdb_to_stream<W>(
serde_style: SerdeStyle,
stream: &mut W,
@ -125,7 +120,7 @@ where
match serde_style {
SerdeStyle::Newer => serialize_into(
stream,
&SerializableAccountsDb::<TypeContextFuture> {
&SerializableAccountsDb::<newer::Context> {
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<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,
{
@ -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(),