Skip to content

Commit

Permalink
fix wrap around
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Sep 26, 2024
1 parent 17afdaf commit 0f4eb9c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-relayer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- main
- release-v1.0.0
- populate-checkpoint-fix
workflow_dispatch:

env:
Expand Down
8 changes: 6 additions & 2 deletions relayer/relays/beacon/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,15 @@ func (h *Header) findLatestCheckPoint(slot uint64) (state.FinalizedHeader, error
return beaconState, fmt.Errorf("GetLastFinalizedStateIndex error: %w", err)
}
startIndex := uint64(lastIndex)
endIndex := uint64(0)
endIndex := startIndex + 1

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-- {
for index := startIndex; index != endIndex; index = (index - 1 + totalStates) % totalStates {
log.WithFields(log.Fields{"index": index}).Info("searching for checkpoint on-chain")
beaconRoot, err := h.writer.GetFinalizedBeaconRootByIndex(uint32(index))
if err != nil {
return beaconState, fmt.Errorf("GetFinalizedBeaconRootByIndex %d, error: %w", index, err)
Expand All @@ -538,6 +541,7 @@ func (h *Header) findLatestCheckPoint(slot uint64) (state.FinalizedHeader, error
return beaconState, fmt.Errorf("GetFinalizedHeaderStateByBlockRoot %s, error: %w", beaconRoot.Hex(), err)
}
statePeriodIndex := beaconState.BeaconSlot / syncCommitteePeriod

if beaconState.BeaconSlot < slot {
break
}
Expand Down

0 comments on commit 0f4eb9c

Please sign in to comment.