polkadot-sdk icon indicating copy to clipboard operation
polkadot-sdk copied to clipboard

fatp: Implement blockchain revert handling

Open AlexandruCihodaru opened this issue 4 months ago • 9 comments

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

AlexandruCihodaru avatar Nov 28 '25 08:11 AlexandruCihodaru

/cmd fmt

AlexandruCihodaru avatar Nov 28 '25 09:11 AlexandruCihodaru

/cmd prdoc --audience runtime_dev --bump patch

AlexandruCihodaru avatar Nov 28 '25 09:11 AlexandruCihodaru

DQ:

          D1-E1-F1-G1-..-X1
         /
A - B - C - D2-E2-F2-G2-..-X2
         \
          D3-E3-F3-G3-..-X3

Is it realistic scenario? Should we handle this properly? If we revert from X1 to B, shold we also remove all transactions included on D2-...-X2 and D3-...-X3 forks (as we do for D1-...-X1)?

If we assume that revert can only be called if there is single fork - should we somehow check this in handle_revert function? (or at least document it somehow).

michalkucharczyk avatar Nov 28 '25 16:11 michalkucharczyk

DQ:

          D1-E1-F1-G1-..-X1
         /
A - B - C - D2-E2-F2-G2-..-X2
         \
          D3-E3-F3-G3-..-X3

Is it realistic scenario? Should we handle this properly? If we revert from X1 to B, shold we also remove all transactions included on D2-...-X2 and D3-...-X3 forks (as we do for D1-...-X1)?

If we assume that revert can only be called if there is single fork - should we somehow check this in handle_revert function? (or at least document it somehow).

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.

AlexandruCihodaru avatar Nov 28 '25 17:11 AlexandruCihodaru

/cmd fmt

AlexandruCihodaru avatar Dec 02 '25 12:12 AlexandruCihodaru

/cmd fmt

AlexandruCihodaru avatar Dec 02 '25 16:12 AlexandruCihodaru

All GitHub workflows were cancelled due to failure one of the required jobs. Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/19868343219 Failed job name: fmt

/cmd fmt

AlexandruCihodaru avatar Dec 02 '25 18:12 AlexandruCihodaru

And one more "general" question - assuming that we have transaction that were submitted by submit_and_watch - will there be any event notifying that they were dropped once revert is done?

michalkucharczyk avatar Dec 05 '25 13:12 michalkucharczyk