From aa89e04e07ca9ff51b1d7d310a11821c6ad963cf Mon Sep 17 00:00:00 2001 From: stickies-v Date: Tue, 25 Jul 2023 14:57:28 +0100 Subject: [PATCH 1/3] doc: document PeerManager::Options members --- src/net_processing.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/net_processing.h b/src/net_processing.h index a0cbe92289..b1e6e4eebb 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -18,7 +18,8 @@ class ChainstateManager; static constexpr bool DEFAULT_TXRECONCILIATION_ENABLE{false}; /** Default for -maxorphantx, maximum number of orphan transactions kept in memory */ static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100; -/** Default number of orphan+recently-replaced txn to keep around for block reconstruction */ +/** Default number of non-mempool transactions to keep around for block reconstruction. Includes + orphan, replaced, and rejected transactions. */ static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100; static const bool DEFAULT_PEERBLOOMFILTERS = false; static const bool DEFAULT_PEERBLOCKFILTERS = false; @@ -46,11 +47,16 @@ class PeerManager : public CValidationInterface, public NetEventsInterface { public: struct Options { - /** Whether this node is running in -blocksonly mode */ + //! Whether this node is running in -blocksonly mode bool ignore_incoming_txs{DEFAULT_BLOCKSONLY}; + //! Whether transaction reconciliation protocol is enabled bool reconcile_txs{DEFAULT_TXRECONCILIATION_ENABLE}; + //! Maximum number of orphan transactions kept in memory uint32_t max_orphan_txs{DEFAULT_MAX_ORPHAN_TRANSACTIONS}; + //! Number of non-mempool transactions to keep around for block reconstruction. Includes + //! orphan, replaced, and rejected transactions. size_t max_extra_txs{DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN}; + //! Whether all P2P messages are captured to disk bool capture_messages{false}; }; From e451d1e3c66350017da195335f428a96fdc7d840 Mon Sep 17 00:00:00 2001 From: stickies-v Date: Tue, 25 Jul 2023 15:41:54 +0100 Subject: [PATCH 2/3] net processing: clamp -maxorphantx to uint32_t bounds --- src/net_processing.h | 2 +- src/node/peerman_args.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/net_processing.h b/src/net_processing.h index b1e6e4eebb..619bf6220d 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -17,7 +17,7 @@ class ChainstateManager; /** Whether transaction reconciliation protocol should be enabled by default. */ static constexpr bool DEFAULT_TXRECONCILIATION_ENABLE{false}; /** Default for -maxorphantx, maximum number of orphan transactions kept in memory */ -static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100; +static const uint32_t DEFAULT_MAX_ORPHAN_TRANSACTIONS{100}; /** Default number of non-mempool transactions to keep around for block reconstruction. Includes orphan, replaced, and rejected transactions. */ static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100; diff --git a/src/node/peerman_args.cpp b/src/node/peerman_args.cpp index e5868ead12..1a70ce96f1 100644 --- a/src/node/peerman_args.cpp +++ b/src/node/peerman_args.cpp @@ -3,6 +3,9 @@ #include #include +#include +#include + namespace node { void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& options) @@ -10,7 +13,7 @@ void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& optio if (auto value{argsman.GetBoolArg("-txreconciliation")}) options.reconcile_txs = *value; if (auto value{argsman.GetIntArg("-maxorphantx")}) { - options.max_orphan_txs = uint32_t(std::max(int64_t{0}, *value)); + options.max_orphan_txs = uint32_t((std::clamp(*value, 0, std::numeric_limits::max()))); } if (auto value{argsman.GetIntArg("-blockreconstructionextratxn")}) { From 547fa52443cbb5e8ccfee993486f5ced8cdbb33b Mon Sep 17 00:00:00 2001 From: stickies-v Date: Tue, 25 Jul 2023 15:49:36 +0100 Subject: [PATCH 3/3] net processing: clamp -blockreconstructionextratxn to uint32_t bounds Also changes max_extra_txs into a uint32_t to avoid platform-specific behaviour --- src/net_processing.h | 4 ++-- src/node/peerman_args.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/net_processing.h b/src/net_processing.h index 619bf6220d..837e308617 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -20,7 +20,7 @@ static constexpr bool DEFAULT_TXRECONCILIATION_ENABLE{false}; static const uint32_t DEFAULT_MAX_ORPHAN_TRANSACTIONS{100}; /** Default number of non-mempool transactions to keep around for block reconstruction. Includes orphan, replaced, and rejected transactions. */ -static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100; +static const uint32_t DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN{100}; static const bool DEFAULT_PEERBLOOMFILTERS = false; static const bool DEFAULT_PEERBLOCKFILTERS = false; /** Threshold for marking a node to be discouraged, e.g. disconnected and added to the discouragement filter. */ @@ -55,7 +55,7 @@ public: uint32_t max_orphan_txs{DEFAULT_MAX_ORPHAN_TRANSACTIONS}; //! Number of non-mempool transactions to keep around for block reconstruction. Includes //! orphan, replaced, and rejected transactions. - size_t max_extra_txs{DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN}; + uint32_t max_extra_txs{DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN}; //! Whether all P2P messages are captured to disk bool capture_messages{false}; }; diff --git a/src/node/peerman_args.cpp b/src/node/peerman_args.cpp index 1a70ce96f1..efe4514271 100644 --- a/src/node/peerman_args.cpp +++ b/src/node/peerman_args.cpp @@ -17,7 +17,7 @@ void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& optio } if (auto value{argsman.GetIntArg("-blockreconstructionextratxn")}) { - options.max_extra_txs = size_t(std::max(int64_t{0}, *value)); + options.max_extra_txs = uint32_t((std::clamp(*value, 0, std::numeric_limits::max()))); } if (auto value{argsman.GetBoolArg("-capturemessages")}) options.capture_messages = *value;