Skip to content

Commit fa663a4

Browse files
author
MarcoFalke
committed
Use mockable time for peer connection time
This allows to revert the temporary commit 0bfb920 (test: fix test failures in test/functional/p2p_timeouts.py).
1 parent fad7ead commit fa663a4

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2975,7 +2975,7 @@ ServiceFlags CConnman::GetLocalServices() const
29752975
unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; }
29762976

29772977
CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion)
2978-
: nTimeConnected(GetTimeSeconds()),
2978+
: nTimeConnected{GetTime<std::chrono::seconds>()},
29792979
addr(addrIn),
29802980
addrBind(addrBindIn),
29812981
m_addr_name{addrNameIn.empty() ? addr.ToStringIPPort() : addrNameIn},

src/test/denialofservice_tests.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
131131
options.m_max_outbound_full_relay = max_outbound_full_relay;
132132
options.nMaxFeeler = MAX_FEELER_CONNECTIONS;
133133

134+
const auto time_init{GetTime<std::chrono::seconds>()};
135+
SetMockTime(time_init);
136+
const auto time_later{time_init + 3 * std::chrono::seconds{chainparams.GetConsensus().nPowTargetSpacing} + 1s};
134137
connman->Init(options);
135138
std::vector<CNode *> vNodes;
136139

@@ -146,7 +149,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
146149
BOOST_CHECK(node->fDisconnect == false);
147150
}
148151

149-
SetMockTime(GetTime() + 3 * chainparams.GetConsensus().nPowTargetSpacing + 1);
152+
SetMockTime(time_later);
150153

151154
// Now tip should definitely be stale, and we should look for an extra
152155
// outbound peer
@@ -161,7 +164,9 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
161164
// If we add one more peer, something should get marked for eviction
162165
// on the next check (since we're mocking the time to be in the future, the
163166
// required time connected check should be satisfied).
167+
SetMockTime(time_init);
164168
AddRandomOutboundPeer(vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY);
169+
SetMockTime(time_later);
165170

166171
peerLogic->CheckForStaleTipAndEvictPeers();
167172
for (int i = 0; i < max_outbound_full_relay; ++i) {

test/functional/p2p_timeouts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def run_test(self):
8686
]
8787

8888
with self.nodes[0].assert_debug_log(expected_msgs=expected_timeout_logs):
89-
self.mock_forward(5)
89+
self.mock_forward(2)
9090
no_verack_node.wait_for_disconnect(timeout=1)
9191
no_version_node.wait_for_disconnect(timeout=1)
9292
no_send_node.wait_for_disconnect(timeout=1)

0 commit comments

Comments
 (0)