Skip to content

Commit 8b87725

Browse files
committed
[net processing] Introduce PeerManager options
1 parent d23fda0 commit 8b87725

File tree

8 files changed

+59
-17
lines changed

8 files changed

+59
-17
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ BITCOIN_CORE_H = \
224224
node/miner.h \
225225
node/mini_miner.h \
226226
node/minisketchwrapper.h \
227+
node/peerman_args.h \
227228
node/psbt.h \
228229
node/transaction.h \
229230
node/txreconciliation.h \
@@ -421,6 +422,7 @@ libbitcoin_node_a_SOURCES = \
421422
node/miner.cpp \
422423
node/mini_miner.cpp \
423424
node/minisketchwrapper.cpp \
425+
node/peerman_args.cpp \
424426
node/psbt.cpp \
425427
node/transaction.cpp \
426428
node/txreconciliation.cpp \

src/init.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <node/mempool_args.h>
5151
#include <node/mempool_persist_args.h>
5252
#include <node/miner.h>
53+
#include <node/peerman_args.h>
5354
#include <node/txreconciliation.h>
5455
#include <node/validation_cache_args.h>
5556
#include <policy/feerate.h>
@@ -1539,9 +1540,16 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15391540

15401541
ChainstateManager& chainman = *Assert(node.chainman);
15411542

1543+
1544+
PeerManager::Options peerman_opts{
1545+
.ignore_incoming_txs = ignores_incoming_txs,
1546+
};
1547+
ApplyArgsManOptions(args, peerman_opts);
1548+
15421549
assert(!node.peerman);
1543-
node.peerman = PeerManager::make(*node.connman, *node.addrman, node.banman.get(),
1544-
chainman, *node.mempool, ignores_incoming_txs);
1550+
node.peerman = PeerManager::make(*node.connman, *node.addrman,
1551+
node.banman.get(), chainman,
1552+
*node.mempool, peerman_opts);
15451553
RegisterValidationInterface(node.peerman.get());
15461554

15471555
// ********************************************************* Step 8: start indexers

src/net_processing.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ class PeerManagerImpl final : public PeerManager
487487
public:
488488
PeerManagerImpl(CConnman& connman, AddrMan& addrman,
489489
BanMan* banman, ChainstateManager& chainman,
490-
CTxMemPool& pool, bool ignore_incoming_txs);
490+
CTxMemPool& pool, Options opts);
491491

492492
/** Overridden from CValidationInterface. */
493493
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override
@@ -721,6 +721,8 @@ class PeerManagerImpl final : public PeerManager
721721
/** Whether this node is running in -blocksonly mode */
722722
const bool m_ignore_incoming_txs;
723723

724+
const Options m_opts;
725+
724726
bool RejectIncomingTxs(const CNode& peer) const;
725727

726728
/** Whether we've completed initial sync yet, for determining when to turn
@@ -1809,21 +1811,22 @@ std::optional<std::string> PeerManagerImpl::FetchBlock(NodeId peer_id, const CBl
18091811

18101812
std::unique_ptr<PeerManager> PeerManager::make(CConnman& connman, AddrMan& addrman,
18111813
BanMan* banman, ChainstateManager& chainman,
1812-
CTxMemPool& pool, bool ignore_incoming_txs)
1814+
CTxMemPool& pool, Options opts)
18131815
{
1814-
return std::make_unique<PeerManagerImpl>(connman, addrman, banman, chainman, pool, ignore_incoming_txs);
1816+
return std::make_unique<PeerManagerImpl>(connman, addrman, banman, chainman, pool, opts);
18151817
}
18161818

18171819
PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman,
18181820
BanMan* banman, ChainstateManager& chainman,
1819-
CTxMemPool& pool, bool ignore_incoming_txs)
1821+
CTxMemPool& pool, Options opts)
18201822
: m_chainparams(chainman.GetParams()),
18211823
m_connman(connman),
18221824
m_addrman(addrman),
18231825
m_banman(banman),
18241826
m_chainman(chainman),
18251827
m_mempool(pool),
1826-
m_ignore_incoming_txs(ignore_incoming_txs)
1828+
m_ignore_incoming_txs(opts.ignore_incoming_txs),
1829+
m_opts{opts}
18271830
{
18281831
// While Erlay support is incomplete, it must be enabled explicitly via -txreconciliation.
18291832
// This argument can go away after Erlay support is complete.

src/net_processing.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ struct CNodeStateStats {
4343
class PeerManager : public CValidationInterface, public NetEventsInterface
4444
{
4545
public:
46+
struct Options {
47+
bool ignore_incoming_txs{DEFAULT_BLOCKSONLY};
48+
};
49+
4650
static std::unique_ptr<PeerManager> make(CConnman& connman, AddrMan& addrman,
4751
BanMan* banman, ChainstateManager& chainman,
48-
CTxMemPool& pool, bool ignore_incoming_txs);
52+
CTxMemPool& pool, Options opts);
4953
virtual ~PeerManager() { }
5054

5155
/**

src/node/peerman_args.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <node/peerman_args.h>
2+
3+
#include <common/args.h>
4+
#include <net_processing.h>
5+
6+
namespace node {
7+
8+
void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& options)
9+
{
10+
}
11+
12+
} // namespace node
13+

src/node/peerman_args.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef BITCOIN_NODE_PEERMAN_ARGS_H
2+
#define BITCOIN_NODE_PEERMAN_ARGS_H
3+
4+
#include <net_processing.h>
5+
6+
class ArgsManager;
7+
8+
namespace node {
9+
void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& options);
10+
} // namespace node
11+
12+
#endif // BITCOIN_NODE_PEERMAN_ARGS_H

src/test/denialofservice_tests.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
132132
{
133133
NodeId id{0};
134134
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
135-
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr,
136-
*m_node.chainman, *m_node.mempool, false);
135+
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
137136

138137
constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
139138
CConnman::Options options;
@@ -209,8 +208,7 @@ BOOST_AUTO_TEST_CASE(block_relay_only_eviction)
209208
{
210209
NodeId id{0};
211210
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
212-
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr,
213-
*m_node.chainman, *m_node.mempool, false);
211+
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
214212

215213
constexpr int max_outbound_block_relay{MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
216214
constexpr int64_t MINIMUM_CONNECT_TIME{30};
@@ -273,8 +271,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
273271

274272
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
275273
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
276-
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(),
277-
*m_node.chainman, *m_node.mempool, false);
274+
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
278275

279276
CNetAddr tor_netaddr;
280277
BOOST_REQUIRE(
@@ -376,8 +373,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
376373

377374
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
378375
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
379-
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(),
380-
*m_node.chainman, *m_node.mempool, false);
376+
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
381377

382378
banman->ClearBanned();
383379
int64_t nStartTime = GetTime();

src/test/util/setup_common.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <node/kernel_notifications.h>
2828
#include <node/mempool_args.h>
2929
#include <node/miner.h>
30+
#include <node/peerman_args.h>
3031
#include <node/validation_cache_args.h>
3132
#include <noui.h>
3233
#include <policy/fees.h>
@@ -251,9 +252,12 @@ TestingSetup::TestingSetup(
251252
m_node.args->GetIntArg("-checkaddrman", 0));
252253
m_node.banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
253254
m_node.connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman); // Deterministic randomness for tests.
255+
PeerManager::Options peerman_opts;
256+
ApplyArgsManOptions(*m_node.args, peerman_opts);
254257
m_node.peerman = PeerManager::make(*m_node.connman, *m_node.addrman,
255258
m_node.banman.get(), *m_node.chainman,
256-
*m_node.mempool, false);
259+
*m_node.mempool, peerman_opts);
260+
257261
{
258262
CConnman::Options options;
259263
options.m_msgproc = m_node.peerman.get();

0 commit comments

Comments
 (0)