Skip to content

Commit 8c9cb29

Browse files
authored
Revert 2075 (#2259)
* Revert "Require all participants to submit equal number of inputs (#2075)" This reverts commit 7ac4b97. * Backward compatibility for nInputCount
1 parent b164bcc commit 8c9cb29

File tree

4 files changed

+24
-99
lines changed

4 files changed

+24
-99
lines changed

src/privatesend-client.cpp

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ void CPrivateSendClientManager::ProcessMessage(CNode* pfrom, const std::string&
6060
LogPrint("privatesend", "DSQUEUE -- %s new\n", dsq.ToString());
6161

6262
if(dsq.IsExpired()) return;
63-
if(dsq.nInputCount < 0 || dsq.nInputCount > PRIVATESEND_ENTRY_MAX_SIZE) return;
6463

6564
masternode_info_t infoMn;
6665
if(!mnodeman.GetMasternodeInfo(dsq.masternodeOutpoint, infoMn)) return;
@@ -1035,16 +1034,10 @@ bool CPrivateSendClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymize
10351034
std::vector<COutput> vCoinsTmp;
10361035
CAmount nMinAmount = vecStandardDenoms[vecBits.front()];
10371036
CAmount nMaxAmount = nBalanceNeedsAnonymized;
1038-
// nInputCount is not covered by legacy signature, require SPORK_6_NEW_SIGS to activate to use new algo
1039-
// (to make sure nInputCount wasn't modified by some intermediary node)
1040-
bool fNewAlgo = infoMn.nProtocolVersion > 70208 && sporkManager.IsSporkActive(SPORK_6_NEW_SIGS);
10411037

1042-
if (fNewAlgo && dsq.nInputCount != 0) {
1043-
nMinAmount = nMaxAmount = dsq.nInputCount * vecStandardDenoms[vecBits.front()];
1044-
}
10451038
// Try to match their denominations if possible, select exact number of denominations
10461039
if(!pwalletMain->SelectCoinsByDenominations(dsq.nDenom, nMinAmount, nMaxAmount, vecTxDSInTmp, vCoinsTmp, nValueInTmp, 0, privateSendClient.nPrivateSendRounds)) {
1047-
LogPrintf("CPrivateSendClientSession::JoinExistingQueue -- Couldn't match %d denominations %d %d (%s)\n", dsq.nInputCount, vecBits.front(), dsq.nDenom, CPrivateSend::GetDenominationsToString(dsq.nDenom));
1040+
LogPrintf("CPrivateSendClientSession::JoinExistingQueue -- Couldn't match %d denominations %d (%s)\n", vecBits.front(), dsq.nDenom, CPrivateSend::GetDenominationsToString(dsq.nDenom));
10481041
continue;
10491042
}
10501043

@@ -1056,15 +1049,14 @@ bool CPrivateSendClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymize
10561049
}
10571050

10581051
nSessionDenom = dsq.nDenom;
1059-
nSessionInputCount = fNewAlgo ? dsq.nInputCount : 0;
10601052
infoMixingMasternode = infoMn;
1061-
pendingDsaRequest = CPendingDsaRequest(infoMn.addr, CDarksendAccept(nSessionDenom, nSessionInputCount, txMyCollateral));
1053+
pendingDsaRequest = CPendingDsaRequest(infoMn.addr, CDarksendAccept(nSessionDenom, txMyCollateral));
10621054
connman.AddPendingMasternode(infoMn.addr);
10631055
// TODO: add new state POOL_STATE_CONNECTING and bump MIN_PRIVATESEND_PEER_PROTO_VERSION
10641056
SetState(POOL_STATE_QUEUE);
10651057
nTimeLastSuccessfulStep = GetTime();
1066-
LogPrintf("CPrivateSendClientSession::JoinExistingQueue -- pending connection (from queue): nSessionDenom: %d (%s), nSessionInputCount: %d, addr=%s\n",
1067-
nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), nSessionInputCount, infoMn.addr.ToString());
1058+
LogPrintf("CPrivateSendClientSession::JoinExistingQueue -- pending connection (from queue): nSessionDenom: %d (%s), addr=%s\n",
1059+
nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), infoMn.addr.ToString());
10681060
strAutoDenomResult = _("Trying to connect...");
10691061
return true;
10701062
}
@@ -1132,37 +1124,14 @@ bool CPrivateSendClientSession::StartNewQueue(CAmount nValueMin, CAmount nBalanc
11321124
nSessionDenom = CPrivateSend::GetDenominationsByAmounts(vecAmounts);
11331125
}
11341126

