Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
66caf47
wallet: drop collateral outpoints filtering from balance calculation
kwvg Sep 6, 2025
356b06d
refactor: drop `fMasternodeMode` global
kwvg Aug 24, 2025
3ae7d02
refactor: move InstantSend signer to new `ActiveContext`
kwvg Aug 25, 2025
ab12c11
refactor: move ChainLock signer to `ActiveContext`
kwvg Aug 25, 2025
0720702
refactor: move CoinJoin server to `ActiveContext`
kwvg Aug 25, 2025
bc4feea
refactor: clean up `CCoinJoinServer`, remove redundant checks
kwvg Aug 25, 2025
0f184a1
refactor: create notification interface for masternode mode
kwvg Sep 8, 2025
326e95c
refactor: move EHF signals handler to `ActiveContext`
kwvg Aug 25, 2025
3ffb11b
lint: update circular dependencies allowlist, minor cleanup
kwvg Aug 25, 2025
102446c
refactor: consolidate `std::unordered_map<uint256, T>` use
kwvg Sep 8, 2025
b7bdf9f
refactor: consolidate `unordered_lru_cache<uint256, T>` use
kwvg Sep 8, 2025
55300bd
lint: apply some `clang-format` suggestions
kwvg Sep 8, 2025
2d44043
refactor: consolidate `CDeterministicMNCPtr` definitions
kwvg Sep 8, 2025
2c62b58
refactor: consolidate `llmq::CQuorum{,C}Ptr` definitions
kwvg Sep 8, 2025
afc9844
refactor: consolidate `CFinalCommitmentPtr` definitions
kwvg Sep 8, 2025
ef27ddb
refactor: remove unused `CSigningManager` from `CChainLocksHandler` ctor
kwvg Sep 8, 2025
035d610
refactor: move `CSigSharesManager` to `ActiveContext`
kwvg Sep 8, 2025
7cb06e1
refactor: move `CDKGSessionManager` thread management to `ActiveContext`
kwvg Sep 8, 2025
4a034b3
refactor: adjust `CSigSharesManager` ctor arguments
kwvg Sep 8, 2025
ab2c8dc
refactor: move `AsyncSignIfMember()` to `CSigSharesManager`
kwvg Sep 8, 2025
390e0b3
refactor: move `RelayRecoveredSig()` call out of `CSigSharesManager`
kwvg Sep 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ endif
.PHONY: FORCE check-symbols check-security
# dash core #
BITCOIN_CORE_H = \
active/context.h \
active/notificationinterface.h \
addrdb.h \
addressindex.h \
spentindex.h \
Expand Down Expand Up @@ -258,6 +260,7 @@ BITCOIN_CORE_H = \
llmq/signing.h \
llmq/signing_shares.h \
llmq/snapshot.h \
llmq/types.h \
llmq/utils.h \
logging.h \
logging/timer.h \
Expand Down Expand Up @@ -450,6 +453,8 @@ libbitcoin_util_a-clientversion.$(OBJEXT): obj/build.h
libbitcoin_node_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS) $(MINIUPNPC_CPPFLAGS) $(NATPMP_CPPFLAGS) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS)
libbitcoin_node_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_node_a_SOURCES = \
active/context.cpp \
active/notificationinterface.cpp \
addrdb.cpp \
addressindex.cpp \
addrman.cpp \
Expand Down
62 changes: 62 additions & 0 deletions src/active/context.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) 2025 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <active/context.h>

#include <chainlock/chainlock.h>
#include <chainlock/signing.h>
#include <coinjoin/server.h>
#include <instantsend/instantsend.h>
#include <instantsend/signing.h>
#include <llmq/context.h>
#include <llmq/dkgsessionmgr.h>
#include <llmq/ehf_signals.h>
#include <llmq/signing_shares.h>
#include <validation.h>

