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

netsync: always download headers first during ibd #236

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

kcalvinalvin
Copy link
Contributor

No description provided.

@kcalvinalvin kcalvinalvin changed the title netsync: netsync: always download headers first during ibd Jan 8, 2025
We only exit headersFirstMode when we have no more checkpoints left.
updateSyncPeer was resetting headersFirstMode by calling
resetHeaderState only to have it turned back on with startSync().

Resetting the headers-first mode when we've not really exited the
headers first mode will cause problems with later commits that add
parallel block downloads so we remove it here.
We were still updating invs for peers but since during ibd new blocks
and txs are irrelevant, don't bother updating either.
For headers first mode, there's no need for a global map of requested
blocks since it's only used when we're caught up and need a quick way to
check which blocks were requested instead of searching through all the
requested blocks map for all the connected peers.
@kcalvinalvin kcalvinalvin force-pushed the 2025-01-03-always-download-headers-first-for-ibd branch 4 times, most recently from 5bd7d82 to cd40440 Compare January 8, 2025 15:58
The headerList includes headers we've already downloaded and verified.
Instead of resetting it and re-downloading them on syncPeer disconnects,
we reset the startHeader to be the first header in the list so that we
can re-use the headers and download the blocks associated with it.
checkpoints

Even when we've synced past the checkpoint, it's possible to sync
headers first. To allow for a headers-first download even past the
checkpoints, we add code to verify the block headers before accepting
them when we no longer have any more checkpoints.
handleBlockMsg

handleBlockMsg only handled cases of headers-first mode when there are
checkpoints. The added code handles cases in where there are no more
checkpoints but when the sync manager is still in headers first mode.
resetHeaderState

Since we can be in headers-first mode, we push the best headerNode
regardless of whether or not there's still checkpoints left.
When the chainstate is current and there's no more blocks to sync up to
from our peers, exit headers-first mode.
@kcalvinalvin kcalvinalvin force-pushed the 2025-01-03-always-download-headers-first-for-ibd branch from cd40440 to 9d0d444 Compare January 9, 2025 02:24
peer has

headers-first download is now always preferred over asking for blocks
directly. This eliminates orphan blocks during the initial block
download.
Since we're purely headers-first during ibd, we need to call
resetHeaderState regardless of whether or not we have more checkpmore
checkpoints.
We create a requestedUtreexoHeaders local to each of the peers to be
able to keep track of the utreexo headers requested from each of the
peers.

Just like with blocks, the global state is not used during headers-first
download.
headers-first download

The logic for checking if the block exists within the list of headers
saved was growing and hurting readability. We refactor out the logic to
a separate function.
@kcalvinalvin kcalvinalvin force-pushed the 2025-01-03-always-download-headers-first-for-ibd branch from 9d0d444 to a517879 Compare January 9, 2025 09:42
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