1135-
// Count available denominations.
1136-
// Should never really fail after this point, since we just selected compatible inputs ourselves.
1137-
std::vector<int> vecBits;
1138-
if (!CPrivateSend::GetDenominationsBits(nSessionDenom, vecBits)) {
1139-
return false;
1140-
}
1141-
1142-
CAmount nValueInTmp = 0;
1143-
std::vector<CTxDSIn> vecTxDSInTmp;
1144-
std::vector<COutput> vCoinsTmp;
1145-
std::vector<CAmount> vecStandardDenoms = CPrivateSend::GetStandardDenominations();
1146-
1147-
bool fSelected = pwalletMain->SelectCoinsByDenominations(nSessionDenom, vecStandardDenoms[vecBits.front()], vecStandardDenoms[vecBits.front()] * PRIVATESEND_ENTRY_MAX_SIZE, vecTxDSInTmp, vCoinsTmp, nValueInTmp, 0, privateSendClient.nPrivateSendRounds);
1148-
if (!fSelected) {
1149-
return false;
1150-
}
1151-
1152-
// nInputCount is not covered by legacy signature, require SPORK_6_NEW_SIGS to activate to use new algo
1153-
// (to make sure nInputCount wasn't modified by some intermediary node)
1154-
bool fNewAlgo = infoMn.nProtocolVersion > 70208 && sporkManager.IsSporkActive(SPORK_6_NEW_SIGS);
1155-
nSessionInputCount = fNewAlgo
1156-
? std::min(vecTxDSInTmp.size(), size_t(5 + GetRand(PRIVATESEND_ENTRY_MAX_SIZE - 5 + 1)))
1157-
: 0;
11581127
infoMixingMasternode = infoMn;
11591128
connman.AddPendingMasternode(infoMn.addr);
1160-
pendingDsaRequest = CPendingDsaRequest(infoMn.addr, CDarksendAccept(nSessionDenom, nSessionInputCount, txMyCollateral));
1129+
pendingDsaRequest = CPendingDsaRequest(infoMn.addr, CDarksendAccept(nSessionDenom, txMyCollateral));
11611130
// TODO: add new state POOL_STATE_CONNECTING and bump MIN_PRIVATESEND_PEER_PROTO_VERSION
11621131
SetState(POOL_STATE_QUEUE);
11631132
nTimeLastSuccessfulStep = GetTime();
1164-
LogPrintf("CPrivateSendClientSession::StartNewQueue -- pending connection, nSessionDenom: %d (%s), nSessionInputCount: %d, addr=%s\n",
1165-
nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), nSessionInputCount, infoMn.addr.ToString());
1133+
LogPrintf("CPrivateSendClientSession::StartNewQueue -- pending connection, nSessionDenom: %d (%s), addr=%s\n",
1134+
nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), infoMn.addr.ToString());
11661135
strAutoDenomResult = _("Trying to connect...");
11671136
return true;
11681137
}
@@ -1282,7 +1251,7 @@ bool CPrivateSendClientSession::PrepareDenominate(int nMinRounds, int nMaxRounds
12821251
return false;
12831252
}
12841253
std::vector<CAmount> vecStandardDenoms = CPrivateSend::GetStandardDenominations();
1285-
bool fSelected = pwalletMain->SelectCoinsByDenominations(nSessionDenom, vecStandardDenoms[vecBits.front()], vecStandardDenoms[vecBits.front()] * PRIVATESEND_ENTRY_MAX_SIZE, vecTxDSIn, vCoins, nValueIn, nMinRounds, nMaxRounds);
1254+
bool fSelected = pwalletMain->SelectCoinsByDenominations(nSessionDenom, vecStandardDenoms[vecBits.front()], CPrivateSend::GetMaxPoolAmount(), vecTxDSIn, vCoins, nValueIn, nMinRounds, nMaxRounds);
12861255
if (nMinRounds >= 0 && !fSelected) {
12871256
strErrorRet = "Can't select current denominated inputs";
12881257
return false;
@@ -1303,7 +1272,7 @@ bool CPrivateSendClientSession::PrepareDenominate(int nMinRounds, int nMaxRounds
13031272
// NOTE: No need to randomize order of inputs because they were
13041273
// initially shuffled in CWallet::SelectCoinsByDenominations already.
13051274
int nStep = 0;
1306-
int nStepsMax = nSessionInputCount != 0 ? nSessionInputCount : (5 + GetRandInt(PRIVATESEND_ENTRY_MAX_SIZE - 5 + 1));
1275+
int nStepsMax = 5 + GetRandInt(PRIVATESEND_ENTRY_MAX_SIZE - 5 + 1);
13071276

13081277
while (nStep < nStepsMax) {
13091278
for (const auto& nBit : vecBits) {
@@ -1350,7 +1319,7 @@ bool CPrivateSendClientSession::PrepareDenominate(int nMinRounds, int nMaxRounds
13501319
}
13511320
}
13521321

1353-
if (CPrivateSend::GetDenominations(vecTxOutRet) != nSessionDenom || (nSessionInputCount != 0 && vecTxOutRet.size() != (size_t)nSessionInputCount)) {
1322+
if (CPrivateSend::GetDenominations(vecTxOutRet) != nSessionDenom) {
13541323
{
13551324
// unlock used coins on failure
13561325
LOCK(pwalletMain->cs_wallet);

src/privatesend-server.cpp

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, const std::string& strComm
4545

4646
LogPrint("privatesend", "DSACCEPT -- nDenom %d (%s) txCollateral %s", dsa.nDenom, CPrivateSend::GetDenominationsToString(dsa.nDenom), dsa.txCollateral.ToString());
4747

48-
if(dsa.nInputCount < 0 || dsa.nInputCount > PRIVATESEND_ENTRY_MAX_SIZE) return;
49-
5048
masternode_info_t mnInfo;
5149
if(!mnodeman.GetMasternodeInfo(activeMasternodeInfo.outpoint, mnInfo)) {
5250
PushStatus(pfrom, STATUS_REJECTED, ERR_MN_LIST, connman);
@@ -100,7 +98,6 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, const std::string& strComm
10098
LogPrint("privatesend", "DSQUEUE -- %s new\n", dsq.ToString());
10199

102100
if(dsq.IsExpired()) return;
103-
if(dsq.nInputCount < 0 || dsq.nInputCount > PRIVATESEND_ENTRY_MAX_SIZE) return;
104101

105102
masternode_info_t mnInfo;
106103
if(!mnodeman.GetMasternodeInfo(dsq.masternodeOutpoint, mnInfo)) return;
@@ -168,18 +165,6 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, const std::string& strComm
168165
return;
169166
}
170167

171-
if(nSessionInputCount != 0 && entry.vecTxDSIn.size() != nSessionInputCount) {
172-
LogPrintf("DSVIN -- ERROR: incorrect number of inputs! %d/%d\n", entry.vecTxDSIn.size(), nSessionInputCount);
173-
PushStatus(pfrom, STATUS_REJECTED, ERR_INVALID_INPUT_COUNT, connman);
174-
return;
175-
}
176-
177-
if(nSessionInputCount != 0 && entry.vecTxOut.size() != nSessionInputCount) {
178-
LogPrintf("DSVIN -- ERROR: incorrect number of outputs! %d/%d\n", entry.vecTxOut.size(), nSessionInputCount);
179-
PushStatus(pfrom, STATUS_REJECTED, ERR_INVALID_INPUT_COUNT, connman);
180-
return;
181-
}
182-
183168
//do we have the same denominations as the current session?
184169
if(!IsOutputsCompatibleWithSessionDenom(entry.vecTxOut)) {
185170
LogPrintf("DSVIN -- not compatible with existing transactions!\n");
@@ -525,7 +510,7 @@ void CPrivateSendServer::CheckForCompleteQueue(CConnman& connman)
525510
if(nState == POOL_STATE_QUEUE && IsSessionReady()) {
526511
SetState(POOL_STATE_ACCEPTING_ENTRIES);
527512

528-
CDarksendQueue dsq(nSessionDenom, nSessionInputCount, activeMasternodeInfo.outpoint, GetAdjustedTime(), true);
513+
CDarksendQueue dsq(nSessionDenom, activeMasternodeInfo.outpoint, GetAdjustedTime(), true);
529514
LogPrint("privatesend", "CPrivateSendServer::CheckForCompleteQueue -- queue is ready, signing and relaying (%s)\n", dsq.ToString());
530515
dsq.Sign();
531516
dsq.Relay(connman);
@@ -703,12 +688,6 @@ bool CPrivateSendServer::IsAcceptableDSA(const CDarksendAccept& dsa, PoolMessage
703688
return false;
704689
}
705690

706-
if(dsa.nInputCount < 0 || dsa.nInputCount > PRIVATESEND_ENTRY_MAX_SIZE) {
707-
LogPrint("privatesend", "CPrivateSendServer::%s -- requested count is not valid!\n", __func__);
708-
nMessageIDRet = ERR_INVALID_INPUT_COUNT;
709-
return false;
710-
}
711-
712691
return true;
713692
}
714693

@@ -731,16 +710,13 @@ bool CPrivateSendServer::CreateNewSession(const CDarksendAccept& dsa, PoolMessag
731710
nMessageIDRet = MSG_NOERR;
732711
nSessionID = GetRandInt(999999)+1;
733712
nSessionDenom = dsa.nDenom;
734-
// nInputCount is not covered by legacy signature, require SPORK_6_NEW_SIGS to activate to use new algo
735-
// (to make sure nInputCount wasn't modified by some intermediary node)
736-
nSessionInputCount = sporkManager.IsSporkActive(SPORK_6_NEW_SIGS) ? dsa.nInputCount : 0;
737713

738714
SetState(POOL_STATE_QUEUE);
739715
nTimeLastSuccessfulStep = GetTime();
740716

741717
if(!fUnitTest) {
742718
//broadcast that I'm accepting entries, only if it's the first entry through
743-
CDarksendQueue dsq(dsa.nDenom, dsa.nInputCount, activeMasternodeInfo.outpoint, GetAdjustedTime(), false);
719+
CDarksendQueue dsq(dsa.nDenom, activeMasternodeInfo.outpoint, GetAdjustedTime(), false);
744720
LogPrint("privatesend", "CPrivateSendServer::CreateNewSession -- signing and relaying new queue: %s\n", dsq.ToString());
745721
dsq.Sign();
746722
dsq.Relay(connman);
@@ -776,21 +752,14 @@ bool CPrivateSendServer::AddUserToExistingSession(const CDarksendAccept& dsa, Po
776752
return false;
777753
}
778754

779-
if(dsa.nInputCount != nSessionInputCount) {
780-
LogPrintf("CPrivateSendServer::AddUserToExistingSession -- incompatible count %d != nSessionInputCount %d\n",
781-
dsa.nInputCount, nSessionInputCount);
782-
nMessageIDRet = ERR_INVALID_INPUT_COUNT;
783-
return false;
784-
}
785-
786755
// count new user as accepted to an existing session
787756

788757
nMessageIDRet = MSG_NOERR;
789758
nTimeLastSuccessfulStep = GetTime();
790759
vecSessionCollaterals.push_back(MakeTransactionRef(dsa.txCollateral));
791760

792-
LogPrintf("CPrivateSendServer::AddUserToExistingSession -- new user accepted, nSessionID: %d nSessionDenom: %d (%s) nSessionInputCount: %d vecSessionCollaterals.size(): %d\n",
793-
nSessionID, nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), nSessionInputCount, vecSessionCollaterals.size());
761+
LogPrintf("CPrivateSendServer::AddUserToExistingSession -- new user accepted, nSessionID: %d nSessionDenom: %d (%s) vecSessionCollaterals.size(): %d\n",
762+
nSessionID, nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), vecSessionCollaterals.size());
794763

795764
return true;
796765
}

src/privatesend.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ void CPrivateSendBaseSession::SetNull()
190190
nState = POOL_STATE_IDLE;
191191
nSessionID = 0;
192192
nSessionDenom = 0;
193-
nSessionInputCount = 0;
194193
vecEntries.clear();
195194
finalMutableTransaction.vin.clear();
196195
finalMutableTransaction.vout.clear();
@@ -477,7 +476,6 @@ std::string CPrivateSend::GetMessageByID(PoolMessage nMessageID)
477476
case MSG_NOERR: return _("No errors detected.");
478477
case MSG_SUCCESS: return _("Transaction created successfully.");
479478
case MSG_ENTRIES_ADDED: return _("Your entries added successfully.");
480-
case ERR_INVALID_INPUT_COUNT: return _("Invalid input count.");
481479
default: return _("Unknown response.");
482480
}
483481
}

src/privatesend.h

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ enum PoolMessage {
5151
MSG_NOERR,
5252
MSG_SUCCESS,
5353
MSG_ENTRIES_ADDED,
54-
ERR_INVALID_INPUT_COUNT,
5554
MSG_POOL_MIN = ERR_ALREADY_HAVE,
5655
MSG_POOL_MAX = MSG_ENTRIES_ADDED
5756
};
@@ -100,18 +99,15 @@ class CDarksendAccept
10099
{
101100
public:
102101
int nDenom;
103-
int nInputCount;
104102
CMutableTransaction txCollateral;
105103

106104
CDarksendAccept() :
107105
nDenom(0),
108-
nInputCount(0),
109106
txCollateral(CMutableTransaction())
110107
{};
111108

112-
CDarksendAccept(int nDenom, int nInputCount, const CMutableTransaction& txCollateral) :
109+
CDarksendAccept(int nDenom, const CMutableTransaction& txCollateral) :
113110
nDenom(nDenom),
114-
nInputCount(nInputCount),
115111
txCollateral(txCollateral)
116112
{};
117113

@@ -121,10 +117,9 @@ class CDarksendAccept
121117
inline void SerializationOp(Stream& s, Operation ser_action) {
122118
READWRITE(nDenom);
123119
int nVersion = s.GetVersion();
124-
if (nVersion > 70208) {
120+
if (nVersion > 70208 && nVersion <= 70210) {
121+
int nInputCount = 0;
125122
READWRITE(nInputCount);
126-
} else if (ser_action.ForRead()) {
127-
nInputCount = 0;
128123
}
129124
READWRITE(txCollateral);
130125
}
@@ -179,7 +174,6 @@ class CDarksendQueue
179174
{
180175
public:
181176
int nDenom;
182-
int nInputCount;
183177
COutPoint masternodeOutpoint;
184178
int64_t nTime;
185179
bool fReady; //ready for submit
@@ -189,17 +183,15 @@ class CDarksendQueue
189183

190184
CDarksendQueue() :
191185
nDenom(0),
192-
nInputCount(0),
193186
masternodeOutpoint(COutPoint()),
194187
nTime(0),
195188
fReady(false),
196189
vchSig(std::vector<unsigned char>()),
197190
fTried(false)
198191
{}
199192

200-
CDarksendQueue(int nDenom, int nInputCount, COutPoint outpoint, int64_t nTime, bool fReady) :
193+
CDarksendQueue(int nDenom, COutPoint outpoint, int64_t nTime, bool fReady) :
201194
nDenom(nDenom),
202-
nInputCount(nInputCount),
203195
masternodeOutpoint(outpoint),
204196
nTime(nTime),
205197
fReady(fReady),
@@ -213,10 +205,9 @@ class CDarksendQueue
213205
inline void SerializationOp(Stream& s, Operation ser_action) {
214206
READWRITE(nDenom);
215207
int nVersion = s.GetVersion();
216-
if (nVersion > 70208) {
208+
if (nVersion > 70208 && nVersion <= 70210) {
209+
int nInputCount = 0;
217210
READWRITE(nInputCount);
218-
} else if (ser_action.ForRead()) {
219-
nInputCount = 0;
220211
}
221212
if (nVersion == 70208 && (s.GetType() & SER_NETWORK)) {
222213
// converting from/to old format
@@ -258,13 +249,13 @@ class CDarksendQueue
258249

259250
std::string ToString() const
260251
{
261-
return strprintf("nDenom=%d, nInputCount=%d, nTime=%lld, fReady=%s, fTried=%s, masternode=%s",
262-
nDenom, nInputCount, nTime, fReady ? "true" : "false", fTried ? "true" : "false", masternodeOutpoint.ToStringShort());
252+
return strprintf("nDenom=%d, nTime=%lld, fReady=%s, fTried=%s, masternode=%s",
253+
nDenom, nTime, fReady ? "true" : "false", fTried ? "true" : "false", masternodeOutpoint.ToStringShort());
263254
}
264255

265256
friend bool operator==(const CDarksendQueue& a, const CDarksendQueue& b)
266257
{
267-
return a.nDenom == b.nDenom && a.nInputCount == b.nInputCount && a.masternodeOutpoint == b.masternodeOutpoint && a.nTime == b.nTime && a.fReady == b.fReady;
258+
return a.nDenom == b.nDenom && a.masternodeOutpoint == b.masternodeOutpoint && a.nTime == b.nTime && a.fReady == b.fReady;
268259
}
269260
};
270261

@@ -366,16 +357,14 @@ class CPrivateSendBaseSession
366357

367358
public:
368359
int nSessionDenom; //Users must submit a denom matching this
369-
int nSessionInputCount; //Users must submit a count matching this
370360

371361
CPrivateSendBaseSession() :
372362
vecEntries(),
373363
nState(POOL_STATE_IDLE),
374364
nTimeLastSuccessfulStep(0),
375365
nSessionID(0),
376366
finalMutableTransaction(),
377-
nSessionDenom(0),
378-
nSessionInputCount(0)
367+
nSessionDenom(0)
379368
{}
380369
CPrivateSendBaseSession(const CPrivateSendBaseSession& other) { /* dummy copy constructor*/ SetNull(); }
381370

0 commit comments

Comments
 (0)