Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subxt: Sychronize finalized tx status with chain head #1300

Closed
wants to merge 1 commit into from

Conversation

lexnv
Copy link
Collaborator

@lexnv lexnv commented Dec 1, 2023

This PR synchronizes the finalized hash reported by transaction_unstable with the finalized hashes reported by the chainhead_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 the chainHead 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

chain
|             F1 finalized                  |                 F2 finalized                              |

transaction
          | submit TX1                      | TX1 in F1 block | submit TX 2 |

chainHead
    |  F1 finalized                         |  F2 NewBlock                  | F2 Finalized  |

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

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv requested a review from a team as a code owner December 1, 2023 15:26
@jsdw
Copy link
Collaborator

jsdw commented Dec 4, 2023

Superceded by #1305 :)

@jsdw jsdw closed this Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants