-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix find checkpoint #1304
Fix find checkpoint #1304
Conversation
endIndex := startIndex + 1 | ||
iterations := uint64(0) | ||
|
||
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to simplify the loop pattern to stop at(circle back to) the startIndex, something like:
for {
....
index = (index - 1 + totalStates) % totalStates
if index == startIndex {
log.Debug("loop finished, max iterations reached")
break
}
}
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. 😅 Let me know what you think of ba114cf.
index = (index - 1 + totalStates) % totalStates | ||
if index == startIndex { | ||
log.WithError(err).Debug("unable to find a relevant on-chain header, max iterations reached") | ||
break | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to move this to the end or we may miss the first item at startIndex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch: 757581a Added a test for the condition too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
No description provided.