Skip to content

Commit

Permalink
chore(sidecar): furthest_slot helper
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Oct 28, 2024
1 parent 6f5b344 commit 7640f2d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions bolt-sidecar/src/state/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,8 @@ impl ConsensusState {
) -> Result<BlsPublicKey, ConsensusError> {
let CommitmentRequest::Inclusion(req) = request;

let furthest_slot = self.epoch.start_slot
+ SLOTS_PER_EPOCH
+ if self.unsafe_lookahead_enabled { SLOTS_PER_EPOCH } else { 0 };

// Check if the slot is in the current epoch or next epoch (if unsafe lookahead is enabled)
if req.slot < self.epoch.start_slot || req.slot >= furthest_slot {
if req.slot < self.epoch.start_slot || req.slot >= self.furthest_slot() {
return Err(ConsensusError::InvalidSlot(req.slot));
}

Expand Down Expand Up @@ -200,6 +196,14 @@ impl ConsensusState {
.map(|duty| duty.public_key.clone())
.ok_or(ConsensusError::ValidatorNotFound)
}

/// Returns the furthest slot for which a commitment request is considered valid, whether in
/// the current epoch or next epoch (if unsafe lookahead is enabled)
fn furthest_slot(&self) -> u64 {
self.epoch.start_slot
+ SLOTS_PER_EPOCH
+ if self.unsafe_lookahead_enabled { SLOTS_PER_EPOCH } else { 0 }
}
}

#[cfg(test)]
Expand Down

0 comments on commit 7640f2d

Please sign in to comment.