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

Function test_graceful_htlc

tests/test_misc.py:4414–4465  ·  view source on GitHub ↗

graceful with an HTLC in flight notifies about expiry and completes after HTLC resolves

(node_factory, executor)

Source from the content-addressed store, hash-verified

4412
4413
4414def test_graceful_htlc(node_factory, executor):
4415 """graceful with an HTLC in flight notifies about expiry and completes after HTLC resolves"""
4416 l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True,
4417 opts=[{'may_reconnect': True,
4418 'dev-no-reconnect': None},
4419 {'may_reconnect': True,
4420 'dev-no-reconnect': None},
4421 {'plugin': os.path.join(os.getcwd(), 'tests/plugins/hold_invoice.py')}])
4422
4423 inv = l3.rpc.invoice(10000, 'hold', 'hold invoice')
4424 route = l1.single_route(l3.info['id'], 10000)
4425 l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
4426 wait_for(lambda: len(only_one(l3.rpc.listpeerchannels()['channels'])['htlcs']) == 1)
4427
4428 notifications = []
4429
4430 def run_graceful():
4431 def capture(message, **kwargs):
4432 if message:
4433 notifications.append(message)
4434 with l2.rpc.notify(capture):
4435 return l2.rpc.graceful()
4436
4437 fut = executor.submit(run_graceful)
4438
4439 # Wait until graceful has sent at least one HTLC expiry notification
4440 wait_for(lambda: len(notifications) == 1)
4441 wait_for(lambda: notifications[0] == f'Next HTLC SENT_ADD_ACK_REVOCATION expires at block #118 (10 blocks from now) going to peer {l3.info["id"]} (connected)')
4442
4443 # This will tell us about htlcs and the peers (peers unordered)
4444 ret = l2.rpc.graceful(1)
4445 assert ret in ({'pending_htlc_expiries': [118, 124],
4446 'pending_peers': [l1.info['id'], l3.info['id']]},
4447 {'pending_htlc_expiries': [118, 124],
4448 'pending_peers': [l3.info['id'], l1.info['id']]})
4449
4450 # Close incoming connection, so incoming HTLC gets stuck.
4451 l1.rpc.disconnect(l2.info['id'], force=True)
4452 wait_for(lambda: notifications[-1] == f'Next HTLC SENT_ADD_ACK_REVOCATION expires at block #118 (10 blocks from now) going to peer {l3.info["id"]} (connected)')
4453
4454 # Release the hold so the *outgoing* HTLC resolves
4455 open(os.path.join(l3.daemon.lightning_dir, TEST_NETWORK, "unhold"), "w").close()
4456
4457 wait_for(lambda: notifications[-1] == f'Next HTLC SENT_REMOVE_HTLC expires at block #124 (16 blocks from now) coming from peer {l1.info["id"]} (disconnected)')
4458
4459 ret = l2.rpc.graceful(1)
4460 assert ret == {'pending_htlc_expiries': [124]}
4461
4462 # Reconnect and it will settle.
4463 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
4464
4465 assert fut.result(TIMEOUT) == {}
4466
4467
4468def test_fast_shutdown(node_factory):

Callers

nothing calls this directly

Calls 12

wait_forFunction · 0.90
only_oneFunction · 0.90
line_graphMethod · 0.80
joinMethod · 0.80
single_routeMethod · 0.80
sendpayMethod · 0.80
listpeerchannelsMethod · 0.80
gracefulMethod · 0.80
invoiceMethod · 0.45
disconnectMethod · 0.45
closeMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected