Skip to content

Commit a53046c

Browse files
committed
refactor: remove CDSTXManager global and alias, move to CJContext
We don't need to run `GetDSTX` in `HandleNewRecoveredSig` since we know for sure the transaction being handled is for enhanced hard forking
1 parent f0451fb commit a53046c

File tree

14 files changed

+35
-49
lines changed

14 files changed

+35
-49
lines changed

src/coinjoin/coinjoin.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,6 @@ bilingual_str CoinJoin::GetMessageByID(PoolMessage nMessageID)
431431
}
432432
}
433433

434-
// Definitions for static data members
435-
std::unique_ptr<CDSTXManager> dstxManager;
436-
437434
void CDSTXManager::AddDSTX(const CCoinJoinBroadcastTx& dstx)
438435
{
439436
AssertLockNotHeld(cs_mapdstx);

src/coinjoin/coinjoin.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,4 @@ class CDSTXManager
384384
bool ATMPIfSaneFee(CChainState& active_chainstate, CTxMemPool& pool,
385385
const CTransactionRef &tx, bool test_accept = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
386386

387-
extern std::unique_ptr<CDSTXManager> dstxManager;
388-
389387
#endif // BITCOIN_COINJOIN_COINJOIN_H

src/coinjoin/context.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
#include <coinjoin/server.h>
1515

1616
CJContext::CJContext(CChainState& chainstate, CConnman& connman, CTxMemPool& mempool, const CMasternodeSync& mn_sync, bool relay_txes) :
17+
dstxman{std::make_unique<CDSTXManager>()},
1718
#ifdef ENABLE_WALLET
1819
walletman{std::make_unique<CoinJoinWalletManager>(connman, mempool, mn_sync, queueman)},
1920
queueman {relay_txes ? std::make_unique<CCoinJoinClientQueueManager>(connman, *walletman, mn_sync) : nullptr},
2021
#endif // ENABLE_WALLET
21-
server{std::make_unique<CCoinJoinServer>(chainstate, connman, mempool, mn_sync)}
22+
server{std::make_unique<CCoinJoinServer>(chainstate, connman, *dstxman, mempool, mn_sync)}
2223
{}
2324

2425
CJContext::~CJContext() {}

src/coinjoin/context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class CBlockPolicyEstimator;
1515
class CChainState;
1616
class CCoinJoinServer;
1717
class CConnman;
18+
class CDSTXManager;
1819
class CMasternodeSync;
1920
class CTxMemPool;
2021

@@ -29,6 +30,7 @@ struct CJContext {
2930
CJContext(CChainState& chainstate, CConnman& connman, CTxMemPool& mempool, const CMasternodeSync& mn_sync, bool relay_txes);
3031
~CJContext();
3132

33+
const std::unique_ptr<CDSTXManager> dstxman;
3234
#ifdef ENABLE_WALLET
3335
// The main object for accessing mixing
3436
const std::unique_ptr<CoinJoinWalletManager> walletman;

src/coinjoin/server.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,13 @@ void CCoinJoinServer::CommitFinalTransaction()
330330
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CommitFinalTransaction -- CREATING DSTX\n");
331331

332332
// create and sign masternode dstx transaction
333-
if (!::dstxManager->GetDSTX(hashTx)) {
333+
if (!m_dstxman.GetDSTX(hashTx)) {
334334
CCoinJoinBroadcastTx dstxNew(finalTransaction,
335335
WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.outpoint),
336336
WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash),
337337
GetAdjustedTime());
338338
dstxNew.Sign();
339-
::dstxManager->AddDSTX(dstxNew);
339+
m_dstxman.AddDSTX(dstxNew);
340340
}
341341

342342
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CommitFinalTransaction -- TRANSMITTING DSTX\n");
@@ -453,7 +453,7 @@ void CCoinJoinServer::ConsumeCollateral(const CTransactionRef& txref) const
453453
if (!ATMPIfSaneFee(m_chainstate, mempool, txref, false /* bypass_limits */)) {
454454
LogPrint(BCLog::COINJOIN, "%s -- AcceptToMemoryPool failed\n", __func__);
455455
} else {
456-
connman.RelayTransaction(*txref);
456+
connman.RelayTransaction(*txref, static_cast<bool>(m_dstxman.GetDSTX(txref->GetHash())));
457457
LogPrint(BCLog::COINJOIN, "%s -- Collateral was consumed\n", __func__);
458458
}
459459
}

src/coinjoin/server.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
class CChainState;
1313
class CCoinJoinServer;
1414
class CDataStream;
15+
class CDSTXManager;
1516
class CNode;
1617
class CTxMemPool;
1718

@@ -24,6 +25,7 @@ class CCoinJoinServer : public CCoinJoinBaseSession, public CCoinJoinBaseManager
2425
private:
2526
CChainState& m_chainstate;
2627
CConnman& connman;
28+
CDSTXManager& m_dstxman;
2729
CTxMemPool& mempool;
2830
const CMasternodeSync& m_mn_sync;
2931

@@ -80,9 +82,10 @@ class CCoinJoinServer : public CCoinJoinBaseSession, public CCoinJoinBaseManager
8082
void SetNull() override EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin);
8183

