From 94a0a3847ec3a29d2db3aa70daa04e90141fede9 Mon Sep 17 00:00:00 2001 From: raychu86 <14917648+raychu86@users.noreply.github.com> Date: Tue, 13 Feb 2024 15:50:29 -0800 Subject: [PATCH] Fix committee usage when calculating the next timestamp --- ledger/src/advance.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ledger/src/advance.rs b/ledger/src/advance.rs index ba8de721ff..2c15ae0dc4 100644 --- a/ledger/src/advance.rs +++ b/ledger/src/advance.rs @@ -239,7 +239,17 @@ impl> Ledger { let next_height = previous_block.height().saturating_add(1); // Determine the timestamp for the next block. let next_timestamp = match subdag { - Some(subdag) => subdag.timestamp(&self.latest_committee()?), + Some(subdag) => { + // Get the committee lookback round. + let committee_lookback_round = + subdag.anchor_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}"))?; + // Return the timestamp for the given committee lookback. + subdag.timestamp(&committee_lookback) + } None => OffsetDateTime::now_utc().unix_timestamp(), }; // Compute the next cumulative weight.