forked from btcsuite/btcd
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multi: Refactor and optimize inv discovery.
This refactors the code that locates blocks (inventory discovery) out of server and into blockchain where it can make use of the fact that all block nodes are now in memory and more easily be tested. As an aside, it really belongs in blockchain anyways since it's purely dealing with the block index and best chain. In order to do this reasonably efficiently, a new memory-only height to block node mapping for the main chain is introduced to allow efficient forward traversal of the main chain. This is ultimately intended to be replaced by a chain view. Since the network will be moving to header-based semantics, this also provides an additional optimization to allow headers to be located directly versus needing to first discover the hashes and then fetch the headers. The new functions are named LocateBlocks and LocateHeaders. The former returns a slice of located hashes and the latter returns a slice of located headers. Finally, it also updates the RPC server getheaders call and related plumbing to use the new LocateHeaders function. A comprehensive suite of tests is provided to ensure both functions behave correctly for both correct and incorrect block locators.
- Loading branch information
Showing
6 changed files
with
606 additions
and
150 deletions.
There are no files selected for viewing
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
Oops, something went wrong.