aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-12-13 12:11:14 +0100
committerMarcoFalke <falke.marco@gmail.com>2021-12-13 13:32:05 +0100
commitfa663a4c0d20487ed3f7a93e1c2ca9932b05f5a8 (patch)
tree56c88a822c8ac1eeec05eac4a1d108807d72c29f
parentfad7ead146a152f46b25ce6623e05cbb1dbc8cca (diff)
downloadbitcoin-fa663a4c0d20487ed3f7a93e1c2ca9932b05f5a8.tar.xz
Use mockable time for peer connection time
This allows to revert the temporary commit 0bfb9208df556f77cddfedfd73e5811a0e031d34 (test: fix test failures in test/functional/p2p_timeouts.py).
-rw-r--r--src/net.cpp2
-rw-r--r--src/test/denialofservice_tests.cpp7
-rwxr-xr-xtest/functional/p2p_timeouts.py2
3 files changed, 8 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 094a3f7de6..af57d29e4d 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -2975,7 +2975,7 @@ ServiceFlags CConnman::GetLocalServices() const
unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; }
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)
- : nTimeConnected(GetTimeSeconds()),
+ : nTimeConnected{GetTime<std::chrono::seconds>()},
addr(addrIn),
addrBind(addrBindIn),
m_addr_name{addrNameIn.empty() ? addr.ToStringIPPort() : addrNameIn},
diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp
index a62c799305..082dfcc684 100644
--- a/src/test/denialofservice_tests.cpp
+++ b/src/test/denialofservice_tests.cpp
@@ -131,6 +131,9 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
options.m_max_outbound_full_relay = max_outbound_full_relay;
options.nMaxFeeler = MAX_FEELER_CONNECTIONS;
+ const auto time_init{GetTime<std::chrono::seconds>()};
+ SetMockTime(time_init);
+ const auto time_later{time_init + 3 * std::chrono::seconds{chainparams.GetConsensus().nPowTargetSpacing} + 1s};
connman->Init(options);
std::vector<CNode *> vNodes;
@@ -146,7 +149,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
BOOST_CHECK(node->fDisconnect == false);
}
- SetMockTime(GetTime() + 3 * chainparams.GetConsensus().nPowTargetSpacing + 1);
+ SetMockTime(time_later);
// Now tip should definitely be stale, and we should look for an extra
// outbound peer
@@ -161,7 +164,9 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
// If we add one more peer, something should get marked for eviction
// on the next check (since we're mocking the time to be in the future, the
// required time connected check should be satisfied).
+ SetMockTime(time_init);
AddRandomOutboundPeer(vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY);
+ SetMockTime(time_later);
peerLogic->CheckForStaleTipAndEvictPeers();
for (int i = 0; i < max_outbound_full_relay; ++i) {
diff --git a/test/functional/p2p_timeouts.py b/test/functional/p2p_timeouts.py
index 602f826782..cf714bc888 100755
--- a/test/functional/p2p_timeouts.py
+++ b/test/functional/p2p_timeouts.py
@@ -86,7 +86,7 @@ class TimeoutsTest(BitcoinTestFramework):
]
with self.nodes[0].assert_debug_log(expected_msgs=expected_timeout_logs):
- self.mock_forward(5)
+ self.mock_forward(2)
no_verack_node.wait_for_disconnect(timeout=1)
no_version_node.wait_for_disconnect(timeout=1)
no_send_node.wait_for_disconnect(timeout=1)