Page MenuHomePhabricator

[Chronik] Fix: "Inconsistent mempool" when reorging with chained txs
ClosedPublic

Authored by tobias_ruck on Dec 7 2023, 01:00.

Details

Summary

Currently, Chronik crashes when disconnecting a block with children in the mempool, because the order of removal of transactions in the node is not in reverse topological order.

This problem was introduced in D13133, specifically where TransactionRemovedFromMempool is called in topological order (i.e. parents first), but should've been called in reverse-topological order (i.e. children first), which this diff fixes.

Chronik depends on the removal to happen in reverse-topological order (i.e. children first), otherwise, it might remove UTXOs from the index before they're added, crashing the node. This is what happened a few times on both NNG and in-node Chronik.

Test Plan

./test/functional/test_runner.py chronik_tx_removal_order

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

The build failed due to an unexpected infrastructure outage. The administrators have been notified to investigate. Sorry for the inconvenience.
Fabien edited reviewers, added: tobias_ruck; removed: Fabien.

Fix the test, fix the issue

Fabien retitled this revision from [Chronik] Fix: "Inconsisten mempool" when reorging blocks to [Chronik] Fix: "Inconsistent mempool" when reorging with chained txs.Dec 7 2023, 09:12
Fabien edited the summary of this revision. (Show Details)
Fabien edited the test plan for this revision. (Show Details)

@bot build-chronik

I can confirm the fix on my local machine:

without reverse_iterate (expected bug):

2023-12-07T09:13:49.311054Z (mocktime: 2011-03-13T07:06:40Z) [../src/noui.cpp:42] [noui_ThreadSafeMessageBox] Error: Inconsistent mempool when removing tx: UTXO OutPoint { txid: TxId(d1c8912cbb1db1dfee5cfda184e6b3adc6c0483e07b262b53ac9e8d6e5b1d308), out_idx: 0 } doesn't exist in mempool

with reverse iterate (expected to be working):

test passed

@bot build-linux32 build-linux64 build-linux-aarch64 build-linux-arm build-win64

tobias_ruck edited reviewers, added: Fabien; removed: tobias_ruck.

I'm the captain now (again)

Add a bit of a speech to the functional test so people know why we're testing with -chronik

tobias_ruck edited the test plan for this revision. (Show Details)
tobias_ruck edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Dec 7 2023, 10:08