Skip to content

Commit

Permalink
refactor: combine SlotStateUpdate impls (solana-labs#31578)
Browse files Browse the repository at this point in the history
  • Loading branch information
AshwinSekar authored May 10, 2023
1 parent 18a118b commit c900ef8
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions core/src/cluster_slot_state_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,29 @@ pub enum SlotStateUpdate {
}

impl SlotStateUpdate {
fn into_state_changes(self, slot: Slot) -> Vec<ResultingStateChange> {
let bank_frozen_hash = self.bank_hash();
if bank_frozen_hash.is_none() {
// If the bank hasn't been frozen yet, then there's nothing to do
// since replay of the slot hasn't finished yet.
return vec![];
}

match self {
SlotStateUpdate::Dead(dead_state) => on_dead_slot(slot, dead_state),
SlotStateUpdate::BankFrozen(bank_frozen_state) => {
on_frozen_slot(slot, bank_frozen_state)
}
SlotStateUpdate::DuplicateConfirmed(duplicate_confirmed_state) => {
on_duplicate_confirmed(slot, duplicate_confirmed_state)
}
SlotStateUpdate::Duplicate(duplicate_state) => on_duplicate(duplicate_state),
SlotStateUpdate::EpochSlotsFrozen(epoch_slots_frozen_state) => {
on_epoch_slots_frozen(slot, epoch_slots_frozen_state)
}
}
}

fn bank_hash(&self) -> Option<Hash> {
match self {
SlotStateUpdate::BankFrozen(bank_frozen_state) => Some(bank_frozen_state.frozen_hash),
Expand Down Expand Up @@ -297,31 +320,6 @@ pub enum ResultingStateChange {
SendAncestorHashesReplayUpdate(AncestorHashesReplayUpdate),
}

impl SlotStateUpdate {
fn into_state_changes(self, slot: Slot) -> Vec<ResultingStateChange> {
let bank_frozen_hash = self.bank_hash();
if bank_frozen_hash.is_none() {
// If the bank hasn't been frozen yet, then there's nothing to do
// since replay of the slot hasn't finished yet.
return vec![];
}

match self {
SlotStateUpdate::Dead(dead_state) => on_dead_slot(slot, dead_state),
SlotStateUpdate::BankFrozen(bank_frozen_state) => {
on_frozen_slot(slot, bank_frozen_state)
}
SlotStateUpdate::DuplicateConfirmed(duplicate_confirmed_state) => {
on_duplicate_confirmed(slot, duplicate_confirmed_state)
}
SlotStateUpdate::Duplicate(duplicate_state) => on_duplicate(duplicate_state),
SlotStateUpdate::EpochSlotsFrozen(epoch_slots_frozen_state) => {
on_epoch_slots_frozen(slot, epoch_slots_frozen_state)
}
}
}
}

fn check_duplicate_confirmed_hash_against_frozen_hash(
state_changes: &mut Vec<ResultingStateChange>,
slot: Slot,
Expand Down

0 comments on commit c900ef8

Please sign in to comment.