mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-08 21:59:10 +02:00
Merge #21015: Make all of net_processing (and some of net) use std::chrono types
0eaea66e8bMake tx relay data structure use std::chrono types (Pieter Wuille)55e82881a1Make all Poisson delays use std::chrono types (Pieter Wuille)c733ac4d8aConvert block/header sync timeouts to std::chrono types (Pieter Wuille)4d98b401fbChange all ping times to std::chrono types (Pieter Wuille) Pull request description: (Picking up #20044. Rebased against master.) This changes various uses of integers to represent timestamps and durations to `std::chrono` duration types with type-safe conversions, getting rid of various `.count()`, constructors, and conversion factors. ACKs for top commit: jnewbery: utACK0eaea66e8bvasild: ACK0eaea66e8bMarcoFalke: re-ACK0eaea66e8b, only changes: minor rename, using C++11 member initializer, using 2min chrono literal, rebase 🤚 ajtowns: utACK0eaea66e8bTree-SHA512: 2dbd8d53bf82e98f9b4611e61dc14c448e8957d1a02575b837fadfd59f80e98614d0ccf890fc351f960ade76a6fb8051b282e252e81675a8ee753dba8b1d7f57
This commit is contained in:
@@ -104,7 +104,9 @@ FUZZ_TARGET_INIT(connman, initialize_connman)
|
||||
},
|
||||
[&] {
|
||||
// Limit now to int32_t to avoid signed integer overflow
|
||||
(void)connman.PoissonNextSendInbound(fuzzed_data_provider.ConsumeIntegral<int32_t>(), fuzzed_data_provider.ConsumeIntegral<int>());
|
||||
(void)connman.PoissonNextSendInbound(
|
||||
std::chrono::microseconds{fuzzed_data_provider.ConsumeIntegral<int32_t>()},
|
||||
std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<int>()});
|
||||
},
|
||||
[&] {
|
||||
CSerializedNetMsg serialized_net_msg;
|
||||
|
||||
@@ -21,17 +21,17 @@ FUZZ_TARGET(node_eviction)
|
||||
std::vector<NodeEvictionCandidate> eviction_candidates;
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
eviction_candidates.push_back({
|
||||
fuzzed_data_provider.ConsumeIntegral<NodeId>(),
|
||||
fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
fuzzed_data_provider.ConsumeBool(),
|
||||
fuzzed_data_provider.ConsumeBool(),
|
||||
fuzzed_data_provider.ConsumeBool(),
|
||||
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
||||
fuzzed_data_provider.ConsumeBool(),
|
||||
fuzzed_data_provider.ConsumeBool(),
|
||||
/* id */ fuzzed_data_provider.ConsumeIntegral<NodeId>(),
|
||||
/* nTimeConnected */ fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
/* m_min_ping_time */ std::chrono::microseconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
|
||||
/* nLastBlockTime */ fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
/* nLastTXTime */ fuzzed_data_provider.ConsumeIntegral<int64_t>(),
|
||||
/* fRelevantServices */ fuzzed_data_provider.ConsumeBool(),
|
||||
/* fRelayTxes */ fuzzed_data_provider.ConsumeBool(),
|
||||
/* fBloomFilter */ fuzzed_data_provider.ConsumeBool(),
|
||||
/* nKeyedNetGroup */ fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
||||
/* prefer_evict */ fuzzed_data_provider.ConsumeBool(),
|
||||
/* m_is_local */ fuzzed_data_provider.ConsumeBool(),
|
||||
});
|
||||
}
|
||||
// Make a copy since eviction_candidates may be in some valid but otherwise
|
||||
|
||||
@@ -803,21 +803,6 @@ BOOST_AUTO_TEST_CASE(LocalAddress_BasicLifecycle)
|
||||
BOOST_CHECK_EQUAL(IsLocal(addr), false);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(PoissonNextSend)
|
||||
{
|
||||
g_mock_deterministic_tests = true;
|
||||
|
||||
int64_t now = 5000;
|
||||
int average_interval_seconds = 600;
|
||||
|
||||
auto poisson = ::PoissonNextSend(now, average_interval_seconds);
|
||||
std::chrono::microseconds poisson_chrono = ::PoissonNextSend(std::chrono::microseconds{now}, std::chrono::seconds{average_interval_seconds});
|
||||
|
||||
BOOST_CHECK_EQUAL(poisson, poisson_chrono.count());
|
||||
|
||||
g_mock_deterministic_tests = false;
|
||||
}
|
||||
|
||||
std::vector<NodeEvictionCandidate> GetRandomNodeEvictionCandidates(const int n_candidates, FastRandomContext& random_context)
|
||||
{
|
||||
std::vector<NodeEvictionCandidate> candidates;
|
||||
@@ -825,7 +810,7 @@ std::vector<NodeEvictionCandidate> GetRandomNodeEvictionCandidates(const int n_c
|
||||
candidates.push_back({
|
||||
/* id */ id,
|
||||
/* nTimeConnected */ static_cast<int64_t>(random_context.randrange(100)),
|
||||
/* m_min_ping_time */ static_cast<int64_t>(random_context.randrange(100)),
|
||||
/* m_min_ping_time */ std::chrono::microseconds{random_context.randrange(100)},
|
||||
/* nLastBlockTime */ static_cast<int64_t>(random_context.randrange(100)),
|
||||
/* nLastTXTime */ static_cast<int64_t>(random_context.randrange(100)),
|
||||
/* fRelevantServices */ random_context.randbool(),
|
||||
@@ -885,7 +870,7 @@ BOOST_AUTO_TEST_CASE(node_eviction_test)
|
||||
// from eviction.
|
||||
BOOST_CHECK(!IsEvicted(
|
||||
number_of_nodes, [](NodeEvictionCandidate& candidate) {
|
||||
candidate.m_min_ping_time = candidate.id;
|
||||
candidate.m_min_ping_time = std::chrono::microseconds{candidate.id};
|
||||
},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7}, random_context));
|
||||
|
||||
@@ -931,10 +916,10 @@ BOOST_AUTO_TEST_CASE(node_eviction_test)
|
||||
// Combination of all tests above.
|
||||
BOOST_CHECK(!IsEvicted(
|
||||
number_of_nodes, [number_of_nodes](NodeEvictionCandidate& candidate) {
|
||||
candidate.nKeyedNetGroup = number_of_nodes - candidate.id; // 4 protected
|
||||
candidate.m_min_ping_time = candidate.id; // 8 protected
|
||||
candidate.nLastTXTime = number_of_nodes - candidate.id; // 4 protected
|
||||
candidate.nLastBlockTime = number_of_nodes - candidate.id; // 4 protected
|
||||
candidate.nKeyedNetGroup = number_of_nodes - candidate.id; // 4 protected
|
||||
candidate.m_min_ping_time = std::chrono::microseconds{candidate.id}; // 8 protected
|
||||
candidate.nLastTXTime = number_of_nodes - candidate.id; // 4 protected
|
||||
candidate.nLastBlockTime = number_of_nodes - candidate.id; // 4 protected
|
||||
},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, random_context));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user