mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
[net processing] Introduce PeerManager options
This commit is contained in:
parent
d23fda0584
commit
8b87725921
8 changed files with 59 additions and 17 deletions
|
@ -224,6 +224,7 @@ BITCOIN_CORE_H = \
|
||||||
node/miner.h \
|
node/miner.h \
|
||||||
node/mini_miner.h \
|
node/mini_miner.h \
|
||||||
node/minisketchwrapper.h \
|
node/minisketchwrapper.h \
|
||||||
|
node/peerman_args.h \
|
||||||
node/psbt.h \
|
node/psbt.h \
|
||||||
node/transaction.h \
|
node/transaction.h \
|
||||||
node/txreconciliation.h \
|
node/txreconciliation.h \
|
||||||
|
@ -421,6 +422,7 @@ libbitcoin_node_a_SOURCES = \
|
||||||
node/miner.cpp \
|
node/miner.cpp \
|
||||||
node/mini_miner.cpp \
|
node/mini_miner.cpp \
|
||||||
node/minisketchwrapper.cpp \
|
node/minisketchwrapper.cpp \
|
||||||
|
node/peerman_args.cpp \
|
||||||
node/psbt.cpp \
|
node/psbt.cpp \
|
||||||
node/transaction.cpp \
|
node/transaction.cpp \
|
||||||
node/txreconciliation.cpp \
|
node/txreconciliation.cpp \
|
||||||
|
|
12
src/init.cpp
12
src/init.cpp
|
@ -50,6 +50,7 @@
|
||||||
#include <node/mempool_args.h>
|
#include <node/mempool_args.h>
|
||||||
#include <node/mempool_persist_args.h>
|
#include <node/mempool_persist_args.h>
|
||||||
#include <node/miner.h>
|
#include <node/miner.h>
|
||||||
|
#include <node/peerman_args.h>
|
||||||
#include <node/txreconciliation.h>
|
#include <node/txreconciliation.h>
|
||||||
#include <node/validation_cache_args.h>
|
#include <node/validation_cache_args.h>
|
||||||
#include <policy/feerate.h>
|
#include <policy/feerate.h>
|
||||||
|
@ -1539,9 +1540,16 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
|
|
||||||
ChainstateManager& chainman = *Assert(node.chainman);
|
ChainstateManager& chainman = *Assert(node.chainman);
|
||||||
|
|
||||||
|
|
||||||
|
PeerManager::Options peerman_opts{
|
||||||
|
.ignore_incoming_txs = ignores_incoming_txs,
|
||||||
|
};
|
||||||
|
ApplyArgsManOptions(args, peerman_opts);
|
||||||
|
|
||||||
assert(!node.peerman);
|
assert(!node.peerman);
|
||||||
node.peerman = PeerManager::make(*node.connman, *node.addrman, node.banman.get(),
|
node.peerman = PeerManager::make(*node.connman, *node.addrman,
|
||||||
chainman, *node.mempool, ignores_incoming_txs);
|
node.banman.get(), chainman,
|
||||||
|
*node.mempool, peerman_opts);
|
||||||
RegisterValidationInterface(node.peerman.get());
|
RegisterValidationInterface(node.peerman.get());
|
||||||
|
|
||||||
// ********************************************************* Step 8: start indexers
|
// ********************************************************* Step 8: start indexers
|
||||||
|
|
|
@ -487,7 +487,7 @@ class PeerManagerImpl final : public PeerManager
|
||||||
public:
|
public:
|
||||||
PeerManagerImpl(CConnman& connman, AddrMan& addrman,
|
PeerManagerImpl(CConnman& connman, AddrMan& addrman,
|
||||||
BanMan* banman, ChainstateManager& chainman,
|
BanMan* banman, ChainstateManager& chainman,
|
||||||
CTxMemPool& pool, bool ignore_incoming_txs);
|
CTxMemPool& pool, Options opts);
|
||||||
|
|
||||||
/** Overridden from CValidationInterface. */
|
/** Overridden from CValidationInterface. */
|
||||||
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override
|
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override
|
||||||
|
@ -721,6 +721,8 @@ private:
|
||||||
/** Whether this node is running in -blocksonly mode */
|
/** Whether this node is running in -blocksonly mode */
|
||||||
const bool m_ignore_incoming_txs;
|
const bool m_ignore_incoming_txs;
|
||||||
|
|
||||||
|
const Options m_opts;
|
||||||
|
|
||||||
bool RejectIncomingTxs(const CNode& peer) const;
|
bool RejectIncomingTxs(const CNode& peer) const;
|
||||||
|
|
||||||
/** Whether we've completed initial sync yet, for determining when to turn
|
/** 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
|
||||||
|
|
||||||
std::unique_ptr<PeerManager> PeerManager::make(CConnman& connman, AddrMan& addrman,
|
std::unique_ptr<PeerManager> PeerManager::make(CConnman& connman, AddrMan& addrman,
|
||||||
BanMan* banman, ChainstateManager& chainman,
|
BanMan* banman, ChainstateManager& chainman,
|
||||||
CTxMemPool& pool, bool ignore_incoming_txs)
|
CTxMemPool& pool, Options opts)
|
||||||
{
|
{
|
||||||
return std::make_unique<PeerManagerImpl>(connman, addrman, banman, chainman, pool, ignore_incoming_txs);
|
return std::make_unique<PeerManagerImpl>(connman, addrman, banman, chainman, pool, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman,
|
PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman,
|
||||||
BanMan* banman, ChainstateManager& chainman,
|
BanMan* banman, ChainstateManager& chainman,
|
||||||
CTxMemPool& pool, bool ignore_incoming_txs)
|
CTxMemPool& pool, Options opts)
|
||||||
: m_chainparams(chainman.GetParams()),
|
: m_chainparams(chainman.GetParams()),
|
||||||
m_connman(connman),
|
m_connman(connman),
|
||||||
m_addrman(addrman),
|
m_addrman(addrman),
|
||||||
m_banman(banman),
|
m_banman(banman),
|
||||||
m_chainman(chainman),
|
m_chainman(chainman),
|
||||||
m_mempool(pool),
|
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.
|
// While Erlay support is incomplete, it must be enabled explicitly via -txreconciliation.
|
||||||
// This argument can go away after Erlay support is complete.
|
// This argument can go away after Erlay support is complete.
|
||||||
|
|
|
@ -43,9 +43,13 @@ struct CNodeStateStats {
|
||||||
class PeerManager : public CValidationInterface, public NetEventsInterface
|
class PeerManager : public CValidationInterface, public NetEventsInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
struct Options {
|
||||||
|
bool ignore_incoming_txs{DEFAULT_BLOCKSONLY};
|
||||||
|
};
|
||||||
|
|
||||||
static std::unique_ptr<PeerManager> make(CConnman& connman, AddrMan& addrman,
|
static std::unique_ptr<PeerManager> make(CConnman& connman, AddrMan& addrman,
|
||||||
BanMan* banman, ChainstateManager& chainman,
|
BanMan* banman, ChainstateManager& chainman,
|
||||||
CTxMemPool& pool, bool ignore_incoming_txs);
|
CTxMemPool& pool, Options opts);
|
||||||
virtual ~PeerManager() { }
|
virtual ~PeerManager() { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
13
src/node/peerman_args.cpp
Normal file
13
src/node/peerman_args.cpp
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#include <node/peerman_args.h>
|
||||||
|
|
||||||
|
#include <common/args.h>
|
||||||
|
#include <net_processing.h>
|
||||||
|
|
||||||
|
namespace node {
|
||||||
|
|
||||||
|
void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace node
|
||||||
|
|
12
src/node/peerman_args.h
Normal file
12
src/node/peerman_args.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef BITCOIN_NODE_PEERMAN_ARGS_H
|
||||||
|
#define BITCOIN_NODE_PEERMAN_ARGS_H
|
||||||
|
|
||||||
|
#include <net_processing.h>
|
||||||
|
|
||||||
|
class ArgsManager;
|
||||||
|
|
||||||
|
namespace node {
|
||||||
|
void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& options);
|
||||||
|
} // namespace node
|
||||||
|
|
||||||
|
#endif // BITCOIN_NODE_PEERMAN_ARGS_H
|
|
@ -132,8 +132,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
|
||||||
{
|
{
|
||||||
NodeId id{0};
|
NodeId id{0};
|
||||||
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr,
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
||||||
*m_node.chainman, *m_node.mempool, false);
|
|
||||||
|
|
||||||
constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
|
constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
|
||||||
CConnman::Options options;
|
CConnman::Options options;
|
||||||
|
@ -209,8 +208,7 @@ BOOST_AUTO_TEST_CASE(block_relay_only_eviction)
|
||||||
{
|
{
|
||||||
NodeId id{0};
|
NodeId id{0};
|
||||||
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr,
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
||||||
*m_node.chainman, *m_node.mempool, false);
|
|
||||||
|
|
||||||
constexpr int max_outbound_block_relay{MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
|
constexpr int max_outbound_block_relay{MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
|
||||||
constexpr int64_t MINIMUM_CONNECT_TIME{30};
|
constexpr int64_t MINIMUM_CONNECT_TIME{30};
|
||||||
|
@ -273,8 +271,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
|
||||||
|
|
||||||
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||||
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(),
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
|
||||||
*m_node.chainman, *m_node.mempool, false);
|
|
||||||
|
|
||||||
CNetAddr tor_netaddr;
|
CNetAddr tor_netaddr;
|
||||||
BOOST_REQUIRE(
|
BOOST_REQUIRE(
|
||||||
|
@ -376,8 +373,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
|
||||||
|
|
||||||
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||||
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(),
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
|
||||||
*m_node.chainman, *m_node.mempool, false);
|
|
||||||
|
|
||||||
banman->ClearBanned();
|
banman->ClearBanned();
|
||||||
int64_t nStartTime = GetTime();
|
int64_t nStartTime = GetTime();
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <node/kernel_notifications.h>
|
#include <node/kernel_notifications.h>
|
||||||
#include <node/mempool_args.h>
|
#include <node/mempool_args.h>
|
||||||
#include <node/miner.h>
|
#include <node/miner.h>
|
||||||
|
#include <node/peerman_args.h>
|
||||||
#include <node/validation_cache_args.h>
|
#include <node/validation_cache_args.h>
|
||||||
#include <noui.h>
|
#include <noui.h>
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
|
@ -251,9 +252,12 @@ TestingSetup::TestingSetup(
|
||||||
m_node.args->GetIntArg("-checkaddrman", 0));
|
m_node.args->GetIntArg("-checkaddrman", 0));
|
||||||
m_node.banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
m_node.banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||||
m_node.connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman); // Deterministic randomness for tests.
|
m_node.connman = std::make_unique<ConnmanTestMsg>(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.peerman = PeerManager::make(*m_node.connman, *m_node.addrman,
|
||||||
m_node.banman.get(), *m_node.chainman,
|
m_node.banman.get(), *m_node.chainman,
|
||||||
*m_node.mempool, false);
|
*m_node.mempool, peerman_opts);
|
||||||
|
|
||||||
{
|
{
|
||||||
CConnman::Options options;
|
CConnman::Options options;
|
||||||
options.m_msgproc = m_node.peerman.get();
|
options.m_msgproc = m_node.peerman.get();
|
||||||
|
|
Loading…
Add table
Reference in a new issue