From 8ed496222914311ae67604a1434dfca5894c35b5 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Wed, 17 May 2023 12:53:28 -0500 Subject: [PATCH] refactor serialization tuple into an enum (#31679) --- runtime/src/serde_snapshot/newer.rs | 59 ++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/runtime/src/serde_snapshot/newer.rs b/runtime/src/serde_snapshot/newer.rs index f65943e88d..ee7d23f38c 100644 --- a/runtime/src/serde_snapshot/newer.rs +++ b/runtime/src/serde_snapshot/newer.rs @@ -202,7 +202,7 @@ impl<'a> TypeContext<'a> for Context { let ancestors = HashMap::from(&serializable_bank.bank.ancestors); let fields = serializable_bank.bank.get_fields_to_serialize(&ancestors); let lamports_per_signature = fields.fee_rate_governor.lamports_per_signature; - ( + match get_serialize_bank_fields( SerializableVersionedBank::from(fields), SerializableAccountsDb::<'a, Self> { accounts_db: &serializable_bank.bank.rc.accounts.accounts_db, @@ -219,8 +219,9 @@ impl<'a> TypeContext<'a> for Context { .bank .get_epoch_accounts_hash_to_serialize() .map(|epoch_accounts_hash| *epoch_accounts_hash.as_ref()), - ) - .serialize(serializer) + ) { + BankFieldsToSerialize::WithoutEpochRewardStatus(data) => data.serialize(serializer), + } } #[cfg(test)] @@ -411,15 +412,47 @@ impl<'a> TypeContext<'a> for Context { is_delta: rhs.is_delta, }; - bincode::serialize_into( - stream_writer, - &( - bank, - accounts_db_fields, - lamports_per_signature, - incremental_snapshot_persistence, - epoch_accounts_hash, - ), - ) + match get_serialize_bank_fields( + bank, + accounts_db_fields, + lamports_per_signature, + incremental_snapshot_persistence.cloned(), + epoch_accounts_hash.copied(), + ) { + BankFieldsToSerialize::WithoutEpochRewardStatus(data) => { + bincode::serialize_into(stream_writer, &data) + } + } } } + +enum BankFieldsToSerialize<'a, T: Serialize> { + /// this is compatible with 1.14 + WithoutEpochRewardStatus( + ( + SerializableVersionedBank<'a>, + T, + u64, + Option, + Option, + ), + ), +} + +/// serializing involves building these fields into a tuple +/// This occurs during normal serialization and again during re-serialization. +fn get_serialize_bank_fields( + bank: SerializableVersionedBank<'_>, + accounts_db_fields: T, + lamports_per_signature: u64, + incremental_snapshot_persistence: Option, + epoch_accounts_hash: Option, +) -> BankFieldsToSerialize<'_, T> { + BankFieldsToSerialize::WithoutEpochRewardStatus(( + bank, + accounts_db_fields, + lamports_per_signature, + incremental_snapshot_persistence, + epoch_accounts_hash, + )) +}