What I am all for is at what level does node begin requesting for
blocks? Is it throughout IBD or does it first obtain headers from all
friends, create an entire header tree and solely then begin downloading
blocks for the chain with essentially the most cumulative energy and transfer the
energetic chain tip?
There are two completely different processes.
The primary is IBD. It’s divided in two phases (attributable to header pre-sync). In first we choose one peer because the sync peer and ship him one after the other getheaders
requests. Because the timestamp of acquired headers begins to method the present timestamp, we begin sending getheaders
messages to different friends as effectively. Peer responses with corresponding headers, we validate them and retailer their tiny identifiers (nothing is saved in block header tree at this second).
Solely after the friends ship us all of the headers they’ve (all header messages with lower than 2000 objects) we transfer to the second part.
Within the second part, we ship getheaders
messages just for headers which might be a part of the chain that has sufficient cumulative work. There are two situations: that cumulative work have to be inside at some point of the present energetic chain tip and better than a sure predefined worth. For the reason that first situation on the very first second is a genesis block (and a few low issue blocks), it is going to be simply bypassed by malicious peer, nevertheless, the second situation is not going to. At this part, it doesn’t matter which peer you’re requesting (whether or not it’s sync peer or another), it is just necessary that we ask some peer for which we all know it has given header.
Extra to examine header pre-synchronization yow will discover in this submit.
The second course of works, one thing like, on occasions. At any time when a brand new header is added to the tree (occasion) this course of is triggered. If numerous vital situations are met, a request for the block can be despatched to one of many friends that’s thought-about to have it.
When a node is simply began, since in preliminary synchronization we solely “speak” to 1 peer, then as sync peer sends us headers, we validate them and put within the tree, getdata
requests for these blocks can be despatched to that sync peer instantly.
Due to this fact, no! We don’t retailer all headers first, create full tree after which obtain blocks. All the things is finished concurrently. Nevertheless, we do obtain all headers within the tree for pre-sync first, earlier than doing anything.
For this and far more different info test this submit.