ActiveContext::ActiveContext(ChainstateManager& chainman, CConnman& connman, CDeterministicMNManager& dmnman,
CDSTXManager& dstxman, CMasternodeMetaMan& mn_metaman, CMNHFManager& mnhfman,
LLMQContext& llmq_ctx, CSporkManager& sporkman, CTxMemPool& mempool, PeerManager& peerman,
const CActiveMasternodeManager& mn_activeman, const CMasternodeSync& mn_sync) :
m_llmq_ctx{llmq_ctx},
cj_server{std::make_unique<CCoinJoinServer>(chainman, connman, dmnman, dstxman, mn_metaman, mempool, peerman,
mn_activeman, mn_sync, *llmq_ctx.isman)},
shareman{std::make_unique<llmq::CSigSharesManager>(connman, chainman.ActiveChainstate(), *llmq_ctx.sigman, peerman,
mn_activeman, *llmq_ctx.qman, sporkman)},
ehf_sighandler{
std::make_unique<llmq::CEHFSignalsHandler>(chainman, mnhfman, *llmq_ctx.sigman, *shareman, *llmq_ctx.qman)},
cl_signer{std::make_unique<chainlock::ChainLockSigner>(chainman.ActiveChainstate(), *llmq_ctx.clhandler,
*llmq_ctx.sigman, *shareman, sporkman, mn_sync)},
is_signer{std::make_unique<instantsend::InstantSendSigner>(chainman.ActiveChainstate(), *llmq_ctx.clhandler,
*llmq_ctx.isman, *llmq_ctx.sigman, *shareman,
*llmq_ctx.qman, sporkman, mempool, mn_sync)}
{
m_llmq_ctx.clhandler->ConnectSigner(cl_signer.get());
m_llmq_ctx.isman->ConnectSigner(is_signer.get());
}

ActiveContext::~ActiveContext()
{
m_llmq_ctx.clhandler->DisconnectSigner();
m_llmq_ctx.isman->DisconnectSigner();
}

void ActiveContext::Interrupt()
{
shareman->InterruptWorkerThread();
}

void ActiveContext::Start(CConnman& connman, PeerManager& peerman)
{
m_llmq_ctx.qdkgsman->StartThreads(connman, peerman);
shareman->RegisterAsRecoveredSigsListener();
shareman->StartWorkerThread();
}

void ActiveContext::Stop()
{
shareman->StopWorkerThread();
shareman->UnregisterAsRecoveredSigsListener();
m_llmq_ctx.qdkgsman->StopThreads();
}
70 changes: 70 additions & 0 deletions src/active/context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2025 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_ACTIVE_CONTEXT_H
#define BITCOIN_ACTIVE_CONTEXT_H

#include <memory>

class CActiveMasternodeManager;
class ChainstateManager;
class CCoinJoinServer;
class CConnman;
class CDeterministicMNManager;
class CDSTXManager;
class CMasternodeMetaMan;
class CMasternodeSync;
class CMNHFManager;
class CSporkManager;
class CTxMemPool;
class PeerManager;
struct LLMQContext;
namespace chainlock {
class ChainLockSigner;
} // namespace chainlock
namespace instantsend {
class InstantSendSigner;
} // namespace instantsend
namespace llmq {
class CEHFSignalsHandler;
class CSigSharesManager;
} // namespace llmq

struct ActiveContext {
private:
// TODO: Switch to references to members when migration is finished
LLMQContext& m_llmq_ctx;

public:
ActiveContext() = delete;
ActiveContext(const ActiveContext&) = delete;
ActiveContext(ChainstateManager& chainman, CConnman& connman, CDeterministicMNManager& dmnman,
CDSTXManager& dstxman, CMasternodeMetaMan& mn_metaman, CMNHFManager& mnhfman, LLMQContext& llmq_ctx,
CSporkManager& sporkman, CTxMemPool& mempool, PeerManager& peerman,
const CActiveMasternodeManager& mn_activeman, const CMasternodeSync& mn_sync);
~ActiveContext();

void Interrupt();
void Start(CConnman& connman, PeerManager& peerman);
void Stop();

/*
* Entities that are only utilized when masternode mode is enabled
* and are accessible in their own right
* TODO: Move CActiveMasternodeManager here when dependents have been migrated
*/
const std::unique_ptr<CCoinJoinServer> cj_server;
const std::unique_ptr<llmq::CSigSharesManager> shareman;
const std::unique_ptr<llmq::CEHFSignalsHandler> ehf_sighandler;

private:
/*
* Entities that are registered with LLMQContext members are not accessible
* and are managed with (Dis)connectSigner() in the (c/d)tor instead
*/
const std::unique_ptr<chainlock::ChainLockSigner> cl_signer;
const std::unique_ptr<instantsend::InstantSendSigner> is_signer;
};

#endif // BITCOIN_ACTIVE_CONTEXT_H
33 changes: 33 additions & 0 deletions src/active/notificationinterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2025 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <active/notificationinterface.h>

#include <active/context.h>
#include <llmq/ehf_signals.h>
#include <llmq/signing_shares.h>
#include <masternode/node.h>

ActiveNotificationInterface::ActiveNotificationInterface(ActiveContext& active_ctx, CActiveMasternodeManager& mn_activeman) :
m_active_ctx{active_ctx},
m_mn_activeman{mn_activeman}
{
}

