Skip to content

Commit 4528c73

Browse files
authored
Replace some instantsend/privatesend magic numbers with constants (#1924)
1 parent d7f55d5 commit 4528c73

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

src/init.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -552,14 +552,15 @@ std::string HelpMessage(HelpMessageMode mode)
552552
strUsage += HelpMessageGroup(_("PrivateSend options:"));
553553
strUsage += HelpMessageOpt("-enableprivatesend=<n>", strprintf(_("Enable use of automated PrivateSend for funds stored in this wallet (0-1, default: %u)"), 0));
554554
strUsage += HelpMessageOpt("-privatesendmultisession=<n>", strprintf(_("Enable multiple PrivateSend mixing sessions per block, experimental (0-1, default: %u)"), DEFAULT_PRIVATESEND_MULTISESSION));
555-
strUsage += HelpMessageOpt("-privatesendrounds=<n>", strprintf(_("Use N separate masternodes for each denominated input to mix funds (2-16, default: %u)"), DEFAULT_PRIVATESEND_ROUNDS));
556-
strUsage += HelpMessageOpt("-privatesendamount=<n>", strprintf(_("Keep N DASH anonymized (default: %u)"), DEFAULT_PRIVATESEND_AMOUNT));
557-
strUsage += HelpMessageOpt("-liquidityprovider=<n>", strprintf(_("Provide liquidity to PrivateSend by infrequently mixing coins on a continual basis (0-100, default: %u, 1=very frequent, high fees, 100=very infrequent, low fees)"), DEFAULT_PRIVATESEND_LIQUIDITY));
555+
strUsage += HelpMessageOpt("-privatesendrounds=<n>", strprintf(_("Use N separate masternodes for each denominated input to mix funds (%u-%u, default: %u)"), MIN_PRIVATESEND_ROUNDS, MAX_PRIVATESEND_ROUNDS, DEFAULT_PRIVATESEND_ROUNDS));
556+
strUsage += HelpMessageOpt("-privatesendamount=<n>", strprintf(_("Keep N DASH anonymized (%u-%u, default: %u)"), MIN_PRIVATESEND_AMOUNT, MAX_PRIVATESEND_AMOUNT, DEFAULT_PRIVATESEND_AMOUNT));
557+
strUsage += HelpMessageOpt("-liquidityprovider=<n>", strprintf(_("Provide liquidity to PrivateSend by infrequently mixing coins on a continual basis (%u-%u, default: %u, 1=very frequent, high fees, %u=very infrequent, low fees)"),
558+
MIN_PRIVATESEND_LIQUIDITY, MAX_PRIVATESEND_LIQUIDITY, DEFAULT_PRIVATESEND_LIQUIDITY, MAX_PRIVATESEND_LIQUIDITY));
558559
#endif // ENABLE_WALLET
559560

560561
strUsage += HelpMessageGroup(_("InstantSend options:"));
561562
strUsage += HelpMessageOpt("-enableinstantsend=<n>", strprintf(_("Enable InstantSend, show confirmations for locked transactions (0-1, default: %u)"), 1));
562-
strUsage += HelpMessageOpt("-instantsenddepth=<n>", strprintf(_("Show N confirmations for a successfully locked transaction (0-9999, default: %u)"), DEFAULT_INSTANTSEND_DEPTH));
563+
strUsage += HelpMessageOpt("-instantsenddepth=<n>", strprintf(_("Show N confirmations for a successfully locked transaction (%u-%u, default: %u)"), MIN_INSTANTSEND_DEPTH, MAX_INSTANTSEND_DEPTH, DEFAULT_INSTANTSEND_DEPTH));
563564
strUsage += HelpMessageOpt("-instantsendnotify=<cmd>", _("Execute command when a wallet InstantSend transaction is successfully locked (%s in cmd is replaced by TxID)"));
564565

565566

@@ -886,10 +887,10 @@ void InitParameterInteraction()
886887
if (nLiqProvTmp > 0) {
887888
ForceSetArg("-enableprivatesend", "1");
888889
LogPrintf("%s: parameter interaction: -liquidityprovider=%d -> setting -enableprivatesend=1\n", __func__, nLiqProvTmp);
889-
ForceSetArg("-privatesendrounds", "99999");
890-
LogPrintf("%s: parameter interaction: -liquidityprovider=%d -> setting -privatesendrounds=99999\n", __func__, nLiqProvTmp);
891-
ForceSetArg("-privatesendamount", "999999");
892-
LogPrintf("%s: parameter interaction: -liquidityprovider=%d -> setting -privatesendamount=999999\n", __func__, nLiqProvTmp);
890+
ForceSetArg("-privatesendrounds", itostr(std::numeric_limits<int>::max()));
891+
LogPrintf("%s: parameter interaction: -liquidityprovider=%d -> setting -privatesendrounds=%d\n", __func__, nLiqProvTmp, itostr(std::numeric_limits<int>::max()));
892+
ForceSetArg("-privatesendamount", itostr(MAX_PRIVATESEND_AMOUNT));
893+
LogPrintf("%s: parameter interaction: -liquidityprovider=%d -> setting -privatesendamount=%d\n", __func__, nLiqProvTmp, MAX_PRIVATESEND_AMOUNT);
893894
ForceSetArg("-privatesendmultisession", "0");
894895
LogPrintf("%s: parameter interaction: -liquidityprovider=%d -> setting -privatesendmultisession=0\n", __func__, nLiqProvTmp);
895896
}
@@ -1823,21 +1824,23 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
18231824
}
18241825
}
18251826

