Skip to content

Commit e27dee0

Browse files
committed
connectd: fix nagle disabling logic.
Our CORK logic was wrong, and it's better to use Nagle anyway: we disable Nagle just before sending timing-critical messages. Time for 100 (failed) payments: Before: 148.8573575 After: 10.7356977 Note this revealed a timing problem in test_reject_invalid_payload: we would miss the cause of the sendonion failure, and waitsendpay would be called *after* it had failed, so simply returns "Payment failure reason unknown". Signed-off-by: Rusty Russell <[email protected]> Changelog-Fixed: Protocol: Removed 200ms latency from sending commit/revoke messages.
1 parent 863aac4 commit e27dee0

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

connectd/multiplex.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,6 @@ void setup_peer_gossip_store(struct peer *peer,
307307
static void set_urgent_flag(struct peer *peer, bool urgent)
308308
{
309309
int val;
310-
int opt;
311-
const char *optname;
312310

313311
if (urgent == peer->urgent)
314312
return;
@@ -318,23 +316,13 @@ static void set_urgent_flag(struct peer *peer, bool urgent)
318316
if (peer->is_websocket != NORMAL_SOCKET)
319317
return;
320318

321-
#ifdef TCP_CORK
322-
opt = TCP_CORK;
323-
optname = "TCP_CORK";
324-
#elif defined(TCP_NODELAY)
325-
opt = TCP_NODELAY;
326-
optname = "TCP_NODELAY";
327-
#else
328-
#error "Please report platform with neither TCP_CORK nor TCP_NODELAY?"
329-
#endif
330-
331319
val = urgent;
332320
if (setsockopt(io_conn_fd(peer->to_peer),
333-
IPPROTO_TCP, opt, &val, sizeof(val)) != 0
321+
IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)) != 0
334322
/* This actually happens in testing, where we blackhole the fd */
335323
&& peer->daemon->dev_disconnect_fd == -1) {
336-
status_broken("setsockopt %s=1 fd=%u: %s",
337-
optname, io_conn_fd(peer->to_peer),
324+
status_broken("setsockopt TCP_NODELAY=1 fd=%u: %s",
325+
io_conn_fd(peer->to_peer),
338326
strerror(errno));
339327
}
340328
peer->urgent = urgent;

tests/test_connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4822,7 +4822,6 @@ def test_private_channel_no_reconnect(node_factory):
48224822
assert only_one(l1.rpc.listpeers()['peers'])['connected'] is False
48234823

48244824

4825-
@pytest.mark.xfail(strict=True)
48264825
@unittest.skipIf(VALGRIND, "We assume machine is reasonably fast")
48274826
def test_no_delay(node_factory):
48284827
"""Is our Nagle disabling for critical messages working?"""

tests/test_pay.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,12 +3423,11 @@ def test_reject_invalid_payload(node_factory):
34233423
first_hop=first_hop,
34243424
payment_hash=inv['payment_hash'],
34253425
shared_secrets=onion['shared_secrets'])
3426-
3427-
l2.daemon.wait_for_log(r'Failing HTLC because of an invalid payload')
3428-
34293426
with pytest.raises(RpcError, match=r'WIRE_INVALID_ONION_PAYLOAD'):
34303427
l1.rpc.waitsendpay(inv['payment_hash'])
34313428

3429+
l2.daemon.wait_for_log(r'Failing HTLC because of an invalid payload')
3430+
34323431

34333432
@unittest.skip("Test is flaky causing CI to be unusable.")
34343433
def test_excluded_adjacent_routehint(node_factory, bitcoind):

0 commit comments

Comments
 (0)