diff --git a/src/avalanche/test/processor_tests.cpp b/src/avalanche/test/processor_tests.cpp --- a/src/avalanche/test/processor_tests.cpp +++ b/src/avalanche/test/processor_tests.cpp @@ -75,7 +75,7 @@ m_connman = connman.get(); m_node.connman = std::move(connman); m_node.peer_logic = std::make_unique( - m_connman, m_node.banman.get(), *m_node.scheduler); + m_connman, m_node.banman.get()); } ~AvalancheTestingSetup() { m_connman->ClearNodes(); } diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -2207,8 +2207,8 @@ config, GetRand(std::numeric_limits::max()), GetRand(std::numeric_limits::max())); - node.peer_logic.reset(new PeerLogicValidation( - node.connman.get(), node.banman.get(), *node.scheduler)); + node.peer_logic.reset( + new PeerLogicValidation(node.connman.get(), node.banman.get())); RegisterValidationInterface(node.peer_logic.get()); // sanitize comments per BIP-0014, format user agent and check total size @@ -2822,6 +2822,8 @@ return false; } + node.peer_logic->Start(*node.scheduler); + // Step 13: finished SetRPCWarmupFinished(); diff --git a/src/net_processing.h b/src/net_processing.h --- a/src/net_processing.h +++ b/src/net_processing.h @@ -37,8 +37,7 @@ bool CheckIfBanned(CNode &pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main); public: - PeerLogicValidation(CConnman *connman, BanMan *banman, - CScheduler &scheduler); + PeerLogicValidation(CConnman *connman, BanMan *banman); /** * Overridden from CValidationInterface. @@ -64,6 +63,12 @@ void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr &pblock) override; + /** + * Start the peer logic validation thread. + * Should be called after CConman initialization has completed. + */ + void Start(CScheduler &scheduler); + /** * Initialize a peer by adding it to mapNodeState and pushing a message * requesting its version. diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1345,12 +1345,13 @@ STALE_RELAY_AGE_LIMIT); } -PeerLogicValidation::PeerLogicValidation(CConnman *connmanIn, BanMan *banman, - CScheduler &scheduler) +PeerLogicValidation::PeerLogicValidation(CConnman *connmanIn, BanMan *banman) : connman(connmanIn), m_banman(banman), m_stale_tip_check_time(0) { // Initialize global variables that cannot be constructed at startup. recentRejects.reset(new CRollingBloomFilter(120000, 0.000001)); +} +void PeerLogicValidation::Start(CScheduler &scheduler) { const Consensus::Params &consensusParams = Params().GetConsensus(); // Stale tip checking and peer eviction are on two different timers, but we // don't want them to get out of sync due to drift in the scheduler, so we diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -78,8 +78,8 @@ std::atomic interruptDummy(false); auto connman = std::make_unique(config, 0x1337, 0x1337); - auto peerLogic = std::make_unique( - connman.get(), nullptr, *m_node.scheduler); + auto peerLogic = + std::make_unique(connman.get(), nullptr); // Mock an outbound peer CAddress addr1(ip(0xa0b0c001), NODE_NONE); @@ -162,8 +162,8 @@ const Config &config = GetConfig(); auto connman = std::make_unique(config, 0x1337, 0x1337); - auto peerLogic = std::make_unique( - connman.get(), nullptr, *m_node.scheduler); + auto peerLogic = + std::make_unique(connman.get(), nullptr); const Consensus::Params &consensusParams = config.GetChainParams().GetConsensus(); @@ -241,8 +241,8 @@ config.GetChainParams(), nullptr, DEFAULT_MISBEHAVING_BANTIME); auto connman = std::make_unique(config, 0x1337, 0x1337); - auto peerLogic = std::make_unique( - connman.get(), banman.get(), *m_node.scheduler); + auto peerLogic = + std::make_unique(connman.get(), banman.get()); banman->ClearBanned(); CAddress addr1(ip(0xa0b0c001), NODE_NONE); @@ -310,8 +310,8 @@ config.GetChainParams(), nullptr, DEFAULT_MISBEHAVING_BANTIME); auto connman = std::make_unique(config, 0x1337, 0x1337); - auto peerLogic = std::make_unique( - connman.get(), banman.get(), *m_node.scheduler); + auto peerLogic = + std::make_unique(connman.get(), banman.get()); banman->ClearBanned(); // because 11 is my favorite number. @@ -367,8 +367,8 @@ config.GetChainParams(), nullptr, DEFAULT_MISBEHAVING_BANTIME); auto connman = std::make_unique(config, 0x1337, 0x1337); - auto peerLogic = std::make_unique( - connman.get(), banman.get(), *m_node.scheduler); + auto peerLogic = + std::make_unique(connman.get(), banman.get()); banman->ClearBanned(); int64_t nStartTime = GetTime(); diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -177,12 +177,13 @@ // Deterministic randomness for tests. m_node.connman = std::make_unique(config, 0x1337, 0x1337); m_node.peer_logic = std::make_unique( - m_node.connman.get(), m_node.banman.get(), *m_node.scheduler); + m_node.connman.get(), m_node.banman.get()); { CConnman::Options options; options.m_msgproc = m_node.peer_logic.get(); m_node.connman->Init(options); } + m_node.peer_logic->Start(*m_node.scheduler); } TestingSetup::~TestingSetup() {