mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
pytest: Make LightningNode.fund_channel more resilient
It was really flaky, especially under `test_mpp_interference_2`, most likely due to multiple calls to `fund_channel`. This commit looks for the specific txids in the `listfunds` output and the `getrawmempool` output, avoiding strange artifacts from multiple calls.
This commit is contained in:
committed by
Rusty Russell
parent
1563bbc2fa
commit
8d8b807793
@@ -748,21 +748,31 @@ class LightningNode(object):
|
|||||||
def fundchannel(self, l2, amount, wait_for_active=True, announce_channel=True):
|
def fundchannel(self, l2, amount, wait_for_active=True, announce_channel=True):
|
||||||
# Give yourself some funds to work with
|
# Give yourself some funds to work with
|
||||||
addr = self.rpc.newaddr()['bech32']
|
addr = self.rpc.newaddr()['bech32']
|
||||||
|
|
||||||
|
def has_funds_on_addr(addr):
|
||||||
|
"""Check if the given address has funds in the internal wallet.
|
||||||
|
"""
|
||||||
|
outs = self.rpc.listfunds()['outputs']
|
||||||
|
addrs = [o['address'] for o in outs]
|
||||||
|
return addr in addrs
|
||||||
|
|
||||||
|
# We should not have funds on that address yet, we just generated it.
|
||||||
|
assert(not has_funds_on_addr(addr))
|
||||||
|
|
||||||
self.bitcoin.rpc.sendtoaddress(addr, (amount + 1000000) / 10**8)
|
self.bitcoin.rpc.sendtoaddress(addr, (amount + 1000000) / 10**8)
|
||||||
numfunds = len(self.rpc.listfunds()['outputs'])
|
|
||||||
self.bitcoin.generate_block(1)
|
self.bitcoin.generate_block(1)
|
||||||
wait_for(lambda: len(self.rpc.listfunds()['outputs']) > numfunds)
|
|
||||||
|
# Now we should.
|
||||||
|
wait_for(lambda: has_funds_on_addr(addr))
|
||||||
|
|
||||||
# Now go ahead and open a channel
|
# Now go ahead and open a channel
|
||||||
num_tx = len(self.bitcoin.rpc.getrawmempool())
|
res = self.rpc.fundchannel(l2.info['id'], amount, announce=announce_channel)
|
||||||
tx = self.rpc.fundchannel(l2.info['id'], amount, announce=announce_channel)['tx']
|
wait_for(lambda: res['txid'] in self.bitcoin.rpc.getrawmempool())
|
||||||
|
|
||||||
wait_for(lambda: len(self.bitcoin.rpc.getrawmempool()) == num_tx + 1)
|
|
||||||
self.bitcoin.generate_block(1)
|
self.bitcoin.generate_block(1)
|
||||||
|
|
||||||
# Hacky way to find our output.
|
# Hacky way to find our output.
|
||||||
scid = "{}x1x{}".format(self.bitcoin.rpc.getblockcount(),
|
scid = "{}x1x{}".format(self.bitcoin.rpc.getblockcount(),
|
||||||
get_tx_p2wsh_outnum(self.bitcoin, tx, amount))
|
get_tx_p2wsh_outnum(self.bitcoin, res['tx'], amount))
|
||||||
|
|
||||||
if wait_for_active:
|
if wait_for_active:
|
||||||
self.wait_channel_active(scid)
|
self.wait_channel_active(scid)
|
||||||
|
|||||||
Reference in New Issue
Block a user