pytest: Stabilize LightningNode.openchannel for multiple channels

When opening a number channels from a single node we could end up not waiting
for the funding tx to make it into the mempool, instead triggering on a previous
`sendrawtransaction` or `CHANNEL_NORMAL` in the logs. This now checks that the
actual funding transaction makes it into the mempool and that we wait for the
depth change for that specific channel.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-05-29 13:50:34 +02:00 committed by Rusty Russell
parent c550fd1752
commit 27a186be9c
1 changed files with 14 additions and 4 deletions

View File

@ -338,12 +338,22 @@ class LightningNode(object):
self.may_fail = may_fail
self.may_reconnect = may_reconnect
def openchannel(self, remote_node, capacity, addrtype="p2sh-segwit"):
def openchannel(self, remote_node, capacity, addrtype="p2sh-segwit", confirm=True, announce=True):
addr, wallettxid = self.fundwallet(capacity, addrtype)
fundingtx = self.rpc.fundchannel(remote_node.info['id'], capacity)
self.daemon.wait_for_log('sendrawtx exit 0, gave')
self.bitcoin.generate_block(6)
self.daemon.wait_for_log('to CHANNELD_NORMAL|STATE_NORMAL')
# Wait for the funding transaction to be in bitcoind's mempool
wait_for(lambda: fundingtx['txid'] in self.bitcoin.rpc.getrawmempool())
if confirm or announce:
self.bitcoin.generate_block(1)
if announce:
self.bitcoin.generate_block(5)
if confirm or announce:
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"):