1826-
privateSendClient.nLiquidityProvider = std::min(std::max((int)GetArg("-liquidityprovider", DEFAULT_PRIVATESEND_LIQUIDITY), 0), 100);
1827+
privateSendClient.nLiquidityProvider = std::min(std::max((int)GetArg("-liquidityprovider", DEFAULT_PRIVATESEND_LIQUIDITY), MIN_PRIVATESEND_LIQUIDITY), MAX_PRIVATESEND_LIQUIDITY);
1828+
int nMaxRounds = MAX_PRIVATESEND_ROUNDS;
18271829
if(privateSendClient.nLiquidityProvider) {
18281830
// special case for liquidity providers only, normal clients should use default value
18291831
privateSendClient.SetMinBlocksToWait(privateSendClient.nLiquidityProvider * 15);
1832+
nMaxRounds = std::numeric_limits<int>::max();
18301833
}
18311834

18321835
privateSendClient.fEnablePrivateSend = GetBoolArg("-enableprivatesend", false);
18331836
privateSendClient.fPrivateSendMultiSession = GetBoolArg("-privatesendmultisession", DEFAULT_PRIVATESEND_MULTISESSION);
1834-
privateSendClient.nPrivateSendRounds = std::min(std::max((int)GetArg("-privatesendrounds", DEFAULT_PRIVATESEND_ROUNDS), 2), privateSendClient.nLiquidityProvider ? 99999 : 16);
1835-
privateSendClient.nPrivateSendAmount = std::min(std::max((int)GetArg("-privatesendamount", DEFAULT_PRIVATESEND_AMOUNT), 2), 999999);
1837+
privateSendClient.nPrivateSendRounds = std::min(std::max((int)GetArg("-privatesendrounds", DEFAULT_PRIVATESEND_ROUNDS), MIN_PRIVATESEND_ROUNDS), nMaxRounds);
1838+
privateSendClient.nPrivateSendAmount = std::min(std::max((int)GetArg("-privatesendamount", DEFAULT_PRIVATESEND_AMOUNT), MIN_PRIVATESEND_AMOUNT), MAX_PRIVATESEND_AMOUNT);
18361839
#endif // ENABLE_WALLET
18371840

18381841
fEnableInstantSend = GetBoolArg("-enableinstantsend", 1);
18391842
nInstantSendDepth = GetArg("-instantsenddepth", DEFAULT_INSTANTSEND_DEPTH);
1840-
nInstantSendDepth = std::min(std::max(nInstantSendDepth, 0), 60);
1843+
nInstantSendDepth = std::min(std::max(nInstantSendDepth, MIN_INSTANTSEND_DEPTH), MAX_INSTANTSEND_DEPTH);
18411844

18421845
//lite mode disables all Masternode and Darksend related functionality
18431846
fLiteMode = GetBoolArg("-litemode", false);

src/instantx.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ extern CInstantSend instantsend;
2626
(1000/2900.0)**5 = 0.004875397277841433
2727
*/
2828
static const int INSTANTSEND_CONFIRMATIONS_REQUIRED = 6;
29+
30+
static const int MIN_INSTANTSEND_DEPTH = 0;
31+
static const int MAX_INSTANTSEND_DEPTH = 60;
2932
static const int DEFAULT_INSTANTSEND_DEPTH = 5;
3033

3134
static const int MIN_INSTANTSEND_PROTO_VERSION = 70208;

src/privatesend-client.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ class CConnman;
1515

1616
static const int DENOMS_COUNT_MAX = 100;
1717

18+
static const int MIN_PRIVATESEND_ROUNDS = 2;
19+
static const int MIN_PRIVATESEND_AMOUNT = 2;
20+
static const int MIN_PRIVATESEND_LIQUIDITY = 0;
21+
static const int MAX_PRIVATESEND_ROUNDS = 16;
22+
static const int MAX_PRIVATESEND_AMOUNT = MAX_MONEY / COIN;
23+
static const int MAX_PRIVATESEND_LIQUIDITY = 100;
1824
static const int DEFAULT_PRIVATESEND_ROUNDS = 2;
1925
static const int DEFAULT_PRIVATESEND_AMOUNT = 1000;
2026
static const int DEFAULT_PRIVATESEND_LIQUIDITY = 0;
27+
2128
static const bool DEFAULT_PRIVATESEND_MULTISESSION = false;
2229

2330
// Warn user if mixing in gui or try to create backup if mixing in daemon mode

src/wallet/wallet.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,10 @@ int CWallet::GetRealOutpointPrivateSendRounds(const COutPoint& outpoint, int nRo
14291429
{
14301430
static std::map<uint256, CMutableTransaction> mDenomWtxes;
14311431

1432-
if(nRounds >= 16) return 15; // 16 rounds max
1432+
if(nRounds >= MAX_PRIVATESEND_ROUNDS) {
1433+
// there can only be MAX_PRIVATESEND_ROUNDS rounds max
1434+
return MAX_PRIVATESEND_ROUNDS - 1;
1435+
}
14331436

14341437
uint256 hash = outpoint.hash;
14351438
unsigned int nout = outpoint.n;
@@ -1494,7 +1497,7 @@ int CWallet::GetRealOutpointPrivateSendRounds(const COutPoint& outpoint, int nRo
14941497
}
14951498
}
14961499
mDenomWtxes[hash].vout[nout].nRounds = fDenomFound
1497-
? (nShortest >= 15 ? 16 : nShortest + 1) // good, we a +1 to the shortest one but only 16 rounds max allowed
1500+
? (nShortest >= MAX_PRIVATESEND_ROUNDS - 1 ? MAX_PRIVATESEND_ROUNDS : nShortest + 1) // good, we a +1 to the shortest one but only MAX_PRIVATESEND_ROUNDS rounds max allowed
14981501
: 0; // too bad, we are the fist one in that chain
14991502
LogPrint("privatesend", "GetRealOutpointPrivateSendRounds UPDATED %s %3d %3d\n", hash.ToString(), nout, mDenomWtxes[hash].vout[nout].nRounds);
15001503
return mDenomWtxes[hash].vout[nout].nRounds;

0 commit comments

Comments
 (0)