Skip to content

Commit 84b39d9

Browse files
committed
Further PS changes
1 parent 14d0771 commit 84b39d9

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/privatesend-client.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ void CPrivateSendClientManager::CheckTimeout()
469469

470470
if (!fEnablePrivateSend)
471471
return;
472-
472+
473473
LOCK(cs_peqsessions);
474474
for (auto& session : peqSessions) {
475475
if (session.CheckTimeout()) {
@@ -1473,8 +1473,12 @@ bool CPrivateSendClientSession::CreateDenominated(CConnman& connman)
14731473

14741474
LOCK2(cs_main, pwalletMain->cs_wallet);
14751475

1476+
// NOTE: We do not allow txes larger than 100kB, so we have to limit number of inputs here.
1477+
// We still want to consume a lot of inputs to avoid creating only smaller denoms though.
1478+
// Knowing that each CTxIn is at least 148b big, 400 inputs should take 400 x ~148b = ~60kB.
1479+
// This still leaves more than enough room for another data of typical CreateDenominated tx.
14761480
std::vector<CompactTallyItem> vecTally;
1477-
if (!pwalletMain->SelectCoinsGroupedByAddresses(vecTally)) {
1481+
if (!pwalletMain->SelectCoinsGroupedByAddresses(vecTally, true, true, true, 400)) {
14781482
LogPrint("privatesend", "CPrivateSendClientSession::CreateDenominated -- SelectCoinsGroupedByAddresses can't find any inputs!\n");
14791483
return false;
14801484
}

src/wallet/wallet.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -2999,14 +2999,14 @@ struct CompareByAmount {
29992999
}
30003000
};
30013001

3002-
bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTallyRet, bool fSkipDenominated, bool fAnonymizable, bool fSkipUnconfirmed) const
3002+
bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTallyRet, bool fSkipDenominated, bool fAnonymizable, bool fSkipUnconfirmed, int nMaxOupointsPerAddress) const
30033003
{
30043004
LOCK2(cs_main, cs_wallet);
30053005

30063006
isminefilter filter = ISMINE_SPENDABLE;
30073007

3008-
// try to use cache
3009-
if (fAnonymizable && fSkipUnconfirmed) {
3008+
// try to use cache for already confirmed anonymizable inputs, no cache should be used when the limit is specified
3009+
if(nMaxOupointsPerAddress != -1 && fAnonymizable && fSkipUnconfirmed) {
30103010
if (fSkipDenominated && fAnonymizableTallyCachedNonDenom) {
30113011
vecTallyRet = vecAnonymizableTallyCachedNonDenom;
30123012
LogPrint("selectcoins", "SelectCoinsGroupedByAddresses - using cache for non-denom inputs\n");
@@ -3049,6 +3049,10 @@ bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTa
30493049
if (!(mine & filter))
30503050
continue;
30513051

3052+
auto itTallyItem = mapTally.find(txdest);
3053+
if (nMaxOupointsPerAddress != -1 && itTallyItem != mapTally.end() && itTallyItem->second.vecOutPoints.size() >= nMaxOupointsPerAddress)
3054+
continue;
3055+
30523056
if (IsSpent(outpoint.hash, i) || IsLockedCoin(outpoint.hash, i))
30533057
continue;
30543058

@@ -3070,10 +3074,12 @@ bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTa
30703074
continue;
30713075
}
30723076

3073-
CompactTallyItem& item = mapTally[txdest];
3074-
item.txdest = txdest;
3075-
item.nAmount += wtx.tx->vout[i].nValue;
3076-
item.vecOutPoints.emplace_back(outpoint.hash, i);
3077+
if (itTallyItem == mapTally.end()) {
3078+
itTallyItem = mapTally.emplace(txdest, CompactTallyItem()).first;
3079+
itTallyItem->second.txdest = txdest;
3080+
}
3081+
itTallyItem->second.nAmount += wtx.tx->vout[i].nValue;
3082+
itTallyItem->second.vecOutPoints.emplace_back(outpoint.hash, i);
30773083
}
30783084
}
30793085

@@ -3088,8 +3094,8 @@ bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTa
30883094
// order by amounts per address, from smallest to largest
30893095
sort(vecTallyRet.rbegin(), vecTallyRet.rend(), CompareByAmount());
30903096

3091-
// cache anonymizable for later use
3092-
if (fAnonymizable && fSkipUnconfirmed) {
3097+
// cache already confirmed anonymizable entries for later use, no cache should be saved when the limit is specified
3098+
if(nMaxOupointsPerAddress != -1 && fAnonymizable && fSkipUnconfirmed) {
30933099
if (fSkipDenominated) {
30943100
vecAnonymizableTallyCachedNonDenom = vecTallyRet;
30953101
fAnonymizableTallyCachedNonDenom = true;

src/wallet/wallet.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
817817
bool GetCollateralTxPSIn(CTxPSIn& txpsinRet, CAmount& nValueRet) const;
818818
bool SelectPrivateCoins(CAmount nValueMin, CAmount nValueMax, std::vector<CTxIn>& vecTxInRet, CAmount& nValueRet, int nPrivateSendRoundsMin, int nPrivateSendRoundsMax) const;
819819

820-
bool SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTallyRet, bool fSkipDenominated = true, bool fAnonymizable = true, bool fSkipUnconfirmed = true) const;
820+
bool SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTallyRet, bool fSkipDenominated = true, bool fAnonymizable = true, bool fSkipUnconfirmed = true, int nMaxOupointsPerAddress = -1) const;
821821

822822
/// Get 1000DYN output and keys which can be used for the Dynode
823823
bool GetDynodeOutpointAndKeys(COutPoint& outpointRet, CPubKey& pubKeyRet, CKey& keyRet, std::string strTxHash = "", std::string strOutputIndex = "");

0 commit comments

Comments
 (0)