Skip to content

Commit

Permalink
simplify circular search
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Oct 9, 2024
1 parent 7d7bd67 commit ba114cf
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions relayer/relays/beacon/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,16 +553,14 @@ func (h *Header) findLatestCheckPoint(slot uint64) (state.FinalizedHeader, error
}
startIndex := uint64(lastIndex)

endIndex := startIndex + 1
iterations := uint64(0)
index := startIndex

syncCommitteePeriod := h.protocol.Settings.SlotsInEpoch * h.protocol.Settings.EpochsPerSyncCommitteePeriod
totalStates := h.protocol.Settings.EpochsPerSyncCommitteePeriod * h.protocol.HeaderRedundancy // 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 {
iterations++
// Sanity check, in case the number of loops are more than the states available in the ring buffer
if iterations > totalStates {
for {
index = (index - 1 + totalStates) % totalStates
if index == startIndex {
log.WithError(err).Debug("unable to find a relevant on-chain header, max iterations reached")
break
}
Expand Down

0 comments on commit ba114cf

Please sign in to comment.