[2.x.x] Fix check_known logic for blocks/headers #2943
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.
We made some recent changes (on the 2.x.x branch) to how we check for "known" blocks when processing headers in the block processing pipeline - #2834
This introduced a subtle bug in how we process full blocks.
Processing a full block that is an orphan (processed out of order, not yet processed the previous block) will add the block the the "orphan block pool".
When checking for "known" blocks we would look in the orphan block pool in addition to the db.
#2834 changed how we process block headers to use the same "known" rules as full blocks - the rationale being we processed headers as part of processing full blocks and we cared about full blocks themselves. Processing a header could stop early if we know we already processed the full block.
But - we do not want to halt processing a header if the block is known via the orphan pool. It has not yet been processed successfully.
This PR changes the
check_known
rules to only look in the db (and the current head, itself in the db). We already handle "orphan" blocks in a performant way by looking for the previous block (in the db). We don not need to inspect the "block orphan pool" when checking if we have seen a block before. We only want to use the orphan pool when seeing if we can now process ex-orphans (which we are already doing).