014aff1 net_processing: compute headers sync parameters at runtime:
With the rewrite down to about 3 µs per call and fixed clocks already in these fuzz targets, is the override still worth keeping?
<details>
<summary>Use the existing fixed fuzz clocks</summary>
(Based on previous local suggestions, so this patch may not apply cleanly)
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index ea800ba9a3..d107c5fbc8 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -2135,17 +2135,11 @@ std::unique_ptr<PeerManager> PeerManager::make(CConnman& connman, AddrMan& addrm
return std::make_unique<PeerManagerImpl>(connman, addrman, banman, chainman, pool, warnings, opts);
}
-//! Compute the headers sync DoS-protection parameters for the given chain (unless precomputed
-//! ones are provided), using its age (genesis to now) and the height at which its minimum chain
-//! work was taken, and log the result.
-static HeadersSyncParams MakeHeadersSyncParams(const CChainParams& chainparams,
- const std::optional<std::pair<size_t, size_t>>& precomputed)
+//! Compute the headers sync DoS-protection parameters for the given chain, using its age (genesis
+//! to now) and the height at which its minimum chain work was taken, and log the result.
+static HeadersSyncParams MakeHeadersSyncParams(const CChainParams& chainparams)
{
- const auto params{precomputed ? HeadersSyncParams{.commitment_period = precomputed->first, .redownload_buffer_size = precomputed->second} : [&] {
- const auto genesis_time{NodeSeconds{std::chrono::seconds{chainparams.GenesisBlock().nTime}}};
- const auto timespan{std::chrono::duration_cast<std::chrono::seconds>(NodeClock::now() - genesis_time)};
- return ComputeHeadersSyncParams(timespan, chainparams.GetConsensus().minchainwork_height);
- }()};
+ const auto params{ComputeHeadersSyncParams(Now<NodeSeconds>() - chainparams.GenesisBlock().Time(), chainparams.GetConsensus().minchainwork_height)};
LogInfo("Headers sync parameters: commitment period=%u, redownload buffer size=%u", params.commitment_period, params.redownload_buffer_size);
return params;
}
@@ -2156,7 +2150,7 @@ PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman,
: m_rng{opts.deterministic_rng},
m_fee_filter_rounder{CFeeRate{DEFAULT_MIN_RELAY_TX_FEE}, m_rng},
m_chainparams(chainman.GetParams()),
- m_headers_sync_params{MakeHeadersSyncParams(m_chainparams, opts.headers_sync_params)},
+ m_headers_sync_params{MakeHeadersSyncParams(m_chainparams)},
m_connman(connman),
m_addrman(addrman),
m_banman(banman),
diff --git a/src/net_processing.h b/src/net_processing.h
index 3a9ecbab63..edaf48418f 100644
--- a/src/net_processing.h
+++ b/src/net_processing.h
@@ -18,12 +18,10 @@
#include <atomic>
#include <chrono>
-#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
-#include <utility>
#include <vector>
class AddrMan;
@@ -112,9 +110,6 @@ public:
bool private_broadcast{DEFAULT_PRIVATE_BROADCAST};
//! Maximum per-second rate for sending transaction inventory to peers.
unsigned int tx_send_rate{DEFAULT_TX_SEND_RATE};
- //! Precomputed headers-sync parameters, as {commitment period, redownload buffer size};
- //! when unset, they are computed at construction time (this is a test-only option).
- std::optional<std::pair<size_t, size_t>> headers_sync_params{std::nullopt};
};
static std::unique_ptr<PeerManager> make(CConnman& connman, AddrMan& addrman,
diff --git a/src/test/fuzz/cmpctblock.cpp b/src/test/fuzz/cmpctblock.cpp
index 4f1e0df805..fea6229790 100644
--- a/src/test/fuzz/cmpctblock.cpp
+++ b/src/test/fuzz/cmpctblock.cpp
@@ -24,7 +24,6 @@
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
-#include <test/fuzz/util/headerssync.h>
#include <test/fuzz/util/net.h>
#include <test/util/net.h>
#include <test/util/random.h>
@@ -141,7 +140,6 @@ FUZZ_TARGET(cmpctblock, .init = initialize_cmpctblock)
mempool, *setup->m_node.warnings,
PeerManager::Options{
.deterministic_rng = true,
- .headers_sync_params = FUZZ_HEADERS_SYNC_PARAMS,
});
connman.SetMsgProc(peerman.get());
diff --git a/src/test/fuzz/p2p_handshake.cpp b/src/test/fuzz/p2p_handshake.cpp
index 8d1c1b2373..0ab3e0c248 100644
--- a/src/test/fuzz/p2p_handshake.cpp
+++ b/src/test/fuzz/p2p_handshake.cpp
@@ -10,7 +10,6 @@
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
-#include <test/fuzz/util/headerssync.h>
#include <test/fuzz/util/net.h>
#include <test/util/net.h>
#include <test/util/setup_common.h>
@@ -58,7 +57,6 @@ FUZZ_TARGET(p2p_handshake, .init = ::initialize)
PeerManager::Options{
.reconcile_txs = true,
.deterministic_rng = true,
- .headers_sync_params = FUZZ_HEADERS_SYNC_PARAMS,
});
connman.SetMsgProc(node.peerman.get());
connman.SetAddrman(*node.addrman);
diff --git a/src/test/fuzz/process_message.cpp b/src/test/fuzz/process_message.cpp
index e5320155a8..a63f8a0a6a 100644
--- a/src/test/fuzz/process_message.cpp
+++ b/src/test/fuzz/process_message.cpp
@@ -14,7 +14,6 @@
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
-#include <test/fuzz/util/headerssync.h>
#include <test/fuzz/util/net.h>
#include <test/util/net.h>
#include <test/util/random.h>
@@ -91,7 +90,6 @@ FUZZ_TARGET(process_message, .init = initialize_process_message)
PeerManager::Options{
.reconcile_txs = true,
.deterministic_rng = true,
- .headers_sync_params = FUZZ_HEADERS_SYNC_PARAMS,
});
connman.SetMsgProc(node.peerman.get());
diff --git a/src/test/fuzz/process_messages.cpp b/src/test/fuzz/process_messages.cpp
index 4ede3ce674..f4a93df8dc 100644
--- a/src/test/fuzz/process_messages.cpp
+++ b/src/test/fuzz/process_messages.cpp
@@ -14,7 +14,6 @@
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
-#include <test/fuzz/util/headerssync.h>
#include <test/fuzz/util/net.h>
#include <test/util/net.h>
#include <test/util/random.h>
@@ -83,7 +82,6 @@ FUZZ_TARGET(process_messages, .init = initialize_process_messages)
PeerManager::Options{
.reconcile_txs = true,
.deterministic_rng = true,
- .headers_sync_params = FUZZ_HEADERS_SYNC_PARAMS,
});
connman.SetMsgProc(node.peerman.get());
connman.SetAddrman(*node.addrman);
diff --git a/src/test/fuzz/util/headerssync.h b/src/test/fuzz/util/headerssync.h
deleted file mode 100644
index abfea0ab68..0000000000
--- a/src/test/fuzz/util/headerssync.h
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (c) The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#ifndef BITCOIN_TEST_FUZZ_UTIL_HEADERSSYNC_H
-#define BITCOIN_TEST_FUZZ_UTIL_HEADERSSYNC_H
-
-#include <cstddef>
-#include <utility>
-
-/** Fixed headers-sync parameters for fuzz targets that construct a PeerManager per iteration,
- * avoiding both recomputing them every time and any dependence on the (mocked) clock at
- * construction time, as {commitment period, redownload buffer size}. The values are the regtest
- * constants that were committed in chainparams before the parameters became runtime-computed,
- * but any sane values would do. */
-inline constexpr std::pair<size_t, size_t> FUZZ_HEADERS_SYNC_PARAMS{275, 7017};
-
-#endif // BITCOIN_TEST_FUZZ_UTIL_HEADERSSYNC_H
</details>