pyln-testing: in LightningNode.openchannel, make wait_for_announce more reliable

it now waits for 'alias' in node_announcement, not just block confirms.
more cleanup
This commit is contained in:
Simon Vrouwe
2022-01-16 11:56:15 +02:00
committed by Rusty Russell
parent f84e1a0536
commit 84bead9396
2 changed files with 7 additions and 14 deletions

View File

@@ -731,21 +731,16 @@ class LightningNode(object):
if connect and not self.is_connected(remote_node): if connect and not self.is_connected(remote_node):
self.connect(remote_node) self.connect(remote_node)
fundingtx = self.rpc.fundchannel(remote_node.info['id'], capacity) res = self.rpc.fundchannel(remote_node.info['id'], capacity)
# Wait for the funding transaction to be in bitcoind's mempool
wait_for(lambda: fundingtx['txid'] in self.bitcoin.rpc.getrawmempool())
if confirm or wait_for_announce: if confirm or wait_for_announce:
self.bitcoin.generate_block(1) self.bitcoin.generate_block(1, wait_for_mempool=res['txid'])
if wait_for_announce: if wait_for_announce:
self.bitcoin.generate_block(5) self.bitcoin.generate_block(5)
wait_for(lambda: ['alias' in e for e in self.rpc.listnodes(remote_node.info['id'])['nodes']])
if confirm or wait_for_announce: return {'address': addr, 'wallettxid': wallettxid, 'fundingtx': res['tx']}
self.daemon.wait_for_log(
r'Funding tx {} depth'.format(fundingtx['txid']))
return {'address': addr, 'wallettxid': wallettxid, 'fundingtx': fundingtx}
def fundwallet(self, sats, addrtype="p2sh-segwit", mine_block=True): def fundwallet(self, sats, addrtype="p2sh-segwit", mine_block=True):
addr = self.rpc.newaddr(addrtype)[addrtype] addr = self.rpc.newaddr(addrtype)[addrtype]
@@ -1360,7 +1355,7 @@ class NodeFactory(object):
return node return node
def join_nodes(self, nodes, fundchannel=True, fundamount=FUNDAMOUNT, wait_for_announce=False, announce_channels=True) -> None: def join_nodes(self, nodes, fundchannel=True, fundamount=FUNDAMOUNT, wait_for_announce=False, announce_channels=True) -> None:
"""Given nodes, connect them in a line, optionally funding a channel""" """Given nodes, connect them in a line, optionally funding a channel, wait_for_announce waits for channel and node announcements"""
assert not (wait_for_announce and not announce_channels), "You've asked to wait for an announcement that's not coming. (wait_for_announce=True,announce_channels=False)" assert not (wait_for_announce and not announce_channels), "You've asked to wait for an announcement that's not coming. (wait_for_announce=True,announce_channels=False)"
connections = [(nodes[i], nodes[i + 1]) for i in range(len(nodes) - 1)] connections = [(nodes[i], nodes[i + 1]) for i in range(len(nodes) - 1)]
@@ -1386,10 +1381,8 @@ class NodeFactory(object):
for src, dst in connections: for src, dst in connections:
txids.append(src.rpc.fundchannel(dst.info['id'], fundamount, announce=announce_channels)['txid']) txids.append(src.rpc.fundchannel(dst.info['id'], fundamount, announce=announce_channels)['txid'])
wait_for(lambda: set(txids).issubset(set(bitcoind.rpc.getrawmempool())))
# Confirm all channels and wait for them to become usable # Confirm all channels and wait for them to become usable
bitcoind.generate_block(1) bitcoind.generate_block(1, wait_for_mempool=txids)
scids = [] scids = []
for src, dst in connections: for src, dst in connections:
wait_for(lambda: src.channel_state(dst) == 'CHANNELD_NORMAL') wait_for(lambda: src.channel_state(dst) == 'CHANNELD_NORMAL')

View File

@@ -452,7 +452,7 @@ def test_bech32_funding(node_factory, chainparams):
wallettxid = res['wallettxid'] wallettxid = res['wallettxid']
wallettx = l1.bitcoin.rpc.getrawtransaction(wallettxid, True) wallettx = l1.bitcoin.rpc.getrawtransaction(wallettxid, True)
fundingtx = l1.bitcoin.rpc.decoderawtransaction(res['fundingtx']['tx']) fundingtx = l1.bitcoin.rpc.decoderawtransaction(res['fundingtx'])
def is_p2wpkh(output): def is_p2wpkh(output):
return output['type'] == 'witness_v0_keyhash' and \ return output['type'] == 'witness_v0_keyhash' and \