@@ -34,92 +34,91 @@ void CCoinJoinClientQueueManager::ProcessMessage(CNode* pfrom, const std::string
3434 if (fMasternodeMode ) return ;
3535 if (!CCoinJoinClientOptions::IsEnabled ()) return ;
3636 if (!masternodeSync.IsBlockchainSynced ()) return ;
37+ if (strCommand != NetMsgType::DSQUEUE) return ;
3738
3839 if (!CheckDiskSpace (GetDataDir ())) {
3940 LogPrint (BCLog::COINJOIN, " CCoinJoinClientQueueManager::ProcessMessage -- Not enough disk space, disabling CoinJoin.\n " );
4041 return ;
4142 }
4243
43- if (strCommand == NetMsgType::DSQUEUE) {
44- if (pfrom->nVersion < MIN_COINJOIN_PEER_PROTO_VERSION) {
45- LogPrint (BCLog::COINJOIN, " DSQUEUE -- peer=%d using obsolete version %i\n " , pfrom->GetId (), pfrom->nVersion );
46- if (enable_bip61) {
47- connman.PushMessage (pfrom, CNetMsgMaker (pfrom->GetSendVersion ()).Make (NetMsgType::REJECT, strCommand,
48- REJECT_OBSOLETE, strprintf (
49- " Version must be %d or greater" , MIN_COINJOIN_PEER_PROTO_VERSION)));
50- }
51- return ;
44+ if (pfrom->nVersion < MIN_COINJOIN_PEER_PROTO_VERSION) {
45+ LogPrint (BCLog::COINJOIN, " DSQUEUE -- peer=%d using obsolete version %i\n " , pfrom->GetId (), pfrom->nVersion );
46+ if (enable_bip61) {
47+ connman.PushMessage (pfrom, CNetMsgMaker (pfrom->GetSendVersion ()).Make (NetMsgType::REJECT, strCommand,
48+ REJECT_OBSOLETE, strprintf (
49+ " Version must be %d or greater" , MIN_COINJOIN_PEER_PROTO_VERSION)));
5250 }
51+ return ;
52+ }
5353
54- CCoinJoinQueue dsq;
55- vRecv >> dsq;
54+ CCoinJoinQueue dsq;
55+ vRecv >> dsq;
5656
57- {
58- TRY_LOCK (cs_vecqueue, lockRecv);
59- if (!lockRecv) return ;
57+ {
58+ TRY_LOCK (cs_vecqueue, lockRecv);
59+ if (!lockRecv) return ;
6060
61- // process every dsq only once
62- for (const auto & q : vecCoinJoinQueue) {
63- if (q == dsq) {
64- return ;
65- }
66- if (q.fReady == dsq.fReady && q.masternodeOutpoint == dsq.masternodeOutpoint ) {
67- // no way the same mn can send another dsq with the same readiness this soon
68- LogPrint (BCLog::COINJOIN, " DSQUEUE -- Peer %s is sending WAY too many dsq messages for a masternode with collateral %s\n " , pfrom->GetLogString (), dsq.masternodeOutpoint .ToStringShort ());
69- return ;
70- }
61+ // process every dsq only once
62+ for (const auto & q : vecCoinJoinQueue) {
63+ if (q == dsq) {
64+ return ;
7165 }
72- } // cs_vecqueue
66+ if (q.fReady == dsq.fReady && q.masternodeOutpoint == dsq.masternodeOutpoint ) {
67+ // no way the same mn can send another dsq with the same readiness this soon
68+ LogPrint (BCLog::COINJOIN, " DSQUEUE -- Peer %s is sending WAY too many dsq messages for a masternode with collateral %s\n " , pfrom->GetLogString (), dsq.masternodeOutpoint .ToStringShort ());
69+ return ;
70+ }
71+ }
72+ } // cs_vecqueue
7373
74- LogPrint (BCLog::COINJOIN, " DSQUEUE -- %s new\n " , dsq.ToString ());
74+ LogPrint (BCLog::COINJOIN, " DSQUEUE -- %s new\n " , dsq.ToString ());
7575
76- if (dsq.IsTimeOutOfBounds ()) return ;
76+ if (dsq.IsTimeOutOfBounds ()) return ;
7777
78- auto mnList = deterministicMNManager->GetListAtChainTip ();
79- auto dmn = mnList.GetValidMNByCollateral (dsq.masternodeOutpoint );
80- if (!dmn) return ;
78+ auto mnList = deterministicMNManager->GetListAtChainTip ();
79+ auto dmn = mnList.GetValidMNByCollateral (dsq.masternodeOutpoint );
80+ if (!dmn) return ;
8181
82- if (!dsq.CheckSignature (dmn->pdmnState ->pubKeyOperator .Get ())) {
83- LOCK (cs_main);
84- Misbehaving (pfrom->GetId (), 10 );
85- return ;
86- }
82+ if (!dsq.CheckSignature (dmn->pdmnState ->pubKeyOperator .Get ())) {
83+ LOCK (cs_main);
84+ Misbehaving (pfrom->GetId (), 10 );
85+ return ;
86+ }
8787
88- // if the queue is ready, submit if we can
89- if (dsq.fReady ) {
90- for (const auto & pair : coinJoinClientManagers) {
91- if (pair.second ->TrySubmitDenominate (dmn->pdmnState ->addr , connman)) {
92- LogPrint (BCLog::COINJOIN, " DSQUEUE -- CoinJoin queue (%s) is ready on masternode %s\n " , dsq.ToString (), dmn->pdmnState ->addr .ToString ());
93- return ;
94- }
95- }
96- } else {
97- int64_t nLastDsq = mmetaman.GetMetaInfo (dmn->proTxHash )->GetLastDsq ();
98- int64_t nDsqThreshold = mmetaman.GetDsqThreshold (dmn->proTxHash , mnList.GetValidMNsCount ());
99- LogPrint (BCLog::COINJOIN, " DSQUEUE -- nLastDsq: %d nDsqThreshold: %d nDsqCount: %d\n " , nLastDsq, nDsqThreshold, mmetaman.GetDsqCount ());
100- // don't allow a few nodes to dominate the queuing process
101- if (nLastDsq != 0 && nDsqThreshold > mmetaman.GetDsqCount ()) {
102- LogPrint (BCLog::COINJOIN, " DSQUEUE -- Masternode %s is sending too many dsq messages\n " , dmn->proTxHash .ToString ());
88+ // if the queue is ready, submit if we can
89+ if (dsq.fReady ) {
90+ for (const auto & [_, coinJoinMan] : coinJoinClientManagers) {
91+ if (coinJoinMan->TrySubmitDenominate (dmn->pdmnState ->addr , connman)) {
92+ LogPrint (BCLog::COINJOIN, " DSQUEUE -- CoinJoin queue (%s) is ready on masternode %s\n " , dsq.ToString (), dmn->pdmnState ->addr .ToString ());
10393 return ;
10494 }
95+ }
96+ } else {
97+ int64_t nLastDsq = mmetaman.GetMetaInfo (dmn->proTxHash )->GetLastDsq ();
98+ int64_t nDsqThreshold = mmetaman.GetDsqThreshold (dmn->proTxHash , mnList.GetValidMNsCount ());
99+ LogPrint (BCLog::COINJOIN, " DSQUEUE -- nLastDsq: %d nDsqThreshold: %d nDsqCount: %d\n " , nLastDsq, nDsqThreshold, mmetaman.GetDsqCount ());
100+ // don't allow a few nodes to dominate the queuing process
101+ if (nLastDsq != 0 && nDsqThreshold > mmetaman.GetDsqCount ()) {
102+ LogPrint (BCLog::COINJOIN, " DSQUEUE -- Masternode %s is sending too many dsq messages\n " , dmn->proTxHash .ToString ());
103+ return ;
104+ }
105105
106- mmetaman.AllowMixing (dmn->proTxHash );
106+ mmetaman.AllowMixing (dmn->proTxHash );
107107
108- LogPrint (BCLog::COINJOIN, " DSQUEUE -- new CoinJoin queue (%s) from masternode %s\n " , dsq.ToString (), dmn->pdmnState ->addr .ToString ());
108+ LogPrint (BCLog::COINJOIN, " DSQUEUE -- new CoinJoin queue (%s) from masternode %s\n " , dsq.ToString (), dmn->pdmnState ->addr .ToString ());
109109
110- for (const auto & pair : coinJoinClientManagers) {
111- if (pair.second ->MarkAlreadyJoinedQueueAsTried (dsq)) {
112- break ;
113- }
110+ for (const auto & [_, coinJoinMan] : coinJoinClientManagers) {
111+ if (coinJoinMan->MarkAlreadyJoinedQueueAsTried (dsq)) {
112+ break ;
114113 }
115-
116- TRY_LOCK (cs_vecqueue, lockRecv);
117- if (!lockRecv) return ;
118- vecCoinJoinQueue.push_back (dsq);
119- dsq.Relay (connman);
120114 }
121115
116+ TRY_LOCK (cs_vecqueue, lockRecv);
117+ if (!lockRecv) return ;
118+ vecCoinJoinQueue.push_back (dsq);
119+ dsq.Relay (connman);
122120 }
121+
123122}
124123
125124void CCoinJoinClientManager::ProcessMessage (CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman, bool enable_bip61)
@@ -479,11 +478,11 @@ bool CCoinJoinClientSession::SendDenominate(const std::vector<std::pair<CTxDSIn,
479478 std::vector<CTxDSIn> vecTxDSInTmp;
480479 std::vector<CTxOut> vecTxOutTmp;
481480
482- for (const auto & pair : vecPSInOutPairsIn) {
483- vecTxDSInTmp.emplace_back (pair. first );
484- vecTxOutTmp.emplace_back (pair. second );
485- tx.vin .emplace_back (pair. first );
486- tx.vout .emplace_back (pair. second );
481+ for (const auto & [txDsIn, txOut] : vecPSInOutPairsIn) {
482+ vecTxDSInTmp.emplace_back (txDsIn );
483+ vecTxOutTmp.emplace_back (txOut );
484+ tx.vin .emplace_back (txDsIn );
485+ tx.vout .emplace_back (txOut );
487486 }
488487
489488 LogPrint (BCLog::COINJOIN, " CCoinJoinClientSession::SendDenominate -- Submitting partial tx %s" , tx.ToString ()); /* Continued */
@@ -1053,7 +1052,7 @@ bool CCoinJoinClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymized,
10531052
10541053 // Look through the queues and see if anything matches
10551054 while (auto opt_dsq = coinJoinClientQueueManager.GetQueueItemAndTry ()) {
1056- auto dsq = *opt_dsq;
1055+ const auto & dsq = *opt_dsq;
10571056 auto dmn = mnList.GetValidMNByCollateral (dsq.masternodeOutpoint );
10581057
10591058 if (!dmn) {
@@ -1367,9 +1366,9 @@ std::optional<std::vector<std::pair<CTxDSIn, CTxOut>>> CCoinJoinClientSession::P
13671366 }
13681367
13691368 if (!fDryRun ) {
1370- for (const auto & pair : vecPSInOutPairsRet) {
1371- mixingWallet.LockCoin (pair. first .prevout );
1372- vecOutPointLocked.push_back (pair. first .prevout );
1369+ for (const auto & [txDsIn, _] : vecPSInOutPairsRet) {
1370+ mixingWallet.LockCoin (txDsIn .prevout );
1371+ vecOutPointLocked.push_back (txDsIn .prevout );
13731372 }
13741373 }
13751374
@@ -1541,7 +1540,7 @@ bool CCoinJoinClientSession::CreateCollateralTransaction(CMutableTransaction& tx
15411540 CScript scriptChange;
15421541 CPubKey vchPubKey;
15431542 CReserveKey reservekey (&mixingWallet);
1544- bool success = reservekey.GetReservedKey (vchPubKey, true );
1543+ [[maybe_unused]] bool success = reservekey.GetReservedKey (vchPubKey, true );
15451544 assert (success); // should never fail, as we just unlocked
15461545 scriptChange = GetScriptForDestination (vchPubKey.GetID ());
15471546 reservekey.KeepKey ();
@@ -1688,17 +1687,17 @@ bool CCoinJoinClientSession::CreateDenominated(CAmount nBalanceToDenominate, con
16881687 }
16891688
16901689 bool finished = true ;
1691- for (const auto it : mapDenomCount) {
1690+ for (const auto [denom, count] : mapDenomCount) {
16921691 // Check if this specific denom could use another loop, check that there aren't nCoinJoinDenomsGoal of this
16931692 // denom and that our nValueLeft/nBalanceToDenominate is enough to create one of these denoms, if so, loop again.
1694- if (it. second < CCoinJoinClientOptions::GetDenomsGoal () && txBuilder.CouldAddOutput (it. first ) && nBalanceToDenominate > 0 ) {
1693+ if (count < CCoinJoinClientOptions::GetDenomsGoal () && txBuilder.CouldAddOutput (denom ) && nBalanceToDenominate > 0 ) {
16951694 finished = false ;
16961695 LogPrint (BCLog::COINJOIN, " CCoinJoinClientSession::%s -- 1 - NOT finished - nDenomValue: %f, count: %d, nBalanceToDenominate: %f, %s\n " ,
1697- __func__, (float ) it. first / COIN, it. second , (float ) nBalanceToDenominate / COIN, txBuilder.ToString ());
1696+ __func__, (float ) denom / COIN, count , (float ) nBalanceToDenominate / COIN, txBuilder.ToString ());
16981697 break ;
16991698 }
17001699 LogPrint (BCLog::COINJOIN, " CCoinJoinClientSession::%s -- 1 - FINISHED - nDenomValue: %f, count: %d, nBalanceToDenominate: %f, %s\n " ,
1701- __func__, (float ) it. first / COIN, it. second , (float ) nBalanceToDenominate / COIN, txBuilder.ToString ());
1700+ __func__, (float ) denom / COIN, count , (float ) nBalanceToDenominate / COIN, txBuilder.ToString ());
17021701 }
17031702
17041703 if (finished) break ;
@@ -1767,8 +1766,8 @@ bool CCoinJoinClientSession::CreateDenominated(CAmount nBalanceToDenominate, con
17671766
17681767 LogPrint (BCLog::COINJOIN, " CCoinJoinClientSession::%s -- 3 - nBalanceToDenominate: %f, %s\n " , __func__, (float ) nBalanceToDenominate / COIN, txBuilder.ToString ());
17691768
1770- for (const auto it : mapDenomCount) {
1771- LogPrint (BCLog::COINJOIN, " CCoinJoinClientSession::%s -- 3 - DONE - nDenomValue: %f, count: %d\n " , __func__, (float ) it. first / COIN, it. second );
1769+ for (const auto [denom, count] : mapDenomCount) {
1770+ LogPrint (BCLog::COINJOIN, " CCoinJoinClientSession::%s -- 3 - DONE - nDenomValue: %f, count: %d\n " , __func__, (float ) denom / COIN, count );
17721771 }
17731772
17741773 // No reasons to create mixing collaterals if we can't create denoms to mix
@@ -1877,8 +1876,8 @@ void CCoinJoinClientManager::GetJsonInfo(UniValue& obj) const
18771876void DoCoinJoinMaintenance (CConnman& connman)
18781877{
18791878 coinJoinClientQueueManager.DoMaintenance ();
1880- for (const auto & pair : coinJoinClientManagers) {
1881- pair. second ->DoMaintenance (connman);
1879+ for (const auto & [_, coinJoinMan] : coinJoinClientManagers) {
1880+ coinJoinMan ->DoMaintenance (connman);
18821881 }
18831882}
18841883
0 commit comments