Rebase of #12138:
This adds a
setBlockIndexHeaderCandidates
which mimicssetBlockIndexCandidates
and is The set of all leafCBlockIndex
entries withBLOCK_VALID_TREE
(for itself and all ancestors) and as good as our current tip or better. Entries here are potential future candidates for insertion intosetBlockIndexCandidates
, once we get all the required block data. Thus, entries here represent chains on which we should be actively downloading block data.Note that we define “as good as our current tip or better” slightly differently here than in setBlockIndexCandidates - we include things which will have a higher nSequence (but have the same chain work) here, but do not include such entries in setBlockIndexCandidates. This is because we prefer to also download towards chains which have the same total work as our current chain (as an optimization since a reorg is very possible in such cases).
Note that, unlike
setBlockIndexCandidates
, we only store “leaf” entries here, as we are not as aggressively prune-able (setBlockIndexCandidates
are things which we can, and usually do, try to connect immediately, and thus entries dont stick around for long). Thus, it may be the case thatchainActive.Tip()
is NOT insetBlockIndexHeaderCandidates
.Additionally, unlike setBlockIndexCandidates, we are happy to store entries which are not connectable due to pruning here.
This is useful as it (finally) disconnects net_processing logic from the “store on disk” logic in validation.cpp. More importantly, it represents what you’d need from the consensus logic to implement a spv-first sync mode, as this provides a best-header which will follow invalidity - always pointing to the best-possible header even after block(s) are found to be invalid.
Not included:
- #13912 (test framework change)
- #13930 (source code comment which is useful on its own)
- a9db3dada0119c183d16627805e90c4dbca05c6a “Do not unlock cs_main in ABC unless we’ve actually made progress”: already merged as part of #13023
Noteble rebase changes:
pindex_was_in_chain
is still needed due to #12431, in order to notify the gui about a new block tip, only if the active chain was modifiedqt/clientmodel.cpp
changed significantly, because things were moved tointerfaces/node.cpp
- updated
ProcessNewBlock
bench
I added an additional commit, because the new !fHasMoreOrSameWork && !parent_of_header_candidate
check in AcceptBlock
can cause submitblock
(modified in #13439) to mistakingly believe the block is a duplicate.
Added debug log statements to rpc_preciousblock.py
that helped me figure out the above issue.