I have seen this one two or three times in the CI:
def test_bwatch_spk_watch_reorg_demotes_outputs(node_factory, bitcoind):
"""A reorg that disconnects a deposit's block must undo the confirmation:
the wallet's scriptpubkey watch_revert handler demotes the rows in
our_outputs/our_txs to unconfirmed (it must not delete them, or state
like reservations would be lost), matching the legacy output demoted
via its blocks FK. The funds show as unconfirmed until the tx
confirms again.
"""
l1 = node_factory.get_node(options=BWATCH_OPTS)
wait_bwatch_caught_up(l1)
addr = l1.rpc.newaddr('bech32')['bech32']
txid = bitcoind.rpc.sendtoaddress(addr, 1.0)
bitcoind.generate_block(1, wait_for_mempool=txid)
deposit_height = bitcoind.rpc.getblockcount()
# The perennial wallet scriptpubkey watch discovers the deposit.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 1)
output = only_one(l1.rpc.listfunds()['outputs'])
assert output['txid'] == txid
assert output['status'] == 'confirmed'
assert output['blockheight'] == deposit_height
assert output['amount_msat'] == 100_000_000_000
assert l1.db_query('SELECT blockheight, spendheight FROM our_outputs') \
== [{'blockheight': deposit_height, 'spendheight': None}]
assert (l1.db_query('SELECT blockheight FROM our_txs')
== [{'blockheight': deposit_height}])
assert l1.db_query('SELECT COUNT(*) AS c FROM outputs')[0]['c'] == 1
# Reorg the deposit block away. Deprioritize the returned mempool tx
# (same trick as simple_reorg) so the replacement blocks don't just
# re-confirm it.
bitcoind.rpc.invalidateblock(bitcoind.rpc.getblockhash(deposit_height))
memp = bitcoind.rpc.getrawmempool()
assert txid in memp
for t in memp:
bitcoind.rpc.prioritisetransaction(t, None, -1000000)
bitcoind.generate_block(2)
> l1.daemon.wait_for_log(r'Reorg detected', timeout=60)
tests/test_plugin.py:5840:
lightningd-1 2026-08-03T08:45:37.363Z DEBUG plugin-cln-bwatch: Saved watch to datastore (type=0, num_owners=1)
lightningd-1 2026-08-03T08:45:37.363Z DEBUG lightningd: Acknowledged pending op: addscriptpubkeywatch:wallet/spk/31/p2wpkh
lightningd-1 2026-08-03T08:45:37.365Z DEBUG plugin-cln-bwatch: Saved watch to datastore (type=0, num_owners=1)
lightningd-1 2026-08-03T08:45:37.366Z DEBUG lightningd: Acknowledged pending op: addscriptpubkeywatch:wallet/spk/36/p2tr
lightningd-1 2026-08-03T08:45:37.367Z DEBUG plugin-cln-bwatch: No block change, current_height remains 101
lightningd-1 2026-08-03T08:45:37.586Z DEBUG plugin-cln-bwatch: No block change, current_height remains 101
lightningd-1 2026-08-03T08:45:37.931Z DEBUG jsonrpc#84: Pausing parsing after 1 requests and 251msec (last method=newaddr)
lightningd-1 2026-08-03T08:45:38.247Z DEBUG plugin-cln-bwatch: Saved watch to datastore (type=0, num_owners=1)
lightningd-1 2026-08-03T08:45:38.250Z DEBUG plugin-cln-bwatch: Owner wallet/spk/1/p2wpkh already watching, rescanning for missed events at 4294967295
lightningd-1 2026-08-03T08:45:38.251Z DEBUG lightningd: Acknowledged pending op: addscriptpubkeywatch:wallet/spk/1/p2wpkh
lightningd-1 2026-08-03T08:45:39.314Z DEBUG lightningd: Adding block 102: 56f2507408ad5244b13bfa17c4d37d68e01652983af91e451e4b5870361eb53d
lightningd-1 2026-08-03T08:45:39.677Z DEBUG wallet: Owning output 1 100000000sat (p2wpkh) txid 52df000592def1c4fb2acd052f655acd107a044772797f1452e550553355fc3c CONFIRMED
lightningd-1 2026-08-03T08:45:40.709Z DEBUG gossipd: REPLY WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY with 0 fds
lightningd-1 2026-08-03T08:45:41.629Z DEBUG gossipd: seeker: no peers, waiting
lightningd-1 2026-08-03T08:45:41.675Z DEBUG plugin-cln-bwatch: Added block 102 to history (now 2 blocks)
lightningd-1 2026-08-03T08:45:41.675Z DEBUG plugin-cln-bwatch: Added block 102 to datastore
lightningd-1 2026-08-03T08:45:41.718Z INFO lightningd: block_processed: 101 -> 102
lightningd-1 2026-08-03T08:45:41.825Z DEBUG lightningd: Removing stale block 102: 56f2507408ad5244b13bfa17c4d37d68e01652983af91e451e4b5870361eb53d
lightningd-1 2026-08-03T08:45:41.969Z DEBUG gossipd: REPLY WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY with 0 fds
lightningd-1 2026-08-03T08:45:42.042Z DEBUG plugin-cln-bwatch: Received block_processed ack for height 102
lightningd-1 2026-08-03T08:45:42.458Z DEBUG lightningd: Adding block 102: 736b8082e6f52a5e22fa79bcd4f6a4d0b7c2aa3fb42dbbf1b03cfe6152263d51
lightningd-1 2026-08-03T08:45:42.886Z DEBUG lightningd: Adding block 103: 75cb1cdaa05a7ebd8b8aabfa3a258332d7a3c017547d3b66a4b01540cf0eb508
lightningd-1 2026-08-03T08:45:42.962Z DEBUG plugin-cln-bwatch: Added block 103 to history (now 3 blocks)
lightningd-1 2026-08-03T08:45:42.963Z DEBUG plugin-cln-bwatch: Added block 103 to datastore
lightningd-1 2026-08-03T08:45:43.038Z DEBUG gossipd: REPLY WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY with 0 fds
lightningd-1 2026-08-03T08:45:43.064Z INFO lightningd: block_processed: 102 -> 103
lightningd-1 2026-08-03T08:45:43.090Z DEBUG gossipd: REPLY WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY with 0 fds
lightningd-1 2026-08-03T08:45:43.121Z DEBUG plugin-cln-bwatch: Received block_processed ack for height 103
lightningd-1 2026-08-03T08:45:43.270Z DEBUG plugin-cln-bwatch: No block change, current_height remains 103
lightningd-1 2026-08-03T08:45:43.846Z DEBUG plugin-cln-bwatch: No block change, current_height remains 103
lightningd-1 2026-08-03T08:45:44.428Z DEBUG plugin-cln-bwatch: No block change, current_height remains 103
lightningd-1 2026-08-03T08:45:44.467Z DEBUG lightningd: channel_gossip: no longer in startup mode
lightningd-1 2026-08-03T08:45:45.007Z DEBUG plugin-cln-bwatch: No block change, current_height remains 103
lightningd-1 2026-08-03T08:45:45.695Z DEBUG plugin-cln-bwatch: No block change, current_height remains 103
lightningd-1 2026-08-03T08:45:46.606Z DEBUG gossipd: seeker: no peers, waiting
lightningd-1 2026-08-03T08:45:46.727Z DEBUG plugin-cln-bwatch: No block change, current_height remains 103
lightningd-1 2026-08-03T08:45:47.324Z DEBUG plugin-cln-bwatch: No block change, current_height remains 103
https://github.com/ElementsProject/lightning/actions/runs/30795252798/job/91630727111
I have seen this one two or three times in the CI:
https://github.com/ElementsProject/lightning/actions/runs/30795252798/job/91630727111