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

Update syncing logic to fix duplicate block requests #3410

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from

Conversation

kpandl
Copy link
Contributor

@kpandl kpandl commented Oct 3, 2024

Motivation

As issue #3404 described, validators send out duplicate block requests when syncing. This PR updates the syncing logic to make sure we only remove a block response after it was added to the ledger or if we encountered an error.

For background, currently, syncing works as follows: BlockSync requests the blocks, and stores it in the internal responses map. Sync calls block_sync.process_next_block(current_height) to get the next block to process. This removes it from BlockSync’s responses and returns it to Sync. Sync performs the checks, and if successful, adds the block to the ledger. This also updates BlockSync’s canon.

The issue is that BlockSync‘s view of the canon is only updated after Sync is done processing blocks (and adding to the ledger). There’s a window where BlockSync is unaware of blocks that are pending validation in Sync. Thus, it re-requests them.

This PR adjusts the block processing interface to the Sync module as follows:

  • process_next_block READS a block from a particular height
  • remove_block_response REMOVES a block from a particular height, which MUST be called after advancing completed or failed

Test Plan

Ran it locally and verified it removes the duplicate block request.

The following figure shows a syncing process before the fix, with a longer pause until a duplicate request is generated:
syncing_not_fixed

The following figure shows the syncing process with the fix (note there is no double request and no delay, as such, the syncing is much faster):
syncing_fixed

Closes #3404

@vicsn vicsn requested a review from zkxuerb October 3, 2024 13:24
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.

[Bug] Duplicate block requests when validators sync
1 participant