Skip to content

Commit

Permalink
pytest: fix flake in test_onchain_slow_anchor.
Browse files Browse the repository at this point in the history
If we get "lucky" then commit tx will have short sig, one less weight (1 in 256 chance):

```
    @unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd anchors not supportd')
    def test_onchain_slow_anchor(node_factory, bitcoind):
        """We still use anchors for non-critical closes"""
        l1, l2 = node_factory.line_graph(2)
    
        # Don't let l1 succeed in sending commit tx
        def censoring_sendrawtx(r):
            return {'id': r['id'], 'result': {}}
    
        l1.daemon.rpcproxy.mock_rpc('sendrawtransaction', censoring_sendrawtx)
    
        close_start_depth = bitcoind.rpc.getblockchaininfo()['blocks']
    
        # Make l1 close unilaterally.
        l1.rpc.disconnect(l2.info['id'], force=True)
        l1.rpc.close(l2.info['id'], unilateraltimeout=1)
    
        # We will have a super-low-prio anchor spend.
        l1.daemon.wait_for_log(r"Low-priority anchorspend aiming for block {} \(feerate 253\)".format(close_start_depth + 2016))
    
        # Restart with reduced block time.
        l1.stop()
        l1.daemon.opts['dev-low-prio-anchor-blocks'] = 20
        l1.start()
    
        l1.daemon.wait_for_log("Low-priority anchorspend aiming for block {}".format(close_start_depth + 20))
        l1.daemon.wait_for_log("Anchorspend for local commit tx")
    
        # Won't go under 12 blocks though.
    
        # Make sure it sees all these blocks at once, to avoid test flakes!
        l1.stop()
        bitcoind.generate_block(7)
        l1.start()
    
        height = bitcoind.rpc.getblockchaininfo()['blocks']
        l1.daemon.wait_for_log(r"Low-priority anchorspend aiming for block {} \(feerate 7458\)".format(height + 13))
>       l1.daemon.wait_for_log(r"Anchorspend for local commit tx fee 12335sat \(w=714\), commit_tx fee 4545sat \(w=768\): package feerate 11390 perkw")
```

Here's the log we *did* get:

```
2025-01-25T08:46:40.9399213Z lightningd-1 2025-01-25T08:40:06.312Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-chan#1: Anchorspend for local commit tx fee 12328sat (w=714), commit_tx fee 4545sat (w=767): package feerate 11392 perkw
```

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jan 27, 2025
1 parent e1e476f commit 9565b3a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/test_closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4239,7 +4239,8 @@ def censoring_sendrawtx(r):

height = bitcoind.rpc.getblockchaininfo()['blocks']
l1.daemon.wait_for_log(r"Low-priority anchorspend aiming for block {} \(feerate 7458\)".format(height + 13))
l1.daemon.wait_for_log(r"Anchorspend for local commit tx fee 12335sat \(w=714\), commit_tx fee 4545sat \(w=768\): package feerate 11390 perkw")
# Can be out-by-one (short sig)!
l1.daemon.wait_for_log(r"Anchorspend for local commit tx fee (12335|12328)sat \(w=714\), commit_tx fee 4545sat \(w=76[78]\): package feerate 1139[02] perkw")
assert not l1.daemon.is_in_log("Low-priority anchorspend aiming for block {}".format(height + 12))

bitcoind.generate_block(1)
Expand Down

0 comments on commit 9565b3a

Please sign in to comment.