Skip to content

Commit

Permalink
Properly subtract the committee lookback range
Browse files Browse the repository at this point in the history
  • Loading branch information
raychu86 committed Feb 15, 2024
1 parent b822aa8 commit c78aaf5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 7 additions & 5 deletions ledger/src/advance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,18 @@ impl<N: Network, C: ConsensusStorage<N>> Ledger<N, C> {
let penultimate_round = subdag.anchor_round().saturating_sub(1);
// Get the round number for the previous committee. Note, we subtract 2 from odd rounds,
// because committees are updated in even rounds.
let committee_lookback_round = match penultimate_round % 2 == 0 {
let previous_penultimate_round = match penultimate_round % 2 == 0 {
true => penultimate_round.saturating_sub(1),
false => penultimate_round.saturating_sub(2),
};
let penultimate_committee_lookback_round =
previous_penultimate_round.saturating_sub(Committee::<N>::COMMITTEE_LOOKBACK_RANGE);
// Retrieve the committee lookback.
let committee_lookback = self
.get_committee_for_round(committee_lookback_round)?
.ok_or(anyhow!("Failed to fetch committee for round {committee_lookback_round}"))?;
let previous_committee_lookback =
self.get_committee_for_round(penultimate_committee_lookback_round)?
.ok_or(anyhow!("Failed to fetch committee for round {penultimate_committee_lookback_round}"))?;
// Return the timestamp for the given committee lookback.
subdag.timestamp(&committee_lookback)
subdag.timestamp(&previous_committee_lookback)
}
None => OffsetDateTime::now_utc().unix_timestamp(),
};
Expand Down
5 changes: 4 additions & 1 deletion ledger/src/check_next_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ impl<N: Network, C: ConsensusStorage<N>> Ledger<N, C> {
let penultimate_round = block.round().saturating_sub(1);
// Get the round number for the previous committee. Note, we subtract 2 from odd rounds,
// because committees are updated in even rounds.
let penultimate_committee_lookback_round = match penultimate_round % 2 == 0 {
let previous_penultimate_round = match penultimate_round % 2 == 0 {
true => penultimate_round.saturating_sub(1),
false => penultimate_round.saturating_sub(2),
};
// Get the previous committee lookback round.
let penultimate_committee_lookback_round =
previous_penultimate_round.saturating_sub(Committee::<N>::COMMITTEE_LOOKBACK_RANGE);
// Retrieve the previous committee lookback.
let previous_committee_lookback = self
.get_committee_for_round(penultimate_committee_lookback_round)?
Expand Down

0 comments on commit c78aaf5

Please sign in to comment.