Skip to content

Commit 6396c89

Browse files
committed
refactor: replace references to mempool global with references
1 parent b76d8cb commit 6396c89

27 files changed

+144
-125
lines changed

src/coinjoin/client.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataStream&
134134
}
135135
}
136136

137-
void CCoinJoinClientManager::ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman)
137+
void CCoinJoinClientManager::ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman, CTxMemPool& mempool)
138138
{
139139
if (fMasternodeMode) return;
140140
if (!CCoinJoinClientOptions::IsEnabled()) return;
@@ -153,12 +153,12 @@ void CCoinJoinClientManager::ProcessMessage(CNode& peer, std::string_view msg_ty
153153
AssertLockNotHeld(cs_deqsessions);
154154
LOCK(cs_deqsessions);
155155
for (auto& session : deqSessions) {
156-
session.ProcessMessage(peer, msg_type, vRecv, connman);
156+
session.ProcessMessage(peer, msg_type, vRecv, connman, mempool);
157157
}
158158
}
159159
}
160160

161-
void CCoinJoinClientSession::ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman)
161+
void CCoinJoinClientSession::ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman, CTxMemPool& mempool)
162162
{
163163
if (fMasternodeMode) return;
164164
if (!CCoinJoinClientOptions::IsEnabled()) return;
@@ -193,7 +193,7 @@ void CCoinJoinClientSession::ProcessMessage(CNode& peer, std::string_view msg_ty
193193
LogPrint(BCLog::COINJOIN, "DSFINALTX -- txNew %s", txNew.ToString()); /* Continued */
194194

195195
// check to see if input is spent already? (and probably not confirmed)
196-
SignFinalTransaction(txNew, peer, connman);
196+
SignFinalTransaction(txNew, peer, connman, mempool);
197197

198198
} else if (msg_type == NetMsgType::DSCOMPLETE) {
199199
if (!mixingMasternode) return;
@@ -539,7 +539,7 @@ void CCoinJoinClientSession::ProcessPoolStateUpdate(CCoinJoinStatusUpdate psssup
539539
// check it to make sure it's what we want, then sign it if we agree.
540540
// If we refuse to sign, it's possible we'll be charged collateral
541541
//
542-
bool CCoinJoinClientSession::SignFinalTransaction(const CTransaction& finalTransactionNew, CNode& peer, CConnman& connman)
542+
bool CCoinJoinClientSession::SignFinalTransaction(const CTransaction& finalTransactionNew, CNode& peer, CConnman& connman, CTxMemPool& mempool)
543543
{
544544
if (!CCoinJoinClientOptions::IsEnabled()) return false;
545545

@@ -568,7 +568,7 @@ bool CCoinJoinClientSession::SignFinalTransaction(const CTransaction& finalTrans
568568

569569
// Make sure all inputs/outputs are valid
570570
PoolMessage nMessageID{MSG_NOERR};
571-
if (!IsValidInOuts(finalMutableTransaction.vin, finalMutableTransaction.vout, nMessageID, nullptr)) {
571+
if (!IsValidInOuts(mempool, finalMutableTransaction.vin, finalMutableTransaction.vout, nMessageID, nullptr)) {
572572
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- ERROR! IsValidInOuts() failed: %s\n", __func__, CCoinJoin::GetMessageByID(nMessageID).translated);
573573
UnlockCoins();
574574
keyHolderStorage.ReturnAll();
@@ -756,7 +756,7 @@ bool CCoinJoinClientManager::CheckAutomaticBackup()
756756
//
757757
// Passively run mixing in the background to mix funds based on the given configuration.
758758
//
759-
bool CCoinJoinClientSession::DoAutomaticDenominating(CConnman& connman, bool fDryRun)
759+
bool CCoinJoinClientSession::DoAutomaticDenominating(CConnman& connman, CTxMemPool& mempool, bool fDryRun)
760760
{
761761
if (fMasternodeMode) return false; // no client-side mixing on masternodes
762762
if (nState != POOL_STATE_IDLE) return false;
@@ -909,7 +909,7 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(CConnman& connman, bool fDr
909909
return false;
910910
}
911911
} else {
912-
if (!CCoinJoin::IsCollateralValid(CTransaction(txMyCollateral))) {
912+
if (!CCoinJoin::IsCollateralValid(mempool, CTransaction(txMyCollateral))) {
913913
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::DoAutomaticDenominating -- invalid collateral, recreating...\n");
914914
if (!CreateCollateralTransaction(txMyCollateral, strReason)) {
915915
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::DoAutomaticDenominating -- create collateral error: %s\n", strReason);
@@ -936,7 +936,7 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(CConnman& connman, bool fDr
936936
return false;
937937
}
938938

939-
bool CCoinJoinClientManager::DoAutomaticDenominating(CConnman& connman, bool fDryRun)
939+
bool CCoinJoinClientManager::DoAutomaticDenominating(CConnman& connman, CTxMemPool& mempool, bool fDryRun)
940940
{
941941
if (fMasternodeMode) return false; // no client-side mixing on masternodes
942942
if (!CCoinJoinClientOptions::IsEnabled() || !IsMixing()) return false;
@@ -978,7 +978,7 @@ bool CCoinJoinClientManager::DoAutomaticDenominating(CConnman& connman, bool fDr
978978
return false;
979979
}
980980

981-
fResult &= session.DoAutomaticDenominating(connman, fDryRun);
981+
fResult &= session.DoAutomaticDenominating(connman, mempool, fDryRun);
982982
}
983983

984984
return fResult;
@@ -1815,7 +1815,7 @@ void CCoinJoinClientQueueManager::DoMaintenance()
18151815
CheckQueue();
18161816
}
18171817

1818-
void CCoinJoinClientManager::DoMaintenance(CConnman& connman)
1818+
void CCoinJoinClientManager::DoMaintenance(CConnman& connman, CTxMemPool& mempool)
18191819
{
18201820
if (!CCoinJoinClientOptions::IsEnabled()) return;
18211821
if (m_mn_sync == nullptr) return;
@@ -1830,7 +1830,7 @@ void CCoinJoinClientManager::DoMaintenance(CConnman& connman)
18301830
CheckTimeout();
18311831
ProcessPendingDsaRequest(connman);
18321832
if (nDoAutoNextRun == nTick) {
1833-
DoAutomaticDenominating(connman);
1833+
DoAutomaticDenominating(connman, mempool);
18341834
nDoAutoNextRun = nTick + COINJOIN_AUTO_TIMEOUT_MIN + GetRandInt(COINJOIN_AUTO_TIMEOUT_MAX - COINJOIN_AUTO_TIMEOUT_MIN);
18351835
}
18361836
}
@@ -1867,14 +1867,14 @@ void CCoinJoinClientManager::GetJsonInfo(UniValue& obj) const
18671867
obj.pushKV("sessions", arrSessions);
18681868
}
18691869

1870-
void DoCoinJoinMaintenance(CConnman& connman)
1870+
void DoCoinJoinMaintenance(CConnman& connman, CTxMemPool& mempool)
18711871
{
18721872
if (coinJoinClientQueueManager != nullptr) {
18731873
coinJoinClientQueueManager->DoMaintenance();
18741874
}
18751875

18761876
for (const auto& pair : coinJoinClientManagers) {
1877-
pair.second->DoMaintenance(connman);
1877+
pair.second->DoMaintenance(connman, mempool);
18781878
}
18791879
}
18801880

src/coinjoin/client.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession
114114
void CompletedTransaction(PoolMessage nMessageID);
115115

116116
/// As a client, check and sign the final transaction
117-
bool SignFinalTransaction(const CTransaction& finalTransactionNew, CNode& peer, CConnman& connman) LOCKS_EXCLUDED(cs_coinjoin);
117+
bool SignFinalTransaction(const CTransaction& finalTransactionNew, CNode& peer, CConnman& connman, CTxMemPool& mempool) LOCKS_EXCLUDED(cs_coinjoin);
118118

119119
void RelayIn(const CCoinJoinEntry& entry, CConnman& connman) const;
120120

@@ -126,7 +126,7 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession
126126
{
127127
}
128128

129-
void ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman);
129+
void ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman, CTxMemPool& mempool);
130130

131131
void UnlockCoins();
132132

@@ -137,7 +137,7 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession
137137
bool GetMixingMasternodeInfo(CDeterministicMNCPtr& ret) const;
138138

139139
/// Passively run mixing in the background according to the configuration in settings
140-
bool DoAutomaticDenominating(CConnman& connman, bool fDryRun = false) LOCKS_EXCLUDED(cs_coinjoin);
140+
bool DoAutomaticDenominating(CConnman& connman, CTxMemPool& mempool, bool fDryRun = false) LOCKS_EXCLUDED(cs_coinjoin);
141141

142142
/// As a client, submit part of a future mixing transaction to a Masternode to start the process
143143
bool SubmitDenominate(CConnman& connman);
@@ -207,7 +207,7 @@ class CCoinJoinClientManager
207207
explicit CCoinJoinClientManager(CWallet& wallet, const std::unique_ptr<CMasternodeSync>& mn_sync) :
208208
mixingWallet(wallet), m_mn_sync(mn_sync) {}
209209

210-
void ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman) LOCKS_EXCLUDED(cs_deqsessions);
210+
void ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman, CTxMemPool& mempool) LOCKS_EXCLUDED(cs_deqsessions);
211211

212212
bool StartMixing();
213213
void StopMixing();
@@ -220,7 +220,7 @@ class CCoinJoinClientManager
220220
bool GetMixingMasternodesInfo(std::vector<CDeterministicMNCPtr>& vecDmnsRet) const LOCKS_EXCLUDED(cs_deqsessions);
221221

222222
/// Passively run mixing in the background according to the configuration in settings
223-
bool DoAutomaticDenominating(CConnman& connman, bool fDryRun = false) LOCKS_EXCLUDED(cs_deqsessions);
223+
bool DoAutomaticDenominating(CConnman& connman, CTxMemPool& mempool, bool fDryRun = false) LOCKS_EXCLUDED(cs_deqsessions);
224224

225225
bool TrySubmitDenominate(const CService& mnAddr, CConnman& connman) LOCKS_EXCLUDED(cs_deqsessions);
226226
bool MarkAlreadyJoinedQueueAsTried(CCoinJoinQueue& dsq) const LOCKS_EXCLUDED(cs_deqsessions);
@@ -236,12 +236,12 @@ class CCoinJoinClientManager
236236

237237
void UpdatedBlockTip(const CBlockIndex* pindex);
238238

239-
void DoMaintenance(CConnman& connman);
239+
void DoMaintenance(CConnman& connman, CTxMemPool& mempool);
240240

241241
void GetJsonInfo(UniValue& obj) const LOCKS_EXCLUDED(cs_deqsessions);
242242
};
243243

244244

245-
void DoCoinJoinMaintenance(CConnman& connman);
245+
void DoCoinJoinMaintenance(CConnman& connman, CTxMemPool& mempool);
246246

247247
#endif // BITCOIN_COINJOIN_CLIENT_H

src/coinjoin/coinjoin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ std::string CCoinJoinBaseSession::GetStateString() const
217217
}
218218
}
219219

220-
bool CCoinJoinBaseSession::IsValidInOuts(const std::vector<CTxIn>& vin, const std::vector<CTxOut>& vout, PoolMessage& nMessageIDRet, bool* fConsumeCollateralRet) const
220+
bool CCoinJoinBaseSession::IsValidInOuts(CTxMemPool& mempool, const std::vector<CTxIn>& vin, const std::vector<CTxOut>& vout, PoolMessage& nMessageIDRet, bool* fConsumeCollateralRet) const
221221
{
222222
std::set<CScript> setScripPubKeys;
223223
nMessageIDRet = MSG_NOERR;
@@ -308,7 +308,7 @@ Mutex CCoinJoin::cs_mapdstx;
308308
std::map<uint256, CCoinJoinBroadcastTx> CCoinJoin::mapDSTX GUARDED_BY(CCoinJoin::cs_mapdstx);
309309

310310
// check to make sure the collateral provided by the client is valid
311-
bool CCoinJoin::IsCollateralValid(const CTransaction& txCollateral)
311+
bool CCoinJoin::IsCollateralValid(CTxMemPool& mempool, const CTransaction& txCollateral)
312312
{
313313
if (txCollateral.vout.empty()) return false;
314314
if (txCollateral.nLockTime != 0) return false;

src/coinjoin/coinjoin.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class CConnman;
2424
class CBLSPublicKey;
2525
class CBlockIndex;
2626
class CMasternodeSync;
27+
class CTxMemPool;
2728

2829
namespace llmq {
2930
class CChainLocksHandler;
@@ -347,7 +348,7 @@ class CCoinJoinBaseSession
347348

348349
void SetNull() EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin);
349350

350-
bool IsValidInOuts(const std::vector<CTxIn>& vin, const std::vector<CTxOut>& vout, PoolMessage& nMessageIDRet, bool* fConsumeCollateralRet) const;
351+
bool IsValidInOuts(CTxMemPool& mempool, const std::vector<CTxIn>& vin, const std::vector<CTxOut>& vout, PoolMessage& nMessageIDRet, bool* fConsumeCollateralRet) const;
351352

352353
public:
353354
int nSessionDenom{0}; // Users must submit a denom matching this
@@ -476,7 +477,7 @@ class CCoinJoin
476477
static constexpr CAmount GetMaxPoolAmount() { return COINJOIN_ENTRY_MAX_SIZE * vecStandardDenominations.front(); }
477478

478479
/// If the collateral is valid given by a client
479-
static bool IsCollateralValid(const CTransaction& txCollateral);
480+
static bool IsCollateralValid(CTxMemPool& mempool, const CTransaction& txCollateral);
480481
static constexpr CAmount GetCollateralAmount() { return GetSmallestDenomination() / 10; }
481482
static constexpr CAmount GetMaxCollateralAmount() { return GetCollateralAmount() * 4; }
482483

src/coinjoin/server.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ bool CCoinJoinServer::AddEntry(const CCoinJoinEntry& entry, PoolMessage& nMessag
577577
return false;
578578
}
579579

580-
if (!CCoinJoin::IsCollateralValid(*entry.txCollateral)) {
580+
if (!CCoinJoin::IsCollateralValid(mempool, *entry.txCollateral)) {
581581
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- ERROR: collateral not valid!\n", __func__);
582582
nMessageIDRet = ERR_INVALID_COLLATERAL;
583583
return false;
@@ -611,7 +611,7 @@ bool CCoinJoinServer::AddEntry(const CCoinJoinEntry& entry, PoolMessage& nMessag
611611
}
612612

613613
bool fConsumeCollateral{false};
614-
if (!IsValidInOuts(vin, entry.vecTxOut, nMessageIDRet, &fConsumeCollateral)) {
614+
if (!IsValidInOuts(mempool, vin, entry.vecTxOut, nMessageIDRet, &fConsumeCollateral)) {
615615
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- ERROR! IsValidInOuts() failed: %s\n", __func__, CCoinJoin::GetMessageByID(nMessageIDRet).translated);
616616
if (fConsumeCollateral) {
617617
ConsumeCollateral(entry.txCollateral);
@@ -688,7 +688,7 @@ bool CCoinJoinServer::IsAcceptableDSA(const CCoinJoinAccept& dsa, PoolMessage& n
688688
}
689689

690690
// check collateral
691-
if (!fUnitTest && !CCoinJoin::IsCollateralValid(CTransaction(dsa.txCollateral))) {
691+
if (!fUnitTest && !CCoinJoin::IsCollateralValid(mempool, CTransaction(dsa.txCollateral))) {
692692
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- collateral not valid!\n", __func__);
693693
nMessageIDRet = ERR_INVALID_COLLATERAL;
694694
return false;

src/coinjoin/server.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CCoinJoinServer : public CCoinJoinBaseSession, public CCoinJoinBaseManager
2020
{
2121
private:
2222
CConnman& connman;
23+
CTxMemPool& mempool;
2324
const std::unique_ptr<CMasternodeSync>& m_mn_sync;
2425

2526
// Mixing uses collateral transactions to trust parties entering the pool
@@ -75,10 +76,11 @@ class CCoinJoinServer : public CCoinJoinBaseSession, public CCoinJoinBaseManager
7576
void SetNull() EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin);
7677

7778
public:
78-
explicit CCoinJoinServer(CConnman& _connman, const std::unique_ptr<CMasternodeSync>& mn_sync) :
79+
explicit CCoinJoinServer(CConnman& _connman, CTxMemPool& _mempool, const std::unique_ptr<CMasternodeSync>& mn_sync) :
7980
vecSessionCollaterals(),
8081
fUnitTest(false),
8182
connman(_connman),
83+
mempool(_mempool),
8284
m_mn_sync(mn_sync) {};
8385

8486
void ProcessMessage(CNode& pfrom, std::string_view msg_type, CDataStream& vRecv);

src/dsnotificationinterface.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
#include <llmq/instantsend.h>
2222
#include <llmq/quorums.h>
2323

24-
CDSNotificationInterface::CDSNotificationInterface(CConnman& _connman,
24+
CDSNotificationInterface::CDSNotificationInterface(CConnman& _connman, CTxMemPool& _mempool,
2525
std::unique_ptr<CMasternodeSync>& _mn_sync, std::unique_ptr<CDeterministicMNManager>& _dmnman,
2626
std::unique_ptr<CGovernanceManager>& _govman, std::unique_ptr<LLMQContext>& _llmq_ctx
27-
) : connman(_connman), m_mn_sync(_mn_sync), dmnman(_dmnman), govman(_govman), llmq_ctx(_llmq_ctx) {}
27+
) : connman(_connman), mempool(_mempool), m_mn_sync(_mn_sync), dmnman(_dmnman), govman(_govman), llmq_ctx(_llmq_ctx) {}
2828

2929
void CDSNotificationInterface::InitializeCurrentBlockTip()
3030
{
@@ -79,7 +79,7 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con
7979
llmq_ctx->qman->UpdatedBlockTip(pindexNew, fInitialDownload);
8080
llmq_ctx->qdkgsman->UpdatedBlockTip(pindexNew, fInitialDownload);
8181

82-
if (!fDisableGovernance) govman->UpdatedBlockTip(pindexNew, connman);
82+
if (!fDisableGovernance) govman->UpdatedBlockTip(pindexNew, connman, mempool);
8383
}
8484

8585
void CDSNotificationInterface::TransactionAddedToMempool(const CTransactionRef& ptx, int64_t nAcceptTime)
@@ -119,7 +119,7 @@ void CDSNotificationInterface::BlockDisconnected(const std::shared_ptr<const CBl
119119
void CDSNotificationInterface::NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff, CConnman& connman)
120120
{
121121
CMNAuth::NotifyMasternodeListChanged(undo, oldMNList, diff, connman);
122-
govman->UpdateCachesAndClean();
122+
govman->UpdateCachesAndClean(&mempool);
123123
}
124124

125125
void CDSNotificationInterface::NotifyChainLock(const CBlockIndex* pindex, const std::shared_ptr<const llmq::CChainLockSig>& clsig)

src/dsnotificationinterface.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct LLMQContext;
1616
class CDSNotificationInterface : public CValidationInterface
1717
{
1818
public:
19-
explicit CDSNotificationInterface(CConnman& _connman,
19+
explicit CDSNotificationInterface(CConnman& _connman, CTxMemPool& _mempool,
2020
std::unique_ptr<CMasternodeSync>& _mn_sync, std::unique_ptr<CDeterministicMNManager>& _dmnman,
2121
std::unique_ptr<CGovernanceManager>& _govman, std::unique_ptr<LLMQContext>& _llmq_ctx);
2222
virtual ~CDSNotificationInterface() = default;
@@ -39,6 +39,7 @@ class CDSNotificationInterface : public CValidationInterface
3939

4040
private:
4141
CConnman& connman;
42+
CTxMemPool& mempool;
4243

4344
std::unique_ptr<CMasternodeSync>& m_mn_sync;
4445
std::unique_ptr<CDeterministicMNManager>& dmnman;

0 commit comments

Comments
 (0)