-
Notifications
You must be signed in to change notification settings - Fork 21
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
kcalvinalvin
wants to merge
13
commits into
utreexo:main
Choose a base branch
from
kcalvinalvin:2025-01-03-always-download-headers-first-for-ibd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
netsync: always download headers first during ibd #236
kcalvinalvin
wants to merge
13
commits into
utreexo:main
from
kcalvinalvin:2025-01-03-always-download-headers-first-for-ibd
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
force-pushed
the
2025-01-03-always-download-headers-first-for-ibd
branch
4 times, most recently
from
January 8, 2025 15:58
5bd7d82
to
cd40440
Compare
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
force-pushed
the
2025-01-03-always-download-headers-first-for-ibd
branch
from
January 9, 2025 02:24
cd40440
to
9d0d444
Compare
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.
handleUtreexoHeaderMsg
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
force-pushed
the
2025-01-03-always-download-headers-first-for-ibd
branch
from
January 9, 2025 09:42
9d0d444
to
a517879
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.