Fix revert txs and inconsistent state #433
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 PR fixes the potential inconsistent state during mem-pool reset.
Issue
Some users report they found txs revert after get the tx receipt.
Context:
The mem-pool reset it's state when receive new l2block, then calculate new state of the next block:
Unlike withdrawals & txs, the deposits is collected from layer1 CKB's cells, and the count of collected deposits is uncertain everytime.
This 'uncertain' causes the problem, every time we reset the mem-pool the deposits cells may changed, and new created accounts are changed, for example:
The first time mem-pool reset creates 3 accounts:
But when the mem-pool resets again, the accounts are changed:
In example, we collected another new deposit cell, the new deposit changes the id of contract account.
Solution:
This PR introduce a pending_deposits fields in the mem-pool. The new collected deposits cells are stored in the
pending_deposits
field.Thus, everytime we reset mem-pool, we use the same pending_deposits to construct next block, so we can get consistent state.
There are two refresh strategy of
pending_deposits
: