From 27a186be9ca0e552472041c71b012a7ef57c53fb Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 29 May 2018 13:50:34 +0200 Subject: [PATCH] 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 --- tests/utils.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index 60e4ff006..f6ef25c6a 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -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"):