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

Function test_payment_success_persistence

tests/test_pay.py:394–443  ·  view source on GitHub ↗
(node_factory, bitcoind, executor)

Source from the content-addressed store, hash-verified

392@pytest.mark.openchannel('v1')
393@pytest.mark.openchannel('v2')
394def test_payment_success_persistence(node_factory, bitcoind, executor):
395 # Start two nodes and open a channel.. die during payment.
396 # Feerates identical so we don't get gratuitous commit to update them
397 disconnect = ['+WIRE_COMMITMENT_SIGNED']
398 if EXPERIMENTAL_DUAL_FUND:
399 # We have to add an extra 'wire-commitment-signed' because
400 # dual funding uses this for channel establishment also
401 disconnect = ['=WIRE_COMMITMENT_SIGNED'] + disconnect
402
403 l1 = node_factory.get_node(disconnect=disconnect,
404 options={'dev-no-reconnect': None},
405 may_reconnect=True,
406 feerates=(7500, 7500, 7500, 7500))
407 l2 = node_factory.get_node(may_reconnect=True)
408 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
409
410 chanid, _ = l1.fundchannel(l2, 100000)
411
412 inv1 = l2.rpc.invoice(1000, 'inv1', 'inv1')
413
414 # Fire off a pay request, it'll get interrupted by a restart
415 executor.submit(l1.dev_pay, inv1['bolt11'], use_shadow=False)
416
417 l1.daemon.wait_for_log(r'dev_disconnect: \+WIRE_COMMITMENT_SIGNED')
418
419 print("Killing l1 in mid HTLC")
420 l1.daemon.kill()
421
422 # Restart l1, without disconnect stuff.
423 del l1.daemon.opts['dev-no-reconnect']
424 del l1.daemon.opts['dev-disconnect']
425
426 # Should reconnect, and sort the payment out.
427 l1.start()
428
429 wait_for(lambda: l1.rpc.listsendpays()['payments'][0]['status'] != 'pending')
430
431 payments = l1.rpc.listsendpays()['payments']
432 invoices = l2.rpc.listinvoices('inv1')['invoices']
433 assert len(payments) == 1 and payments[0]['status'] == 'complete'
434 assert len(invoices) == 1 and invoices[0]['status'] == 'paid'
435
436 l1.wait_channel_active(chanid)
437
438 # A duplicate should succeed immediately (nop) and return correct preimage.
439 preimage = l1.dev_pay(
440 inv1['bolt11'],
441 use_shadow=False
442 )['payment_preimage']
443 assert l1.rpc.dev_rhash(preimage)['rhash'] == inv1['payment_hash']
444
445
446@pytest.mark.developer("needs DEVELOPER=1")

Callers

nothing calls this directly

Calls 13

wait_forFunction · 0.90
wait_for_logMethod · 0.80
killMethod · 0.80
listsendpaysMethod · 0.80
wait_channel_activeMethod · 0.80
dev_rhashMethod · 0.80
get_nodeMethod · 0.45
connectMethod · 0.45
fundchannelMethod · 0.45
invoiceMethod · 0.45
startMethod · 0.45
listinvoicesMethod · 0.45

Tested by

no test coverage detected