Skip to content

Conversation

@TDemeco
Copy link
Contributor

@TDemeco TDemeco commented Oct 31, 2025

This PR solves the issue regarding nonce management and transactions being emitted with future nonces when reorgs or other issues happen, which bricked the blockchain service as from that point on no transaction sent by it would make it into a block.

This PR is a complete refactor of how the blockchain service handles transactions. Now, instead of relying on getting the InBlock notification for transactions it sent, the blockchain service has its own transaction pool that logs and keeps track of all status updates of all the transactions it sends.
Not only this is useful for traceability, but with this plus some clever logic we manage to solve the nonce gap issue that was bricking the bcsv: now, dropped or invalid transactions get detected, its nonce gets cleared and the next transaction that the blockchain service has to send (or a remark if that takes too long) uses this now free nonce, making it so any other transactions that had a greater nonce get unstuck and make it into the pool.

It's still a draft as there are three key TODOs to fix:

  • Retrieve the events generated by the submitted extrinsic when required.
  • Add a test scenario to ensure the new nonce manager system works appropiately (with a dropped or invalid transaction)
    • We did it with an Invalid one, so try to add a test for the Dropped case
  • Add a way to spin up the Providers in an integration test with the debug log level, since the tests for this functionality rely on that.

These three things are already in the works and should be ready soon. In the meantime, I'm opening this PR as a draft to facilitate the reviewing process. Done, marked as ready to review

@TDemeco TDemeco requested a review from ffarall October 31, 2025 18:22
@TDemeco TDemeco marked this pull request as ready for review October 31, 2025 23:04
@ffarall ffarall self-requested a review October 31, 2025 23:15
Copy link
Collaborator

@ffarall ffarall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LFGTM

@ffarall ffarall added B5-clientnoteworthy Changes should be mentioned client-related release notes D5-needsaudit👮 PR contains changes to logic that should be properly reviewed and externally audited not-breaking Does not need to be mentioned in breaking changes labels Oct 31, 2025
@ffarall ffarall merged commit 815902c into main Nov 3, 2025
65 of 66 checks passed
@ffarall ffarall deleted the fix/nonce-manager-bcsv branch November 3, 2025 04:28
Karrq pushed a commit that referenced this pull request Nov 3, 2025
* feat: ✨ initial transaction pool and nonce manager logic

* feat: ♻️ refactor watches to sync with new transaction pool

* fix: 🐛 issue with status subscriptions

* fix: 🩹 also process tx status updates on finality

* feat: 🔊 improve log clarity by specifying which tx is being dropped

* test: ✅ add Retracted and Usurped test cases for new logic

* fix: 🎨 run cargo fmt

* feat: ✨ add event extraction from successful transactions

* style: 🎨 run cargo fmt

* test: ✅ add Invalid transaction and nonce gap fulfilling test

* feat: 🔊 Add error logs in case of failing to send status update of transactions

* feat: ✅ add a way to select log level for actors in integration tests

* feat: 🔊 Add logging of which call is related to which hash

* fix: 🩹 Remove leftover `only: true` flag

* perf: ⚡ Decrease retry timout in test

* fix: 🩹 amend review (pool -> manager)

* feat: ✨ add tip tracking in transaction manager

* docs: 💡 add permalink to Polkadot SDK's `TransactionStatus`

* test: ✅ rename and fix transaction manager integration test

* fix: ✅ single volunteer test

* test: ✅ improve BSP volunteer for multiple files test

* feat: ✨ Allow arbitrary strings for log level in tests

* feat: 🔊 Improve logs of transactions adding nonce

* fix: 🐛 add initial check when watching for tx success

* fix: 🐛 check for the `ExtrinsicSuccess` event to ensure the new ext didn't fail

* test: ✅ minor test fixes

* fix: 🩹 Fix typos and names of tests

* fix: 🐛 Update transaction status in `run()` cycle of blockchain service

* fix: 🩹 Remove processing of transaction status in block import and block finalised

* fix: 🐛 skip to correct block when testing MSP charge

* fix: 🩹 Remove `only: true` flag from test

* fix: 🩹 Move `tx_status_receiver` out of `actor` struct

* fix: 🐛 Avoid cross-talk between updates from replaced transactions

* test: ✅ fix invalid transaction test by dropping retry tx

---------

Co-authored-by: Facundo Farall <[email protected]>
snowmead pushed a commit that referenced this pull request Nov 3, 2025
* feat: ✨ initial transaction pool and nonce manager logic

* feat: ♻️ refactor watches to sync with new transaction pool

* fix: 🐛 issue with status subscriptions

* fix: 🩹 also process tx status updates on finality

* feat: 🔊 improve log clarity by specifying which tx is being dropped

* test: ✅ add Retracted and Usurped test cases for new logic

* fix: 🎨 run cargo fmt

* feat: ✨ add event extraction from successful transactions

* style: 🎨 run cargo fmt

* test: ✅ add Invalid transaction and nonce gap fulfilling test

* feat: 🔊 Add error logs in case of failing to send status update of transactions

* feat: ✅ add a way to select log level for actors in integration tests

* feat: 🔊 Add logging of which call is related to which hash

* fix: 🩹 Remove leftover `only: true` flag

* perf: ⚡ Decrease retry timout in test

* fix: 🩹 amend review (pool -> manager)

* feat: ✨ add tip tracking in transaction manager

* docs: 💡 add permalink to Polkadot SDK's `TransactionStatus`

* test: ✅ rename and fix transaction manager integration test

* fix: ✅ single volunteer test

* test: ✅ improve BSP volunteer for multiple files test

* feat: ✨ Allow arbitrary strings for log level in tests

* feat: 🔊 Improve logs of transactions adding nonce

* fix: 🐛 add initial check when watching for tx success

* fix: 🐛 check for the `ExtrinsicSuccess` event to ensure the new ext didn't fail

* test: ✅ minor test fixes

* fix: 🩹 Fix typos and names of tests

* fix: 🐛 Update transaction status in `run()` cycle of blockchain service

* fix: 🩹 Remove processing of transaction status in block import and block finalised

* fix: 🐛 skip to correct block when testing MSP charge

* fix: 🩹 Remove `only: true` flag from test

* fix: 🩹 Move `tx_status_receiver` out of `actor` struct

* fix: 🐛 Avoid cross-talk between updates from replaced transactions

* test: ✅ fix invalid transaction test by dropping retry tx

---------

Co-authored-by: Facundo Farall <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B5-clientnoteworthy Changes should be mentioned client-related release notes D5-needsaudit👮 PR contains changes to logic that should be properly reviewed and externally audited not-breaking Does not need to be mentioned in breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants