From c78aaf5b83e9a95873b2fd4bbdda7970696e8b7f Mon Sep 17 00:00:00 2001 From: raychu86 <14917648+raychu86@users.noreply.github.com> Date: Thu, 15 Feb 2024 15:59:36 -0800 Subject: [PATCH] Properly subtract the committee lookback range --- ledger/src/advance.rs | 12 +++++++----- ledger/src/check_next_block.rs | 5 ++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ledger/src/advance.rs b/ledger/src/advance.rs index eebdb62b74..2dcd1d7ca9 100644 --- a/ledger/src/advance.rs +++ b/ledger/src/advance.rs @@ -244,16 +244,18 @@ impl> Ledger { 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::::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(), }; diff --git a/ledger/src/check_next_block.rs b/ledger/src/check_next_block.rs index 78e33c262d..3a22a21129 100644 --- a/ledger/src/check_next_block.rs +++ b/ledger/src/check_next_block.rs @@ -99,10 +99,13 @@ impl> Ledger { 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::::COMMITTEE_LOOKBACK_RANGE); // Retrieve the previous committee lookback. let previous_committee_lookback = self .get_committee_for_round(penultimate_committee_lookback_round)?