working towards persistence for EpochRewardStatus (#31678)

This commit is contained in:
Jeff Washington (jwash) 2023-05-17 15:23:20 -05:00 committed by GitHub
parent 8ed4962229
commit 3f625e47df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 10 deletions

View File

@ -202,6 +202,7 @@ impl<'a> TypeContext<'a> for Context {
let ancestors = HashMap::from(&serializable_bank.bank.ancestors); let ancestors = HashMap::from(&serializable_bank.bank.ancestors);
let fields = serializable_bank.bank.get_fields_to_serialize(&ancestors); let fields = serializable_bank.bank.get_fields_to_serialize(&ancestors);
let lamports_per_signature = fields.fee_rate_governor.lamports_per_signature; let lamports_per_signature = fields.fee_rate_governor.lamports_per_signature;
let epoch_reward_status = None;
match get_serialize_bank_fields( match get_serialize_bank_fields(
SerializableVersionedBank::from(fields), SerializableVersionedBank::from(fields),
SerializableAccountsDb::<'a, Self> { SerializableAccountsDb::<'a, Self> {
@ -219,8 +220,10 @@ impl<'a> TypeContext<'a> for Context {
.bank .bank
.get_epoch_accounts_hash_to_serialize() .get_epoch_accounts_hash_to_serialize()
.map(|epoch_accounts_hash| *epoch_accounts_hash.as_ref()), .map(|epoch_accounts_hash| *epoch_accounts_hash.as_ref()),
epoch_reward_status,
) { ) {
BankFieldsToSerialize::WithoutEpochRewardStatus(data) => data.serialize(serializer), BankFieldsToSerialize::WithoutEpochRewardStatus(data) => data.serialize(serializer),
BankFieldsToSerialize::WithEpochRewardStatus(data) => data.serialize(serializer),
} }
} }
@ -376,6 +379,7 @@ impl<'a> TypeContext<'a> for Context {
let hard_forks = RwLock::new(std::mem::take(&mut rhs.hard_forks)); let hard_forks = RwLock::new(std::mem::take(&mut rhs.hard_forks));
let lamports_per_signature = rhs.fee_rate_governor.lamports_per_signature; let lamports_per_signature = rhs.fee_rate_governor.lamports_per_signature;
let epoch_accounts_hash = rhs.epoch_accounts_hash.as_ref(); let epoch_accounts_hash = rhs.epoch_accounts_hash.as_ref();
let epoch_reward_status = rhs.epoch_reward_status;
let bank = SerializableVersionedBank { let bank = SerializableVersionedBank {
blockhash_queue: &blockhash_queue, blockhash_queue: &blockhash_queue,
@ -418,10 +422,15 @@ impl<'a> TypeContext<'a> for Context {
lamports_per_signature, lamports_per_signature,
incremental_snapshot_persistence.cloned(), incremental_snapshot_persistence.cloned(),
epoch_accounts_hash.copied(), epoch_accounts_hash.copied(),
matches!(epoch_reward_status, EpochRewardStatus::Active(_))
.then_some(&epoch_reward_status),
) { ) {
BankFieldsToSerialize::WithoutEpochRewardStatus(data) => { BankFieldsToSerialize::WithoutEpochRewardStatus(data) => {
bincode::serialize_into(stream_writer, &data) bincode::serialize_into(stream_writer, &data)
} }
BankFieldsToSerialize::WithEpochRewardStatus(data) => {
bincode::serialize_into(stream_writer, &data)
}
} }
} }
} }
@ -437,22 +446,46 @@ enum BankFieldsToSerialize<'a, T: Serialize> {
Option<Hash>, Option<Hash>,
), ),
), ),
// this will not be readable by <= 1.14
// serialize this if EpochRewardStatus is non-default.
// This allows this code to be present and harmless
WithEpochRewardStatus(
(
SerializableVersionedBank<'a>,
T,
u64,
Option<BankIncrementalSnapshotPersistence>,
Option<Hash>,
&'a EpochRewardStatus,
),
),
} }
/// serializing involves building these fields into a tuple /// serializing involves building these fields into a tuple
/// This occurs during normal serialization and again during re-serialization. /// This occurs during normal serialization and again during re-serialization.
fn get_serialize_bank_fields<T: Serialize>( fn get_serialize_bank_fields<'a, T: Serialize>(
bank: SerializableVersionedBank<'_>, bank: SerializableVersionedBank<'a>,
accounts_db_fields: T, accounts_db_fields: T,
lamports_per_signature: u64, lamports_per_signature: u64,
incremental_snapshot_persistence: Option<BankIncrementalSnapshotPersistence>, incremental_snapshot_persistence: Option<BankIncrementalSnapshotPersistence>,
epoch_accounts_hash: Option<Hash>, epoch_accounts_hash: Option<Hash>,
) -> BankFieldsToSerialize<'_, T> { epoch_reward_status: Option<&'a EpochRewardStatus>,
BankFieldsToSerialize::WithoutEpochRewardStatus(( ) -> BankFieldsToSerialize<'a, T> {
match epoch_reward_status {
Some(epoch_reward_status) => BankFieldsToSerialize::WithEpochRewardStatus((
bank, bank,
accounts_db_fields, accounts_db_fields,
lamports_per_signature, lamports_per_signature,
incremental_snapshot_persistence, incremental_snapshot_persistence,
epoch_accounts_hash, epoch_accounts_hash,
)) epoch_reward_status,
)),
None => BankFieldsToSerialize::WithoutEpochRewardStatus((
bank,
accounts_db_fields,
lamports_per_signature,
incremental_snapshot_persistence,
epoch_accounts_hash,
)),
}
} }