mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
Introduce CDarksendAccept class (for DSACCEPT messages) (#1875)
This commit is contained in:
parent
88646bd0d0
commit
b1817dd936
@ -888,9 +888,9 @@ bool CPrivateSendClient::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CCon
|
|||||||
bool fSuccess = connman.ForNode(addr, CConnman::AllNodes, [&](CNode* pnode){
|
bool fSuccess = connman.ForNode(addr, CConnman::AllNodes, [&](CNode* pnode){
|
||||||
infoMixingMasternode = infoMn;
|
infoMixingMasternode = infoMn;
|
||||||
nSessionDenom = dsq.nDenom;
|
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)
|
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",
|
LogPrintf("CPrivateSendClient::JoinExistingQueue -- connected (from queue), sending DSACCEPT: nSessionDenom: %d (%s), addr=%s\n",
|
||||||
nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), pnode->addr.ToString());
|
nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), pnode->addr.ToString());
|
||||||
strAutoDenomResult = _("Mixing in progress...");
|
strAutoDenomResult = _("Mixing in progress...");
|
||||||
@ -962,9 +962,9 @@ bool CPrivateSendClient::StartNewQueue(CAmount nValueMin, CAmount nBalanceNeedsA
|
|||||||
while(nSessionDenom == 0) {
|
while(nSessionDenom == 0) {
|
||||||
nSessionDenom = CPrivateSend::GetDenominationsByAmounts(vecAmounts);
|
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)
|
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",
|
LogPrintf("CPrivateSendClient::StartNewQueue -- connected, sending DSACCEPT, nSessionDenom: %d (%s)\n",
|
||||||
nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom));
|
nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom));
|
||||||
strAutoDenomResult = _("Mixing in progress...");
|
strAutoDenomResult = _("Mixing in progress...");
|
||||||
|
@ -38,11 +38,10 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, std::string& strCommand, C
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nDenom;
|
CDarksendAccept dsa;
|
||||||
vRecv >> nDenom;
|
vRecv >> dsa;
|
||||||
CTransaction txCollateral(deserialize, vRecv);
|
|
||||||
|
|
||||||
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;
|
masternode_info_t mnInfo;
|
||||||
if(!mnodeman.GetMasternodeInfo(activeMasternode.outpoint, mnInfo)) {
|
if(!mnodeman.GetMasternodeInfo(activeMasternode.outpoint, mnInfo)) {
|
||||||
@ -60,8 +59,8 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, std::string& strCommand, C
|
|||||||
|
|
||||||
PoolMessage nMessageID = MSG_NOERR;
|
PoolMessage nMessageID = MSG_NOERR;
|
||||||
|
|
||||||
bool fResult = nSessionID == 0 ? CreateNewSession(nDenom, txCollateral, nMessageID, connman)
|
bool fResult = nSessionID == 0 ? CreateNewSession(dsa, nMessageID, connman)
|
||||||
: AddUserToExistingSession(nDenom, txCollateral, nMessageID);
|
: AddUserToExistingSession(dsa, nMessageID);
|
||||||
if(fResult) {
|
if(fResult) {
|
||||||
LogPrintf("DSACCEPT -- is compatible, please submit!\n");
|
LogPrintf("DSACCEPT -- is compatible, please submit!\n");
|
||||||
PushStatus(pfrom, STATUS_ACCEPTED, nMessageID, connman);
|
PushStatus(pfrom, STATUS_ACCEPTED, nMessageID, connman);
|
||||||
@ -684,21 +683,21 @@ bool CPrivateSendServer::IsOutputsCompatibleWithSessionDenom(const std::vector<C
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CPrivateSendServer::IsAcceptableDenomAndCollateral(int nDenom, CTransaction txCollateral, PoolMessage& nMessageIDRet)
|
bool CPrivateSendServer::IsAcceptableDSA(const CDarksendAccept& dsa, PoolMessage& nMessageIDRet)
|
||||||
{
|
{
|
||||||
if(!fMasternodeMode) return false;
|
if(!fMasternodeMode) return false;
|
||||||
|
|
||||||
// is denom even smth legit?
|
// is denom even smth legit?
|
||||||
std::vector<int> vecBits;
|
std::vector<int> vecBits;
|
||||||
if(!CPrivateSend::GetDenominationsBits(nDenom, vecBits)) {
|
if(!CPrivateSend::GetDenominationsBits(dsa.nDenom, vecBits)) {
|
||||||
LogPrint("privatesend", "CPrivateSendServer::IsAcceptableDenomAndCollateral -- denom not valid!\n");
|
LogPrint("privatesend", "CPrivateSendServer::%s -- denom not valid!\n", __func__);
|
||||||
nMessageIDRet = ERR_DENOM;
|
nMessageIDRet = ERR_DENOM;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check collateral
|
// check collateral
|
||||||
if(!fUnitTest && !CPrivateSend::IsCollateralValid(txCollateral)) {
|
if(!fUnitTest && !CPrivateSend::IsCollateralValid(dsa.txCollateral)) {
|
||||||
LogPrint("privatesend", "CPrivateSendServer::IsAcceptableDenomAndCollateral -- collateral not valid!\n");
|
LogPrint("privatesend", "CPrivateSendServer::%s -- collateral not valid!\n", __func__);
|
||||||
nMessageIDRet = ERR_INVALID_COLLATERAL;
|
nMessageIDRet = ERR_INVALID_COLLATERAL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -706,7 +705,7 @@ bool CPrivateSendServer::IsAcceptableDenomAndCollateral(int nDenom, CTransaction
|
|||||||
return true;
|
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;
|
if(!fMasternodeMode || nSessionID != 0) return false;
|
||||||
|
|
||||||
@ -717,39 +716,39 @@ bool CPrivateSendServer::CreateNewSession(int nDenom, CTransaction txCollateral,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!IsAcceptableDenomAndCollateral(nDenom, txCollateral, nMessageIDRet)) {
|
if(!IsAcceptableDSA(dsa, nMessageIDRet)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// start new session
|
// start new session
|
||||||
nMessageIDRet = MSG_NOERR;
|
nMessageIDRet = MSG_NOERR;
|
||||||
nSessionID = GetRandInt(999999)+1;
|
nSessionID = GetRandInt(999999)+1;
|
||||||
nSessionDenom = nDenom;
|
nSessionDenom = dsa.nDenom;
|
||||||
|
|
||||||
SetState(POOL_STATE_QUEUE);
|
SetState(POOL_STATE_QUEUE);
|
||||||
nTimeLastSuccessfulStep = GetTimeMillis();
|
nTimeLastSuccessfulStep = GetTimeMillis();
|
||||||
|
|
||||||
if(!fUnitTest) {
|
if(!fUnitTest) {
|
||||||
//broadcast that I'm accepting entries, only if it's the first entry through
|
//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());
|
LogPrint("privatesend", "CPrivateSendServer::CreateNewSession -- signing and relaying new queue: %s\n", dsq.ToString());
|
||||||
dsq.Sign();
|
dsq.Sign();
|
||||||
dsq.Relay(connman);
|
dsq.Relay(connman);
|
||||||
vecDarksendQueue.push_back(dsq);
|
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",
|
LogPrintf("CPrivateSendServer::CreateNewSession -- new session created, nSessionID: %d nSessionDenom: %d (%s) vecSessionCollaterals.size(): %d\n",
|
||||||
nSessionID, nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), vecSessionCollaterals.size());
|
nSessionID, nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), vecSessionCollaterals.size());
|
||||||
|
|
||||||
return true;
|
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(!fMasternodeMode || nSessionID == 0 || IsSessionReady()) return false;
|
||||||
|
|
||||||
if(!IsAcceptableDenomAndCollateral(nDenom, txCollateral, nMessageIDRet)) {
|
if(!IsAcceptableDSA(dsa, nMessageIDRet)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -760,9 +759,9 @@ bool CPrivateSendServer::AddUserToExistingSession(int nDenom, CTransaction txCol
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nDenom != nSessionDenom) {
|
if(dsa.nDenom != nSessionDenom) {
|
||||||
LogPrintf("CPrivateSendServer::AddUserToExistingSession -- incompatible denom %d (%s) != nSessionDenom %d (%s)\n",
|
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;
|
nMessageIDRet = ERR_DENOM;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -771,7 +770,7 @@ bool CPrivateSendServer::AddUserToExistingSession(int nDenom, CTransaction txCol
|
|||||||
|
|
||||||
nMessageIDRet = MSG_NOERR;
|
nMessageIDRet = MSG_NOERR;
|
||||||
nTimeLastSuccessfulStep = GetTimeMillis();
|
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",
|
LogPrintf("CPrivateSendServer::AddUserToExistingSession -- new user accepted, nSessionID: %d nSessionDenom: %d (%s) vecSessionCollaterals.size(): %d\n",
|
||||||
nSessionID, nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), vecSessionCollaterals.size());
|
nSessionID, nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), vecSessionCollaterals.size());
|
||||||
|
@ -41,9 +41,9 @@ private:
|
|||||||
void CommitFinalTransaction(CConnman& connman);
|
void CommitFinalTransaction(CConnman& connman);
|
||||||
|
|
||||||
/// Is this nDenom and txCollateral acceptable?
|
/// Is this nDenom and txCollateral acceptable?
|
||||||
bool IsAcceptableDenomAndCollateral(int nDenom, CTransaction txCollateral, PoolMessage &nMessageIDRet);
|
bool IsAcceptableDSA(const CDarksendAccept& dsa, PoolMessage &nMessageIDRet);
|
||||||
bool CreateNewSession(int nDenom, CTransaction txCollateral, PoolMessage &nMessageIDRet, CConnman& connman);
|
bool CreateNewSession(const CDarksendAccept& dsa, PoolMessage &nMessageIDRet, CConnman& connman);
|
||||||
bool AddUserToExistingSession(int nDenom, CTransaction txCollateral, PoolMessage &nMessageIDRet);
|
bool AddUserToExistingSession(const CDarksendAccept& dsa, PoolMessage &nMessageIDRet);
|
||||||
/// Do we have enough users to take entries?
|
/// Do we have enough users to take entries?
|
||||||
bool IsSessionReady() { return (int)vecSessionCollaterals.size() >= CPrivateSend::GetMaxPoolTransactions(); }
|
bool IsSessionReady() { return (int)vecSessionCollaterals.size() >= CPrivateSend::GetMaxPoolTransactions(); }
|
||||||
|
|
||||||
|
@ -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
|
// A clients transaction in the mixing pool
|
||||||
class CDarkSendEntry
|
class CDarkSendEntry
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user