blockchain: Optimize block locator generation. #1237
Merged
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.
This requires PRs #1229 and #1230.
This significantly optimizes and simplifies the generation of block locators by making use of the fact that all block nodes are now in memory and therefore it is no longer necessary to consult the database for the hashes or worry about issues related to dynamic loading of nodes.
Also, it slightly modifies the algorithm so that the doubling doesn't start for one additional iteration in order to mirror the upstream code. Due to the way block locators are used, this does not change any semantics in terms of requesting and locating blocks.
Finally, the semantics of
BlockLocatorFromHash
have been changed to return a locator for the current tip in the case the hash is unknown. This is preferable since only including the passed block hash, when it isn't known, could end up leading to causing a redownload of the entire chain under certain circumstances.This is work towards #1145.