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

Function test_splice_gossip

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

Source from the content-addressed store, hash-verified

208@pytest.mark.openchannel('v2')
209@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
210def test_splice_gossip(node_factory, bitcoind):
211 l1, l2, l3 = node_factory.line_graph(3, fundamount=1000000, wait_for_announce=True)
212
213 chan_id = l1.get_channel_id(l2)
214 pre_splice_scid = first_scid(l1, l2)
215
216 # add extra sats to pay fee
217 funds_result = l1.rpc.fundpsbt("111722sat", 0, 0, excess_as_change=True)
218
219 result = l1.rpc.splice_init(chan_id, 100000, funds_result['psbt'])
220 result = l1.rpc.splice_update(chan_id, result['psbt'])
221 assert(result['commitments_secured'] is False)
222 result = l1.rpc.splice_update(chan_id, result['psbt'])
223 assert(result['commitments_secured'] is True)
224 result = l1.rpc.signpsbt(result['psbt'])
225 result = l1.rpc.splice_signed(chan_id, result['signed_psbt'])
226
227 wait_for(lambda: only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['state'] == 'CHANNELD_AWAITING_SPLICE')
228 wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['state'] == 'CHANNELD_AWAITING_SPLICE')
229
230 bitcoind.generate_block(5, wait_for_mempool=result['txid'])
231
232 # l3 will see channel dying, but still consider it OK for 72 blocks.
233 l3.daemon.wait_for_log(f'gossipd: channel {pre_splice_scid} closing soon due to the funding outpoint being spent')
234 assert len(l3.rpc.listchannels(short_channel_id=pre_splice_scid)['channels']) == 2
235 assert len(l3.rpc.listchannels(source=l1.info['id'])['channels']) == 1
236
237 # Final one will allow splice announcement to proceed.
238 bitcoind.generate_block(1)
239 wait_for(lambda: only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['state'] == 'CHANNELD_NORMAL')
240 wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['state'] == 'CHANNELD_NORMAL')
241
242 post_splice_scid = first_scid(l1, l2)
243 assert post_splice_scid != pre_splice_scid
244
245 # l3 should see the new channel now.
246 wait_for(lambda: len(l3.rpc.listchannels(short_channel_id=post_splice_scid)['channels']) == 2)
247 assert len(l3.rpc.listchannels(short_channel_id=pre_splice_scid)['channels']) == 2
248
249 bitcoind.generate_block(67)
250
251 # The old channel should fall off l3's perspective
252 wait_for(lambda: l3.rpc.listchannels(short_channel_id=pre_splice_scid)['channels'] == [])
253 assert len(l3.rpc.listchannels(short_channel_id=post_splice_scid)['channels']) == 2
254
255 # Check that the splice doesn't generate a unilateral close transaction
256 time.sleep(5)
257 assert l1.db_query("SELECT count(*) as c FROM channeltxs;")[0]['c'] == 0
258
259 # Still looks normal from both sides
260 assert only_one(l1.rpc.listpeerchannels()['channels'])['short_channel_id'] == post_splice_scid
261 assert only_one(l1.rpc.listpeerchannels()['channels'])['state'] == 'CHANNELD_NORMAL'
262 assert only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['short_channel_id'] == post_splice_scid
263 assert only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['state'] == 'CHANNELD_NORMAL'
264
265 # Check for channel announcement failure
266 assert not l1.daemon.is_in_log("invalid local_channel_announcement")
267 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