From ffcf2d6211600b53fb80fe4fcaaf015d18cb8b23 Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:20:36 +0800 Subject: [PATCH] fix: beacon: validate drand change at nv16 correctly --- pkg/beacon/beacon.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/beacon/beacon.go b/pkg/beacon/beacon.go index fb17a4e8e8..abf27c9f59 100644 --- a/pkg/beacon/beacon.go +++ b/pkg/beacon/beacon.go @@ -78,11 +78,15 @@ func ValidateBlockValues(bSchedule Schedule, nv network.Version, h *types.BlockH return fmt.Errorf("expected final beacon entry in block to be at round %d, got %d", maxRound, last.Round) } - // Verify that all other entries' rounds are as expected for the epochs in between parentEpoch and h.Height - for i, e := range h.BeaconEntries { - correctRound := currBeacon.MaxBeaconRoundForEpoch(nv, parentEpoch+abi.ChainEpoch(i)+1) - if e.Round != correctRound { - return fmt.Errorf("unexpected beacon round %d, expected %d for epoch %d", e.Round, correctRound, parentEpoch+abi.ChainEpoch(i)) + // If the beacon is UNchained, verify that the block only includes the rounds we want for the epochs in between parentEpoch and h.Height + // For chained beacons, you must have all the rounds forming a valid chain with prevEntry, so we can skip this step + if !currBeacon.IsChained() { + // Verify that all other entries' rounds are as expected for the epochs in between parentEpoch and h.Height + for i, e := range h.BeaconEntries { + correctRound := currBeacon.MaxBeaconRoundForEpoch(nv, parentEpoch+abi.ChainEpoch(i)+1) + if e.Round != correctRound { + return fmt.Errorf("unexpected beacon round %d, expected %d for epoch %d", e.Round, correctRound, parentEpoch+abi.ChainEpoch(i)) + } } }