Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 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 @@ -450,6 +452,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
39 changes: 39 additions & 0 deletions src/active/context.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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/ehf_signals.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},
cl_signer{std::make_unique<chainlock::ChainLockSigner>(chainman.ActiveChainstate(), *llmq_ctx.clhandler,
*llmq_ctx.sigman, *llmq_ctx.shareman, sporkman, mn_sync)},
is_signer{std::make_unique<instantsend::InstantSendSigner>(chainman.ActiveChainstate(), *llmq_ctx.clhandler,
*llmq_ctx.isman, *llmq_ctx.sigman, *llmq_ctx.shareman,
*llmq_ctx.qman, sporkman, mempool, mn_sync)},
cj_server{std::make_unique<CCoinJoinServer>(chainman, connman, dmnman, dstxman, mn_metaman, mempool, peerman,
mn_activeman, mn_sync, *llmq_ctx.isman)},
ehf_sighandler{std::make_unique<llmq::CEHFSignalsHandler>(chainman, mnhfman, *llmq_ctx.sigman, *llmq_ctx.shareman,
*llmq_ctx.qman)}
{
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();
}
63 changes: 63 additions & 0 deletions src/active/context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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;
} // namespace llmq

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

/*
* 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;

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();

/*
* 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::CEHFSignalsHandler> ehf_sighandler;
};

#endif // BITCOIN_ACTIVE_CONTEXT_H
24 changes: 24 additions & 0 deletions src/active/notificationinterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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 <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)
{
m_mn_activeman.UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload);
m_active_ctx.ehf_sighandler->UpdatedBlockTip(pindexNew);
}

std::unique_ptr<ActiveNotificationInterface> g_active_notification_interface;
32 changes: 32 additions & 0 deletions src/active/notificationinterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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>

class CActiveMasternodeManager;
struct ActiveContext;

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 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
8 changes: 2 additions & 6 deletions src/chainlock/chainlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,15 @@ bool AreChainLocksEnabled(const CSporkManager& sporkman)
}

CChainLocksHandler::CChainLocksHandler(CChainState& chainstate, CQuorumManager& _qman, CSigningManager& _sigman,
CSigSharesManager& _shareman, CSporkManager& sporkman, CTxMemPool& _mempool,
const CMasternodeSync& mn_sync, bool is_masternode) :
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
14 changes: 10 additions & 4 deletions src/chainlock/chainlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace llmq {
class CInstantSendManager;
class CQuorumManager;
class CSigningManager;
class CSigSharesManager;
enum class VerifyRecSigStatus;

class CChainLocksHandler final : public chainlock::ChainLockSignerParent
Expand All @@ -47,7 +46,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 @@ -68,10 +67,17 @@ class CChainLocksHandler final : public chainlock::ChainLockSignerParent

public:
explicit CChainLocksHandler(CChainState& chainstate, CQuorumManager& _qman, CSigningManager& _sigman,
CSigSharesManager& _shareman, CSporkManager& sporkman, CTxMemPool& _mempool,
const CMasternodeSync& mn_sync, bool is_masternode);
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
27 changes: 16 additions & 11 deletions src/coinjoin/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(ChainstateManager& chainman
}

// including denoms but applying some restrictions
CAmount nBalanceAnonymizable = m_wallet->GetAnonymizableBalance();
const CAmount nBalanceAnonymizable{m_wallet->GetAnonymizableBalance(
/*fSkipDenominated=*/false, /*fSkipMnCollateral=*/false, /*fSkipUnconfirmed=*/true)};

