Conversation
Blocks are fetched from a single peer, so the sync runs at the speed of whichever peer was chosen and makes no progress while that peer is slow or unresponsive. Raise DEFAULT_MAX_PEERS from 1 to 8 and give the peers a shared DownloadState holding the blocks left to fetch, the ones in flight, and the ones already received. populate_download_queue fills it by walking back from the best header to the active chain. A block is claimed by one peer, and a peer that disconnects requeues whatever it still owes, so no block is left unfetched. Blocks now arrive out of order, so the block_buffer each peer kept in AwaitingBlock moves into DownloadState and the validation thread drains it. is_on_active_chain releases a block only once its parent has connected, so the kernel sees each chain in order up to whatever has connected so far. Once no peer has work left, the oldest buffered block is sent regardless, since it belongs to a competing branch that will never satisfy that check on its own.
Currently block download runs against whichever peers the address book hands out, but connect names a single address and caps the node at one peer, so there is no way to ask for several specific peers. On regtest, where there are no DNS seeds, that makes a single peer the only reachable setup. Core takes its connect once per address, so joining repeated occurrences keeps each one, and the node splits them apart and raises the peer cap to how many were given. A single address behaves as before. The addresses are read before the kernel starts, so a malformed one now names the value that failed and exits rather than unwinding partway through startup.
Every integration test currently connects to a single peer, so blocks arrive in the order they were asked for and the shared download queue is never split between peers. Add three tests that give the node two peers holding the same chain, one for a plain sync, one for a reorg, and one for a peer going away partway through.
This file contains hidden or 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
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.
Currently, every integration test currently connects to a single peer, so blocks arrive in the order they were asked for and the shared download queue is never split between peers.
This adds three tests that give the node two peers holding the same chain, one for a plain sync, one for a reorg, and one for a peer going away partway through.
This is on top of #107