A reorg of the commitment tx must restart onchaind exactly once. The funding output watch is owned by the channel, not by onchaind, so it survives the teardown and starts onchaind again once the commitment tx is mined elsewhere. We must not also restart it ourselves, or we'd have two
(node_factory, bitcoind)
| 2272 | |
| 2273 | @unittest.skipIf(TEST_NETWORK != 'regtest', 'must be able to invalidate blocks') |
| 2274 | def test_onchaind_reorg_commitment_tx(node_factory, bitcoind): |
| 2275 | """A reorg of the commitment tx must restart onchaind exactly once. |
| 2276 | |
| 2277 | The funding output watch is owned by the channel, not by onchaind, so it |
| 2278 | survives the teardown and starts onchaind again once the commitment tx is |
| 2279 | mined elsewhere. We must not also restart it ourselves, or we'd have two |
| 2280 | onchaind processes signing spends for one channel. |
| 2281 | |
| 2282 | """ |
| 2283 | l1, l2 = node_factory.line_graph(2, opts={'dev-force-features': "-23", |
| 2284 | 'may_reconnect': True, |
| 2285 | 'dev-no-reconnect': None}) |
| 2286 | |
| 2287 | l1.rpc.disconnect(l2.info['id'], force=True) |
| 2288 | commit_txid = only_one(l1.rpc.close(l2.info['id'], 1)['txids']) |
| 2289 | |
| 2290 | bitcoind.generate_block(1, wait_for_mempool=commit_txid) |
| 2291 | l1.daemon.wait_for_log(' to ONCHAIN') |
| 2292 | wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels']).get('owner') == 'onchaind') |
| 2293 | |
| 2294 | commit_block = bitcoind.rpc.getrawtransaction(commit_txid, True)['blockhash'] |
| 2295 | commit_height = bitcoind.rpc.getblock(commit_block)['height'] |
| 2296 | |
| 2297 | # Reorg out the commitment tx itself, replacing it with empty blocks. |
| 2298 | bitcoind.rpc.invalidateblock(commit_block) |
| 2299 | bitcoind.wait_for_log(r'InvalidChainFound: invalid block=.* height={}' |
| 2300 | .format(commit_height)) |
| 2301 | addr = bitcoind.rpc.getnewaddress() |
| 2302 | for _ in range(2): |
| 2303 | bitcoind.rpc.generateblock(addr, []) |
| 2304 | sync_blockheight(bitcoind, [l1]) |
| 2305 | |
| 2306 | l1.daemon.wait_for_log('Chain reorganization!') |
| 2307 | |
| 2308 | # There's no confirmed funding spend to replay, so we leave it to the |
| 2309 | # funding output watch, which fires when the commitment tx is mined again. |
| 2310 | wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels']).get('owner') is None) |
| 2311 | |
| 2312 | bitcoind.generate_block(1, wait_for_mempool=commit_txid) |
| 2313 | wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels']).get('owner') == 'onchaind') |
| 2314 | # ie. it came back through onchaind_funding_spent(), not the reorg path: |
| 2315 | # two onchaind on one channel would sign conflicting spends. |
| 2316 | assert not l1.daemon.is_in_log('Restarting onchaind') |
| 2317 | |
| 2318 | # And it still resolves. |
| 2319 | _, txid, blocks = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET', |
| 2320 | 'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US') |
| 2321 | bitcoind.generate_block(blocks) |
| 2322 | bitcoind.generate_block(1, wait_for_mempool=txid) |
| 2323 | bitcoind.generate_block(99) |
| 2324 | l1.daemon.wait_for_log('onchaind complete, forgetting peer') |
| 2325 | |
| 2326 | |
| 2327 | @pytest.mark.parametrize("anchors", [False, True]) |
nothing calls this directly
no test coverage detected