subxt: Sychronize finalized tx status with chain head #1300
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 synchronizes the finalized hash reported by
transaction_unstable
with the finalized hashes reported by thechainhead_follow
.The CI has detected two issues with the Unstable Backend:
Invalid transaction: Transaction is outdated"
assertion failed: alice_pre.data.free - 10_000 >= alice_post.data.free
After about 500 runs in a loop, I was not able to reproduce the issue locally.
Code Analysis
Both issues could arise when the
wait_for_finalized
method on a transaction finishes before the finalized block has been reported by thechainHead
class.The first issue would reproduce when the account nonce is fetched from the previous block hash, therefore resubmitting the transaction. Similarly, for the second issue, the store is fetched from an older block where the transaction was not present, because of the above race.
Timeline
This timeline illustrates the edge-case, where the TX1 is reported as included in F1 finalized block.
However, when the TX2 is submitted, the chainHead state contains F1 as finalized and F2 as NewBlock.
This means that the UnstableBackend would use the
latest_finalized_block
F1 to submit the TX2, which means the account nonce is reused.Solution
To mitigate this edge-case, an extra step is added to ensure that chainHead is synchronized with the finalized hash reported by the Transaction class.
Closes: #1248
Closes: #1240