Skip to content

Commit

Permalink
testing something
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Sep 26, 2024
1 parent a224c2d commit 0a200df
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions relayer/relays/beacon/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,23 +523,32 @@ 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
for index := startIndex; index >= endIndex; index-- {
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")
beaconRoot, err := h.writer.GetFinalizedBeaconRootByIndex(uint32(index))
if err != nil {
return beaconState, fmt.Errorf("GetFinalizedBeaconRootByIndex %d, error: %w", index, err)
}
beaconState, err = h.writer.GetFinalizedHeaderStateByBlockRoot(beaconRoot)
if err != nil {
return beaconState, fmt.Errorf("GetFinalizedHeaderStateByBlockRoot %s, error: %w", beaconRoot.Hex(), err)
log.WithFields(log.Fields{"index": index, "blockRoot": beaconRoot.Hex()}).WithError(err).Info("searching for checkpoint on-chain failed")
break
}
statePeriodIndex := beaconState.BeaconSlot / syncCommitteePeriod

if beaconState.BeaconSlot < slot {
break
}
// Found the beaconState
if beaconState.BeaconSlot > slot && beaconState.BeaconSlot < slot+syncCommitteePeriod {
if beaconState.BeaconSlot > slot && beaconState.BeaconSlot < slot+syncCommitteePeriod && slotPeriodIndex == statePeriodIndex {
log.WithFields(log.Fields{"index": index}).Info("found it!")
break
}
}
Expand Down

0 comments on commit 0a200df

Please # to comment.