Skip to content
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

Merged
merged 5 commits into from
Oct 9, 2024

Conversation

claravanstaden
Copy link
Contributor

No description provided.

@claravanstaden claravanstaden marked this pull request as ready for review October 8, 2024 19:09
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 {
Copy link
Contributor

@yrong yrong Oct 8, 2024

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
    }
}
...

Copy link
Contributor Author

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.

Comment on lines 562 to 567
index = (index - 1 + totalStates) % totalStates
if index == startIndex {
log.WithError(err).Debug("unable to find a relevant on-chain header, max iterations reached")
break
}

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@yrong yrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@claravanstaden claravanstaden merged commit 1f8252d into ron/fix-find-checkpoint Oct 9, 2024
1 check passed
@claravanstaden claravanstaden deleted the clara/fix-find-checkpoint branch October 9, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants