pytest: fix flake in penalty tests

Make sure we've completely processed htlc, so we will definitely consider it an old spend.  If we're too fast, l2 might consider it a legitimate unilateral close:

```
        # Make sure both sides got revoke_and_ack for final.
        l1.daemon.wait_for_log('peer_in WIRE_REVOKE_AND_ACK')
        l2.daemon.wait_for_log('peer_in WIRE_REVOKE_AND_ACK')
    
        # Now we really mess things up!
        bitcoind.rpc.sendrawtransaction(tx)
        bitcoind.generate_block(1)
    
        l2.daemon.wait_for_log(' to ONCHAIN')
        # FIXME: l1 should try to stumble along!
    
        # l2 should spend all of the outputs (except to-us).
        # Could happen in any order, depending on commitment tx.
        needle = l2.daemon.logsearch_start
        ((_, txid1, blocks1), (_, txid2, blocks2)) = \
>           l2.wait_for_onchaind_txs(('OUR_PENALTY_TX',
                                      'THEIR_REVOKED_UNILATERAL/DELAYED_CHEAT_OUTPUT_TO_THEM'),
                                     ('OUR_PENALTY_TX',
                                      'THEIR_REVOKED_UNILATERAL/OUR_HTLC'))

tests/test_closing.py:687: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
contrib/pyln-testing/pyln/testing/utils.py:1264: in wait_for_onchaind_txs
    r = self.daemon.wait_for_log('Telling lightningd about {} to resolve {}'
contrib/pyln-testing/pyln/testing/utils.py:346: in wait_for_log
    return self.wait_for_logs([regex], timeout)
```

You can see l2 here:

```
lightningd-2 2023-07-27T03:34:24.533Z DEBUG   0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-onchaind-chan#1: Their unilateral tx, old commit point
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-07-27 14:15:56 +09:30
parent b2c1ef73cb
commit e39fe41ff0

View File

@@ -539,6 +539,9 @@ def test_penalty_inhtlc(node_factory, bitcoind, executor, chainparams, anchors):
# Payment should now complete.
t.result(timeout=10)
# Make sure both sides completely settled.
wait_for(lambda: all([only_one(n.rpc.listpeerchannels()['channels'])['htlcs'] == [] for n in (l1, l2)]))
# Now we really mess things up!
bitcoind.rpc.sendrawtransaction(tx)
bitcoind.generate_block(1)
@@ -670,8 +673,7 @@ def test_penalty_outhtlc(node_factory, bitcoind, executor, chainparams, anchors)
t.result(timeout=10)
# Make sure both sides got revoke_and_ack for final.
l1.daemon.wait_for_log('peer_in WIRE_REVOKE_AND_ACK')
l2.daemon.wait_for_log('peer_in WIRE_REVOKE_AND_ACK')
wait_for(lambda: all([only_one(n.rpc.listpeerchannels()['channels'])['htlcs'] == [] for n in (l1, l2)]))
# Now we really mess things up!
bitcoind.rpc.sendrawtransaction(tx)