Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test flake, improve close handling #8116

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rustyrussell
Copy link
Contributor

My machine started failing reliably on a number of tests, and this fixes it. It's definitely an improvement, though a minor one in real life.

@rustyrussell rustyrussell added this to the v25.05 milestone Feb 25, 2025
This is a bit too much boilerplate for these, which mainly do the same
thing.

We add annotaitons to new_peer_fd so the compiler knows that it cannot
return NULL, otherwise with -O3 we get:

```
lightningd/peer_control.c: In function ‘peer_connected_hook_final’:
lightningd/peer_control.c:1388:28: error: ‘error’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1388 |                       take(towire_connectd_peer_send_msg(NULL, &channel->peer->id,
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lightningd/peer_control.c:1313:19: note: ‘error’ was declared here
 1313 |         const u8 *error;
      |                   ^~~~~
lightningd/peer_control.c: In function ‘peer_spoke’:
lightningd/peer_control.c:1999:28: error: ‘error’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1999 |                       take(towire_connectd_peer_send_msg(NULL, &peer->id,
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:311: lightningd/peer_control.o] Error 1
```

Signed-off-by: Rusty Russell <[email protected]>
This corner case started triggering on my machine with latest Bitcoind.

This test sabotages the closing negotiation, and as a result l1
doesn't see l2's CLOSING_SIGNED.  l2 is happy, however, and it is in
CLOSINGD_COMPLETE.  When l1 reconnects, it gets an error, and this causes
it to drop the unilateral tx to chain.

This unilateral tx from l1 replaces or races the mutual close tx from
l2, causing a unilateral close, which breaks our test.

Though this is a corner case, it's much friendlier to allow the
closing negotiation again until we actually see the close onchain.
This fixes the tests here, too.

```
    def test_closing_negotiation_reconnect(node_factory, bitcoind):
        disconnects = ['-WIRE_CLOSING_SIGNED',
                       '+WIRE_CLOSING_SIGNED']
        l1, l2 = node_factory.line_graph(2, opts=[{'disconnect': disconnects,
                                                   'may_reconnect': True},
                                                  {'may_reconnect': True}])
        l1.pay(l2, 200000000)
    
        assert bitcoind.rpc.getmempoolinfo()['size'] == 0
    
        l1.rpc.close(l2.info['id'])
        l1.daemon.wait_for_log(r'State changed from CHANNELD_NORMAL to CHANNELD_SHUTTING_DOWN')
        l2.daemon.wait_for_log(r'State changed from CHANNELD_NORMAL to CHANNELD_SHUTTING_DOWN')
    
        # Now verify that the closing tx is in the mempool.
        bitcoind.generate_block(6, wait_for_mempool=1)
        sync_blockheight(bitcoind, [l1, l2])
        for n in [l1, l2]:
            # Ensure we actually got a mutual close.
>           n.daemon.wait_for_log(r'Resolved FUNDING_TRANSACTION/FUNDING_OUTPUT by MUTUAL_CLOSE')

tests/test_closing.py:275: 
```

Signed-off-by: Rusty Russell <[email protected]>
Changelog-Fixed: Protocol: We now renegotiate an interrupted close, even if we don't need it, instead of sending an error.
Copy link
Collaborator

@endothermicdev endothermicdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK bc4a659

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants