diff --git a/src/privatesend-client.cpp b/src/privatesend-client.cpp index 2d5b80d19f..b9934c8b74 100644 --- a/src/privatesend-client.cpp +++ b/src/privatesend-client.cpp @@ -888,9 +888,9 @@ bool CPrivateSendClient::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CCon bool fSuccess = connman.ForNode(addr, CConnman::AllNodes, [&](CNode* pnode){ infoMixingMasternode = infoMn; nSessionDenom = dsq.nDenom; - + CDarksendAccept dsa(nSessionDenom, txMyCollateral); CNetMsgMaker msgMaker(pnode->GetSendVersion()); // TODO this gives a warning about version not being set (we should wait for VERSION exchange) - connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSACCEPT, nSessionDenom, txMyCollateral)); + connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSACCEPT, dsa)); LogPrintf("CPrivateSendClient::JoinExistingQueue -- connected (from queue), sending DSACCEPT: nSessionDenom: %d (%s), addr=%s\n", nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), pnode->addr.ToString()); strAutoDenomResult = _("Mixing in progress..."); @@ -962,9 +962,9 @@ bool CPrivateSendClient::StartNewQueue(CAmount nValueMin, CAmount nBalanceNeedsA while(nSessionDenom == 0) { nSessionDenom = CPrivateSend::GetDenominationsByAmounts(vecAmounts); } - + CDarksendAccept dsa(nSessionDenom, txMyCollateral); CNetMsgMaker msgMaker(pnode->GetSendVersion()); // TODO this gives a warning about version not being set (we should wait for VERSION exchange) - connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSACCEPT, nSessionDenom, txMyCollateral)); + connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSACCEPT, dsa)); LogPrintf("CPrivateSendClient::StartNewQueue -- connected, sending DSACCEPT, nSessionDenom: %d (%s)\n", nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom)); strAutoDenomResult = _("Mixing in progress..."); diff --git a/src/privatesend-server.cpp b/src/privatesend-server.cpp index 611dd47d38..edf92736a5 100644 --- a/src/privatesend-server.cpp +++ b/src/privatesend-server.cpp @@ -38,11 +38,10 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, std::string& strCommand, C return; } - int nDenom; - vRecv >> nDenom; - CTransaction txCollateral(deserialize, vRecv); + CDarksendAccept dsa; + vRecv >> dsa; - LogPrint("privatesend", "DSACCEPT -- nDenom %d (%s) txCollateral %s", nDenom, CPrivateSend::GetDenominationsToString(nDenom), txCollateral.ToString()); + LogPrint("privatesend", "DSACCEPT -- nDenom %d (%s) txCollateral %s", dsa.nDenom, CPrivateSend::GetDenominationsToString(dsa.nDenom), dsa.txCollateral.ToString()); masternode_info_t mnInfo; if(!mnodeman.GetMasternodeInfo(activeMasternode.outpoint, mnInfo)) { @@ -60,8 +59,8 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, std::string& strCommand, C PoolMessage nMessageID = MSG_NOERR; - bool fResult = nSessionID == 0 ? CreateNewSession(nDenom, txCollateral, nMessageID, connman) - : AddUserToExistingSession(nDenom, txCollateral, nMessageID); + bool fResult = nSessionID == 0 ? CreateNewSession(dsa, nMessageID, connman) + : AddUserToExistingSession(dsa, nMessageID); if(fResult) { LogPrintf("DSACCEPT -- is compatible, please submit!\n"); PushStatus(pfrom, STATUS_ACCEPTED, nMessageID, connman); @@ -684,21 +683,21 @@ bool CPrivateSendServer::IsOutputsCompatibleWithSessionDenom(const std::vector vecBits; - if(!CPrivateSend::GetDenominationsBits(nDenom, vecBits)) { - LogPrint("privatesend", "CPrivateSendServer::IsAcceptableDenomAndCollateral -- denom not valid!\n"); + if(!CPrivateSend::GetDenominationsBits(dsa.nDenom, vecBits)) { + LogPrint("privatesend", "CPrivateSendServer::%s -- denom not valid!\n", __func__); nMessageIDRet = ERR_DENOM; return false; } // check collateral - if(!fUnitTest && !CPrivateSend::IsCollateralValid(txCollateral)) { - LogPrint("privatesend", "CPrivateSendServer::IsAcceptableDenomAndCollateral -- collateral not valid!\n"); + if(!fUnitTest && !CPrivateSend::IsCollateralValid(dsa.txCollateral)) { + LogPrint("privatesend", "CPrivateSendServer::%s -- collateral not valid!\n", __func__); nMessageIDRet = ERR_INVALID_COLLATERAL; return false; } @@ -706,7 +705,7 @@ bool CPrivateSendServer::IsAcceptableDenomAndCollateral(int nDenom, CTransaction return true; } -bool CPrivateSendServer::CreateNewSession(int nDenom, CTransaction txCollateral, PoolMessage& nMessageIDRet, CConnman& connman) +bool CPrivateSendServer::CreateNewSession(const CDarksendAccept& dsa, PoolMessage& nMessageIDRet, CConnman& connman) { if(!fMasternodeMode || nSessionID != 0) return false; @@ -717,39 +716,39 @@ bool CPrivateSendServer::CreateNewSession(int nDenom, CTransaction txCollateral, return false; } - if(!IsAcceptableDenomAndCollateral(nDenom, txCollateral, nMessageIDRet)) { + if(!IsAcceptableDSA(dsa, nMessageIDRet)) { return false; } // start new session nMessageIDRet = MSG_NOERR; nSessionID = GetRandInt(999999)+1; - nSessionDenom = nDenom; + nSessionDenom = dsa.nDenom; SetState(POOL_STATE_QUEUE); nTimeLastSuccessfulStep = GetTimeMillis(); if(!fUnitTest) { //broadcast that I'm accepting entries, only if it's the first entry through - CDarksendQueue dsq(nDenom, activeMasternode.outpoint, GetAdjustedTime(), false); + CDarksendQueue dsq(dsa.nDenom, activeMasternode.outpoint, GetAdjustedTime(), false); LogPrint("privatesend", "CPrivateSendServer::CreateNewSession -- signing and relaying new queue: %s\n", dsq.ToString()); dsq.Sign(); dsq.Relay(connman); vecDarksendQueue.push_back(dsq); } - vecSessionCollaterals.push_back(MakeTransactionRef(txCollateral)); + vecSessionCollaterals.push_back(MakeTransactionRef(dsa.txCollateral)); LogPrintf("CPrivateSendServer::CreateNewSession -- new session created, nSessionID: %d nSessionDenom: %d (%s) vecSessionCollaterals.size(): %d\n", nSessionID, nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), vecSessionCollaterals.size()); return true; } -bool CPrivateSendServer::AddUserToExistingSession(int nDenom, CTransaction txCollateral, PoolMessage& nMessageIDRet) +bool CPrivateSendServer::AddUserToExistingSession(const CDarksendAccept& dsa, PoolMessage& nMessageIDRet) { if(!fMasternodeMode || nSessionID == 0 || IsSessionReady()) return false; - if(!IsAcceptableDenomAndCollateral(nDenom, txCollateral, nMessageIDRet)) { + if(!IsAcceptableDSA(dsa, nMessageIDRet)) { return false; } @@ -760,9 +759,9 @@ bool CPrivateSendServer::AddUserToExistingSession(int nDenom, CTransaction txCol return false; } - if(nDenom != nSessionDenom) { + if(dsa.nDenom != nSessionDenom) { LogPrintf("CPrivateSendServer::AddUserToExistingSession -- incompatible denom %d (%s) != nSessionDenom %d (%s)\n", - nDenom, CPrivateSend::GetDenominationsToString(nDenom), nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom)); + dsa.nDenom, CPrivateSend::GetDenominationsToString(dsa.nDenom), nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom)); nMessageIDRet = ERR_DENOM; return false; } @@ -771,7 +770,7 @@ bool CPrivateSendServer::AddUserToExistingSession(int nDenom, CTransaction txCol nMessageIDRet = MSG_NOERR; nTimeLastSuccessfulStep = GetTimeMillis(); - vecSessionCollaterals.push_back(MakeTransactionRef(txCollateral)); + vecSessionCollaterals.push_back(MakeTransactionRef(dsa.txCollateral)); LogPrintf("CPrivateSendServer::AddUserToExistingSession -- new user accepted, nSessionID: %d nSessionDenom: %d (%s) vecSessionCollaterals.size(): %d\n", nSessionID, nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), vecSessionCollaterals.size()); diff --git a/src/privatesend-server.h b/src/privatesend-server.h index f6b09c7ff8..b6d205259b 100644 --- a/src/privatesend-server.h +++ b/src/privatesend-server.h @@ -41,9 +41,9 @@ private: void CommitFinalTransaction(CConnman& connman); /// Is this nDenom and txCollateral acceptable? - bool IsAcceptableDenomAndCollateral(int nDenom, CTransaction txCollateral, PoolMessage &nMessageIDRet); - bool CreateNewSession(int nDenom, CTransaction txCollateral, PoolMessage &nMessageIDRet, CConnman& connman); - bool AddUserToExistingSession(int nDenom, CTransaction txCollateral, PoolMessage &nMessageIDRet); + bool IsAcceptableDSA(const CDarksendAccept& dsa, PoolMessage &nMessageIDRet); + bool CreateNewSession(const CDarksendAccept& dsa, PoolMessage &nMessageIDRet, CConnman& connman); + bool AddUserToExistingSession(const CDarksendAccept& dsa, PoolMessage &nMessageIDRet); /// Do we have enough users to take entries? bool IsSessionReady() { return (int)vecSessionCollaterals.size() >= CPrivateSend::GetMaxPoolTransactions(); } diff --git a/src/privatesend.h b/src/privatesend.h index 37a413c449..eea4e5acc2 100644 --- a/src/privatesend.h +++ b/src/privatesend.h @@ -98,6 +98,31 @@ public: {} }; +class CDarksendAccept +{ +public: + int nDenom; + CMutableTransaction txCollateral; + + CDarksendAccept() : + nDenom(0), + txCollateral(CMutableTransaction()) + {}; + + CDarksendAccept(int nDenom, const CMutableTransaction& txCollateral) : + nDenom(nDenom), + txCollateral(txCollateral) + {}; + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream& s, Operation ser_action) { + READWRITE(nDenom); + READWRITE(txCollateral); + } +}; + // A clients transaction in the mixing pool class CDarkSendEntry {