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

Function test_splice_gossip

tests/test_splicing.py:382–439  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

380@pytest.mark.openchannel('v2')
381@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
382def test_splice_gossip(node_factory, bitcoind):
383 l1, l2, l3 = node_factory.line_graph(3, fundamount=1000000, wait_for_announce=True)
384
385 chan_id = l1.get_channel_id(l2)
386 pre_splice_scid = first_scid(l1, l2)
387
388 # add extra sats to pay fee
389 funds_result = l1.rpc.fundpsbt("111722sat", 0, 0, excess_as_change=True)
390
391 result = l1.rpc.splice_init(chan_id, 100000, funds_result['psbt'])
392 result = l1.rpc.splice_update(chan_id, result['psbt'])
393 assert(result['commitments_secured'] is False)
394 result = l1.rpc.splice_update(chan_id, result['psbt'])
395 assert(result['commitments_secured'] is True)
396 result = l1.rpc.signpsbt(result['psbt'])
397 result = l1.rpc.splice_signed(chan_id, result['signed_psbt'])
398
399 wait_for(lambda: only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['state'] == 'CHANNELD_AWAITING_SPLICE')
400 wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['state'] == 'CHANNELD_AWAITING_SPLICE')
401
402 bitcoind.generate_block(5, wait_for_mempool=result['txid'])
403
404 # l3 will see channel dying, but still consider it OK for 72 blocks.
405 l3.daemon.wait_for_log(f'gossipd: channel {pre_splice_scid} closing soon due to the funding outpoint being spent')
406 assert len(l3.rpc.listchannels(short_channel_id=pre_splice_scid)['channels']) == 2
407 assert len(l3.rpc.listchannels(source=l1.info['id'])['channels']) == 1
408
409 # Final one will allow splice announcement to proceed.
410 bitcoind.generate_block(1)
411 wait_for(lambda: only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['state'] == 'CHANNELD_NORMAL')
412 wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['state'] == 'CHANNELD_NORMAL')
413
414 post_splice_scid = first_scid(l1, l2)
415 assert post_splice_scid != pre_splice_scid
416
417 # l3 should see the new channel now.
418 wait_for(lambda: len(l3.rpc.listchannels(short_channel_id=post_splice_scid)['channels']) == 2)
419 assert len(l3.rpc.listchannels(short_channel_id=pre_splice_scid)['channels']) == 2
420
421 bitcoind.generate_block(67)
422
423 # The old channel should fall off l3's perspective
424 wait_for(lambda: l3.rpc.listchannels(short_channel_id=pre_splice_scid)['channels'] == [])
425 assert len(l3.rpc.listchannels(short_channel_id=post_splice_scid)['channels']) == 2
426
427 # Check that the splice doesn't generate a unilateral close transaction
428 time.sleep(5)
429 assert l1.db_query("SELECT count(*) as c FROM channeltxs;")[0]['c'] == 0
430
431 # Still looks normal from both sides
432 assert only_one(l1.rpc.listpeerchannels()['channels'])['short_channel_id'] == post_splice_scid
433 assert only_one(l1.rpc.listpeerchannels()['channels'])['state'] == 'CHANNELD_NORMAL'
434 assert only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['short_channel_id'] == post_splice_scid
435 assert only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['state'] == 'CHANNELD_NORMAL'
436
437 # Check for channel announcement failure
438 assert not l1.daemon.is_in_log("invalid local_channel_announcement")
439 assert not l2.daemon.is_in_log("invalid local_channel_announcement")

Callers

nothing calls this directly

Calls 15

first_scidFunction · 0.90
wait_forFunction · 0.90
only_oneFunction · 0.90
line_graphMethod · 0.80
get_channel_idMethod · 0.80
fundpsbtMethod · 0.80
signpsbtMethod · 0.80
listpeerchannelsMethod · 0.80
generate_blockMethod · 0.80
wait_for_logMethod · 0.80
db_queryMethod · 0.80
is_in_logMethod · 0.80

Tested by

no test coverage detected