Stop reporting/processing the number of mixing participants in DSSTATUSUPDATE (#2980)

* Stop reporting/processing the number of mixing participants

* Introduce CPrivateSendStatusUpdate class to encapsulate serialization of DSSTATUSUPDATE msg

And make corresponding enums serializable too.

* Revert range checks removal
This commit is contained in:
UdjinM6 2019-06-18 14:33:30 +03:00 committed by GitHub
parent 7334aa553c
commit 8d5781f408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 65 deletions

View File

@ -147,32 +147,28 @@ void CPrivateSendClientSession::ProcessMessage(CNode* pfrom, const std::string&
return;
}
int nMsgSessionID;
int nMsgState;
int nMsgEntriesCount;
int nMsgStatusUpdate;
int nMsgMessageID;
vRecv >> nMsgSessionID >> nMsgState >> nMsgEntriesCount >> nMsgStatusUpdate >> nMsgMessageID;
CPrivateSendStatusUpdate psssup;
vRecv >> psssup;
if (nMsgState < POOL_STATE_MIN || nMsgState > POOL_STATE_MAX) {
LogPrint(BCLog::PRIVATESEND, "DSSTATUSUPDATE -- nMsgState is out of bounds: %d\n", nMsgState);
if (psssup.nState < POOL_STATE_MIN || psssup.nState > POOL_STATE_MAX) {
LogPrint(BCLog::PRIVATESEND, "DSSTATUSUPDATE -- psssup.nState is out of bounds: %d\n", psssup.nState);
return;
}
if (nMsgStatusUpdate < STATUS_REJECTED || nMsgStatusUpdate > STATUS_ACCEPTED) {
LogPrint(BCLog::PRIVATESEND, "DSSTATUSUPDATE -- nMsgStatusUpdate is out of bounds: %d\n", nMsgStatusUpdate);
if (psssup.nStatusUpdate < STATUS_REJECTED || psssup.nStatusUpdate > STATUS_ACCEPTED) {
LogPrint(BCLog::PRIVATESEND, "DSSTATUSUPDATE -- psssup.nStatusUpdate is out of bounds: %d\n", psssup.nStatusUpdate);
return;
}
if (nMsgMessageID < MSG_POOL_MIN || nMsgMessageID > MSG_POOL_MAX) {
LogPrint(BCLog::PRIVATESEND, "DSSTATUSUPDATE -- nMsgMessageID is out of bounds: %d\n", nMsgMessageID);
if (psssup.nMessageID < MSG_POOL_MIN || psssup.nMessageID > MSG_POOL_MAX) {
LogPrint(BCLog::PRIVATESEND, "DSSTATUSUPDATE -- psssup.nMessageID is out of bounds: %d\n", psssup.nMessageID);
return;
}
LogPrint(BCLog::PRIVATESEND, "DSSTATUSUPDATE -- nMsgSessionID %d nMsgState: %d nEntriesCount: %d nMsgStatusUpdate: %d nMsgMessageID %d (%s)\n",
nMsgSessionID, nMsgState, nEntriesCount, nMsgStatusUpdate, nMsgMessageID, CPrivateSend::GetMessageByID(PoolMessage(nMsgMessageID)));
LogPrint(BCLog::PRIVATESEND, "DSSTATUSUPDATE -- psssup.nSessionID %d psssup.nState: %d psssup.nStatusUpdate: %d psssup.nMessageID %d (%s)\n",
psssup.nSessionID, psssup.nState, psssup.nStatusUpdate, psssup.nMessageID, CPrivateSend::GetMessageByID(psssup.nMessageID));
if (!CheckPoolStateUpdate(PoolState(nMsgState), nMsgEntriesCount, PoolStatusUpdate(nMsgStatusUpdate), PoolMessage(nMsgMessageID), nMsgSessionID)) {
if (!CheckPoolStateUpdate(psssup)) {
LogPrint(BCLog::PRIVATESEND, "DSSTATUSUPDATE -- CheckPoolStateUpdate failed\n");
}
@ -217,7 +213,7 @@ void CPrivateSendClientSession::ProcessMessage(CNode* pfrom, const std::string&
}
int nMsgSessionID;
int nMsgMessageID;
PoolMessage nMsgMessageID;
vRecv >> nMsgSessionID >> nMsgMessageID;
if (nMsgMessageID < MSG_POOL_MIN || nMsgMessageID > MSG_POOL_MAX) {
@ -230,9 +226,9 @@ void CPrivateSendClientSession::ProcessMessage(CNode* pfrom, const std::string&
return;
}
LogPrint(BCLog::PRIVATESEND, "DSCOMPLETE -- nMsgSessionID %d nMsgMessageID %d (%s)\n", nMsgSessionID, nMsgMessageID, CPrivateSend::GetMessageByID(PoolMessage(nMsgMessageID)));
LogPrint(BCLog::PRIVATESEND, "DSCOMPLETE -- nMsgSessionID %d nMsgMessageID %d (%s)\n", nMsgSessionID, nMsgMessageID, CPrivateSend::GetMessageByID(nMsgMessageID));
CompletedTransaction(PoolMessage(nMsgMessageID));
CompletedTransaction(nMsgMessageID);
}
}
@ -258,8 +254,6 @@ void CPrivateSendClientManager::ResetPool()
void CPrivateSendClientSession::SetNull()
{
// Client side
nEntriesCount = 0;
fLastEntryAccepted = false;
mixingMasternode = nullptr;
pendingDsaRequest = CPendingDsaRequest();
@ -309,26 +303,7 @@ std::string CPrivateSendClientSession::GetStatus(bool fWaitForBlock)
strSuffix = "...";
return strprintf(_("Submitted to masternode, waiting in queue %s"), strSuffix);
case POOL_STATE_ACCEPTING_ENTRIES:
if (nEntriesCount == 0) {
nStatusMessageProgress = 0;
return strAutoDenomResult;
} else if (fLastEntryAccepted) {
if (nStatusMessageProgress % 10 > 8) {
fLastEntryAccepted = false;
nStatusMessageProgress = 0;
}
return _("PrivateSend request complete:") + " " + _("Your transaction was accepted into the pool!");
} else {
if (nStatusMessageProgress % 70 <= 40)
return strprintf(_("Submitted following entries to masternode: %u"), nEntriesCount);
else if (nStatusMessageProgress % 70 <= 50)
strSuffix = ".";
else if (nStatusMessageProgress % 70 <= 60)
strSuffix = "..";
else if (nStatusMessageProgress % 70 <= 70)
strSuffix = "...";
return strprintf(_("Submitted to masternode, waiting for more entries ( %u ) %s"), nEntriesCount, strSuffix);
}
return strAutoDenomResult;
case POOL_STATE_SIGNING:
if (nStatusMessageProgress % 70 <= 40)
return _("Found enough users, signing ...");
@ -532,39 +507,33 @@ bool CPrivateSendClientSession::SendDenominate(const std::vector<std::pair<CTxDS
}
// Incoming message from Masternode updating the progress of mixing
bool CPrivateSendClientSession::CheckPoolStateUpdate(PoolState nStateNew, int nEntriesCountNew, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID, int nSessionIDNew)
bool CPrivateSendClientSession::CheckPoolStateUpdate(CPrivateSendStatusUpdate psssup)
{
if (fMasternodeMode) return false;
// do not update state when mixing client state is one of these
if (nState == POOL_STATE_IDLE || nState == POOL_STATE_ERROR || nState == POOL_STATE_SUCCESS) return false;
strAutoDenomResult = _("Masternode:") + " " + CPrivateSend::GetMessageByID(nMessageID);
strAutoDenomResult = _("Masternode:") + " " + CPrivateSend::GetMessageByID(psssup.nMessageID);
// if rejected at any state
if (nStatusUpdate == STATUS_REJECTED) {
if (psssup.nStatusUpdate == STATUS_REJECTED) {
LogPrintf("CPrivateSendClientSession::CheckPoolStateUpdate -- entry is rejected by Masternode\n");
UnlockCoins();
keyHolderStorage.ReturnAll();
SetNull();
SetState(POOL_STATE_ERROR);
strLastMessage = CPrivateSend::GetMessageByID(nMessageID);
strLastMessage = CPrivateSend::GetMessageByID(psssup.nMessageID);
return true;
}
if (nStatusUpdate == STATUS_ACCEPTED && nState == nStateNew) {
if (nStateNew == POOL_STATE_QUEUE && nSessionID == 0 && nSessionIDNew != 0) {
if (psssup.nStatusUpdate == STATUS_ACCEPTED && nState == psssup.nState) {
if (psssup.nState == POOL_STATE_QUEUE && nSessionID == 0 && psssup.nSessionID != 0) {
// new session id should be set only in POOL_STATE_QUEUE state
nSessionID = nSessionIDNew;
nSessionID = psssup.nSessionID;
nTimeLastSuccessfulStep = GetTime();
LogPrintf("CPrivateSendClientSession::CheckPoolStateUpdate -- set nSessionID to %d\n", nSessionID);
return true;
} else if (nStateNew == POOL_STATE_ACCEPTING_ENTRIES && nEntriesCount != nEntriesCountNew) {
nEntriesCount = nEntriesCountNew;
nTimeLastSuccessfulStep = GetTime();
fLastEntryAccepted = true;
LogPrintf("CPrivateSendClientSession::CheckPoolStateUpdate -- new entry accepted!\n");
return true;
}
}

View File

@ -90,9 +90,6 @@ class CPrivateSendClientSession : public CPrivateSendBaseSession
private:
std::vector<COutPoint> vecOutPointLocked;
int nEntriesCount;
bool fLastEntryAccepted;
std::string strLastMessage;
std::string strAutoDenomResult;
@ -121,7 +118,7 @@ private:
bool SendDenominate(const std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsIn, CConnman& connman);
/// Get Masternode updates about the progress of mixing
bool CheckPoolStateUpdate(PoolState nStateNew, int nEntriesCountNew, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID, int nSessionIDNew = 0);
bool CheckPoolStateUpdate(CPrivateSendStatusUpdate psssup);
// Set the 'state' value, with some logging and capturing when the state changed
void SetState(PoolState nStateNew);
@ -139,8 +136,6 @@ private:
public:
CPrivateSendClientSession() :
vecOutPointLocked(),
nEntriesCount(0),
fLastEntryAccepted(false),
strLastMessage(),
strAutoDenomResult(),
mixingMasternode(),

View File

@ -850,8 +850,8 @@ void CPrivateSendServer::RelayFinalTransaction(const CTransaction& txFinal, CCon
void CPrivateSendServer::PushStatus(CNode* pnode, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID, CConnman& connman)
{
if (!pnode) return;
CNetMsgMaker msgMaker(pnode->GetSendVersion());
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSSTATUSUPDATE, nSessionID, (int)nState, (int)vecEntries.size(), (int)nStatusUpdate, (int)nMessageID));
CPrivateSendStatusUpdate psssup(nSessionID, nState, 0, nStatusUpdate, nMessageID);
connman.PushMessage(pnode, CNetMsgMaker(pnode->GetSendVersion()).Make(NetMsgType::DSSTATUSUPDATE, psssup));
}
void CPrivateSendServer::RelayStatus(PoolStatusUpdate nStatusUpdate, CConnman& connman, PoolMessage nMessageID)
@ -899,7 +899,7 @@ void CPrivateSendServer::RelayCompletedTransaction(PoolMessage nMessageID, CConn
for (const auto& entry : vecEntries) {
bool fOk = connman.ForNode(entry.addr, [&nMessageID, &connman, this](CNode* pnode) {
CNetMsgMaker msgMaker(pnode->GetSendVersion());
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSCOMPLETE, nSessionID, (int)nMessageID));
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSCOMPLETE, nSessionID, nMessageID));
return true;
});
if (!fOk) {

View File

@ -29,7 +29,7 @@ static const int MIN_PRIVATESEND_PEER_PROTO_VERSION = 70213;
static const size_t PRIVATESEND_ENTRY_MAX_SIZE = 9;
// pool responses
enum PoolMessage {
enum PoolMessage : int32_t {
ERR_ALREADY_HAVE,
ERR_DENOM,
ERR_ENTRIES_FULL,
@ -56,9 +56,10 @@ enum PoolMessage {
MSG_POOL_MIN = ERR_ALREADY_HAVE,
MSG_POOL_MAX = ERR_SIZE_MISMATCH
};
template<> struct is_serializable_enum<PoolMessage> : std::true_type {};
// pool states
enum PoolState {
enum PoolState : int32_t {
POOL_STATE_IDLE,
POOL_STATE_QUEUE,
POOL_STATE_ACCEPTING_ENTRIES,
@ -68,12 +69,52 @@ enum PoolState {
POOL_STATE_MIN = POOL_STATE_IDLE,
POOL_STATE_MAX = POOL_STATE_SUCCESS
};
template<> struct is_serializable_enum<PoolState> : std::true_type {};
// status update message constants
enum PoolStatusUpdate {
enum PoolStatusUpdate : int32_t {
STATUS_REJECTED,
STATUS_ACCEPTED
};
template<> struct is_serializable_enum<PoolStatusUpdate> : std::true_type {};
class CPrivateSendStatusUpdate
{
public:
int nSessionID;
PoolState nState;
int nEntriesCount; // deprecated, kept for backwards compatibility
PoolStatusUpdate nStatusUpdate;
PoolMessage nMessageID;
CPrivateSendStatusUpdate() :
nSessionID(0),
nState(POOL_STATE_IDLE),
nEntriesCount(0),
nStatusUpdate(STATUS_ACCEPTED),
nMessageID(MSG_NOERR) {};
CPrivateSendStatusUpdate(int nSessionID, PoolState nState, int nEntriesCount, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID) :
nSessionID(nSessionID),
nState(nState),
nEntriesCount(nEntriesCount),
nStatusUpdate(nStatusUpdate),
nMessageID(nMessageID) {};
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(nSessionID);
READWRITE(nState);
if (s.GetVersion() <= 702015) {
READWRITE(nEntriesCount);
}
READWRITE(nStatusUpdate);
READWRITE(nMessageID);
}
};
/** Holds a mixing input
*/