void ActiveNotificationInterface::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork,
bool fInitialDownload)
{
if (fInitialDownload || pindexNew == pindexFork) // In IBD or blocks were disconnected without any new ones
return;

m_mn_activeman.UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload);
m_active_ctx.ehf_sighandler->UpdatedBlockTip(pindexNew);
}

void ActiveNotificationInterface::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig)
{
m_active_ctx.shareman->NotifyRecoveredSig(sig);
}

std::unique_ptr<ActiveNotificationInterface> g_active_notification_interface;
38 changes: 38 additions & 0 deletions src/active/notificationinterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2025 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_ACTIVE_NOTIFICATIONINTERFACE_H
#define BITCOIN_ACTIVE_NOTIFICATIONINTERFACE_H

#include <validationinterface.h>

#include <memory>

class CActiveMasternodeManager;
struct ActiveContext;
namespace llmq {
class CRecoveredSig;
} // namespace llmq

class ActiveNotificationInterface final : public CValidationInterface
{
public:
ActiveNotificationInterface() = delete;
ActiveNotificationInterface(const ActiveNotificationInterface&) = delete;
explicit ActiveNotificationInterface(ActiveContext& active_ctx, CActiveMasternodeManager& mn_activeman);
virtual ~ActiveNotificationInterface() = default;

protected:
// CValidationInterface
void NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig) override;
void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) override;

private:
ActiveContext& m_active_ctx;
CActiveMasternodeManager& m_mn_activeman;
};

extern std::unique_ptr<ActiveNotificationInterface> g_active_notification_interface;

#endif // BITCOIN_ACTIVE_NOTIFICATIONINTERFACE_H
10 changes: 3 additions & 7 deletions src/chainlock/chainlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,16 @@ bool AreChainLocksEnabled(const CSporkManager& sporkman)
return sporkman.IsSporkActive(SPORK_19_CHAINLOCKS_ENABLED);
}

CChainLocksHandler::CChainLocksHandler(CChainState& chainstate, CQuorumManager& _qman, CSigningManager& _sigman,
CSigSharesManager& _shareman, CSporkManager& sporkman, CTxMemPool& _mempool,
const CMasternodeSync& mn_sync, bool is_masternode) :
CChainLocksHandler::CChainLocksHandler(CChainState& chainstate, CQuorumManager& _qman, CSporkManager& sporkman,
CTxMemPool& _mempool, const CMasternodeSync& mn_sync) :
m_chainstate{chainstate},
qman{_qman},
spork_manager{sporkman},
mempool{_mempool},
m_mn_sync{mn_sync},
scheduler{std::make_unique<CScheduler>()},
scheduler_thread{
std::make_unique<std::thread>(std::thread(util::TraceThread, "cl-schdlr", [&] { scheduler->serviceQueue(); }))},
m_signer{is_masternode
? std::make_unique<chainlock::ChainLockSigner>(chainstate, *this, _sigman, _shareman, sporkman, mn_sync)
: nullptr}
std::make_unique<std::thread>(std::thread(util::TraceThread, "cl-schdlr", [&] { scheduler->serviceQueue(); }))}
{
}

Expand Down
19 changes: 13 additions & 6 deletions src/chainlock/chainlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <sync.h>

#include <chainlock/signing.h>
#include <llmq/types.h>

#include <gsl/pointers.h>

