Bitcoin

p2p – When will nodes start downloading blocks of IBD?

What I’m interested in is when does a node start requesting blocks? Is it during IBD, or do you first download headers from all peers, generate a complete header tree, and then start downloading blocks for the chain with the most accumulated power and move the active chain tip?

There are two different processes:

The first is IBD. It is divided into two stages (resulting from header pre-synchronization): First, select one peer as the synchronization peer and send them one by one. getheaders request. Transmission begins when the timestamp of the received header begins to approach the current timestamp. getheaders Send a message to other colleagues as well. Verifies the peer response for that header and stores a small identifier (nothing is currently stored in the block header tree).

We move to the second step only after the peer has sent us all the headers it has (all header messages containing less than 2000 objects).

In the second step, we send: getheaders Send messages only for headers that are part of a chain with sufficient cumulative work. There are two conditions: Cumulative work time must be within 1 day of the currently active chain tip and must be greater than a certain predefined value. The first condition at the first moment is a genesis block (and some lower difficulty blocks), so it is easily bypassed by malicious peers, but the second condition is not. At this stage, it doesn’t matter which peer you’re requesting (the sync peer or another peer), it’s important that you ask some peers that you know provided the headers.

More information about header dictionary synchronization can be found in this post.

The second process works similarly to events. This process is triggered whenever a new header is added to the tree (event). Once various prerequisites are met, a block request is sent to one of the peers that is considered to hold that block.

When a node just starts up, the initial sync only “talks” to one peer, so when the sync peer sends us a header, we validate it and put it into the tree. getdata Requests for these blocks are sent immediately to their sync peers.

Therefore no! We build the complete tree without first storing all the headers and then download the blocks. Everything happens simultaneously. But before doing anything else, we first download all headers in the tree for pre-synchronization.

Check out this post for information on this and more.

Related Articles

Back to top button