// mixable balance is way too small
if (nBalanceAnonymizable < nValueMin) {
Expand All @@ -859,12 +860,14 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(ChainstateManager& chainman
}

// excluding denoms
CAmount nBalanceAnonimizableNonDenom = m_wallet->GetAnonymizableBalance(true);
const CAmount nBalanceAnonimizableNonDenom{m_wallet->GetAnonymizableBalance(
/*fSkipDenominated=*/true, /*fSkipMnCollateral=*/false, /*fSkipUnconfirmed=*/true)};

// denoms
CAmount nBalanceDenominatedConf = bal.m_denominated_trusted;
CAmount nBalanceDenominatedUnconf = bal.m_denominated_untrusted_pending;
CAmount nBalanceDenominated = nBalanceDenominatedConf + nBalanceDenominatedUnconf;
CAmount nBalanceToDenominate = CCoinJoinClientOptions::GetAmount() * COIN - nBalanceDenominated;
const CAmount nBalanceDenominatedConf{bal.m_denominated_trusted};
const CAmount nBalanceDenominatedUnconf{bal.m_denominated_untrusted_pending};
const CAmount nBalanceDenominated{nBalanceDenominatedConf + nBalanceDenominatedUnconf};
const CAmount nBalanceToDenominate{CCoinJoinClientOptions::GetAmount() * COIN - nBalanceDenominated};

// adjust nBalanceNeedsAnonymized to consume final denom
if (nBalanceDenominated - nBalanceAnonymized > nBalanceNeedsAnonymized) {
Expand Down Expand Up @@ -1430,7 +1433,8 @@ bool CCoinJoinClientSession::MakeCollateralAmounts()
// We still want to consume a lot of inputs to avoid creating only smaller denoms though.
// Knowing that each CTxIn is at least 148 B big, 400 inputs should take 400 x ~148 B = ~60 kB.
// This still leaves more than enough room for another data of typical MakeCollateralAmounts tx.
std::vector<CompactTallyItem> vecTally = m_wallet->SelectCoinsGroupedByAddresses(false, false, true, 400);
std::vector<CompactTallyItem> vecTally = m_wallet->SelectCoinsGroupedByAddresses(
/*fSkipDenominated=*/false, /*fAnonymizable=*/false, /*fSkipUnconfirmed=*/true, /*nMaxOutpointsPerAddress=*/400);
if (vecTally.empty()) {
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::MakeCollateralAmounts -- SelectCoinsGroupedByAddresses can't find any inputs!\n");
return false;
Expand Down Expand Up @@ -1469,12 +1473,12 @@ bool CCoinJoinClientSession::MakeCollateralAmounts(const CompactTallyItem& tally
if (!CCoinJoinClientOptions::IsEnabled()) return false;

// Denominated input is always a single one, so we can check its amount directly and return early
if (!fTryDenominated && tallyItem.outpoints.size() == 1 && CoinJoin::IsDenominatedAmount(tallyItem.nAmount)) {
if (!fTryDenominated && tallyItem.coins.size() == 1 && CoinJoin::IsDenominatedAmount(tallyItem.nAmount)) {
return false;
}

// Skip single inputs that can be used as collaterals already
if (tallyItem.outpoints.size() == 1 && CoinJoin::IsCollateralAmount(tallyItem.nAmount)) {
if (tallyItem.coins.size() == 1 && CoinJoin::IsCollateralAmount(tallyItem.nAmount)) {
return false;
}

Expand Down Expand Up @@ -1602,7 +1606,8 @@ bool CCoinJoinClientSession::CreateDenominated(CAmount nBalanceToDenominate)
// We still want to consume a lot of inputs to avoid creating only smaller denoms though.
// Knowing that each CTxIn is at least 148 B big, 400 inputs should take 400 x ~148 B = ~60 kB.
// This still leaves more than enough room for another data of typical CreateDenominated tx.
std::vector<CompactTallyItem> vecTally = m_wallet->SelectCoinsGroupedByAddresses(true, true, true, 400);
std::vector<CompactTallyItem> vecTally = m_wallet->SelectCoinsGroupedByAddresses(
/*fSkipDenominated=*/true, /*fAnonymizable=*/true, /*fSkipUnconfirmed=*/true, /*nMaxOutpointsPerAddress=*/400);
if (vecTally.empty()) {
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::CreateDenominated -- SelectCoinsGroupedByAddresses can't find any inputs!\n");
return false;
Expand Down Expand Up @@ -1632,7 +1637,7 @@ bool CCoinJoinClientSession::CreateDenominated(CAmount nBalanceToDenominate, con
if (!CCoinJoinClientOptions::IsEnabled()) return false;

// denominated input is always a single one, so we can check its amount directly and return early
if (tallyItem.outpoints.size() == 1 && CoinJoin::IsDenominatedAmount(tallyItem.nAmount)) {
if (tallyItem.coins.size() == 1 && CoinJoin::IsDenominatedAmount(tallyItem.nAmount)) {
return false;
}

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() {}
14 changes: 4 additions & 10 deletions src/coinjoin/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@
#include <memory>

class CActiveMasternodeManager;
class CBlockPolicyEstimator;
class CCoinJoinServer;
class CConnman;
class CDeterministicMNManager;
class CDSTXManager;
class ChainstateManager;
class CMasternodeMetaMan;
class CMasternodeSync;
class CTxMemPool;
class PeerManager;
namespace llmq {
class CInstantSendManager;
};
Expand All @@ -34,19 +30,17 @@ class CoinJoinWalletManager;
struct CJContext {
CJContext() = delete;
CJContext(const CJContext&) = delete;
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);
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);
~CJContext();

const std::unique_ptr<CDSTXManager> dstxman;
#ifdef ENABLE_WALLET
// The main object for accessing mixing
const std::unique_ptr<CoinJoinWalletManager> walletman;
const std::unique_ptr<CCoinJoinClientQueueManager> queueman;
#endif // ENABLE_WALLET
const std::unique_ptr<CCoinJoinServer> server;
const std::unique_ptr<CDSTXManager> dstxman;
};

#endif // BITCOIN_COINJOIN_CONTEXT_H
Loading
Loading