8284
public:
83-
explicit CCoinJoinServer(CChainState& chainstate, CConnman& _connman, CTxMemPool& mempool, const CMasternodeSync& mn_sync) :
85+
explicit CCoinJoinServer(CChainState& chainstate, CConnman& _connman, CDSTXManager& dstxman, CTxMemPool& mempool, const CMasternodeSync& mn_sync) :
8486
m_chainstate(chainstate),
8587
connman(_connman),
88+
m_dstxman(dstxman),
8689
mempool(mempool),
8790
m_mn_sync(mn_sync),
8891
vecSessionCollaterals(),

src/dsnotificationinterface.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void CDSNotificationInterface::SynchronousUpdatedBlockTip(const CBlockIndex *pin
6767

6868
void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
6969
{
70-
assert(m_cj_ctx && ::dstxManager && m_llmq_ctx);
70+
assert(m_cj_ctx && m_llmq_ctx);
7171

7272
if (pindexNew == pindexFork) // blocks were disconnected without any new ones
7373
return;
@@ -80,7 +80,7 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con
8080
if (fInitialDownload)
8181
return;
8282

83-
::dstxManager->UpdatedBlockTip(pindexNew, *m_llmq_ctx->clhandler, m_mn_sync);
83+
m_cj_ctx->dstxman->UpdatedBlockTip(pindexNew, *m_llmq_ctx->clhandler, m_mn_sync);
8484
#ifdef ENABLE_WALLET
8585
for (auto& pair : m_cj_ctx->walletman->raw()) {
8686
pair.second->UpdatedBlockTip(pindexNew);
@@ -99,11 +99,11 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con
9999

100100
void CDSNotificationInterface::TransactionAddedToMempool(const CTransactionRef& ptx, int64_t nAcceptTime)
101101
{
102-
assert(m_llmq_ctx && ::dstxManager);
102+
assert(m_cj_ctx && m_llmq_ctx);
103103

104104
m_llmq_ctx->isman->TransactionAddedToMempool(ptx);
105105
m_llmq_ctx->clhandler->TransactionAddedToMempool(ptx, nAcceptTime);
106-
::dstxManager->TransactionAddedToMempool(ptx);
106+
m_cj_ctx->dstxman->TransactionAddedToMempool(ptx);
107107
}
108108

109109
void CDSNotificationInterface::TransactionRemovedFromMempool(const CTransactionRef& ptx, MemPoolRemovalReason reason)
@@ -115,20 +115,20 @@ void CDSNotificationInterface::TransactionRemovedFromMempool(const CTransactionR
115115

116116
void CDSNotificationInterface::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
117117
{
118-
assert(m_llmq_ctx && ::dstxManager);
118+
assert(m_cj_ctx && m_llmq_ctx);
119119

120120
m_llmq_ctx->isman->BlockConnected(pblock, pindex);
121121
m_llmq_ctx->clhandler->BlockConnected(pblock, pindex);
122-
::dstxManager->BlockConnected(pblock, pindex);
122+
m_cj_ctx->dstxman->BlockConnected(pblock, pindex);
123123
}
124124

125125
void CDSNotificationInterface::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected)
126126
{
127-
assert(m_llmq_ctx && ::dstxManager);
127+
assert(m_cj_ctx && m_llmq_ctx);
128128

129129
m_llmq_ctx->isman->BlockDisconnected(pblock, pindexDisconnected);
130130
m_llmq_ctx->clhandler->BlockDisconnected(pblock, pindexDisconnected);
131-
::dstxManager->BlockDisconnected(pblock, pindexDisconnected);
131+
m_cj_ctx->dstxman->BlockDisconnected(pblock, pindexDisconnected);
132132
}
133133

134134
void CDSNotificationInterface::NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff)
@@ -139,8 +139,8 @@ void CDSNotificationInterface::NotifyMasternodeListChanged(bool undo, const CDet
139139

140140
void CDSNotificationInterface::NotifyChainLock(const CBlockIndex* pindex, const std::shared_ptr<const llmq::CChainLockSig>& clsig)
141141
{
142-
assert(m_llmq_ctx && ::dstxManager);
142+
assert(m_cj_ctx && m_llmq_ctx);
143143

144144
m_llmq_ctx->isman->NotifyChainLock(pindex);
145-
::dstxManager->NotifyChainLock(pindex, *m_llmq_ctx->clhandler, m_mn_sync);
145+
m_cj_ctx->dstxman->NotifyChainLock(pindex, *m_llmq_ctx->clhandler, m_mn_sync);
146146
}

src/init.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,6 @@ void PrepareShutdown(NodeContext& node)
309309
::netfulfilledman.reset();
310310
node.mn_metaman = nullptr;
311311
::mmetaman.reset();
312-
node.dstxman = nullptr;
313-
::dstxManager.reset();
314312
node.mn_sync = nullptr;
315313
::masternodeSync.reset();
316314
node.sporkman.reset();
@@ -2241,10 +2239,6 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
22412239
}
22422240
}
22432241

2244-
assert(!::dstxManager);
2245-
::dstxManager = std::make_unique<CDSTXManager>();
2246-
node.dstxman = ::dstxManager.get();
2247-
22482242
assert(!::mmetaman);
22492243
::mmetaman = std::make_unique<CMasternodeMetaMan>(fLoadCacheFiles);
22502244
node.mn_metaman = ::mmetaman.get();

src/llmq/ehf_signals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void CEHFSignalsHandler::HandleNewRecoveredSig(const CRecoveredSig& recoveredSig
139139
LOCK(cs_main);
140140
const MempoolAcceptResult result = AcceptToMemoryPool(chainstate, mempool, tx_to_sent, /* bypass_limits */ false);
141141
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
142-
connman.RelayTransaction(*tx_to_sent);
142+
connman.RelayTransaction(*tx_to_sent, /*is_dstx=*/ false);
143143
} else {
144144
LogPrintf("CEHFSignalsHandler::HandleNewRecoveredSig -- AcceptToMemoryPool failed: %s\n", result.m_state.ToString());
145145
}

src/net.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3859,14 +3859,10 @@ bool CConnman::DisconnectNode(NodeId id)
38593859
return false;
38603860
}
38613861

3862-
void CConnman::RelayTransaction(const CTransaction& tx)
3862+
void CConnman::RelayTransaction(const CTransaction& tx, const bool is_dstx)
38633863
{
38643864
uint256 hash = tx.GetHash();
3865-
int nInv = MSG_TX;
3866-
if (::dstxManager->GetDSTX(hash)) {
3867-
nInv = MSG_DSTX;
3868-
}
3869-
CInv inv(nInv, hash);
3865+
CInv inv(is_dstx ? MSG_DSTX : MSG_TX, hash);
38703866
RelayInv(inv);
38713867
}
38723868

0 commit comments

Comments
 (0)