Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3184,8 +3184,20 @@ def test_dataloss_protection(node_factory, bitcoind):
assert not l2.daemon.is_in_log('sendrawtx exit 0',
start=l2.daemon.logsearch_start)

# l1 should receive error and drop to chain
l1.daemon.wait_for_log("They sent ERROR.*Awaiting unilateral close")
# l1 should receive error and drop to chain. Usually it arrives when l1
# has no channeld (so lightningd logs "They sent ERROR"), but if l1's
# channeld has not exited yet the error is routed to it and gets lost
# when it dies. Reconnect to make l2 resend it: channel->error is sent
# again when the peer reconnects.
try:
l1.daemon.wait_for_log("They sent ERROR.*Awaiting unilateral close", timeout=10)
except TimeoutError:
# The peer may already have gone; connect() below is what matters.
try:
l1.rpc.disconnect(l2.info['id'], force=True)
except RpcError as err:
assert "Peer not connected" in err.error['message']
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

maybe we should check the real connected field, matching the existing convention already used elsewhere in this same file (tests/test_connection.py at line 1374 - wait_for(lambda: not only_one(l1.rpc.listpeers()['peers'])['connected'])), so we can have something like:

peer = only_one(l1.rpc.listpeers(l2.info['id'])['peers'])
if peer['connected']:
    l1.rpc.disconnect(l2.info['id'], force=True)
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)

or!! just try the disconnect and ignore "not connected" errors, since connect() afterwards is what actually matters, because from what i see now we are checking whether the peer appears in listpeers, not whether it is actually connected

l1.wait_for_channel_onchain(l2.info['id'])

closetxid = only_one(bitcoind.rpc.getrawmempool(False))
Expand Down
Loading