From ce2d5c9b6328bfc609a504c42665d35c2f0df74b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 29 Jan 2024 10:11:39 +1030 Subject: [PATCH 1/2] pytest: fix flake in test_custommsg_triggers_notification If listpeers on l2 is called too fast, then it won't return any peers, and we will fail: ``` # Connect l1 to l2 l1.connect(l2) > wait_for(lambda: l2.rpc.listpeers(l1.info['id'])['peers'][0]['connected']) tests/test_misc.py:2690: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ contrib/pyln-testing/pyln/testing/utils.py:88: in wait_for while not success(): _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > wait_for(lambda: l2.rpc.listpeers(l1.info['id'])['peers'][0]['connected']) E IndexError: list index out of range ``` Signed-off-by: Rusty Russell --- tests/test_misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_misc.py b/tests/test_misc.py index 163f06e2b85d..b5faa873d634 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -2687,7 +2687,7 @@ def test_custommsg_triggers_notification(node_factory): # Connect l1 to l2 l1.connect(l2) - wait_for(lambda: l2.rpc.listpeers(l1.info['id'])['peers'][0]['connected']) + wait_for(lambda: [p['connected'] for p in l2.rpc.listpeers(l1.info['id'])['peers']] == [True]) # Send a custommsg from l2 to l1 # The message id 7777 is chosen to be sufficiently high and shouldn't be used by the From caa4a68f8d14b11c48fd3d3340bbc9b591ec51df Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 29 Jan 2024 13:29:19 +1030 Subject: [PATCH 2/2] pytest: fix flake in test_peer_anchor_push If l1 is one block behind, l2 goes onchain one block early: ``` # Drops to chain > wait_for(lambda: only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['state'] == 'AWAITING_UNILATERAL') tests/test_closing.py:3951: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ success = . at 0x7f799f9cd1f0> timeout = 180 def wait_for(success, timeout=TIMEOUT): start_time = time.time() interval = 0.25 while not success(): time_left = start_time + timeout - time.time() if time_left <= 0: > raise ValueError("Timeout while waiting for {}".format(success)) E ValueError: Timeout while waiting for . at 0x7f799f9cd1f0> ``` Signed-off-by: Rusty Russell --- tests/test_closing.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_closing.py b/tests/test_closing.py index c1c354da75dd..0494a2a026b0 100644 --- a/tests/test_closing.py +++ b/tests/test_closing.py @@ -3919,7 +3919,7 @@ def test_peer_anchor_push(node_factory, bitcoind, executor, chainparams): psbt = l2.rpc.addpsbtoutput(OUTPUT_SAT, psbt)['psbt'] l2.rpc.sendpsbt(l2.rpc.signpsbt(psbt)['signed_psbt']) bitcoind.generate_block(1, wait_for_mempool=1) - sync_blockheight(bitcoind, [l2]) + sync_blockheight(bitcoind, [l1, l2]) # Make sure all amounts are below OUTPUT_SAT sats! assert [x for x in l2.rpc.listfunds()['outputs'] if x['amount_msat'] > Millisatoshi(str(OUTPUT_SAT) + "sat")] == [] @@ -3931,6 +3931,9 @@ def test_peer_anchor_push(node_factory, bitcoind, executor, chainparams): l1.rpc.sendpay(route, sticky_inv['payment_hash'], payment_secret=sticky_inv['payment_secret']) l3.daemon.wait_for_log('dev_disconnect: -WIRE_UPDATE_FULFILL_HTLC') + # Make sure HTLC expiry is what we expect! + l2.daemon.wait_for_log('Adding HTLC 0 amount=100000000msat cltv=119 gave CHANNEL_ERR_ADD_OK') + # l3 drops to chain, but make sure it doesn't CPFP its own anchor. wait_for(lambda: only_one(l3.rpc.listpeerchannels(l2.info['id'])['channels'])['htlcs'] != []) closetx = l3.rpc.dev_sign_last_tx(l2.info['id'])['tx']