From b666f139bdc596e2f22abb556e7bdbaae5580b55 Mon Sep 17 00:00:00 2001 From: Ron Date: Thu, 2 May 2024 21:27:56 +0800 Subject: [PATCH] Fix findLatestCheckPoint (#1187) --- relayer/relays/beacon/header/header.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/relayer/relays/beacon/header/header.go b/relayer/relays/beacon/header/header.go index c13e9cbc94..76d2771c15 100644 --- a/relayer/relays/beacon/header/header.go +++ b/relayer/relays/beacon/header/header.go @@ -436,11 +436,9 @@ func (h *Header) findLatestCheckPoint(slot uint64) (state.FinalizedHeader, error } startIndex := uint64(lastIndex) endIndex := uint64(0) - if uint64(lastIndex) > h.protocol.Settings.EpochsPerSyncCommitteePeriod { - endIndex = endIndex - h.protocol.Settings.EpochsPerSyncCommitteePeriod - } syncCommitteePeriod := h.protocol.Settings.SlotsInEpoch * h.protocol.Settings.EpochsPerSyncCommitteePeriod + slotPeriodIndex := slot / syncCommitteePeriod for index := startIndex; index >= endIndex; index-- { beaconRoot, err := h.writer.GetFinalizedBeaconRootByIndex(uint32(index)) @@ -451,10 +449,12 @@ func (h *Header) findLatestCheckPoint(slot uint64) (state.FinalizedHeader, error if err != nil { return beaconState, fmt.Errorf("GetFinalizedHeaderStateByBlockRoot %s, error: %w", beaconRoot.Hex(), err) } + statePeriodIndex := beaconState.BeaconSlot / syncCommitteePeriod if beaconState.BeaconSlot < slot { break } - if beaconState.BeaconSlot > slot && beaconState.BeaconSlot < slot+syncCommitteePeriod { + // Found the beaconState + if beaconState.BeaconSlot > slot && beaconState.BeaconSlot < slot+syncCommitteePeriod && slotPeriodIndex == statePeriodIndex { break } }