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

Function test_closing_specified_destination

tests/test_closing.py:288–364  ·  view source on GitHub ↗
(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

286
287
288def test_closing_specified_destination(node_factory, bitcoind, chainparams):
289 l1, l2, l3, l4 = node_factory.get_nodes(4)
290
291 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
292 l1.rpc.connect(l3.info['id'], 'localhost', l3.port)
293 l1.rpc.connect(l4.info['id'], 'localhost', l4.port)
294
295 chan12, _ = l1.fundchannel(l2, 10**6)
296 chan13, _ = l1.fundchannel(l3, 10**6)
297 chan14, _ = l1.fundchannel(l4, 10**6)
298
299 l1.pay(l2, 100000000)
300 l1.pay(l3, 100000000)
301 l1.pay(l4, 100000000)
302
303 # Make sure HTLCs completely expired before we mine, so they don't
304 # unilaterally close!
305 for n in l1, l2, l3, l4:
306 wait_for(lambda: all(c['htlcs'] == [] for c in n.rpc.listpeerchannels()['channels']))
307
308 mine_funding_to_announce(bitcoind, [l1, l2, l3, l4])
309
310 # Make sure they all see all the gossip before close, otherwise they might
311 # get upset with "bad gossip!"
312 for n in [l1, l2, l3, l4]:
313 wait_for(lambda: len(n.rpc.listchannels()['channels']) == 6)
314 wait_for(lambda: ['alias' in node for node in n.rpc.listnodes()['nodes']] == [True] * 4)
315
316 # If we don't wait for gossip to propagate, then we can get bad gossip msgs if it
317 # propagates after close!
318 for n in l1, l2, l3, l4:
319 wait_for(lambda: len(n.rpc.listchannels()['channels']) == 6)
320 wait_for(lambda: ['alias' in node for node in n.rpc.listnodes()['nodes']] == [True] * 4)
321
322 addr = chainparams['example_addr']
323 l1.rpc.close(chan12, None, addr)
324 l1.rpc.call('close', {'id': chan13, 'destination': addr})
325 l1.rpc.call('close', [chan14, None, addr])
326
327 l1.daemon.wait_for_logs([' to CLOSINGD_SIGEXCHANGE'] * 3)
328
329 # Both nodes should have disabled the channel in gossip
330 wait_for(lambda: not any([c['active'] for c in l1.rpc.listchannels()['channels']]))
331 wait_for(lambda: not any([c['active'] for c in l2.rpc.listchannels()['channels']]))
332
333 wait_for(lambda: bitcoind.rpc.getmempoolinfo()['size'] == 3)
334
335 # Now grab the close transaction
336 closetxs = {}
337 for i, n in enumerate([l2, l3, l4]):
338 billboard = only_one(l1.rpc.listpeerchannels(n.info['id'])['channels'])['status'][0]
339 m = re.search(r'CLOSINGD_SIGEXCHANGE.* tx:([a-f0-9]{64})', billboard)
340 closetxs[n] = m.group(1)
341
342 bitcoind.generate_block(1)
343 sync_blockheight(bitcoind, [l1, l2, l3, l4])
344
345 outtype = 'p2tr' if not chainparams['elements'] else 'p2wpkh'

Callers

nothing calls this directly

Calls 15

wait_forFunction · 0.90
mine_funding_to_announceFunction · 0.90
only_oneFunction · 0.90
sync_blockheightFunction · 0.90
scriptpubkey_addrFunction · 0.90
get_nodesMethod · 0.80
listpeerchannelsMethod · 0.80
wait_for_logsMethod · 0.80
generate_blockMethod · 0.80
is_in_logMethod · 0.80
wait_for_logMethod · 0.80
anyClass · 0.50

Tested by

no test coverage detected