Skip to content

Commit

Permalink
doesnt have to be in the same period
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Sep 26, 2024
1 parent 098ae79 commit a224c2d
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions relayer/relays/beacon/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
}
Expand Down

0 comments on commit a224c2d

Please sign in to comment.