fix: ensure that accumulated orphan chain data is committed before header validation #3462
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.
Description
accumulated target difficulty is available for chain comparison
checked against the fork height.
Motivation and Context
Observed errors:
The above error occurs because of orphan accumulated data was set in the
DbTransaction
but is notactually committed to lmdb. This manifests as a validation error and was not picked up by other tests because
the validator was mocked out.
The solution in this PR is to write the transactions as needed. This means that in a rollback situation, the
accumulated orphan chain data will remain. That should be ok since that data can be overwritten/replaced
on the next reorg evaluation if needed.
This demonstrates the shortcomings of the current approach and the need for the calling code in
BlockchainDatabase<B>
to have access to ACID DB transactions.I have played with the idea of abstracting and generifying atomic transactions but found the need for GAT to get it to work. We no longer
have or use any other BlockchainBackend impl other than LMDB so leaking LMDB
Read,WriteTransaction
may be acceptable. Passing the transaction in to every function in BlockchainBackend may be a deal breaker.
How Has This Been Tested?
handle_possible_reorg::it_links_many_orphan_branches_to_main_chain
Consolidated some of the existing "blockchain builder" test infra that was duplicated and added
a declarative macro for building chains
let specs = block_spec!(["A->GB"], ["B->A", difficulty: 100]);