Repository navigation
Conversation
The test send buffer limit is zero, so queued messages set `fPauseSend`. Move the repeated resets into `ProcessMessagesOnce()`. This adds resets at four call sites in `orphan_reconsideration_interruptible`, where the peer is already unpaused. Keeping resets here will hide the later unpaused timestamp sentinel from test callers.
Hide the flag and timestamp behind `CNode` accessors and extract their shared updates into `SetPauseSend()`. Both production update sites already hold `cs_vSend`. Cover preserving an active pause's start time and recording a fresh one after resuming.
Encode the paused state in the timestamp, using epoch for unpaused. This removes the separate flag and gives readers one atomic snapshot. Preserve the original start time across repeated pause updates.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
| ); | ||
| return true; | ||
| } | ||
| if (auto last_pause{node.GetPauseSendSince()}; last_pause && now > *last_pause + TIMEOUT_INTERVAL) { |
There was a problem hiding this comment.
Ralph suggested a test for this branch, which has had none since #36667.
The test below fails if the branch is removed or > is changed to >=.
Suggestion
diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp
index 21ab8937ac..6f5a78da71 100644
--- a/src/test/net_tests.cpp
+++ b/src/test/net_tests.cpp
@@ -163,6 +163,15 @@ BOOST_AUTO_TEST_CASE(cnode_pause_send)
peer.SetPauseSend(true);
BOOST_CHECK(peer.IsSendPaused());
BOOST_CHECK_EQUAL(peer.GetPauseSendSince(), NodeClock::now());
+
+ auto& connman{static_cast<ConnmanTestMsg&>(*m_node.connman)};
+ peer.fSuccessfullyConnected = true;
+ clock += TIMEOUT_INTERVAL;
+ peer.m_last_send = NodeClock::now();
+ peer.m_last_recv = NodeClock::now();
+ BOOST_CHECK(!connman.InactivityCheckPublic(peer, NodeClock::now()));
+ clock += 1s;
+ BOOST_CHECK(connman.InactivityCheckPublic(peer, NodeClock::now()));
}
BOOST_AUTO_TEST_CASE(cnetaddr_basic)
diff --git a/src/test/util/net.h b/src/test/util/net.h
index 7317e49075..23556eb650 100644
--- a/src/test/util/net.h
+++ b/src/test/util/net.h
@@ -94,6 +94,11 @@ struct ConnmanTestMsg : public CConnman {
SocketHandler();
}
+ bool InactivityCheckPublic(const CNode& node, NodeClock::time_point now) const
+ {
+ return InactivityCheck(node, now);
+ }
+
void Handshake(CNode& node,
bool successfully_connected,
ServiceFlags remote_services,There was a problem hiding this comment.
Is that an interesting difference?
There was a problem hiding this comment.
No, not by itself. The >= was only there to show the test checks the timeout too. My point was that this disconnect has no test coverage today.
| // The send buffer provides backpressure. If there's no space in | ||
| // the buffer, pause processing until the next call. | ||
| if (pfrom.fPauseSend) break; | ||
| if (pfrom.IsSendPaused()) break; |
There was a problem hiding this comment.
No test fails with this check, the one for blocks below and the one in ProcessMessages all removed, and none did before this PR either.
The test below fails without any one of the three.
Suggestion
diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp
index 21ab8937ac..d114ed4e66 100644
--- a/src/test/net_tests.cpp
+++ b/src/test/net_tests.cpp
@@ -1822,4 +1822,37 @@ BOOST_AUTO_TEST_CASE(addlocal_onlynet_externalip)
fDiscover = discover_orig;
}
+BOOST_AUTO_TEST_CASE(paused_peer_backpressure)
+{
+ LOCK(NetEventsInterface::g_msgproc_mutex);
+ auto& connman{static_cast<ConnmanTestMsg&>(*m_node.connman)};
+ CNode peer{/*id=*/0, /*sock=*/nullptr, /*addrIn=*/CAddress{}, /*nKeyedNetGroupIn=*/0, /*nLocalHostNonceIn=*/0, /*addrBindIn=*/CService{}, /*addrNameIn=*/"", ConnectionType::INBOUND, /*inbound_onion=*/false, /*network_key=*/0};
+ connman.Handshake(peer, /*successfully_connected=*/true, ServiceFlags(NODE_NETWORK | NODE_WITNESS), ServiceFlags(NODE_NETWORK | NODE_WITNESS), PROTOCOL_VERSION, /*relay_txs=*/true);
+ std::vector<std::string> sent;
+ const auto capture_orig{CaptureMessage};
+ CaptureMessage = [&](const CAddress&, const std::string& type, std::span<const unsigned char>, bool incoming) { if (!incoming) sent.push_back(type); };
+ connman.SetCaptureMessages(true);
+
+ // Serving the first block fills the send buffer, so the rest of the request has to wait.
+ std::atomic<bool> interrupt{false};
+ const CInv block{MSG_WITNESS_BLOCK, Params().GenesisBlock().GetHash()};
+ for (const CInv& queued : {block, CInv{MSG_WTX, uint256::ONE}}) {
+ connman.FlushSendBuffer(peer);
+ BOOST_REQUIRE(connman.ReceiveMsgFrom(peer, NetMsg::Make(NetMsgType::GETDATA, std::vector{block, queued})));
+ connman.ProcessMessagesOnce(peer);
+ m_node.peerman->ProcessMessages(peer, interrupt);
+ BOOST_CHECK_EQUAL(sent.size(), 1U);
+ connman.ProcessMessagesOnce(peer);
+ sent.clear();
+ }
+
+ // Nor is a new message processed while the peer stays paused.
+ connman.FlushSendBuffer(peer);
+ BOOST_REQUIRE(connman.ReceiveMsgFrom(peer, NetMsg::Make(NetMsgType::PING, uint64_t{0})));
+ m_node.peerman->ProcessMessages(peer, interrupt);
+ BOOST_CHECK(sent.empty());
+ CaptureMessage = capture_orig;
+ m_node.peerman->FinalizeNode(peer);
+}
+
BOOST_AUTO_TEST_SUITE_END()
Problem: Each peer's send pause state is a flag plus a separate start timestamp.
Message queueing and socket sends each duplicate the transition logic that keeps the two in sync, and the inactivity check (which needs both), reads them separately.
Fix: Move the pause transitions into
CNodeaccessors over one atomic timestamp.The inactivity check then reads the pause status and start time as one snapshot.
Follow-up to #36667.