Expand All @@ -33,7 +34,6 @@ namespace llmq {
class CInstantSendManager;
class CQuorumManager;
class CSigningManager;
class CSigSharesManager;
enum class VerifyRecSigStatus;

class CChainLocksHandler final : public chainlock::ChainLockSignerParent
Expand All @@ -47,7 +47,7 @@ class CChainLocksHandler final : public chainlock::ChainLockSignerParent
std::unique_ptr<CScheduler> scheduler;
std::unique_ptr<std::thread> scheduler_thread;

std::unique_ptr<chainlock::ChainLockSigner> m_signer{nullptr};
chainlock::ChainLockSigner* m_signer{nullptr};

mutable Mutex cs;
std::atomic<bool> tryLockChainTipScheduled{false};
Expand All @@ -60,18 +60,25 @@ class CChainLocksHandler final : public chainlock::ChainLockSignerParent
const CBlockIndex* bestChainLockBlockIndex GUARDED_BY(cs){nullptr};
const CBlockIndex* lastNotifyChainLockBlockIndex GUARDED_BY(cs){nullptr};

std::unordered_map<uint256, std::chrono::seconds, StaticSaltedHasher> txFirstSeenTime GUARDED_BY(cs);
Uint256HashMap<std::chrono::seconds> txFirstSeenTime GUARDED_BY(cs);

std::map<uint256, std::chrono::seconds> seenChainLocks GUARDED_BY(cs);

std::atomic<std::chrono::seconds> lastCleanupTime{0s};

public:
explicit CChainLocksHandler(CChainState& chainstate, CQuorumManager& _qman, CSigningManager& _sigman,
CSigSharesManager& _shareman, CSporkManager& sporkman, CTxMemPool& _mempool,
const CMasternodeSync& mn_sync, bool is_masternode);
explicit CChainLocksHandler(CChainState& chainstate, CQuorumManager& _qman, CSporkManager& sporkman,
CTxMemPool& _mempool, const CMasternodeSync& mn_sync);
~CChainLocksHandler();

void ConnectSigner(gsl::not_null<chainlock::ChainLockSigner*> signer)
{
// Prohibit double initialization
assert(m_signer == nullptr);
m_signer = signer;
}
void DisconnectSigner() { m_signer = nullptr; }

void Start(const llmq::CInstantSendManager& isman);
void Stop();

Expand Down
3 changes: 2 additions & 1 deletion src/chainlock/signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <chainlock/clsig.h>
#include <instantsend/instantsend.h>
#include <llmq/signing_shares.h>
#include <masternode/sync.h>
#include <spork.h>

Expand Down Expand Up @@ -140,7 +141,7 @@ void ChainLockSigner::TrySignChainTip(const llmq::CInstantSendManager& isman)
lastSignedMsgHash = msgHash;
}

m_sigman.AsyncSignIfMember(Params().GetConsensus().llmqTypeChainLocks, m_shareman, requestId, msgHash);
m_shareman.AsyncSignIfMember(Params().GetConsensus().llmqTypeChainLocks, m_sigman, requestId, msgHash);
}

void ChainLockSigner::EraseFromBlockHashTxidMap(const uint256& hash)
Expand Down
10 changes: 4 additions & 6 deletions src/coinjoin/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#ifndef BITCOIN_COINJOIN_CLIENT_H
#define BITCOIN_COINJOIN_CLIENT_H

#include <coinjoin/util.h>
#include <coinjoin/coinjoin.h>

#include <net_types.h>
#include <protocol.h>
#include <util/ranges.h>
#include <util/translation.h>

#include <coinjoin/coinjoin.h>
#include <coinjoin/util.h>
#include <llmq/types.h>

#include <atomic>
#include <deque>
#include <memory>
Expand All @@ -21,7 +22,6 @@
class CCoinJoinClientManager;
class CCoinJoinClientQueueManager;
class CConnman;
class CDeterministicMN;
class CDeterministicMNManager;
class ChainstateManager;
class CMasternodeMetaMan;
Expand All @@ -33,8 +33,6 @@ class PeerManager;

class UniValue;

using CDeterministicMNCPtr = std::shared_ptr<const CDeterministicMN>;

class CPendingDsaRequest
{
private:
Expand Down
13 changes: 5 additions & 8 deletions src/coinjoin/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,19 @@
#ifdef ENABLE_WALLET
#include <coinjoin/client.h>
#endif // ENABLE_WALLET
#include <coinjoin/server.h>
#include <coinjoin/coinjoin.h>

CJContext::CJContext(ChainstateManager& chainman, CConnman& connman, CDeterministicMNManager& dmnman,
CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool,
const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync,
const llmq::CInstantSendManager& isman, std::unique_ptr<PeerManager>& peerman, bool relay_txes) :
dstxman{std::make_unique<CDSTXManager>()},
CJContext::CJContext(ChainstateManager& chainman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman,
const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman, bool relay_txes) :
#ifdef ENABLE_WALLET
walletman{std::make_unique<CoinJoinWalletManager>(chainman, dmnman, mn_metaman, mempool, mn_sync, isman, queueman,
/*is_masternode=*/mn_activeman != nullptr)},
queueman{relay_txes ? std::make_unique<CCoinJoinClientQueueManager>(*walletman, dmnman, mn_metaman, mn_sync,
/*is_masternode=*/mn_activeman != nullptr)
: nullptr},
#endif // ENABLE_WALLET
server{std::make_unique<CCoinJoinServer>(chainman, connman, dmnman, *dstxman, mn_metaman, mempool, mn_activeman,
mn_sync, isman, peerman)}
dstxman{std::make_unique<CDSTXManager>()}
{}

CJContext::~CJContext() {}
Loading
Loading