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 start height edge case #426

Merged
merged 8 commits into from
Aug 14, 2024
Merged

Fix start height edge case #426

merged 8 commits into from
Aug 14, 2024

Conversation

cam-schultz
Copy link
Collaborator

Why this should be merged

Fixes a bug when handling the edge case in which the the DB stores a height, but the catch up mechanism is disabled. In that scenario, we were initializing the checkpoint manager in such a way that it never committed to the database.

How this works

Suppose the DB stores block 100, the current height is 200, and on restart, we set process-missed-blocks=false. The relayer will correctly skip blocks 100-200 for processing, but will initialize the checkpoint manager with block 100. To prevent gaps, the checkpoint manager only commits blocks if they are exactly 1 greater than the max committed height. In this scenario, the next block height the checkpoint manager sees is 200, which is never committed.

This fixes this by:

  1. Explicitly setting the starting height to the next block (current height + 1) if process-missed-blocks=false
  2. Always starts the goroutine to process blocks on startup, so that there are no gaps. Even if process-missed-blocks=false, there's a race condition between fetching of the current height and the beginning of the Listener that could cause a gap.

How this was tested

CI

How is this documented

N/A

Copy link
Contributor

@iansuvak iansuvak left a comment

Choose a reason for hiding this comment

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

Generally LGTM, few non-blocking comments that I am posting early.

I'll add an approval soon but want to read/think some more on the catchup mechanism before I do.

main/main.go Outdated Show resolved Hide resolved
main/main.go Outdated
zap.Error(err),
// Calculate the starting block height for the relayer only if we're processing historical blocks
// Otherwies, the first block we process is the next block after the current height
height := currentHeight + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, free to drop: I prefer having this in an else statement below the if cfg.ProcessMissedBlocks instead of setting it here and overwriting it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I agree the else statement would make it clearer

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I went with a slightly different approach so that we can emit the process-missed-blocks=false log only once per source chain. Lmk if you agree.

tests/relay_message_api.go Outdated Show resolved Hide resolved
Copy link
Contributor

@geoff-vball geoff-vball left a comment

Choose a reason for hiding this comment

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

LGTM after the comments are addressed

main/main.go Outdated
zap.Error(err),
// Calculate the starting block height for the relayer only if we're processing historical blocks
// Otherwies, the first block we process is the next block after the current height
height := currentHeight + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I agree the else statement would make it clearer

Copy link
Contributor

@iansuvak iansuvak left a comment

Choose a reason for hiding this comment

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

Minor typo but LGTM

main/main.go Outdated Show resolved Hide resolved
Co-authored-by: Ian Suvak <ian.suvak@avalabs.org>
Signed-off-by: cam-schultz <78878559+cam-schultz@users.noreply.github.com>
@cam-schultz cam-schultz merged commit f2c2606 into main Aug 14, 2024
7 checks passed
@cam-schultz cam-schultz deleted the start-height-edge-case branch August 14, 2024 16:37
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.

4 participants