fix(pending): Inconsistent pending state #717
Open
+519
−394
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.
Pull Request type
What is the current behavior?
Current Madara pending block storage functions as follows:
The issue with this is that since #623 we are storing part of the pending block in RAM and this update is not being synchronized with the database.
Consider the following flow:
tx.Aqueries the state oftxwithgetTransactionStatus.Bqueries the state oftxwithgetTransactionStatus.What happens in that when
Aqueries the state oftxwe will returnAcceptedOnL2, since that information is in the pending block. WhenBqueries the state oftxagain though, we will return aTrasactionHashNotFounderror: this is because we have just cleared the pending state in RAM and have not yet updated the database to reflect this change.What is the new behavior?
New database update flow is as follows:
This has the effect that pending information can no longer be lost until it has been updated in db. In out previous example,
Bwould still receiveAcceptedOnL2since the state has not yet been flushed from RAM.The
latest_block_nwas also updated to accommodate this change: now it is derived from the state of the pending block in RAM instead of db. This is so as to ensure that the node does not think we have finished flushing the pending block until the RAM cache has been cleared.This also has the advantage that the pending block is now aware of its parent block number, which is useful in some WS RPC methods.
Does this introduce a breaking change?
No