Skip to content

Commit

Permalink
Fix findLatestCheckPoint (#1187)
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong authored May 2, 2024
1 parent 2eef473 commit b666f13
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions relayer/relays/beacon/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,9 @@ func (h *Header) findLatestCheckPoint(slot uint64) (state.FinalizedHeader, error
}
startIndex := uint64(lastIndex)
endIndex := uint64(0)
if uint64(lastIndex) > h.protocol.Settings.EpochsPerSyncCommitteePeriod {
endIndex = endIndex - h.protocol.Settings.EpochsPerSyncCommitteePeriod
}

syncCommitteePeriod := h.protocol.Settings.SlotsInEpoch * h.protocol.Settings.EpochsPerSyncCommitteePeriod
slotPeriodIndex := slot / syncCommitteePeriod

for index := startIndex; index >= endIndex; index-- {
beaconRoot, err := h.writer.GetFinalizedBeaconRootByIndex(uint32(index))
Expand All @@ -451,10 +449,12 @@ 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 {
break
}
if beaconState.BeaconSlot > slot && beaconState.BeaconSlot < slot+syncCommitteePeriod {
// Found the beaconState
if beaconState.BeaconSlot > slot && beaconState.BeaconSlot < slot+syncCommitteePeriod && slotPeriodIndex == statePeriodIndex {
break
}
}
Expand Down

0 comments on commit b666f13

Please sign in to comment.