From 8b877259217c6da316153afb136a55c2dbd401c2 Mon Sep 17 00:00:00 2001 From: dergoegge Date: Thu, 20 Apr 2023 13:05:23 +0200 Subject: [PATCH 1/6] [net processing] Introduce PeerManager options --- src/Makefile.am | 2 ++ src/init.cpp | 12 ++++++++++-- src/net_processing.cpp | 13 ++++++++----- src/net_processing.h | 6 +++++- src/node/peerman_args.cpp | 13 +++++++++++++ src/node/peerman_args.h | 12 ++++++++++++ src/test/denialofservice_tests.cpp | 12 ++++-------- src/test/util/setup_common.cpp | 6 +++++- 8 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 src/node/peerman_args.cpp create mode 100644 src/node/peerman_args.h diff --git a/src/Makefile.am b/src/Makefile.am index e1ae049b15a..aba6f00756a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -224,6 +224,7 @@ BITCOIN_CORE_H = \ node/miner.h \ node/mini_miner.h \ node/minisketchwrapper.h \ + node/peerman_args.h \ node/psbt.h \ node/transaction.h \ node/txreconciliation.h \ @@ -421,6 +422,7 @@ libbitcoin_node_a_SOURCES = \ node/miner.cpp \ node/mini_miner.cpp \ node/minisketchwrapper.cpp \ + node/peerman_args.cpp \ node/psbt.cpp \ node/transaction.cpp \ node/txreconciliation.cpp \ diff --git a/src/init.cpp b/src/init.cpp index f726fe54cae..5f47b1c0f6f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -1539,9 +1540,16 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) ChainstateManager& chainman = *Assert(node.chainman); + + PeerManager::Options peerman_opts{ + .ignore_incoming_txs = ignores_incoming_txs, + }; + ApplyArgsManOptions(args, peerman_opts); + assert(!node.peerman); - node.peerman = PeerManager::make(*node.connman, *node.addrman, node.banman.get(), - chainman, *node.mempool, ignores_incoming_txs); + node.peerman = PeerManager::make(*node.connman, *node.addrman, + node.banman.get(), chainman, + *node.mempool, peerman_opts); RegisterValidationInterface(node.peerman.get()); // ********************************************************* Step 8: start indexers diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 8da2c701d3b..e438c881e61 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -487,7 +487,7 @@ class PeerManagerImpl final : public PeerManager public: PeerManagerImpl(CConnman& connman, AddrMan& addrman, BanMan* banman, ChainstateManager& chainman, - CTxMemPool& pool, bool ignore_incoming_txs); + CTxMemPool& pool, Options opts); /** Overridden from CValidationInterface. */ void BlockConnected(const std::shared_ptr& pblock, const CBlockIndex* pindexConnected) override @@ -721,6 +721,8 @@ private: /** Whether this node is running in -blocksonly mode */ const bool m_ignore_incoming_txs; + const Options m_opts; + bool RejectIncomingTxs(const CNode& peer) const; /** Whether we've completed initial sync yet, for determining when to turn @@ -1809,21 +1811,22 @@ std::optional PeerManagerImpl::FetchBlock(NodeId peer_id, const CBl std::unique_ptr PeerManager::make(CConnman& connman, AddrMan& addrman, BanMan* banman, ChainstateManager& chainman, - CTxMemPool& pool, bool ignore_incoming_txs) + CTxMemPool& pool, Options opts) { - return std::make_unique(connman, addrman, banman, chainman, pool, ignore_incoming_txs); + return std::make_unique(connman, addrman, banman, chainman, pool, opts); } PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman, BanMan* banman, ChainstateManager& chainman, - CTxMemPool& pool, bool ignore_incoming_txs) + CTxMemPool& pool, Options opts) : m_chainparams(chainman.GetParams()), m_connman(connman), m_addrman(addrman), m_banman(banman), m_chainman(chainman), m_mempool(pool), - m_ignore_incoming_txs(ignore_incoming_txs) + m_ignore_incoming_txs(opts.ignore_incoming_txs), + m_opts{opts} { // While Erlay support is incomplete, it must be enabled explicitly via -txreconciliation. // This argument can go away after Erlay support is complete. diff --git a/src/net_processing.h b/src/net_processing.h index deebb24c94e..c79987515db 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -43,9 +43,13 @@ struct CNodeStateStats { class PeerManager : public CValidationInterface, public NetEventsInterface { public: + struct Options { + bool ignore_incoming_txs{DEFAULT_BLOCKSONLY}; + }; + static std::unique_ptr make(CConnman& connman, AddrMan& addrman, BanMan* banman, ChainstateManager& chainman, - CTxMemPool& pool, bool ignore_incoming_txs); + CTxMemPool& pool, Options opts); virtual ~PeerManager() { } /** diff --git a/src/node/peerman_args.cpp b/src/node/peerman_args.cpp new file mode 100644 index 00000000000..b490d1d0796 --- /dev/null +++ b/src/node/peerman_args.cpp @@ -0,0 +1,13 @@ +#include + +#include +#include + +namespace node { + +void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& options) +{ +} + +} // namespace node + diff --git a/src/node/peerman_args.h b/src/node/peerman_args.h new file mode 100644 index 00000000000..73dbdb446c2 --- /dev/null +++ b/src/node/peerman_args.h @@ -0,0 +1,12 @@ +#ifndef BITCOIN_NODE_PEERMAN_ARGS_H +#define BITCOIN_NODE_PEERMAN_ARGS_H + +#include + +class ArgsManager; + +namespace node { +void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& options); +} // namespace node + +#endif // BITCOIN_NODE_PEERMAN_ARGS_H diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp index 13349329ff1..9193d9a8b3c 100644 --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -132,8 +132,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management) { NodeId id{0}; auto connman = std::make_unique(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman); - auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, - *m_node.chainman, *m_node.mempool, false); + auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {}); constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS; CConnman::Options options; @@ -209,8 +208,7 @@ BOOST_AUTO_TEST_CASE(block_relay_only_eviction) { NodeId id{0}; auto connman = std::make_unique(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman); - auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, - *m_node.chainman, *m_node.mempool, false); + auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {}); constexpr int max_outbound_block_relay{MAX_BLOCK_RELAY_ONLY_CONNECTIONS}; constexpr int64_t MINIMUM_CONNECT_TIME{30}; @@ -273,8 +271,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement) auto banman = std::make_unique(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME); auto connman = std::make_unique(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman); - auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), - *m_node.chainman, *m_node.mempool, false); + auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {}); CNetAddr tor_netaddr; BOOST_REQUIRE( @@ -376,8 +373,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime) auto banman = std::make_unique(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME); auto connman = std::make_unique(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman); - auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), - *m_node.chainman, *m_node.mempool, false); + auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {}); banman->ClearBanned(); int64_t nStartTime = GetTime(); diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 6ae2187974a..65c657da96b 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -251,9 +252,12 @@ TestingSetup::TestingSetup( m_node.args->GetIntArg("-checkaddrman", 0)); m_node.banman = std::make_unique(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME); m_node.connman = std::make_unique(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman); // Deterministic randomness for tests. + PeerManager::Options peerman_opts; + ApplyArgsManOptions(*m_node.args, peerman_opts); m_node.peerman = PeerManager::make(*m_node.connman, *m_node.addrman, m_node.banman.get(), *m_node.chainman, - *m_node.mempool, false); + *m_node.mempool, peerman_opts); + { CConnman::Options options; options.m_msgproc = m_node.peerman.get(); From 4cfb7b925f8fea818f03433882138a7d3d7e179a Mon Sep 17 00:00:00 2001 From: dergoegge Date: Thu, 20 Apr 2023 13:36:36 +0200 Subject: [PATCH 2/6] [net processing] Use ignore_incoming_txs from m_opts --- src/net_processing.cpp | 16 ++++++---------- src/net_processing.h | 1 + 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index e438c881e61..4b7b114fa46 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -515,7 +515,7 @@ public: std::optional FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); - bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; } + bool IgnoresIncomingTxs() override { return m_opts.ignore_incoming_txs; } void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void RelayTransaction(const uint256& txid, const uint256& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void SetBestHeight(int height) override { m_best_height = height; }; @@ -718,9 +718,6 @@ private: /** Next time to check for stale tip */ std::chrono::seconds m_stale_tip_check_time GUARDED_BY(cs_main){0s}; - /** Whether this node is running in -blocksonly mode */ - const bool m_ignore_incoming_txs; - const Options m_opts; bool RejectIncomingTxs(const CNode& peer) const; @@ -1214,7 +1211,7 @@ void PeerManagerImpl::MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid) // When in -blocksonly mode, never request high-bandwidth mode from peers. Our // mempool will not contain the transactions necessary to reconstruct the // compact block. - if (m_ignore_incoming_txs) return; + if (m_opts.ignore_incoming_txs) return; CNodeState* nodestate = State(nodeid); if (!nodestate || !nodestate->m_provides_cmpctblocks) { @@ -1825,7 +1822,6 @@ PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman, m_banman(banman), m_chainman(chainman), m_mempool(pool), - m_ignore_incoming_txs(opts.ignore_incoming_txs), m_opts{opts} { // While Erlay support is incomplete, it must be enabled explicitly via -txreconciliation. @@ -2732,7 +2728,7 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c last_header.nHeight); } if (vGetData.size() > 0) { - if (!m_ignore_incoming_txs && + if (!m_opts.ignore_incoming_txs && nodestate->m_provides_cmpctblocks && vGetData.size() == 1 && mapBlocksInFlight.size() == 1 && @@ -3437,7 +3433,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, // - we are not in -blocksonly mode. const auto* tx_relay = peer->GetTxRelay(); if (tx_relay && WITH_LOCK(tx_relay->m_bloom_filter_mutex, return tx_relay->m_relay_txs) && - !pfrom.IsAddrFetchConn() && !m_ignore_incoming_txs) { + !pfrom.IsAddrFetchConn() && !m_opts.ignore_incoming_txs) { const uint64_t recon_salt = m_txreconciliation->PreRegisterPeer(pfrom.GetId()); m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::SENDTXRCNCL, TXRECONCILIATION_VERSION, recon_salt)); @@ -5361,7 +5357,7 @@ void PeerManagerImpl::MaybeSendSendHeaders(CNode& node, Peer& peer) void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::microseconds current_time) { - if (m_ignore_incoming_txs) return; + if (m_opts.ignore_incoming_txs) return; if (pto.GetCommonVersion() < FEEFILTER_VERSION) return; // peers with the forcerelay permission should not filter txs to us if (pto.HasPermission(NetPermissionFlags::ForceRelay)) return; @@ -5429,7 +5425,7 @@ bool PeerManagerImpl::RejectIncomingTxs(const CNode& peer) const if (peer.IsBlockOnlyConn()) return true; if (peer.IsFeelerConn()) return true; // In -blocksonly mode, peers need the 'relay' permission to send txs to us - if (m_ignore_incoming_txs && !peer.HasPermission(NetPermissionFlags::Relay)) return true; + if (m_opts.ignore_incoming_txs && !peer.HasPermission(NetPermissionFlags::Relay)) return true; return false; } diff --git a/src/net_processing.h b/src/net_processing.h index c79987515db..b88ed0c5554 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -44,6 +44,7 @@ class PeerManager : public CValidationInterface, public NetEventsInterface { public: struct Options { + /** Whether this node is running in -blocksonly mode */ bool ignore_incoming_txs{DEFAULT_BLOCKSONLY}; }; From fa9e6d80d1c55f8b1bb2691bfd67e8c2b7189b38 Mon Sep 17 00:00:00 2001 From: dergoegge Date: Thu, 20 Apr 2023 13:13:11 +0200 Subject: [PATCH 3/6] [net processing] Move -txreconciliation to PeerManager::Options --- src/init.cpp | 1 - src/net_processing.cpp | 2 +- src/net_processing.h | 3 +++ src/node/peerman_args.cpp | 1 + src/node/txreconciliation.h | 2 -- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 5f47b1c0f6f..997996ef12a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -51,7 +51,6 @@ #include #include #include -#include #include #include #include diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 4b7b114fa46..a1889ae2b5c 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1826,7 +1826,7 @@ PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman, { // While Erlay support is incomplete, it must be enabled explicitly via -txreconciliation. // This argument can go away after Erlay support is complete. - if (gArgs.GetBoolArg("-txreconciliation", DEFAULT_TXRECONCILIATION_ENABLE)) { + if (opts.reconcile_txs) { m_txreconciliation = std::make_unique(TXRECONCILIATION_VERSION); } } diff --git a/src/net_processing.h b/src/net_processing.h index b88ed0c5554..87c65baf017 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -14,6 +14,8 @@ class CChainParams; class CTxMemPool; 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; /** Default number of orphan+recently-replaced txn to keep around for block reconstruction */ @@ -46,6 +48,7 @@ public: struct Options { /** Whether this node is running in -blocksonly mode */ bool ignore_incoming_txs{DEFAULT_BLOCKSONLY}; + bool reconcile_txs{DEFAULT_TXRECONCILIATION_ENABLE}; }; static std::unique_ptr make(CConnman& connman, AddrMan& addrman, diff --git a/src/node/peerman_args.cpp b/src/node/peerman_args.cpp index b490d1d0796..b1242d0fdfe 100644 --- a/src/node/peerman_args.cpp +++ b/src/node/peerman_args.cpp @@ -7,6 +7,7 @@ namespace node { void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& options) { + if(auto value{argsman.GetBoolArg("-txreconciliation")}) options.reconcile_txs = *value; } } // namespace node diff --git a/src/node/txreconciliation.h b/src/node/txreconciliation.h index 4591dd5df7c..3bbb0773664 100644 --- a/src/node/txreconciliation.h +++ b/src/node/txreconciliation.h @@ -11,8 +11,6 @@ #include #include -/** Whether transaction reconciliation protocol should be enabled by default. */ -static constexpr bool DEFAULT_TXRECONCILIATION_ENABLE{false}; /** Supported transaction reconciliation protocol version */ static constexpr uint32_t TXRECONCILIATION_VERSION{1}; From 567c4e0b6a3fadd2fd1be732076026bf491519b2 Mon Sep 17 00:00:00 2001 From: dergoegge Date: Thu, 20 Apr 2023 13:33:11 +0200 Subject: [PATCH 4/6] [net processing] Move -maxorphantx to PeerManager::Options --- src/net_processing.cpp | 3 +-- src/net_processing.h | 1 + src/node/peerman_args.cpp | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index a1889ae2b5c..f061f981f24 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -4238,8 +4238,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, m_txrequest.ForgetTxHash(tx.GetWitnessHash()); // DoS prevention: do not allow m_orphanage to grow unbounded (see CVE-2012-3789) - unsigned int nMaxOrphanTx = (unsigned int)std::max((int64_t)0, gArgs.GetIntArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS)); - m_orphanage.LimitOrphans(nMaxOrphanTx); + m_orphanage.LimitOrphans(m_opts.max_orphan_txs); } else { LogPrint(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s\n",tx.GetHash().ToString()); // We will continue to reject this tx since it has rejected diff --git a/src/net_processing.h b/src/net_processing.h index 87c65baf017..422bf6879b3 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -49,6 +49,7 @@ public: /** Whether this node is running in -blocksonly mode */ bool ignore_incoming_txs{DEFAULT_BLOCKSONLY}; bool reconcile_txs{DEFAULT_TXRECONCILIATION_ENABLE}; + uint32_t max_orphan_txs{DEFAULT_MAX_ORPHAN_TRANSACTIONS}; }; static std::unique_ptr make(CConnman& connman, AddrMan& addrman, diff --git a/src/node/peerman_args.cpp b/src/node/peerman_args.cpp index b1242d0fdfe..8a1da693f4e 100644 --- a/src/node/peerman_args.cpp +++ b/src/node/peerman_args.cpp @@ -7,7 +7,11 @@ namespace node { void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& options) { - if(auto value{argsman.GetBoolArg("-txreconciliation")}) options.reconcile_txs = *value; + 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)); + } } } // namespace node From bd59bda26b67b53293a5cef7433e992203da325a Mon Sep 17 00:00:00 2001 From: dergoegge Date: Thu, 20 Apr 2023 13:49:00 +0200 Subject: [PATCH 5/6] [net processing] Move -blockreconstructionextratxn to PeerManager::Options --- src/net_processing.cpp | 7 +++---- src/net_processing.h | 1 + src/node/peerman_args.cpp | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index f061f981f24..399c751bd97 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1649,13 +1649,12 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx) { - size_t max_extra_txn = gArgs.GetIntArg("-blockreconstructionextratxn", DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN); - if (max_extra_txn <= 0) + if (m_opts.max_extra_txs <= 0) return; if (!vExtraTxnForCompact.size()) - vExtraTxnForCompact.resize(max_extra_txn); + vExtraTxnForCompact.resize(m_opts.max_extra_txs); vExtraTxnForCompact[vExtraTxnForCompactIt] = std::make_pair(tx->GetWitnessHash(), tx); - vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1) % max_extra_txn; + vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1) % m_opts.max_extra_txs; } void PeerManagerImpl::Misbehaving(Peer& peer, int howmuch, const std::string& message) diff --git a/src/net_processing.h b/src/net_processing.h index 422bf6879b3..6ee4f229607 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -50,6 +50,7 @@ public: bool ignore_incoming_txs{DEFAULT_BLOCKSONLY}; bool reconcile_txs{DEFAULT_TXRECONCILIATION_ENABLE}; uint32_t max_orphan_txs{DEFAULT_MAX_ORPHAN_TRANSACTIONS}; + size_t max_extra_txs{DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN}; }; static std::unique_ptr make(CConnman& connman, AddrMan& addrman, diff --git a/src/node/peerman_args.cpp b/src/node/peerman_args.cpp index 8a1da693f4e..4a000de83ff 100644 --- a/src/node/peerman_args.cpp +++ b/src/node/peerman_args.cpp @@ -12,6 +12,10 @@ void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& optio if (auto value{argsman.GetIntArg("-maxorphantx")}) { options.max_orphan_txs = uint32_t(std::max(int64_t{0}, *value)); } + + if (auto value{argsman.GetIntArg("-blockreconstructionextratxn")}) { + options.max_extra_txs = size_t(std::max(int64_t{0}, *value)); + } } } // namespace node From 23c7b51ddd2888cf7fb260c439f004bd28768473 Mon Sep 17 00:00:00 2001 From: dergoegge Date: Thu, 20 Apr 2023 13:50:47 +0200 Subject: [PATCH 6/6] [net processing] Move -capturemessages to PeerManager::Options --- src/net_processing.cpp | 3 +-- src/net_processing.h | 1 + src/node/peerman_args.cpp | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 399c751bd97..be6777d14bc 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -5005,7 +5004,7 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic& interrupt msg.m_recv.data() ); - if (gArgs.GetBoolArg("-capturemessages", false)) { + if (m_opts.capture_messages) { CaptureMessage(pfrom->addr, msg.m_type, MakeUCharSpan(msg.m_recv), /*is_incoming=*/true); } diff --git a/src/net_processing.h b/src/net_processing.h index 6ee4f229607..a0cbe92289d 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -51,6 +51,7 @@ public: bool reconcile_txs{DEFAULT_TXRECONCILIATION_ENABLE}; uint32_t max_orphan_txs{DEFAULT_MAX_ORPHAN_TRANSACTIONS}; size_t max_extra_txs{DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN}; + bool capture_messages{false}; }; static std::unique_ptr make(CConnman& connman, AddrMan& addrman, diff --git a/src/node/peerman_args.cpp b/src/node/peerman_args.cpp index 4a000de83ff..e5868ead125 100644 --- a/src/node/peerman_args.cpp +++ b/src/node/peerman_args.cpp @@ -16,6 +16,8 @@ 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)); } + + if (auto value{argsman.GetBoolArg("-capturemessages")}) options.capture_messages = *value; } } // namespace node