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

Retire sync head (and sync MMR) #3556

Merged
merged 1 commit into from
Feb 24, 2021

Conversation

antiochp
Copy link
Member

@antiochp antiochp commented Feb 3, 2021

This PR retires the sync_head concept along with the underlying sync_header MMR backend structure.

We previously introduced the sync_head alongside the existing header_head to support the scenario where a peer advertises a large fork with greater total difficulty that requires a header sync + full block sync.

  • head would refer to the full block with greatest total difficulty.
  • header_head would refer to the header with greatest total difficulty.
  • sync_head would refer to the current header along the newly advertised fork as we progress with header sync.

This implementation has evolved over time and given our current approach with get_header_by_height and the ability to efficiently lookup headers along the best known header chain back from header_head the concept of sync_head is effectively redundant.

Given the head and header_head we can (in parallel) effectively support new blocks coming in via p2p relay alongside a newly advertised fork (via updated header_head). The sync_head is entirely redundant.
The only time sync_head will be ahead of and distinct to header_head will be during a header sync that involves in excess of 512 headers (multiple batches of headers) and only as long as the new fork is behind the main chain w.r.t. total difficulty. As soon as the total difficulty increases beyond the main chain then header_head will update to reflect the fork.

This PR removes sync_head and the associated MMR backend and reworks header sync to use header_head exclusively and consistently.

Performance wise - this should result in a reasonable improvement as we no longer need to maintain a pair of header MMR (header and sync) structures during header sync.

Stability and robustness wise - less data structures to maintain and keep consistent. Less chance of things getting out of alignment etc.

@antiochp antiochp marked this pull request as ready for review February 10, 2021 15:18
@antiochp antiochp force-pushed the retire_sync_head branch 2 times, most recently from 4d7af0b to 0913744 Compare February 10, 2021 15:21
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.

1 participant