Skip to content

Commit 83707a0

Browse files
committed
refactor: create notification interface for masternode mode
1 parent d52795c commit 83707a0

File tree

5 files changed

+67
-7
lines changed

5 files changed

+67
-7
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ BITCOIN_CORE_H = \
263263
logging/timer.h \
264264
mapport.h \
265265
masternode/active/context.h \
266+
masternode/active/notificationinterface.h \
266267
masternode/node.h \
267268
masternode/meta.h \
268269
masternode/payments.h \
@@ -522,6 +523,7 @@ libbitcoin_node_a_SOURCES = \
522523
llmq/utils.cpp \
523524
mapport.cpp \
524525
masternode/active/context.cpp \
526+
masternode/active/notificationinterface.cpp \
525527
masternode/node.cpp \
526528
masternode/meta.cpp \
527529
masternode/payments.cpp \

src/init.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#include <llmq/options.h>
9393
#include <llmq/signing.h>
9494
#include <masternode/active/context.h>
95+
#include <masternode/active/notificationinterface.h>
9596
#include <masternode/meta.h>
9697
#include <masternode/node.h>
9798
#include <masternode/sync.h>
@@ -320,6 +321,11 @@ void PrepareShutdown(NodeContext& node)
320321
// CValidationInterface callbacks, flush them...
321322
GetMainSignals().FlushBackgroundCallbacks();
322323

324+
if (g_active_notification_interface) {
325+
UnregisterValidationInterface(g_active_notification_interface.get());
326+
g_active_notification_interface.reset();
327+
}
328+
323329
// After all scheduled tasks have been flushed, destroy pointers
324330
// and reset all to nullptr.
325331
node.active_ctx.reset();
@@ -376,10 +382,7 @@ void PrepareShutdown(NodeContext& node)
376382
g_ds_notification_interface.reset();
377383
}
378384

379-
if (node.mn_activeman) {
380-
UnregisterValidationInterface(node.mn_activeman.get());
381-
node.mn_activeman.reset();
382-
}
385+
node.mn_activeman.reset();
383386

384387
node.chain_clients.clear();
385388

@@ -1702,7 +1705,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17021705
}
17031706
// Create and register mn_activeman, will init later in ThreadImport
17041707
node.mn_activeman = std::make_unique<CActiveMasternodeManager>(keyOperator, *node.connman, node.dmnman);
1705-
RegisterValidationInterface(node.mn_activeman.get());
17061708
}
17071709

17081710
// Check port numbers
@@ -2163,10 +2165,13 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
21632165

21642166
// ********************************************************* Step 7d: Setup masternode mode
21652167
assert(!node.active_ctx);
2168+
assert(!g_active_notification_interface);
21662169
if (node.mn_activeman) {
21672170
node.active_ctx = std::make_unique<ActiveContext>(chainman, *node.connman, *node.dmnman, *node.cj_ctx->dstxman, *node.mn_metaman,
21682171
*node.llmq_ctx, *node.sporkman, *node.mempool, *node.peerman, *node.mn_activeman,
21692172
*node.mn_sync);
2173+
g_active_notification_interface = std::make_unique<ActiveNotificationInterface>(*node.mn_activeman);
2174+
RegisterValidationInterface(g_active_notification_interface.get());
21702175
}
21712176

21722177
// ********************************************************* Step 7e: Setup other Dash services
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2025 The Dash Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <masternode/active/notificationinterface.h>
6+
7+
#include <masternode/node.h>
8+
9+
ActiveNotificationInterface::ActiveNotificationInterface(CActiveMasternodeManager& mn_activeman) :
10+
m_mn_activeman{mn_activeman}
11+
{
12+
}
13+
14+
void ActiveNotificationInterface::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork,
15+
bool fInitialDownload)
16+
{
17+
if (fInitialDownload || pindexNew == pindexFork) // In IBD or blocks were disconnected without any new ones
18+
return;
19+
20+
m_mn_activeman.UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload);
21+
}
22+
23+
std::unique_ptr<ActiveNotificationInterface> g_active_notification_interface;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2025 The Dash Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_MASTERNODE_ACTIVE_NOTIFICATIONINTERFACE_H
6+
#define BITCOIN_MASTERNODE_ACTIVE_NOTIFICATIONINTERFACE_H
7+
8+
#include <validationinterface.h>
9+
10+
class CActiveMasternodeManager;
11+
12+
class ActiveNotificationInterface final : public CValidationInterface
13+
{
14+
public:
15+
ActiveNotificationInterface() = delete;
16+
ActiveNotificationInterface(const ActiveNotificationInterface&) = delete;
17+
explicit ActiveNotificationInterface(CActiveMasternodeManager& mn_activeman);
18+
virtual ~ActiveNotificationInterface() = default;
19+
20+
protected:
21+
// CValidationInterface
22+
void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) override;
23+
24+
private:
25+
CActiveMasternodeManager& m_mn_activeman;
26+
};
27+
28+
extern std::unique_ptr<ActiveNotificationInterface> g_active_notification_interface;
29+
30+
#endif // BITCOIN_MASTERNODE_ACTIVE_NOTIFICATIONINTERFACE_H

src/masternode/node.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct CActiveMasternodeInfo {
2727
blsKeyOperator(blsKeyOperator), blsPubKeyOperator(blsPubKeyOperator) {};
2828
};
2929

30-
class CActiveMasternodeManager final : public CValidationInterface
30+
class CActiveMasternodeManager
3131
{
3232
public:
3333
enum class MasternodeState {
@@ -52,7 +52,7 @@ class CActiveMasternodeManager final : public CValidationInterface
5252
public:
5353
explicit CActiveMasternodeManager(const CBLSSecretKey& sk, CConnman& connman, const std::unique_ptr<CDeterministicMNManager>& dmnman);
5454

55-
void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) override
55+
void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload)
5656
EXCLUSIVE_LOCKS_REQUIRED(!cs);
5757

5858
void Init(const CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(!cs) { LOCK(cs); InitInternal(pindex); };

0 commit comments

Comments
 (0)