* 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:
parent
c715bc93cf
commit
12e40a40f5
@ -1,5 +1,3 @@
|
|||||||
#[cfg(RUSTC_WITH_SPECIALIZATION)]
|
|
||||||
use solana_frozen_abi::abi_example::IgnoreAsHelper;
|
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
accounts::Accounts,
|
accounts::Accounts,
|
||||||
@ -16,7 +14,7 @@ use {
|
|||||||
epoch_stakes::EpochStakes,
|
epoch_stakes::EpochStakes,
|
||||||
hardened_unpack::UnpackedAppendVecMap,
|
hardened_unpack::UnpackedAppendVecMap,
|
||||||
rent_collector::RentCollector,
|
rent_collector::RentCollector,
|
||||||
serde_snapshot::future::SerializableStorage,
|
serde_snapshot::newer::SerializableStorage,
|
||||||
stakes::Stakes,
|
stakes::Stakes,
|
||||||
},
|
},
|
||||||
bincode::{self, config::Options, Error},
|
bincode::{self, config::Options, Error},
|
||||||
@ -48,7 +46,7 @@ use {
|
|||||||
};
|
};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
mod future;
|
mod newer;
|
||||||
mod tests;
|
mod tests;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
@ -56,7 +54,6 @@ mod utils;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) use self::tests::reconstruct_accounts_db_via_serialization;
|
pub(crate) use self::tests::reconstruct_accounts_db_via_serialization;
|
||||||
pub(crate) use crate::accounts_db::{SnapshotStorage, SnapshotStorages};
|
pub(crate) use crate::accounts_db::{SnapshotStorage, SnapshotStorages};
|
||||||
use future::Context as TypeContextFuture;
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use utils::{serialize_iter_as_map, serialize_iter_as_seq, serialize_iter_as_tuple};
|
use utils::{serialize_iter_as_map, serialize_iter_as_seq, serialize_iter_as_tuple};
|
||||||
|
|
||||||
@ -204,15 +201,15 @@ where
|
|||||||
R: Read,
|
R: Read,
|
||||||
{
|
{
|
||||||
macro_rules! INTO {
|
macro_rules! INTO {
|
||||||
($x:ident) => {{
|
($style:ident) => {{
|
||||||
let (full_snapshot_bank_fields, full_snapshot_accounts_db_fields) =
|
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) =
|
let (incremental_snapshot_bank_fields, incremental_snapshot_accounts_db_fields) =
|
||||||
if let Some(ref mut incremental_snapshot_stream) =
|
if let Some(ref mut incremental_snapshot_stream) =
|
||||||
snapshot_streams.incremental_snapshot_stream
|
snapshot_streams.incremental_snapshot_stream
|
||||||
{
|
{
|
||||||
let (bank_fields, accounts_db_fields) =
|
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))
|
(Some(bank_fields), Some(accounts_db_fields))
|
||||||
} else {
|
} else {
|
||||||
(None, None)
|
(None, None)
|
||||||
@ -242,7 +239,7 @@ where
|
|||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
match serde_style {
|
match serde_style {
|
||||||
SerdeStyle::Newer => INTO!(TypeContextFuture),
|
SerdeStyle::Newer => INTO!(newer),
|
||||||
}
|
}
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("bankrc_from_stream error: {:?}", err);
|
warn!("bankrc_from_stream error: {:?}", err);
|
||||||
@ -260,10 +257,10 @@ where
|
|||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
macro_rules! INTO {
|
macro_rules! INTO {
|
||||||
($x:ident) => {
|
($style:ident) => {
|
||||||
bincode::serialize_into(
|
bincode::serialize_into(
|
||||||
stream,
|
stream,
|
||||||
&SerializableBankAndStorage::<$x> {
|
&SerializableBankAndStorage::<$style::Context> {
|
||||||
bank,
|
bank,
|
||||||
snapshot_storages,
|
snapshot_storages,
|
||||||
phantom: std::marker::PhantomData::default(),
|
phantom: std::marker::PhantomData::default(),
|
||||||
@ -272,7 +269,7 @@ where
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
match serde_style {
|
match serde_style {
|
||||||
SerdeStyle::Newer => INTO!(TypeContextFuture),
|
SerdeStyle::Newer => INTO!(newer),
|
||||||
}
|
}
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("bankrc_to_stream error: {:?}", 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)]
|
#[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)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn reconstruct_bank_from_fields<E>(
|
fn reconstruct_bank_from_fields<E>(
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#[cfg(all(test, RUSTC_WITH_SPECIALIZATION))]
|
|
||||||
use solana_frozen_abi::abi_example::IgnoreAsHelper;
|
|
||||||
use {
|
use {
|
||||||
super::{common::UnusedAccounts, *},
|
super::{common::UnusedAccounts, *},
|
||||||
crate::{ancestors::AncestorsForSerialization, stakes::StakesCache},
|
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 solana_frozen_abi::abi_example::IgnoreAsHelper for SerializableAccountStorageEntry {}
|
||||||
|
|
||||||
impl From<&AccountStorageEntry> for SerializableAccountStorageEntry {
|
impl From<&AccountStorageEntry> for SerializableAccountStorageEntry {
|
||||||
@ -198,7 +196,7 @@ impl<'a> From<crate::bank::BankFieldsToSerialize<'a>> for SerializableVersionedB
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(RUSTC_WITH_SPECIALIZATION)]
|
#[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 {}
|
pub(super) struct Context {}
|
||||||
impl<'a> TypeContext<'a> for Context {
|
impl<'a> TypeContext<'a> for Context {
|
@ -1,4 +1,4 @@
|
|||||||
#[cfg(test)]
|
#![cfg(test)]
|
||||||
use {
|
use {
|
||||||
super::*,
|
super::*,
|
||||||
crate::{
|
crate::{
|
||||||
@ -23,7 +23,6 @@ use {
|
|||||||
tempfile::TempDir,
|
tempfile::TempDir,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
fn copy_append_vecs<P: AsRef<Path>>(
|
fn copy_append_vecs<P: AsRef<Path>>(
|
||||||
accounts_db: &AccountsDb,
|
accounts_db: &AccountsDb,
|
||||||
output_dir: P,
|
output_dir: P,
|
||||||
@ -43,7 +42,6 @@ fn copy_append_vecs<P: AsRef<Path>>(
|
|||||||
Ok(unpacked_append_vec_map)
|
Ok(unpacked_append_vec_map)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
fn check_accounts(accounts: &Accounts, pubkeys: &[Pubkey], num: usize) {
|
fn check_accounts(accounts: &Accounts, pubkeys: &[Pubkey], num: usize) {
|
||||||
for _ in 1..num {
|
for _ in 1..num {
|
||||||
let idx = thread_rng().gen_range(0, num - 1);
|
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>(
|
fn context_accountsdb_from_stream<'a, C, R>(
|
||||||
stream: &mut BufReader<R>,
|
stream: &mut BufReader<R>,
|
||||||
account_paths: &[PathBuf],
|
account_paths: &[PathBuf],
|
||||||
@ -92,7 +89,6 @@ where
|
|||||||
.map(|(accounts_db, _)| accounts_db)
|
.map(|(accounts_db, _)| accounts_db)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
fn accountsdb_from_stream<R>(
|
fn accountsdb_from_stream<R>(
|
||||||
serde_style: SerdeStyle,
|
serde_style: SerdeStyle,
|
||||||
stream: &mut BufReader<R>,
|
stream: &mut BufReader<R>,
|
||||||
@ -103,7 +99,7 @@ where
|
|||||||
R: Read,
|
R: Read,
|
||||||
{
|
{
|
||||||
match serde_style {
|
match serde_style {
|
||||||
SerdeStyle::Newer => context_accountsdb_from_stream::<TypeContextFuture, R>(
|
SerdeStyle::Newer => context_accountsdb_from_stream::<newer::Context, R>(
|
||||||
stream,
|
stream,
|
||||||
account_paths,
|
account_paths,
|
||||||
unpacked_append_vec_map,
|
unpacked_append_vec_map,
|
||||||
@ -111,7 +107,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
fn accountsdb_to_stream<W>(
|
fn accountsdb_to_stream<W>(
|
||||||
serde_style: SerdeStyle,
|
serde_style: SerdeStyle,
|
||||||
stream: &mut W,
|
stream: &mut W,
|
||||||
@ -125,7 +120,7 @@ where
|
|||||||
match serde_style {
|
match serde_style {
|
||||||
SerdeStyle::Newer => serialize_into(
|
SerdeStyle::Newer => serialize_into(
|
||||||
stream,
|
stream,
|
||||||
&SerializableAccountsDb::<TypeContextFuture> {
|
&SerializableAccountsDb::<newer::Context> {
|
||||||
accounts_db,
|
accounts_db,
|
||||||
slot,
|
slot,
|
||||||
account_storage_entries,
|
account_storage_entries,
|
||||||
@ -135,7 +130,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
fn test_accounts_serialize_style(serde_style: SerdeStyle) {
|
fn test_accounts_serialize_style(serde_style: SerdeStyle) {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let (_accounts_dir, paths) = get_temp_accounts_paths(4).unwrap();
|
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));
|
assert_eq!(accounts.bank_hash_at(0), daccounts.bank_hash_at(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
fn test_bank_serialize_style(serde_style: SerdeStyle) {
|
fn test_bank_serialize_style(serde_style: SerdeStyle) {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let (genesis_config, _) = create_genesis_config(500);
|
let (genesis_config, _) = create_genesis_config(500);
|
||||||
@ -260,7 +253,6 @@ fn test_bank_serialize_style(serde_style: SerdeStyle) {
|
|||||||
assert!(bank2 == dbank);
|
assert!(bank2 == dbank);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub(crate) fn reconstruct_accounts_db_via_serialization(
|
pub(crate) fn reconstruct_accounts_db_via_serialization(
|
||||||
accounts: &AccountsDb,
|
accounts: &AccountsDb,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
@ -307,20 +299,20 @@ fn test_bank_serialize_newer() {
|
|||||||
test_bank_serialize_style(SerdeStyle::Newer)
|
test_bank_serialize_style(SerdeStyle::Newer)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(test, RUSTC_WITH_SPECIALIZATION))]
|
#[cfg(RUSTC_WITH_SPECIALIZATION)]
|
||||||
mod test_bank_serialize {
|
mod test_bank_serialize {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
// This some what long test harness is required to freeze the ABI of
|
// This some what long test harness is required to freeze the ABI of
|
||||||
// Bank's serialization due to versioned nature
|
// Bank's serialization due to versioned nature
|
||||||
#[frozen_abi(digest = "EuYcD3JCEWRnQaFHW1CAy2bBqLkakc88iLJtZH6kYeVF")]
|
#[frozen_abi(digest = "4xi75P1M48JwDjxf5k8y43r2w57AjYmgjMB1BmX6hXKK")]
|
||||||
#[derive(Serialize, AbiExample)]
|
#[derive(Serialize, AbiExample)]
|
||||||
pub struct BankAbiTestWrapperFuture {
|
pub struct BankAbiTestWrapperNewer {
|
||||||
#[serde(serialize_with = "wrapper_future")]
|
#[serde(serialize_with = "wrapper_newer")]
|
||||||
bank: Bank,
|
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
|
where
|
||||||
S: serde::Serializer,
|
S: serde::Serializer,
|
||||||
{
|
{
|
||||||
@ -333,7 +325,7 @@ mod test_bank_serialize {
|
|||||||
// ensure there is a single snapshot storage example for ABI digesting
|
// ensure there is a single snapshot storage example for ABI digesting
|
||||||
assert_eq!(snapshot_storages.len(), 1);
|
assert_eq!(snapshot_storages.len(), 1);
|
||||||
|
|
||||||
(SerializableBankAndStorage::<future::Context> {
|
(SerializableBankAndStorage::<newer::Context> {
|
||||||
bank,
|
bank,
|
||||||
snapshot_storages: &snapshot_storages,
|
snapshot_storages: &snapshot_storages,
|
||||||
phantom: std::marker::PhantomData::default(),
|
phantom: std::marker::PhantomData::default(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user