Test watchtower hook. l1 and l2 open a channel, make a couple of updates and then l1 cheats on l2 while that one is offline. The watchtower plugin meanwhile stashes all the penalty transactions and we release the one matching the offending commitment transaction.
(node_factory, bitcoind, directory, chainparams)
| 2448 | |
| 2449 | |
| 2450 | def test_watchtower(node_factory, bitcoind, directory, chainparams): |
| 2451 | """Test watchtower hook. |
| 2452 | |
| 2453 | l1 and l2 open a channel, make a couple of updates and then l1 cheats on |
| 2454 | l2 while that one is offline. The watchtower plugin meanwhile stashes all |
| 2455 | the penalty transactions and we release the one matching the offending |
| 2456 | commitment transaction. |
| 2457 | |
| 2458 | """ |
| 2459 | p = os.path.join(os.path.dirname(__file__), "plugins/watchtower.py") |
| 2460 | l1, l2 = node_factory.line_graph( |
| 2461 | 2, |
| 2462 | opts=[{'may_fail': True, |
| 2463 | 'broken_log': r"onchaind-chan#[0-9]*: Could not find resolution for output .*: did \*we\* cheat\?"}, |
| 2464 | {'plugin': p}] |
| 2465 | ) |
| 2466 | channel_id = l1.rpc.listpeerchannels()['channels'][0]['channel_id'] |
| 2467 | |
| 2468 | # Force a new commitment |
| 2469 | l1.rpc.xpay(l2.rpc.invoice(25000000, 'lbl1', 'desc1')['bolt11']) |
| 2470 | |
| 2471 | tx = l1.rpc.dev_sign_last_tx(l2.info['id'])['tx'] |
| 2472 | |
| 2473 | # Now make sure it is out of date |
| 2474 | l1.rpc.xpay(l2.rpc.invoice(25000000, 'lbl2', 'desc2')['bolt11']) |
| 2475 | |
| 2476 | # l2 stops watching the chain, allowing the watchtower to react |
| 2477 | l2.stop() |
| 2478 | |
| 2479 | # Now l1 cheats |
| 2480 | bitcoind.rpc.sendrawtransaction(tx) |
| 2481 | time.sleep(1) |
| 2482 | bitcoind.generate_block(1) |
| 2483 | |
| 2484 | wt_file = os.path.join( |
| 2485 | l2.daemon.lightning_dir, |
| 2486 | chainparams['name'], |
| 2487 | 'watchtower.csv' |
| 2488 | ) |
| 2489 | |
| 2490 | cheat_tx = bitcoind.rpc.decoderawtransaction(tx) |
| 2491 | lastcommitnum = 0 |
| 2492 | with open(wt_file, 'r') as f: |
| 2493 | for l in f: |
| 2494 | txid, penalty, channel_id_hook, commitnum = l.strip().split(', ') |
| 2495 | assert lastcommitnum == int(commitnum) |
| 2496 | assert channel_id_hook == channel_id |
| 2497 | lastcommitnum += 1 |
| 2498 | if txid == cheat_tx['txid']: |
| 2499 | # This one should succeed, since it is a response to the cheat_tx |
| 2500 | bitcoind.rpc.sendrawtransaction(penalty) |
| 2501 | break |
| 2502 | |
| 2503 | # Need this to check that l2 gets the funds |
| 2504 | penalty_meta = bitcoind.rpc.decoderawtransaction(penalty) |
| 2505 | |
| 2506 | time.sleep(1) |
| 2507 | bitcoind.generate_block(1) |
nothing calls this directly
no test coverage detected