Skip to content

Commit d4cfc61

Browse files
committed
refactor: rename CCoinJoinBaseManager to CoinJoinQueueManager and make it non-virtual
1 parent e7a8b15 commit d4cfc61

10 files changed

Lines changed: 74 additions & 97 deletions

File tree

contrib/auto_gdb/simple_class_obj.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"CMasternodeBroadcast", "CMasternodePing",
1515
"CMasternodeMan", "CDarksendQueue", "CDarkSendEntry",
1616
"CTransaction", "CMutableTransaction", "CCoinJoinBaseSession",
17-
"CCoinJoinBaseManager", "CCoinJoinClientSession",
17+
"CoinJoinQueueManager", "CCoinJoinClientSession",
1818
"CCoinJoinClientManager", "CCoinJoinServer", "CMasternodePayments",
1919
"CMasternodePaymentVote", "CMasternodeBlockPayees",
2020
"CMasternodePayee", "CInstantSend", "CTxLockRequest",

src/Makefile.test.include

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ BITCOIN_TESTS =\
122122
test/governance_validators_tests.cpp \
123123
test/coinjoin_inouts_tests.cpp \
124124
test/coinjoin_dstxmanager_tests.cpp \
125-
test/coinjoin_basemanager_tests.cpp \
126125
test/coinjoin_queue_tests.cpp \
127126
test/hash_tests.cpp \
128127
test/httpserver_tests.cpp \

src/coinjoin/client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ using wallet::ReserveDestination;
4343
CCoinJoinClientManager::CCoinJoinClientManager(const std::shared_ptr<wallet::CWallet>& wallet,
4444
CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
4545
const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman,
46-
CCoinJoinBaseManager* queueman) :
46+
CoinJoinQueueManager* queueman) :
4747
m_wallet{wallet},
4848
m_dmnman{dmnman},
4949
m_mn_metaman{mn_metaman},

src/coinjoin/client.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class CCoinJoinClientManager
163163
const CMasternodeSync& m_mn_sync;
164164
const llmq::CInstantSendManager& m_isman;
165165
//! Non-owning pointer; null when relay_txes is disabled (no queue processing).
166-
CCoinJoinBaseManager* const m_queueman;
166+
CoinJoinQueueManager* const m_queueman;
167167

168168
mutable Mutex cs_deqsessions;
169169
// TODO: or map<denom, CCoinJoinClientSession> ??
@@ -192,7 +192,7 @@ class CCoinJoinClientManager
192192
CCoinJoinClientManager& operator=(const CCoinJoinClientManager&) = delete;
193193
explicit CCoinJoinClientManager(const std::shared_ptr<wallet::CWallet>& wallet, CDeterministicMNManager& dmnman,
194194
CMasternodeMetaMan& mn_metaman, const CMasternodeSync& mn_sync,
195-
const llmq::CInstantSendManager& isman, CCoinJoinBaseManager* queueman);
195+
const llmq::CInstantSendManager& isman, CoinJoinQueueManager* queueman);
196196
~CCoinJoinClientManager();
197197

198198
void ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);

src/coinjoin/coinjoin.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,13 @@ void CCoinJoinBaseSession::SetNull()
115115
nTimeLastSuccessfulStep = GetTime();
116116
}
117117

118-
CCoinJoinBaseManager::CCoinJoinBaseManager() = default;
119-
120-
CCoinJoinBaseManager::~CCoinJoinBaseManager() = default;
121-
122-
void CCoinJoinBaseManager::SetNull()
118+
void CoinJoinQueueManager::SetNull()
123119
{
124120
LOCK(cs_vecqueue);
125121
vecCoinJoinQueue.clear();
126122
}
127123

128-
void CCoinJoinBaseManager::CheckQueue()
124+
void CoinJoinQueueManager::CheckQueue()
129125
{
130126
TRY_LOCK(cs_vecqueue, lockDS);
131127
if (!lockDS) return; // it's ok to fail here, we run this quite frequently
@@ -134,22 +130,22 @@ void CCoinJoinBaseManager::CheckQueue()
134130
auto it = vecCoinJoinQueue.begin();
135131
while (it != vecCoinJoinQueue.end()) {
136132
if (it->IsTimeOutOfBounds()) {
137-
LogPrint(BCLog::COINJOIN, "CCoinJoinBaseManager::%s -- Removing a queue (%s)\n", __func__, it->ToString());
133+
LogPrint(BCLog::COINJOIN, "CoinJoinQueueManager::%s -- Removing a queue (%s)\n", __func__, it->ToString());
138134
it = vecCoinJoinQueue.erase(it);
139135
} else {
140136
++it;
141137
}
142138
}
143139
}
144140

145-
std::optional<bool> CCoinJoinBaseManager::TryHasQueueFromMasternode(const COutPoint& outpoint) const
141+
std::optional<bool> CoinJoinQueueManager::TryHasQueueFromMasternode(const COutPoint& outpoint) const
146142
{
147143
TRY_LOCK(cs_vecqueue, lockDS);
148144
if (!lockDS) return std::nullopt;
149145
return std::ranges::any_of(vecCoinJoinQueue, [&outpoint](const auto& q) { return q.masternodeOutpoint == outpoint; });
150146
}
151147

152-
std::optional<bool> CCoinJoinBaseManager::TryCheckDuplicate(const CCoinJoinQueue& dsq) const
148+
std::optional<bool> CoinJoinQueueManager::TryCheckDuplicate(const CCoinJoinQueue& dsq) const
153149
{
154150
TRY_LOCK(cs_vecqueue, lockDS);
155151
if (!lockDS) return std::nullopt;
@@ -160,15 +156,15 @@ std::optional<bool> CCoinJoinBaseManager::TryCheckDuplicate(const CCoinJoinQueue
160156
return false;
161157
}
162158

163-
bool CCoinJoinBaseManager::TryAddQueue(CCoinJoinQueue dsq)
159+
bool CoinJoinQueueManager::TryAddQueue(CCoinJoinQueue dsq)
164160
{
165161
TRY_LOCK(cs_vecqueue, lockDS);
166162
if (!lockDS) return false;
167163
vecCoinJoinQueue.push_back(std::move(dsq));
168164
return true;
169165
}
170166

171-
bool CCoinJoinBaseManager::GetQueueItemAndTry(CCoinJoinQueue& dsqRet)
167+
bool CoinJoinQueueManager::GetQueueItemAndTry(CCoinJoinQueue& dsqRet)
172168
{
173169
TRY_LOCK(cs_vecqueue, lockDS);
174170
if (!lockDS) return false; // it's ok to fail here, we run this quite frequently

src/coinjoin/coinjoin.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,15 @@ class CCoinJoinBaseSession
321321
int GetEntriesCountLocked() const EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin) { return vecEntries.size(); }
322322
};
323323

324-
// base class
325-
class CCoinJoinBaseManager
324+
class CoinJoinQueueManager
326325
{
327-
protected:
326+
private:
328327
mutable Mutex cs_vecqueue;
329328

330329
// The current mixing sessions in progress on the network
331330
std::vector<CCoinJoinQueue> vecCoinJoinQueue GUARDED_BY(cs_vecqueue);
332331

333332
public:
334-
CCoinJoinBaseManager();
335-
virtual ~CCoinJoinBaseManager();
336-
337333
void SetNull() EXCLUSIVE_LOCKS_REQUIRED(!cs_vecqueue);
338334

339335
//! Remove timed-out queue entries. Call periodically (e.g. every second).

src/coinjoin/server.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class UniValue;
2828
class CCoinJoinServer : public CCoinJoinBaseSession, public NetHandler
2929
{
3030
private:
31-
CCoinJoinBaseManager m_queueman;
31+
CoinJoinQueueManager m_queueman;
3232

3333
ChainstateManager& m_chainman;
3434
CConnman& connman;

src/coinjoin/walletman.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ class CJWalletManagerImpl final : public CJWalletManager
6262
const CMasternodeSync& m_mn_sync;
6363
const llmq::CInstantSendManager& m_isman;
6464

65-
// m_basequeueman is declared before the wallet map so that it is destroyed
65+
// m_queueman is declared before the wallet map so that it is destroyed
6666
// after all CCoinJoinClientManager instances (which hold a raw pointer to it).
6767
// Null when relay_txes is false (no queue processing).
68-
const std::unique_ptr<CCoinJoinBaseManager> m_basequeueman;
68+
const std::unique_ptr<CoinJoinQueueManager> m_queueman;
6969

7070
mutable Mutex cs_ProcessDSQueue;
7171

@@ -105,7 +105,7 @@ CJWalletManagerImpl::CJWalletManagerImpl(ChainstateManager& chainman, CDetermini
105105
m_mempool{mempool},
106106
m_mn_sync{mn_sync},
107107
m_isman{isman},
108-
m_basequeueman{m_relay_txes ? std::make_unique<CCoinJoinBaseManager>() : nullptr}
108+
m_queueman{m_relay_txes ? std::make_unique<CoinJoinQueueManager>() : nullptr}
109109
{
110110
}
111111

@@ -134,8 +134,8 @@ void CJWalletManagerImpl::UpdatedBlockTip(const CBlockIndex* pindexNew, const CB
134134

135135
bool CJWalletManagerImpl::hasQueue(const uint256& hash) const
136136
{
137-
if (m_basequeueman) {
138-
return m_basequeueman->HasQueue(hash);
137+
if (m_queueman) {
138+
return m_queueman->HasQueue(hash);
139139
}
140140
return false;
141141
}
@@ -149,16 +149,16 @@ CCoinJoinClientManager* CJWalletManagerImpl::getClient(const std::string& name)
149149

150150
std::optional<CCoinJoinQueue> CJWalletManagerImpl::getQueueFromHash(const uint256& hash) const
151151
{
152-
if (m_basequeueman) {
153-
return m_basequeueman->GetQueueFromHash(hash);
152+
if (m_queueman) {
153+
return m_queueman->GetQueueFromHash(hash);
154154
}
155155
return std::nullopt;
156156
}
157157

158158
std::optional<int> CJWalletManagerImpl::getQueueSize() const
159159
{
160-
if (m_basequeueman) {
161-
return m_basequeueman->GetQueueSize();
160+
if (m_queueman) {
161+
return m_queueman->GetQueueSize();
162162
}
163163
return std::nullopt;
164164
}
@@ -175,7 +175,7 @@ void CJWalletManagerImpl::addWallet(const std::shared_ptr<wallet::CWallet>& wall
175175
LOCK(cs_wallet_manager_map);
176176
m_wallet_manager_map.try_emplace(wallet->GetName(),
177177
std::make_unique<CCoinJoinClientManager>(wallet, m_dmnman, m_mn_metaman, m_mn_sync,
178-
m_isman, m_basequeueman.get()));
178+
m_isman, m_queueman.get()));
179179
}
180180

181181
void CJWalletManagerImpl::flushWallet(const std::string& name)
@@ -193,8 +193,8 @@ void CJWalletManagerImpl::removeWallet(const std::string& name)
193193

194194
void CJWalletManagerImpl::DoMaintenance(CConnman& connman)
195195
{
196-
if (m_basequeueman && m_mn_sync.IsBlockchainSynced() && !ShutdownRequested()) {
197-
m_basequeueman->CheckQueue();
196+
if (m_queueman && m_mn_sync.IsBlockchainSynced() && !ShutdownRequested()) {
197+
m_queueman->CheckQueue();
198198
}
199199
LOCK(cs_wallet_manager_map);
200200
for (auto& [_, clientman] : m_wallet_manager_map) {
@@ -209,7 +209,7 @@ MessageProcessingResult CJWalletManagerImpl::processMessage(CNode& pfrom, CChain
209209
ForEachCJClientMan([&](CCoinJoinClientManager& clientman) {
210210
clientman.ProcessMessage(pfrom, chainstate, connman, mempool, msg_type, vRecv);
211211
});
212-
if (m_basequeueman) {
212+
if (m_queueman) {
213213
return ProcessDSQueue(pfrom.GetId(), connman, msg_type, vRecv);
214214
}
215215
return {};
@@ -218,7 +218,7 @@ MessageProcessingResult CJWalletManagerImpl::processMessage(CNode& pfrom, CChain
218218
MessageProcessingResult CJWalletManagerImpl::ProcessDSQueue(NodeId from, CConnman& connman, std::string_view msg_type,
219219
CDataStream& vRecv)
220220
{
221-
assert(m_basequeueman);
221+
assert(m_queueman);
222222

223223
if (msg_type != NetMsgType::DSQUEUE) {
224224
return {};
@@ -251,9 +251,9 @@ MessageProcessingResult CJWalletManagerImpl::ProcessDSQueue(NodeId from, CConnma
251251
{
252252
LOCK(cs_ProcessDSQueue);
253253

254-
if (m_basequeueman->HasQueue(dsq.GetHash())) return ret;
254+
if (m_queueman->HasQueue(dsq.GetHash())) return ret;
255255

256-
if (m_basequeueman->HasQueueFromMasternode(dsq.masternodeOutpoint, dsq.fReady)) {
256+
if (m_queueman->HasQueueFromMasternode(dsq.masternodeOutpoint, dsq.fReady)) {
257257
// no way the same mn can send another dsq with the same readiness this soon
258258
LogPrint(BCLog::COINJOIN, /* Continued */
259259
"DSQUEUE -- Peer %d is sending WAY too many dsq messages for a masternode with collateral %s\n",
@@ -298,7 +298,7 @@ MessageProcessingResult CJWalletManagerImpl::ProcessDSQueue(NodeId from, CConnma
298298
ForAnyCJClientMan(
299299
[&dsq](CCoinJoinClientManager& clientman) { return clientman.MarkAlreadyJoinedQueueAsTried(dsq); });
300300

301-
m_basequeueman->AddQueue(dsq);
301+
m_queueman->AddQueue(dsq);
302302
}
303303
} // cs_ProcessDSQueue
304304
return ret;

src/test/coinjoin_basemanager_tests.cpp

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/test/coinjoin_queue_tests.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,47 @@ BOOST_AUTO_TEST_CASE(queue_timestamp_validation)
9696
BOOST_CHECK(q.IsTimeOutOfBounds(current_time));
9797
}
9898

99+
static CCoinJoinQueue MakeQueue(int denom, int64_t nTime, bool fReady, const COutPoint& outpoint)
100+
{
101+
CCoinJoinQueue q;
102+
q.nDenom = denom;
103+
q.masternodeOutpoint = outpoint;
104+
q.m_protxHash = uint256::ONE;
105+
q.nTime = nTime;
106+
q.fReady = fReady;
107+
return q;
108+
}
109+
110+
BOOST_AUTO_TEST_CASE(queuemanager_checkqueue_removes_timeouts)
111+
{
112+
CoinJoinQueueManager man;
113+
const int denom = CoinJoin::AmountToDenomination(CoinJoin::GetSmallestDenomination());
114+
const int64_t now = GetAdjustedTime();
115+
// Non-expired
116+
man.AddQueue(MakeQueue(denom, now, false, COutPoint(uint256S("11"), 0)));
117+
// Expired (too old)
118+
man.AddQueue(MakeQueue(denom, now - COINJOIN_QUEUE_TIMEOUT - 1, false, COutPoint(uint256S("12"), 0)));
119+
120+
BOOST_CHECK_EQUAL(man.GetQueueSize(), 2);
121+
man.CheckQueue();
122+
// One should be removed
123+
BOOST_CHECK_EQUAL(man.GetQueueSize(), 1);
124+
}
125+
126+
BOOST_AUTO_TEST_CASE(queuemanager_getqueueitem_marks_tried_once)
127+
{
128+
CoinJoinQueueManager man;
129+
const int denom = CoinJoin::AmountToDenomination(CoinJoin::GetSmallestDenomination());
130+
const int64_t now = GetAdjustedTime();
131+
CCoinJoinQueue dsq = MakeQueue(denom, now, false, COutPoint(uint256S("21"), 0));
132+
man.AddQueue(dsq);
133+
134+
CCoinJoinQueue picked;
135+
// First retrieval should succeed
136+
BOOST_CHECK(man.GetQueueItemAndTry(picked));
137+
// No other items left to try (picked is marked tried inside)
138+
CCoinJoinQueue picked2;
139+
BOOST_CHECK(!man.GetQueueItemAndTry(picked2));
140+
}
141+
99142
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)