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

Function test_funding_cancel_race

tests/test_connection.py:1474–1552  ·  view source on GitHub ↗
(node_factory, bitcoind, executor)

Source from the content-addressed store, hash-verified

1472@pytest.mark.slow_test
1473@pytest.mark.openchannel('v1')
1474def test_funding_cancel_race(node_factory, bitcoind, executor):
1475 l1 = node_factory.get_node()
1476
1477 # make sure we can generate PSBTs.
1478 addr = l1.rpc.newaddr('bech32')['bech32']
1479 bitcoind.rpc.sendtoaddress(addr, 200000 / 10**8)
1480 bitcoind.generate_block(1)
1481 wait_for(lambda: len(l1.rpc.listfunds()["outputs"]) != 0)
1482
1483 if VALGRIND:
1484 num = 5
1485 elif SLOW_MACHINE:
1486 num = 20
1487 else:
1488 num = 100
1489
1490 # Allow the other nodes to log unexpected WIRE_FUNDING_CREATED messages
1491 nodes = node_factory.get_nodes(num, opts={})
1492
1493 num_complete = 0
1494 num_cancel = 0
1495
1496 for count, n in enumerate(nodes):
1497 l1.rpc.connect(n.info['id'], 'localhost', n.port)
1498 start = l1.rpc.fundchannel_start(n.info['id'], "100000sat")
1499
1500 prep = l1.rpc.txprepare([{start['funding_address']: "100000sat"}])
1501
1502 # Submit two of each at once.
1503 completes = []
1504 cancels = []
1505
1506 # Switch order around.
1507 for i in range(4):
1508 if (i + count) % 2 == 0:
1509 completes.append(executor.submit(l1.rpc.fundchannel_complete, n.info['id'], prep['psbt']))
1510 else:
1511 cancels.append(executor.submit(l1.rpc.fundchannel_cancel, n.info['id']))
1512
1513 # Only up to one should succeed.
1514 success = False
1515 for c in completes:
1516 try:
1517 c.result(TIMEOUT)
1518 num_complete += 1
1519 assert not success
1520 success = True
1521 except RpcError:
1522 pass
1523
1524 # At least one of these must succeed, regardless of whether
1525 # the completes succeeded or not.
1526 cancelled = False
1527 for c in cancels:
1528 try:
1529 c.result(TIMEOUT)
1530 cancelled = True
1531 except RpcError:

Callers

nothing calls this directly

Calls 12

wait_forFunction · 0.90
generate_blockMethod · 0.80
get_nodesMethod · 0.80
fundchannel_startMethod · 0.80
txprepareMethod · 0.80
txdiscardMethod · 0.80
mapMethod · 0.80
get_nodeMethod · 0.45
newaddrMethod · 0.45
listfundsMethod · 0.45
connectMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected