Skip to content

Commit f45e47d

Browse files
Merge #6959: refactor: separate network and consensus logic 1/N [instantsend]
d4d64f6 fix: don't remove handlers too early (Konstantin Akimov) a26a974 perf: std::move a shared_ptr with islock in ProcessMessage (Konstantin Akimov) 3c26523 fix: update log records from CInstantSendManager for NetInstantSend instead and tidy up them a bit (Konstantin Akimov) 90d7879 refactor: use NetHandler class to separate instantsend logic and network logic (Konstantin Akimov) 466e2a2 feat: introduce new bridge interface NetHandler to separate network logic and consensus (Konstantin Akimov) Pull request description: ## Issue being fixed or feature implemented Separation of consensus & chain code and network & node in Dash Core is blocked by tight connection of network and consensus code; in components such as `llmq::CSigningManager`, `llmq::CSigSharesManager`, `coinjoin::client`, `coinjoin::server`, `governance/`, `llmq::CInstantSendManager`, etc. It blocks backport's of bitcoin related to 'kernel' project. This PR addresses 1st dependency of `llmq::CInstantSendManager` on `PeerManager`. It is a split from proof-of-concept PR #6934 ## What was done? This PR introduces `NetHandler` which is a bridge interface between node/network related code and between consensus/chain code. In case if there is no need any network, objects that inherited by `NetHandler` are not created. ``` class NetHandler { public: NetHandler(PeerManagerInternal* peer_manager) : m_peer_manager{Assert(peer_manager)} {} virtual ~NetHandler() { Interrupt(); Stop(); } virtual void Start() {} virtual void Stop() {} virtual void Interrupt() {} virtual void Schedule(CScheduler& scheduler, CConnman& connman) {} virtual void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv) {} protected: PeerManagerInternal* m_peer_manager; }; ``` ## How Has This Been Tested? Run unit & functional tests. Run a linter `test/lint/lint-circular-dependencies.py` Overall conception is tested in #6934 as potentially successful to finish separation of network & consensus code. ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone Top commit has no ACKs. Tree-SHA512: 5bf0a00f3b10b84019be5b70aa3e4baddd2c7735d4f177a6391ef362d34e62996438ae1ccbc106ea9966b539206b1694e9542a33cf9aca96f681f829f707b2cc
2 parents 002f1b2 + d4d64f6 commit f45e47d

File tree

11 files changed

+545
-379
lines changed

11 files changed

+545
-379
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ BITCOIN_CORE_H = \
252252
instantsend/db.h \
253253
instantsend/instantsend.h \
254254
instantsend/lock.h \
255+
instantsend/net_instantsend.h \
255256
instantsend/signing.h \
256257
kernel/coinstats.h \
257258
key.h \
@@ -523,6 +524,7 @@ libbitcoin_node_a_SOURCES = \
523524
instantsend/db.cpp \
524525
instantsend/instantsend.cpp \
525526
instantsend/lock.cpp \
527+
instantsend/net_instantsend.cpp \
526528
instantsend/signing.cpp \
527529
kernel/coinstats.cpp \
528530
llmq/blockprocessor.cpp \

src/init.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
#include <flat-database.h>
8888
#include <governance/governance.h>
8989
#include <instantsend/instantsend.h>
90+
#include <instantsend/net_instantsend.h>
9091
#include <llmq/context.h>
9192
#include <llmq/dkgsessionmgr.h>
9293
#include <llmq/options.h>
@@ -250,6 +251,9 @@ void Interrupt(NodeContext& node)
250251
if (node.active_ctx) {
251252
node.active_ctx->Interrupt();
252253
}
254+
if (node.peerman) {
255+
node.peerman->InterruptHandlers();
256+
}
253257
if (node.llmq_ctx) {
254258
node.llmq_ctx->Interrupt();
255259
}
@@ -285,7 +289,9 @@ void PrepareShutdown(NodeContext& node)
285289
StopREST();
286290
StopRPC();
287291
StopHTTPServer();
292+
288293
if (node.active_ctx) node.active_ctx->Stop();
294+
if (node.peerman) node.peerman->StopHandlers();
289295
if (node.llmq_ctx) node.llmq_ctx->Stop();
290296

291297
for (const auto& client : node.chain_clients) {
@@ -2193,6 +2199,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
21932199
g_active_notification_interface = std::make_unique<ActiveNotificationInterface>(*node.active_ctx, *node.mn_activeman);
21942200
RegisterValidationInterface(g_active_notification_interface.get());
21952201
}
2202+
node.peerman->AddExtraHandler(std::make_unique<NetInstantSend>(node.peerman.get(), *node.llmq_ctx->isman, *node.llmq_ctx->qman, chainman.ActiveChainstate()));
21962203

21972204
// ********************************************************* Step 7d: Setup other Dash services
21982205

@@ -2288,6 +2295,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
22882295
// ********************************************************* Step 10a: schedule Dash-specific tasks
22892296

22902297
node.llmq_ctx->Start(*node.peerman);
2298+
node.peerman->StartHandlers();
22912299
if (node.active_ctx) node.active_ctx->Start(*node.connman, *node.peerman);
22922300

22932301
node.scheduler->scheduleEvery(std::bind(&CNetFulfilledRequestManager::DoMaintenance, std::ref(*node.netfulfilledman)), std::chrono::minutes{1});

0 commit comments

Comments
 (0)