From a224c2d26a8133676d5df2a63763f8ee274c8b01 Mon Sep 17 00:00:00 2001 From: claravanstaden Date: Thu, 26 Sep 2024 16:47:12 +0200 Subject: [PATCH] doesnt have to be in the same period --- relayer/relays/beacon/header/header.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/relayer/relays/beacon/header/header.go b/relayer/relays/beacon/header/header.go index 48d71ba474..c69e7ff822 100644 --- a/relayer/relays/beacon/header/header.go +++ b/relayer/relays/beacon/header/header.go @@ -523,15 +523,10 @@ func (h *Header) findLatestCheckPoint(slot uint64) (state.FinalizedHeader, error return beaconState, fmt.Errorf("GetLastFinalizedStateIndex error: %w", err) } startIndex := uint64(lastIndex) - endIndex := startIndex + 1 + endIndex := uint64(0) syncCommitteePeriod := h.protocol.Settings.SlotsInEpoch * h.protocol.Settings.EpochsPerSyncCommitteePeriod - slotPeriodIndex := slot / syncCommitteePeriod - totalStates := syncCommitteePeriod * 20 // Total size of the circular buffer, - // https://github.com/paritytech/polkadot-sdk/blob/master/bridges/snowbridge/pallets/ethereum-client/src/lib.rs#L75 - - for index := startIndex; index != endIndex; index = (index - 1 + totalStates) % totalStates { - log.WithFields(log.Fields{"index": index}).Info("searching for checkpoint on-chain") + for index := startIndex; index >= endIndex; index-- { beaconRoot, err := h.writer.GetFinalizedBeaconRootByIndex(uint32(index)) if err != nil { return beaconState, fmt.Errorf("GetFinalizedBeaconRootByIndex %d, error: %w", index, err) @@ -540,15 +535,11 @@ 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 { - log.WithFields(log.Fields{"index": index}).Info("break condition") - //break + break } // Found the beaconState - if beaconState.BeaconSlot > slot && beaconState.BeaconSlot < slot+syncCommitteePeriod && slotPeriodIndex == statePeriodIndex { - log.WithFields(log.Fields{"index": index}).Info("found it!") + if beaconState.BeaconSlot > slot && beaconState.BeaconSlot < slot+syncCommitteePeriod { break } }