MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_penalty_inhtlc

Function test_penalty_inhtlc

tests/test_closing.py:484–602  ·  view source on GitHub ↗

Test penalty transaction with an incoming HTLC

(node_factory, bitcoind, executor, chainparams)

Source from the content-addressed store, hash-verified

482
483@pytest.mark.developer("needs dev-disable-commit-after")
484def test_penalty_inhtlc(node_factory, bitcoind, executor, chainparams):
485 """Test penalty transaction with an incoming HTLC"""
486
487 # We track channel balances, to verify that accounting is ok.
488 coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
489 # We suppress each one after first commit; HTLC gets added not fulfilled.
490 # Feerates identical so we don't get gratuitous commit to update them
491 l1, l2 = node_factory.line_graph(2, opts=[{'dev-disable-commit-after': 1,
492 'may_fail': True,
493 'feerates': (7500, 7500, 7500, 7500),
494 'allow_broken_log': True,
495 'plugin': coin_mvt_plugin},
496 {'dev-disable-commit-after': 1,
497 'plugin': coin_mvt_plugin}])
498
499 channel_id = first_channel_id(l1, l2)
500
501 # Now, this will get stuck due to l1 commit being disabled..
502 t = executor.submit(l1.pay, l2, 100000000)
503
504 assert len(l1.getactivechannels()) == 2
505 assert len(l2.getactivechannels()) == 2
506
507 # They should both have commitments blocked now.
508 l1.daemon.wait_for_log('dev-disable-commit-after: disabling')
509 l2.daemon.wait_for_log('dev-disable-commit-after: disabling')
510
511 # Make sure l1 got l2's commitment to the HTLC, and sent to master.
512 l1.daemon.wait_for_log('got commitsig')
513
514 # Take our snapshot.
515 tx = l1.rpc.dev_sign_last_tx(l2.info['id'])['tx']
516
517 # Let them continue
518 l1.rpc.dev_reenable_commit(l2.info['id'])
519 l2.rpc.dev_reenable_commit(l1.info['id'])
520
521 # Should fulfill.
522 l1.daemon.wait_for_log('peer_in WIRE_UPDATE_FULFILL_HTLC')
523 l1.daemon.wait_for_log('peer_out WIRE_REVOKE_AND_ACK')
524
525 l2.daemon.wait_for_log('peer_out WIRE_UPDATE_FULFILL_HTLC')
526 l1.daemon.wait_for_log('peer_in WIRE_REVOKE_AND_ACK')
527
528 # Payment should now complete.
529 t.result(timeout=10)
530
531 # Now we really mess things up!
532 bitcoind.rpc.sendrawtransaction(tx)
533 bitcoind.generate_block(1)
534
535 l2.daemon.wait_for_log(' to ONCHAIN')
536
537 # FIXME: l1 should try to stumble along!
538 wait_for(lambda: len(l2.getactivechannels()) == 0)
539
540 # l2 should spend all of the outputs (except to-us).
541 # Could happen in any order, depending on commitment tx.

Callers

nothing calls this directly

Calls 15

first_channel_idFunction · 0.90
wait_forFunction · 0.90
sync_blockheightFunction · 0.90
only_oneFunction · 0.90
account_balanceFunction · 0.90
anchor_expectedFunction · 0.90
check_utxos_channelFunction · 0.90
joinMethod · 0.80
line_graphMethod · 0.80
getactivechannelsMethod · 0.80
wait_for_logMethod · 0.80
dev_sign_last_txMethod · 0.80

Tested by

no test coverage detected