-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fatp: Implement blockchain revert handling #10453
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
base: master
Are you sure you want to change the base?
Conversation
Add support for handling blockchain revert. This is useful in testing.
Changes:
- Add ChainEvent::Reverted variant to represent backward blockchain progression
- Implement handle_reverted() method that:
* Collects transactions from retracted blocks via included_transactions cache
or by fetching block bodies from the API
* Removes all views beyond the revert point to prevent zombie views
* Removes included transactions from mempool (they can be resubmitted later)
* Updates enactment state (recent_finalized_block and recent_best_block)
* Ensures a valid view exists at the revert target block
- Add early return in maintain() for Reverted events to prevent normal
forward-progression logic from running
These changes fix issues where reverting would leave zombie views in the view store,
causing issues at subsequent operations.
Note: Transactions that were pending may not be visible after revert if they fail the
revalidation
Signed-off-by: Alexandru Cihodaru <[email protected]>
|
/cmd fmt |
|
/cmd prdoc --audience runtime_dev --bump patch |
…time_dev --bump patch'
Signed-off-by: Alexandru Cihodaru <[email protected]>
substrate/client/transaction-pool/src/common/enactment_state.rs
Outdated
Show resolved
Hide resolved
substrate/client/transaction-pool/src/fork_aware_txpool/fork_aware_txpool.rs
Outdated
Show resolved
Hide resolved
substrate/client/transaction-pool/src/fork_aware_txpool/fork_aware_txpool.rs
Outdated
Show resolved
Hide resolved
Signed-off-by: Alexandru Cihodaru <[email protected]>
substrate/client/transaction-pool/src/fork_aware_txpool/fork_aware_txpool.rs
Outdated
Show resolved
Hide resolved
substrate/client/transaction-pool/src/fork_aware_txpool/fork_aware_txpool.rs
Outdated
Show resolved
Hide resolved
|
DQ: Is it realistic scenario? Should we handle this properly? If we revert from If we assume that revert can only be called if there is single fork - should we somehow check this in |
Excellent question. I think that in anvil it is not possible to have such a scenario but I believe that we should delete the transactions on all possible paths. |
| /// Path from old finalized to new finalized parent. | ||
| tree_route: Arc<[B::Hash]>, | ||
| }, | ||
| /// The chain has been reverted to a new head. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have some more information on the impact of this event to the internal state of the pool, e.g. all included transaction will be removed from the pool, what forks are removed (all or only one defined by tree_route param).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all included transaction will be removed from the pool, what forks are removed
Do you think about more than logging information about how many txs and forks are removed, as in a metric that can be queried later? Given that revert is mostly useful currently in anvil context, I would just add some more logging about the # of reverted forks and the reverted txs on all forks.
iulianbarbu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good in general. It would be great to capture in the event the idea of reverting all existing forks, to have this logic appliable not just to single chain nodes like anvil-polkadot - but tbh not super sure how difficult it is.
| /// Path from old finalized to new finalized parent. | ||
| tree_route: Arc<[B::Hash]>, | ||
| }, | ||
| /// The chain has been reverted to a new head. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all included transaction will be removed from the pool, what forks are removed
Do you think about more than logging information about how many txs and forks are removed, as in a metric that can be queried later? Given that revert is mostly useful currently in anvil context, I would just add some more logging about the # of reverted forks and the reverted txs on all forks.
Signed-off-by: Alexandru Cihodaru <[email protected]>
|
/cmd fmt |
Co-authored-by: Michal Kucharczyk <[email protected]>
substrate/client/transaction-pool/src/common/enactment_state.rs
Outdated
Show resolved
Hide resolved
substrate/client/transaction-pool/src/common/enactment_state.rs
Outdated
Show resolved
Hide resolved
Signed-off-by: Alexandru Cihodaru <[email protected]>
|
/cmd fmt |
Signed-off-by: Alexandru Cihodaru <[email protected]>
|
All GitHub workflows were cancelled due to failure one of the required jobs. |
|
/cmd fmt |
Add support for handling blockchain revert. This is useful in testing.
Changes:
These changes fix issues where reverting would leave zombie views in the view store, causing issues at subsequent operations.
Note: Transactions that were pending may not be visible after revert if they fail the revalidation