refactor serialization tuple into an enum (#31679)
This commit is contained in:
parent
ce32cb43db
commit
8ed4962229
|
@ -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,
|
||||
&(
|
||||
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<BankIncrementalSnapshotPersistence>,
|
||||
Option<Hash>,
|
||||
),
|
||||
),
|
||||
}
|
||||
|
||||
/// serializing involves building these fields into a tuple
|
||||
/// This occurs during normal serialization and again during re-serialization.
|
||||
fn get_serialize_bank_fields<T: Serialize>(
|
||||
bank: SerializableVersionedBank<'_>,
|
||||
accounts_db_fields: T,
|
||||
lamports_per_signature: u64,
|
||||
incremental_snapshot_persistence: Option<BankIncrementalSnapshotPersistence>,
|
||||
epoch_accounts_hash: Option<Hash>,
|
||||
) -> BankFieldsToSerialize<'_, T> {
|
||||
BankFieldsToSerialize::WithoutEpochRewardStatus((
|
||||
bank,
|
||||
accounts_db_fields,
|
||||
lamports_per_signature,
|
||||
incremental_snapshot_persistence,
|
||||
epoch_accounts_hash,
|
||||
),
|
||||
)
|
||||
}
|
||||
))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue