Introduce CDarksendAccept class (for DSACCEPT messages) (#1875)

This commit is contained in:
UdjinM6 2018-01-26 04:11:15 +03:00 committed by GitHub
parent 88646bd0d0
commit b1817dd936
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 28 deletions

View File

@ -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...");

View File

@ -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<C
return true;
}
bool CPrivateSendServer::IsAcceptableDenomAndCollateral(int nDenom, CTransaction txCollateral, PoolMessage& nMessageIDRet)
bool CPrivateSendServer::IsAcceptableDSA(const CDarksendAccept& dsa, PoolMessage& nMessageIDRet)
{
if(!fMasternodeMode) return false;
// is denom even smth legit?
std::vector<int> 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());

View File

@ -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(); }

View File

@ -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 <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(nDenom);
READWRITE(txCollateral);
}
};
// A clients transaction in the mixing pool
class CDarkSendEntry
{