feat: add check to verify mempool state #6316
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.
Description
Added a check to verify that the mempool last processed block is in sync with the blockchain state whenever a new block template is requested, as adding a block to the db and processing the same block in the mempool happens asynchronously. Miners can get block templates with double spending if this is not done.
Motivation and Context
In a recent stress test the following behaviour was observed multiple times:
4776...2001
received with output000e9...6b57c
4776d...82001
inserted into the mempoolaf0c8...c76c0
containing output000e9...6b57c
000e9...6b57c
inserted into the db000e9...6b57c
4776d...82001
with output000e9...6b57c
removed from the mempoolaf0c8...c76c0
containing output000e9...6b57c
GetNewBlock
)pub fn prepare_new_block(&self, template: NewBlockTemplate)
fails atlet roots = match calculate_mmr_roots(&*db, self.rules(), &block, &mut smt)
withERROR Output commitment(000e9e1fd41f672e0b88f89b3d24390beb37d50e8be2967980e24a13d796b57c) already in SMT
How Has This Been Tested?
System-level stress test to be done
What process can a PR reviewer use to test or verify this change?
Review code change
Breaking Changes