privatesend|qt|rpc|wallet: Improve CPrivateSendClientOptions

- Makes it singleton to make sure we always only have one instance of it
- Protects its members by making them private and adding set/getters
- Makes it thread safe
This commit is contained in:
xdustinface 2020-07-17 02:25:11 +02:00 committed by pasta
parent 50b09b88e4
commit 8fedc083fc
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
11 changed files with 178 additions and 118 deletions

View File

@ -24,12 +24,14 @@
std::map<const std::string, CPrivateSendClientManager*> privateSendClientManagers; std::map<const std::string, CPrivateSendClientManager*> privateSendClientManagers;
CPrivateSendClientQueueManager privateSendClientQueueManager; CPrivateSendClientQueueManager privateSendClientQueueManager;
CPrivateSendClientOptions privateSendClientOptions;
CPrivateSendClientOptions* CPrivateSendClientOptions::_instance{nullptr};
std::once_flag CPrivateSendClientOptions::onceFlag;
void CPrivateSendClientQueueManager::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman, bool enable_bip61) void CPrivateSendClientQueueManager::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman, bool enable_bip61)
{ {
if (fMasternodeMode) return; if (fMasternodeMode) return;
if (!privateSendClientOptions.fEnablePrivateSend) return; if (!CPrivateSendClientOptions::IsEnabled()) return;
if (!masternodeSync.IsBlockchainSynced()) return; if (!masternodeSync.IsBlockchainSynced()) return;
if (!CheckDiskSpace()) { if (!CheckDiskSpace()) {
@ -122,7 +124,7 @@ void CPrivateSendClientQueueManager::ProcessMessage(CNode* pfrom, const std::str
void CPrivateSendClientManager::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman, bool enable_bip61) void CPrivateSendClientManager::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman, bool enable_bip61)
{ {
if (fMasternodeMode) return; if (fMasternodeMode) return;
if (!privateSendClientOptions.fEnablePrivateSend) return; if (!CPrivateSendClientOptions::IsEnabled()) return;
if (!masternodeSync.IsBlockchainSynced()) return; if (!masternodeSync.IsBlockchainSynced()) return;
if (!CheckDiskSpace()) { if (!CheckDiskSpace()) {
@ -145,7 +147,7 @@ void CPrivateSendClientManager::ProcessMessage(CNode* pfrom, const std::string&
void CPrivateSendClientSession::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman, bool enable_bip61) void CPrivateSendClientSession::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman, bool enable_bip61)
{ {
if (fMasternodeMode) return; if (fMasternodeMode) return;
if (!privateSendClientOptions.fEnablePrivateSend) return; if (!CPrivateSendClientOptions::IsEnabled()) return;
if (!masternodeSync.IsBlockchainSynced()) return; if (!masternodeSync.IsBlockchainSynced()) return;
if (strCommand == NetMsgType::DSSTATUSUPDATE) { if (strCommand == NetMsgType::DSSTATUSUPDATE) {
@ -287,7 +289,7 @@ void CPrivateSendClientSession::SetNull()
// //
void CPrivateSendClientSession::UnlockCoins() void CPrivateSendClientSession::UnlockCoins()
{ {
if (!privateSendClientOptions.fEnablePrivateSend) return; if (!CPrivateSendClientOptions::IsEnabled()) return;
while (true) { while (true) {
TRY_LOCK(mixingWallet->cs_wallet, lockWallet); TRY_LOCK(mixingWallet->cs_wallet, lockWallet);
@ -427,7 +429,7 @@ void CPrivateSendClientManager::CheckTimeout()
{ {
if (fMasternodeMode) return; if (fMasternodeMode) return;
if (!privateSendClientOptions.fEnablePrivateSend || !IsMixing()) return; if (!CPrivateSendClientOptions::IsEnabled() || !IsMixing()) return;
LOCK(cs_deqsessions); LOCK(cs_deqsessions);
for (auto& session : deqSessions) { for (auto& session : deqSessions) {
@ -551,7 +553,7 @@ void CPrivateSendClientSession::ProcessPoolStateUpdate(CPrivateSendStatusUpdate
// //
bool CPrivateSendClientSession::SignFinalTransaction(const CTransaction& finalTransactionNew, CNode* pnode, CConnman& connman) bool CPrivateSendClientSession::SignFinalTransaction(const CTransaction& finalTransactionNew, CNode* pnode, CConnman& connman)
{ {
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false; if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
if (fMasternodeMode || pnode == nullptr) return false; if (fMasternodeMode || pnode == nullptr) return false;
if (!mixingMasternode) return false; if (!mixingMasternode) return false;
@ -693,14 +695,14 @@ bool CPrivateSendClientManager::WaitForAnotherBlock()
{ {
if (!masternodeSync.IsBlockchainSynced()) return true; if (!masternodeSync.IsBlockchainSynced()) return true;
if (privateSendClientOptions.fPrivateSendMultiSession) return false; if (CPrivateSendClientOptions::IsMultiSessionEnabled()) return false;
return nCachedBlockHeight - nCachedLastSuccessBlock < nMinBlocksToWait; return nCachedBlockHeight - nCachedLastSuccessBlock < nMinBlocksToWait;
} }
bool CPrivateSendClientManager::CheckAutomaticBackup() bool CPrivateSendClientManager::CheckAutomaticBackup()
{ {
if (!privateSendClientOptions.fEnablePrivateSend || !IsMixing()) return false; if (!CPrivateSendClientOptions::IsEnabled() || !IsMixing()) return false;
switch (nWalletBackups) { switch (nWalletBackups) {
case 0: case 0:
@ -778,7 +780,7 @@ bool CPrivateSendClientSession::DoAutomaticDenominating(CConnman& connman, bool
return false; return false;
} }
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false; if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
CAmount nBalanceNeedsAnonymized; CAmount nBalanceNeedsAnonymized;
@ -811,7 +813,7 @@ bool CPrivateSendClientSession::DoAutomaticDenominating(CConnman& connman, bool
// check if there is anything left to do // check if there is anything left to do
CAmount nBalanceAnonymized = mixingWallet->GetAnonymizedBalance(); CAmount nBalanceAnonymized = mixingWallet->GetAnonymizedBalance();
nBalanceNeedsAnonymized = privateSendClientOptions.nPrivateSendAmount*COIN - nBalanceAnonymized; nBalanceNeedsAnonymized = CPrivateSendClientOptions::GetAmount() * COIN - nBalanceAnonymized;
if (nBalanceNeedsAnonymized < 0) { if (nBalanceNeedsAnonymized < 0) {
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- Nothing to do\n"); LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- Nothing to do\n");
@ -843,7 +845,7 @@ bool CPrivateSendClientSession::DoAutomaticDenominating(CConnman& connman, bool
CAmount nBalanceDenominatedConf = mixingWallet->GetDenominatedBalance(); CAmount nBalanceDenominatedConf = mixingWallet->GetDenominatedBalance();
CAmount nBalanceDenominatedUnconf = mixingWallet->GetDenominatedBalance(true); CAmount nBalanceDenominatedUnconf = mixingWallet->GetDenominatedBalance(true);
CAmount nBalanceDenominated = nBalanceDenominatedConf + nBalanceDenominatedUnconf; CAmount nBalanceDenominated = nBalanceDenominatedConf + nBalanceDenominatedUnconf;
CAmount nBalanceToDenominate = privateSendClientOptions.nPrivateSendAmount * COIN - nBalanceDenominated; CAmount nBalanceToDenominate = CPrivateSendClientOptions::GetAmount() * COIN - nBalanceDenominated;
// adjust nBalanceNeedsAnonymized to consume final denom // adjust nBalanceNeedsAnonymized to consume final denom
if (nBalanceDenominated - nBalanceAnonymized > nBalanceNeedsAnonymized) { if (nBalanceDenominated - nBalanceAnonymized > nBalanceNeedsAnonymized) {
@ -906,7 +908,7 @@ bool CPrivateSendClientSession::DoAutomaticDenominating(CConnman& connman, bool
SetNull(); SetNull();
// should be no unconfirmed denoms in non-multi-session mode // should be no unconfirmed denoms in non-multi-session mode
if (!privateSendClientOptions.fPrivateSendMultiSession && nBalanceDenominatedUnconf > 0) { if (!CPrivateSendClientOptions::IsMultiSessionEnabled() && nBalanceDenominatedUnconf > 0) {
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- Found unconfirmed denominated outputs, will wait till they confirm to continue.\n"); LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- Found unconfirmed denominated outputs, will wait till they confirm to continue.\n");
strAutoDenomResult = _("Found unconfirmed denominated outputs, will wait till they confirm to continue."); strAutoDenomResult = _("Found unconfirmed denominated outputs, will wait till they confirm to continue.");
return false; return false;
@ -950,7 +952,7 @@ bool CPrivateSendClientSession::DoAutomaticDenominating(CConnman& connman, bool
bool CPrivateSendClientManager::DoAutomaticDenominating(CConnman& connman, bool fDryRun) bool CPrivateSendClientManager::DoAutomaticDenominating(CConnman& connman, bool fDryRun)
{ {
if (fMasternodeMode) return false; // no client-side mixing on masternodes if (fMasternodeMode) return false; // no client-side mixing on masternodes
if (!privateSendClientOptions.fEnablePrivateSend || !IsMixing()) return false; if (!CPrivateSendClientOptions::IsEnabled() || !IsMixing()) return false;
if (!masternodeSync.IsBlockchainSynced()) { if (!masternodeSync.IsBlockchainSynced()) {
strAutoDenomResult = _("Can't mix while sync in progress."); strAutoDenomResult = _("Can't mix while sync in progress.");
@ -976,7 +978,7 @@ bool CPrivateSendClientManager::DoAutomaticDenominating(CConnman& connman, bool
LOCK(cs_deqsessions); LOCK(cs_deqsessions);
bool fResult = true; bool fResult = true;
if ((int)deqSessions.size() < privateSendClientOptions.nPrivateSendSessions) { if ((int)deqSessions.size() < CPrivateSendClientOptions::GetSessions()) {
deqSessions.emplace_back(mixingWallet); deqSessions.emplace_back(mixingWallet);
} }
for (auto& session : deqSessions) { for (auto& session : deqSessions) {
@ -1040,7 +1042,7 @@ CDeterministicMNCPtr CPrivateSendClientManager::GetRandomNotUsedMasternode()
bool CPrivateSendClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CConnman& connman) bool CPrivateSendClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CConnman& connman)
{ {
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false; if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
auto mnList = deterministicMNManager->GetListAtChainTip(); auto mnList = deterministicMNManager->GetListAtChainTip();
@ -1099,7 +1101,7 @@ bool CPrivateSendClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymize
bool CPrivateSendClientSession::StartNewQueue(CAmount nBalanceNeedsAnonymized, CConnman& connman) bool CPrivateSendClientSession::StartNewQueue(CAmount nBalanceNeedsAnonymized, CConnman& connman)
{ {
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false; if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
if (nBalanceNeedsAnonymized <= 0) return false; if (nBalanceNeedsAnonymized <= 0) return false;
int nTries = 0; int nTries = 0;
@ -1252,7 +1254,7 @@ bool CPrivateSendClientSession::SubmitDenominate(CConnman& connman)
std::vector<std::pair<int, size_t> > vecInputsByRounds; std::vector<std::pair<int, size_t> > vecInputsByRounds;
for (int i = 0; i < privateSendClientOptions.nPrivateSendRounds; i++) { for (int i = 0; i < CPrivateSendClientOptions::GetRounds(); i++) {
if (PrepareDenominate(i, i, strError, vecPSInOutPairs, vecPSInOutPairsTmp, true)) { if (PrepareDenominate(i, i, strError, vecPSInOutPairs, vecPSInOutPairsTmp, true)) {
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, success\n", i); LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, success\n", i);
vecInputsByRounds.emplace_back(i, vecPSInOutPairsTmp.size()); vecInputsByRounds.emplace_back(i, vecPSInOutPairsTmp.size());
@ -1278,7 +1280,7 @@ bool CPrivateSendClientSession::SubmitDenominate(CConnman& connman)
} }
// We failed? That's strange but let's just make final attempt and try to mix everything // We failed? That's strange but let's just make final attempt and try to mix everything
if (PrepareDenominate(0, privateSendClientOptions.nPrivateSendRounds - 1, strError, vecPSInOutPairs, vecPSInOutPairsTmp)) { if (PrepareDenominate(0, CPrivateSendClientOptions::GetRounds() - 1, strError, vecPSInOutPairs, vecPSInOutPairsTmp)) {
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for all rounds, success\n"); LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for all rounds, success\n");
return SendDenominate(vecPSInOutPairsTmp, connman); return SendDenominate(vecPSInOutPairsTmp, connman);
} }
@ -1291,7 +1293,7 @@ bool CPrivateSendClientSession::SubmitDenominate(CConnman& connman)
bool CPrivateSendClientSession::SelectDenominate(std::string& strErrorRet, std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsRet) bool CPrivateSendClientSession::SelectDenominate(std::string& strErrorRet, std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsRet)
{ {
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false; if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
if (mixingWallet->IsLocked(true)) { if (mixingWallet->IsLocked(true)) {
strErrorRet = "Wallet locked, unable to create transaction!"; strErrorRet = "Wallet locked, unable to create transaction!";
@ -1376,7 +1378,7 @@ bool CPrivateSendClientSession::PrepareDenominate(int nMinRounds, int nMaxRounds
// Create collaterals by looping through inputs grouped by addresses // Create collaterals by looping through inputs grouped by addresses
bool CPrivateSendClientSession::MakeCollateralAmounts(CConnman& connman) bool CPrivateSendClientSession::MakeCollateralAmounts(CConnman& connman)
{ {
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false; if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
LOCK2(cs_main, mempool.cs); LOCK2(cs_main, mempool.cs);
LOCK(mixingWallet->cs_wallet); LOCK(mixingWallet->cs_wallet);
@ -1420,7 +1422,7 @@ bool CPrivateSendClientSession::MakeCollateralAmounts(const CompactTallyItem& ta
AssertLockHeld(mempool.cs); AssertLockHeld(mempool.cs);
AssertLockHeld(mixingWallet->cs_wallet); AssertLockHeld(mixingWallet->cs_wallet);
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false; if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
// Skip way too tiny amounts // Skip way too tiny amounts
if (tallyItem.nAmount < CPrivateSend::GetCollateralAmount()) { if (tallyItem.nAmount < CPrivateSend::GetCollateralAmount()) {
@ -1515,7 +1517,7 @@ bool CPrivateSendClientSession::MakeCollateralAmounts(const CompactTallyItem& ta
// Create denominations by looping through inputs grouped by addresses // Create denominations by looping through inputs grouped by addresses
bool CPrivateSendClientSession::CreateDenominated(CAmount nBalanceToDenominate, CConnman& connman) bool CPrivateSendClientSession::CreateDenominated(CAmount nBalanceToDenominate, CConnman& connman)
{ {
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false; if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
LOCK2(cs_main, mempool.cs); LOCK2(cs_main, mempool.cs);
LOCK(mixingWallet->cs_wallet); LOCK(mixingWallet->cs_wallet);
@ -1553,7 +1555,7 @@ bool CPrivateSendClientSession::CreateDenominated(CAmount nBalanceToDenominate,
AssertLockHeld(mempool.cs); AssertLockHeld(mempool.cs);
AssertLockHeld(mixingWallet->cs_wallet); AssertLockHeld(mixingWallet->cs_wallet);
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false; if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
std::vector<CRecipient> vecSend; std::vector<CRecipient> vecSend;
CKeyHolderStorage keyHolderStorageDenom; CKeyHolderStorage keyHolderStorageDenom;
@ -1623,7 +1625,7 @@ bool CPrivateSendClientSession::CreateDenominated(CAmount nBalanceToDenominate,
}; };
// add each output up to 11 times or until it can't be added again or until we reach nPrivateSendDenomsGoal // add each output up to 11 times or until it can't be added again or until we reach nPrivateSendDenomsGoal
while (needMoreOutputs() && nOutputs <= 10 && currentDenomIt->second < privateSendClientOptions.nPrivateSendDenomsGoal) { while (needMoreOutputs() && nOutputs <= 10 && currentDenomIt->second < CPrivateSendClientOptions::GetDenomsGoal()) {
CScript scriptDenom = keyHolderStorageDenom.AddKey(mixingWallet); CScript scriptDenom = keyHolderStorageDenom.AddKey(mixingWallet);
vecSend.push_back((CRecipient) {scriptDenom, nDenomValue, false}); vecSend.push_back((CRecipient) {scriptDenom, nDenomValue, false});
@ -1646,7 +1648,7 @@ bool CPrivateSendClientSession::CreateDenominated(CAmount nBalanceToDenominate,
for (const auto it : mapDenomCount) { for (const auto it : mapDenomCount) {
// Check if this specific denom could use another loop, check that there aren't nPrivateSendDenomsGoal of this // Check if this specific denom could use another loop, check that there aren't nPrivateSendDenomsGoal of this
// denom and that our nValueLeft/nBalanceToDenominate is enough to create one of these denoms, if so, loop again. // denom and that our nValueLeft/nBalanceToDenominate is enough to create one of these denoms, if so, loop again.
if (it.second < privateSendClientOptions.nPrivateSendDenomsGoal && (nValueLeft >= it.first + nOutputFee) && nBalanceToDenominate > 0) { if (it.second < CPrivateSendClientOptions::GetDenomsGoal() && (nValueLeft >= it.first + nOutputFee) && nBalanceToDenominate > 0) {
finished = false; finished = false;
LogPrint(BCLog::PRIVATESEND, LogPrint(BCLog::PRIVATESEND,
"CPrivateSendClientSession::CreateDenominated -- 1 - NOT finished - nDenomValue: %f, count: %d, nValueLeft: %f, nBalanceToDenominate: %f\n", "CPrivateSendClientSession::CreateDenominated -- 1 - NOT finished - nDenomValue: %f, count: %d, nValueLeft: %f, nBalanceToDenominate: %f\n",
@ -1686,7 +1688,7 @@ bool CPrivateSendClientSession::CreateDenominated(CAmount nBalanceToDenominate,
auto it = mapDenomCount.find(nDenomValue); auto it = mapDenomCount.find(nDenomValue);
for (int i = 0; i < denomsToCreate; i++) { for (int i = 0; i < denomsToCreate; i++) {
// Never go above the cap unless it's the largest denom // Never go above the cap unless it's the largest denom
if (nDenomValue != nLargestDenomValue && it->second >= privateSendClientOptions.nPrivateSendDenomsHardCap) break; if (nDenomValue != nLargestDenomValue && it->second >= CPrivateSendClientOptions::GetDenomsHardCap()) break;
CScript scriptDenom = keyHolderStorageDenom.AddKey(mixingWallet); CScript scriptDenom = keyHolderStorageDenom.AddKey(mixingWallet);
vecSend.push_back((CRecipient) {scriptDenom, nDenomValue, false}); vecSend.push_back((CRecipient) {scriptDenom, nDenomValue, false});
@ -1785,7 +1787,7 @@ void CPrivateSendClientManager::UpdatedBlockTip(const CBlockIndex* pindex)
void CPrivateSendClientQueueManager::DoMaintenance() void CPrivateSendClientQueueManager::DoMaintenance()
{ {
if (!privateSendClientOptions.fEnablePrivateSend) return; if (!CPrivateSendClientOptions::IsEnabled()) return;
if (fMasternodeMode) return; // no client-side mixing on masternodes if (fMasternodeMode) return; // no client-side mixing on masternodes
if (!masternodeSync.IsBlockchainSynced() || ShutdownRequested()) return; if (!masternodeSync.IsBlockchainSynced() || ShutdownRequested()) return;
@ -1795,7 +1797,7 @@ void CPrivateSendClientQueueManager::DoMaintenance()
void CPrivateSendClientManager::DoMaintenance(CConnman& connman) void CPrivateSendClientManager::DoMaintenance(CConnman& connman)
{ {
if (!privateSendClientOptions.fEnablePrivateSend) return; if (!CPrivateSendClientOptions::IsEnabled()) return;
if (fMasternodeMode) return; // no client-side mixing on masternodes if (fMasternodeMode) return; // no client-side mixing on masternodes
if (!masternodeSync.IsBlockchainSynced() || ShutdownRequested()) return; if (!masternodeSync.IsBlockchainSynced() || ShutdownRequested()) return;
@ -1843,18 +1845,6 @@ void CPrivateSendClientManager::GetJsonInfo(UniValue& obj) const
obj.pushKV("sessions", arrSessions); obj.pushKV("sessions", arrSessions);
} }
void CPrivateSendClientOptions::GetJsonInfo(UniValue& obj) const
{
assert(obj.isObject());
obj.pushKV("enabled", privateSendClientOptions.fEnablePrivateSend);
obj.pushKV("multisession", privateSendClientOptions.fPrivateSendMultiSession);
obj.pushKV("max_sessions", privateSendClientOptions.nPrivateSendSessions);
obj.pushKV("max_rounds", privateSendClientOptions.nPrivateSendRounds);
obj.pushKV("max_amount", privateSendClientOptions.nPrivateSendAmount);
obj.pushKV("denoms_goal", privateSendClientOptions.nPrivateSendDenomsGoal);
obj.pushKV("denoms_hardcap", privateSendClientOptions.nPrivateSendDenomsHardCap);
}
void DoPrivateSendMaintenance(CConnman& connman) void DoPrivateSendMaintenance(CConnman& connman)
{ {
privateSendClientQueueManager.DoMaintenance(); privateSendClientQueueManager.DoMaintenance();
@ -1862,3 +1852,65 @@ void DoPrivateSendMaintenance(CConnman& connman)
pair.second->DoMaintenance(connman); pair.second->DoMaintenance(connman);
} }
} }
CPrivateSendClientOptions& CPrivateSendClientOptions::Get()
{
std::call_once(onceFlag, CPrivateSendClientOptions::Init);
assert(CPrivateSendClientOptions::_instance);
return *CPrivateSendClientOptions::_instance;
}
void CPrivateSendClientOptions::SetEnabled(bool fEnabled)
{
CPrivateSendClientOptions& options = CPrivateSendClientOptions::Get();
LOCK(options.cs_ps_options);
options.fEnablePrivateSend = fEnabled;
}
void CPrivateSendClientOptions::SetMultiSessionEnabled(bool fEnabled)
{
CPrivateSendClientOptions& options = CPrivateSendClientOptions::Get();
LOCK(options.cs_ps_options);
options.fPrivateSendMultiSession = fEnabled;
}
void CPrivateSendClientOptions::SetRounds(int nRounds)
{
CPrivateSendClientOptions& options = CPrivateSendClientOptions::Get();
LOCK(options.cs_ps_options);
options.nPrivateSendRounds = nRounds;
}
void CPrivateSendClientOptions::SetAmount(CAmount amount)
{
CPrivateSendClientOptions& options = CPrivateSendClientOptions::Get();
LOCK(options.cs_ps_options);
options.nPrivateSendAmount = amount;
}
void CPrivateSendClientOptions::Init()
{
assert(!CPrivateSendClientOptions::_instance);
static CPrivateSendClientOptions instance;
LOCK(instance.cs_ps_options);
instance.fPrivateSendMultiSession = gArgs.GetBoolArg("-privatesendmultisession", DEFAULT_PRIVATESEND_MULTISESSION);
instance.nPrivateSendSessions = std::min(std::max((int)gArgs.GetArg("-privatesendsessions", DEFAULT_PRIVATESEND_SESSIONS), MIN_PRIVATESEND_SESSIONS), MAX_PRIVATESEND_SESSIONS);
instance.nPrivateSendRounds = std::min(std::max((int)gArgs.GetArg("-privatesendrounds", DEFAULT_PRIVATESEND_ROUNDS), MIN_PRIVATESEND_ROUNDS), MAX_PRIVATESEND_ROUNDS);
instance.nPrivateSendAmount = std::min(std::max((int)gArgs.GetArg("-privatesendamount", DEFAULT_PRIVATESEND_AMOUNT), MIN_PRIVATESEND_AMOUNT), MAX_PRIVATESEND_AMOUNT);
instance.nPrivateSendDenomsGoal = std::min(std::max((int)gArgs.GetArg("-privatesenddenomsgoal", DEFAULT_PRIVATESEND_DENOMS_GOAL), MIN_PRIVATESEND_DENOMS_GOAL), MAX_PRIVATESEND_DENOMS_GOAL);
instance.nPrivateSendDenomsHardCap = std::min(std::max((int)gArgs.GetArg("-privatesenddenomshardcap", DEFAULT_PRIVATESEND_DENOMS_HARDCAP), MIN_PRIVATESEND_DENOMS_HARDCAP), MAX_PRIVATESEND_DENOMS_HARDCAP);
CPrivateSendClientOptions::_instance = &instance;
}
void CPrivateSendClientOptions::GetJsonInfo(UniValue& obj)
{
assert(obj.isObject());
CPrivateSendClientOptions& options = CPrivateSendClientOptions::Get();
obj.pushKV("enabled", options.fEnablePrivateSend);
obj.pushKV("multisession", options.fPrivateSendMultiSession);
obj.pushKV("max_sessions", options.nPrivateSendSessions);
obj.pushKV("max_rounds", options.nPrivateSendRounds);
obj.pushKV("max_amount", options.nPrivateSendAmount);
obj.pushKV("denoms_goal", options.nPrivateSendDenomsGoal);
obj.pushKV("denoms_hardcap", options.nPrivateSendDenomsHardCap);
}

View File

@ -61,9 +61,6 @@ extern std::map<const std::string, CPrivateSendClientManager*> privateSendClient
// The object to track mixing queues // The object to track mixing queues
extern CPrivateSendClientQueueManager privateSendClientQueueManager; extern CPrivateSendClientQueueManager privateSendClientQueueManager;
// The object to store application wide mixing options
extern CPrivateSendClientOptions privateSendClientOptions;
class CPendingDsaRequest class CPendingDsaRequest
{ {
private: private:
@ -281,6 +278,27 @@ public:
class CPrivateSendClientOptions class CPrivateSendClientOptions
{ {
public: public:
static int GetSessions() { return CPrivateSendClientOptions::Get().nPrivateSendSessions; }
static int GetRounds() { return CPrivateSendClientOptions::Get().nPrivateSendRounds; }
static int GetAmount() { return CPrivateSendClientOptions::Get().nPrivateSendAmount; }
static int GetDenomsGoal() { return CPrivateSendClientOptions::Get().nPrivateSendDenomsGoal; }
static int GetDenomsHardCap() { return CPrivateSendClientOptions::Get().nPrivateSendDenomsHardCap; }
static void SetEnabled(bool fEnabled);
static void SetMultiSessionEnabled(bool fEnabled);
static void SetRounds(int nRounds);
static void SetAmount(CAmount amount);
static int IsEnabled() { return CPrivateSendClientOptions::Get().fEnablePrivateSend; }
static int IsMultiSessionEnabled() { return CPrivateSendClientOptions::Get().fPrivateSendMultiSession; }
static void GetJsonInfo(UniValue& obj);
private:
static CPrivateSendClientOptions* _instance;
static std::once_flag onceFlag;
CCriticalSection cs_ps_options;
int nPrivateSendSessions; int nPrivateSendSessions;
int nPrivateSendRounds; int nPrivateSendRounds;
int nPrivateSendAmount; int nPrivateSendAmount;
@ -299,7 +317,11 @@ public:
{ {
} }
void GetJsonInfo(UniValue& obj) const; CPrivateSendClientOptions(const CPrivateSendClientOptions& other) = delete;
CPrivateSendClientOptions& operator=(const CPrivateSendClientOptions&) = delete;
static CPrivateSendClientOptions& Get();
static void Init();
}; };
void DoPrivateSendMaintenance(CConnman& connman); void DoPrivateSendMaintenance(CConnman& connman);

View File

@ -780,8 +780,8 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled)
sendCoinsAction->setEnabled(enabled); sendCoinsAction->setEnabled(enabled);
sendCoinsMenuAction->setEnabled(enabled); sendCoinsMenuAction->setEnabled(enabled);
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
privateSendCoinsAction->setEnabled(enabled && privateSendClientOptions.fEnablePrivateSend); privateSendCoinsAction->setEnabled(enabled && CPrivateSendClientOptions::IsEnabled());
privateSendCoinsMenuAction->setEnabled(enabled && privateSendClientOptions.fEnablePrivateSend); privateSendCoinsMenuAction->setEnabled(enabled && CPrivateSendClientOptions::IsEnabled());
#else #else
privateSendCoinsAction->setEnabled(enabled); privateSendCoinsAction->setEnabled(enabled);
privateSendCoinsMenuAction->setEnabled(enabled); privateSendCoinsMenuAction->setEnabled(enabled);

View File

@ -501,7 +501,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
// unselect non-fully-mixed, this can happen when users switch from Send to PrivateSend // unselect non-fully-mixed, this can happen when users switch from Send to PrivateSend
if (coinControl()->IsUsingPrivateSend()) { if (coinControl()->IsUsingPrivateSend()) {
int nRounds = model->getRealOutpointPrivateSendRounds(outpt); int nRounds = model->getRealOutpointPrivateSendRounds(outpt);
if (nRounds < privateSendClientOptions.nPrivateSendRounds) { if (nRounds < CPrivateSendClientOptions::GetRounds()) {
coinControl()->UnSelect(outpt); coinControl()->UnSelect(outpt);
fUnselectedNonMixed = true; fUnselectedNonMixed = true;
continue; continue;
@ -707,7 +707,7 @@ void CoinControlDialog::updateView()
COutPoint outpoint = COutPoint(out.tx->tx->GetHash(), out.i); COutPoint outpoint = COutPoint(out.tx->tx->GetHash(), out.i);
int nRounds = model->getRealOutpointPrivateSendRounds(outpoint); int nRounds = model->getRealOutpointPrivateSendRounds(outpoint);
if ((coinControl()->IsUsingPrivateSend() && nRounds >= privateSendClientOptions.nPrivateSendRounds) || !(coinControl()->IsUsingPrivateSend())) { if ((coinControl()->IsUsingPrivateSend() && nRounds >= CPrivateSendClientOptions::GetRounds()) || !(coinControl()->IsUsingPrivateSend())) {
nSum += out.tx->tx->vout[out.i].nValue; nSum += out.tx->tx->vout[out.i].nValue;
nChildren++; nChildren++;

View File

@ -138,7 +138,7 @@ void OptionsModel::Init(bool resetSettings)
settings.setValue("nPrivateSendRounds", DEFAULT_PRIVATESEND_ROUNDS); settings.setValue("nPrivateSendRounds", DEFAULT_PRIVATESEND_ROUNDS);
if (!gArgs.SoftSetArg("-privatesendrounds", settings.value("nPrivateSendRounds").toString().toStdString())) if (!gArgs.SoftSetArg("-privatesendrounds", settings.value("nPrivateSendRounds").toString().toStdString()))
addOverriddenOption("-privatesendrounds"); addOverriddenOption("-privatesendrounds");
privateSendClientOptions.nPrivateSendRounds = settings.value("nPrivateSendRounds").toInt(); CPrivateSendClientOptions::SetRounds(settings.value("nPrivateSendRounds").toInt());
if (!settings.contains("nPrivateSendAmount")) { if (!settings.contains("nPrivateSendAmount")) {
// for migration from old settings // for migration from old settings
@ -149,13 +149,13 @@ void OptionsModel::Init(bool resetSettings)
} }
if (!gArgs.SoftSetArg("-privatesendamount", settings.value("nPrivateSendAmount").toString().toStdString())) if (!gArgs.SoftSetArg("-privatesendamount", settings.value("nPrivateSendAmount").toString().toStdString()))
addOverriddenOption("-privatesendamount"); addOverriddenOption("-privatesendamount");
privateSendClientOptions.nPrivateSendAmount = settings.value("nPrivateSendAmount").toInt(); CPrivateSendClientOptions::SetAmount(settings.value("nPrivateSendAmount").toInt());
if (!settings.contains("fPrivateSendMultiSession")) if (!settings.contains("fPrivateSendMultiSession"))
settings.setValue("fPrivateSendMultiSession", DEFAULT_PRIVATESEND_MULTISESSION); settings.setValue("fPrivateSendMultiSession", DEFAULT_PRIVATESEND_MULTISESSION);
if (!gArgs.SoftSetBoolArg("-privatesendmultisession", settings.value("fPrivateSendMultiSession").toBool())) if (!gArgs.SoftSetBoolArg("-privatesendmultisession", settings.value("fPrivateSendMultiSession").toBool()))
addOverriddenOption("-privatesendmultisession"); addOverriddenOption("-privatesendmultisession");
privateSendClientOptions.fPrivateSendMultiSession = settings.value("fPrivateSendMultiSession").toBool(); CPrivateSendClientOptions::SetMultiSessionEnabled(settings.value("fPrivateSendMultiSession").toBool());
#endif #endif
// Network // Network
@ -470,24 +470,24 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
case PrivateSendRounds: case PrivateSendRounds:
if (settings.value("nPrivateSendRounds") != value) if (settings.value("nPrivateSendRounds") != value)
{ {
privateSendClientOptions.nPrivateSendRounds = value.toInt(); CPrivateSendClientOptions::SetRounds(value.toInt());
settings.setValue("nPrivateSendRounds", privateSendClientOptions.nPrivateSendRounds); settings.setValue("nPrivateSendRounds", CPrivateSendClientOptions::GetRounds());
Q_EMIT privateSendRoundsChanged(); Q_EMIT privateSendRoundsChanged();
} }
break; break;
case PrivateSendAmount: case PrivateSendAmount:
if (settings.value("nPrivateSendAmount") != value) if (settings.value("nPrivateSendAmount") != value)
{ {
privateSendClientOptions.nPrivateSendAmount = value.toInt(); CPrivateSendClientOptions::SetAmount(value.toInt());
settings.setValue("nPrivateSendAmount", privateSendClientOptions.nPrivateSendAmount); settings.setValue("nPrivateSendAmount", CPrivateSendClientOptions::GetAmount());
Q_EMIT privateSentAmountChanged(); Q_EMIT privateSentAmountChanged();
} }
break; break;
case PrivateSendMultiSession: case PrivateSendMultiSession:
if (settings.value("fPrivateSendMultiSession") != value) if (settings.value("fPrivateSendMultiSession") != value)
{ {
privateSendClientOptions.fPrivateSendMultiSession = value.toBool(); CPrivateSendClientOptions::SetMultiSessionEnabled(value.toBool());
settings.setValue("fPrivateSendMultiSession", privateSendClientOptions.fPrivateSendMultiSession); settings.setValue("fPrivateSendMultiSession", CPrivateSendClientOptions::IsMultiSessionEnabled());
} }
break; break;
#endif #endif

View File

@ -172,7 +172,7 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent)
// start with displaying the "out of sync" warnings // start with displaying the "out of sync" warnings
showOutOfSyncWarning(true); showOutOfSyncWarning(true);
if(!privateSendClientOptions.fEnablePrivateSend) return; if (!CPrivateSendClientOptions::IsEnabled()) return;
// Disable any PS UI for masternode or when autobackup is disabled or failed for whatever reason // Disable any PS UI for masternode or when autobackup is disabled or failed for whatever reason
if(fMasternodeMode || nWalletBackups <= 0){ if(fMasternodeMode || nWalletBackups <= 0){
@ -310,7 +310,7 @@ void OverviewPage::setWalletModel(WalletModel *model)
// Initialize PS UI // Initialize PS UI
privateSendStatus(true); privateSendStatus(true);
if(!privateSendClientOptions.fEnablePrivateSend) return; if (!CPrivateSendClientOptions::IsEnabled()) return;
connect(model->getOptionsModel(), SIGNAL(privateSendRoundsChanged()), this, SLOT(updatePrivateSendProgress())); connect(model->getOptionsModel(), SIGNAL(privateSendRoundsChanged()), this, SLOT(updatePrivateSendProgress()));
connect(model->getOptionsModel(), SIGNAL(privateSentAmountChanged()), this, SLOT(updatePrivateSendProgress())); connect(model->getOptionsModel(), SIGNAL(privateSentAmountChanged()), this, SLOT(updatePrivateSendProgress()));
@ -359,7 +359,7 @@ void OverviewPage::updatePrivateSendProgress()
if(!walletModel) return; if(!walletModel) return;
QString strAmountAndRounds; QString strAmountAndRounds;
QString strPrivateSendAmount = BitcoinUnits::formatHtmlWithUnit(nDisplayUnit, privateSendClientOptions.nPrivateSendAmount * COIN, false, BitcoinUnits::separatorAlways); QString strPrivateSendAmount = BitcoinUnits::formatHtmlWithUnit(nDisplayUnit, CPrivateSendClientOptions::GetAmount() * COIN, false, BitcoinUnits::separatorAlways);
if(currentBalance == 0) if(currentBalance == 0)
{ {
@ -368,7 +368,7 @@ void OverviewPage::updatePrivateSendProgress()
// when balance is zero just show info from settings // when balance is zero just show info from settings
strPrivateSendAmount = strPrivateSendAmount.remove(strPrivateSendAmount.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1); strPrivateSendAmount = strPrivateSendAmount.remove(strPrivateSendAmount.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1);
strAmountAndRounds = strPrivateSendAmount + " / " + tr("%n Rounds", "", privateSendClientOptions.nPrivateSendRounds); strAmountAndRounds = strPrivateSendAmount + " / " + tr("%n Rounds", "", CPrivateSendClientOptions::GetRounds());
ui->labelAmountRounds->setToolTip(tr("No inputs detected")); ui->labelAmountRounds->setToolTip(tr("No inputs detected"));
ui->labelAmountRounds->setText(strAmountAndRounds); ui->labelAmountRounds->setText(strAmountAndRounds);
@ -380,15 +380,15 @@ void OverviewPage::updatePrivateSendProgress()
CAmount nMaxToAnonymize = nAnonymizableBalance + currentAnonymizedBalance; CAmount nMaxToAnonymize = nAnonymizableBalance + currentAnonymizedBalance;
// If it's more than the anon threshold, limit to that. // If it's more than the anon threshold, limit to that.
if(nMaxToAnonymize > privateSendClientOptions.nPrivateSendAmount*COIN) nMaxToAnonymize = privateSendClientOptions.nPrivateSendAmount*COIN; if (nMaxToAnonymize > CPrivateSendClientOptions::GetAmount() * COIN) nMaxToAnonymize = CPrivateSendClientOptions::GetAmount() * COIN;
if(nMaxToAnonymize == 0) return; if(nMaxToAnonymize == 0) return;
if(nMaxToAnonymize >= privateSendClientOptions.nPrivateSendAmount * COIN) { if (nMaxToAnonymize >= CPrivateSendClientOptions::GetAmount() * COIN) {
ui->labelAmountRounds->setToolTip(tr("Found enough compatible inputs to mix %1") ui->labelAmountRounds->setToolTip(tr("Found enough compatible inputs to mix %1")
.arg(strPrivateSendAmount)); .arg(strPrivateSendAmount));
strPrivateSendAmount = strPrivateSendAmount.remove(strPrivateSendAmount.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1); strPrivateSendAmount = strPrivateSendAmount.remove(strPrivateSendAmount.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1);
strAmountAndRounds = strPrivateSendAmount + " / " + tr("%n Rounds", "", privateSendClientOptions.nPrivateSendRounds); strAmountAndRounds = strPrivateSendAmount + " / " + tr("%n Rounds", "", CPrivateSendClientOptions::GetRounds());
} else { } else {
QString strMaxToAnonymize = BitcoinUnits::formatHtmlWithUnit(nDisplayUnit, nMaxToAnonymize, false, BitcoinUnits::separatorAlways); QString strMaxToAnonymize = BitcoinUnits::formatHtmlWithUnit(nDisplayUnit, nMaxToAnonymize, false, BitcoinUnits::separatorAlways);
ui->labelAmountRounds->setToolTip(tr("Not enough compatible inputs to mix <span style='%1'>%2</span>,<br>" ui->labelAmountRounds->setToolTip(tr("Not enough compatible inputs to mix <span style='%1'>%2</span>,<br>"
@ -399,7 +399,7 @@ void OverviewPage::updatePrivateSendProgress()
strMaxToAnonymize = strMaxToAnonymize.remove(strMaxToAnonymize.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1); strMaxToAnonymize = strMaxToAnonymize.remove(strMaxToAnonymize.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1);
strAmountAndRounds = "<span style='" + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR) + "'>" + strAmountAndRounds = "<span style='" + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR) + "'>" +
QString(BitcoinUnits::factor(nDisplayUnit) == 1 ? "" : "~") + strMaxToAnonymize + QString(BitcoinUnits::factor(nDisplayUnit) == 1 ? "" : "~") + strMaxToAnonymize +
" / " + tr("%n Rounds", "", privateSendClientOptions.nPrivateSendRounds) + "</span>"; " / " + tr("%n Rounds", "", CPrivateSendClientOptions::GetRounds()) + "</span>";
} }
ui->labelAmountRounds->setText(strAmountAndRounds); ui->labelAmountRounds->setText(strAmountAndRounds);
@ -438,7 +438,7 @@ void OverviewPage::updatePrivateSendProgress()
// apply some weights to them ... // apply some weights to them ...
float denomWeight = 1; float denomWeight = 1;
float anonNormWeight = privateSendClientOptions.nPrivateSendRounds; float anonNormWeight = CPrivateSendClientOptions::GetRounds();
float anonFullWeight = 2; float anonFullWeight = 2;
float fullWeight = denomWeight + anonNormWeight + anonFullWeight; float fullWeight = denomWeight + anonNormWeight + anonFullWeight;
// ... and calculate the whole progress // ... and calculate the whole progress
@ -454,7 +454,7 @@ void OverviewPage::updatePrivateSendProgress()
tr("Denominated") + ": %2%<br/>" + tr("Denominated") + ": %2%<br/>" +
tr("Partially mixed") + ": %3%<br/>" + tr("Partially mixed") + ": %3%<br/>" +
tr("Mixed") + ": %4%<br/>" + tr("Mixed") + ": %4%<br/>" +
tr("Denominated inputs have %5 of %n rounds on average", "", privateSendClientOptions.nPrivateSendRounds)) tr("Denominated inputs have %5 of %n rounds on average", "", CPrivateSendClientOptions::GetRounds()))
.arg(progress).arg(denomPart).arg(anonNormPart).arg(anonFullPart) .arg(progress).arg(denomPart).arg(anonNormPart).arg(anonFullPart)
.arg(nAverageAnonymizedRounds); .arg(nAverageAnonymizedRounds);
ui->privateSendProgress->setToolTip(strToolPip); ui->privateSendProgress->setToolTip(strToolPip);
@ -462,10 +462,10 @@ void OverviewPage::updatePrivateSendProgress()
void OverviewPage::updateAdvancedPSUI(bool fShowAdvancedPSUI) { void OverviewPage::updateAdvancedPSUI(bool fShowAdvancedPSUI) {
this->fShowAdvancedPSUI = fShowAdvancedPSUI; this->fShowAdvancedPSUI = fShowAdvancedPSUI;
int nNumItems = (!privateSendClientOptions.fEnablePrivateSend || !fShowAdvancedPSUI) ? NUM_ITEMS : NUM_ITEMS_ADV; int nNumItems = (!CPrivateSendClientOptions::IsEnabled() || !fShowAdvancedPSUI) ? NUM_ITEMS : NUM_ITEMS_ADV;
SetupTransactionList(nNumItems); SetupTransactionList(nNumItems);
if (!privateSendClientOptions.fEnablePrivateSend) return; if (!CPrivateSendClientOptions::IsEnabled()) return;
ui->framePrivateSend->setVisible(true); ui->framePrivateSend->setVisible(true);
ui->labelCompletitionText->setVisible(fShowAdvancedPSUI); ui->labelCompletitionText->setVisible(fShowAdvancedPSUI);

View File

@ -155,13 +155,12 @@ void WalletModel::pollBalanceChanged()
if(!lockWallet) if(!lockWallet)
return; return;
if(fForceCheckBalanceChanged || chainActive.Height() != cachedNumBlocks || privateSendClientOptions.nPrivateSendRounds != cachedPrivateSendRounds) if (fForceCheckBalanceChanged || chainActive.Height() != cachedNumBlocks || CPrivateSendClientOptions::GetRounds() != cachedPrivateSendRounds) {
{
fForceCheckBalanceChanged = false; fForceCheckBalanceChanged = false;
// Balance and number of transactions might have changed // Balance and number of transactions might have changed
cachedNumBlocks = chainActive.Height(); cachedNumBlocks = chainActive.Height();
cachedPrivateSendRounds = privateSendClientOptions.nPrivateSendRounds; cachedPrivateSendRounds = CPrivateSendClientOptions::GetRounds();
checkBalanceChanged(); checkBalanceChanged();
if(transactionTableModel) if(transactionTableModel)

View File

@ -32,7 +32,7 @@ UniValue privatesend(const JSONRPCRequest& request)
if (fMasternodeMode) if (fMasternodeMode)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Client-side mixing is not supported on masternodes"); throw JSONRPCError(RPC_INTERNAL_ERROR, "Client-side mixing is not supported on masternodes");
if (!privateSendClientOptions.fEnablePrivateSend) { if (!CPrivateSendClientOptions::IsEnabled()) {
if (!gArgs.GetBoolArg("-enableprivatesend", true)) { if (!gArgs.GetBoolArg("-enableprivatesend", true)) {
// otherwise it's on by default, unless cmd line option says otherwise // otherwise it's on by default, unless cmd line option says otherwise
throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing is disabled via -enableprivatesend=0 command line option, remove it to enable mixing again"); throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing is disabled via -enableprivatesend=0 command line option, remove it to enable mixing again");
@ -136,7 +136,7 @@ UniValue getprivatesendinfo(const JSONRPCRequest& request)
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
privateSendClientOptions.GetJsonInfo(obj); CPrivateSendClientOptions::GetJsonInfo(obj);
obj.pushKV("queue_size", privateSendClientQueueManager.GetQueueSize()); obj.pushKV("queue_size", privateSendClientQueueManager.GetQueueSize());

View File

@ -364,7 +364,7 @@ void WalletInit::Start(CScheduler& scheduler)
// Run a thread to flush wallet periodically // Run a thread to flush wallet periodically
scheduler.scheduleEvery(MaybeCompactWalletDB, 500); scheduler.scheduleEvery(MaybeCompactWalletDB, 500);
if (!fMasternodeMode && privateSendClientOptions.fEnablePrivateSend) { if (!fMasternodeMode && CPrivateSendClientOptions::IsEnabled()) {
scheduler.scheduleEvery(std::bind(&DoPrivateSendMaintenance, std::ref(*g_connman)), 1 * 1000); scheduler.scheduleEvery(std::bind(&DoPrivateSendMaintenance, std::ref(*g_connman)), 1 * 1000);
} }
} }
@ -372,7 +372,7 @@ void WalletInit::Start(CScheduler& scheduler)
void WalletInit::Flush() void WalletInit::Flush()
{ {
for (CWallet* pwallet : GetWallets()) { for (CWallet* pwallet : GetWallets()) {
if (privateSendClientOptions.fEnablePrivateSend) { if (CPrivateSendClientOptions::IsEnabled()) {
// Stop PrivateSend, release keys // Stop PrivateSend, release keys
auto it = privateSendClientManagers.find(pwallet->GetName()); auto it = privateSendClientManagers.find(pwallet->GetName());
it->second->ResetPool(); it->second->ResetPool();
@ -407,37 +407,24 @@ void WalletInit::AutoLockMasternodeCollaterals()
void WalletInit::InitPrivateSendSettings() void WalletInit::InitPrivateSendSettings()
{ {
if (!HasWallets()) { CPrivateSendClientOptions::SetEnabled(HasWallets() ? gArgs.GetBoolArg("-enableprivatesend", true) : false);
privateSendClientOptions.fEnablePrivateSend = false; if (!CPrivateSendClientOptions::IsEnabled()) {
} else { return;
privateSendClientOptions.fEnablePrivateSend = gArgs.GetBoolArg("-enableprivatesend", true);
} }
bool fAutoStart = gArgs.GetBoolArg("-privatesendautostart", DEFAULT_PRIVATESEND_AUTOSTART); bool fAutoStart = gArgs.GetBoolArg("-privatesendautostart", DEFAULT_PRIVATESEND_AUTOSTART);
if (privateSendClientOptions.fEnablePrivateSend) { for (auto& pwallet : GetWallets()) {
for (auto& pwallet : GetWallets()) { if (pwallet->IsLocked()) {
if (pwallet->IsLocked()) { privateSendClientManagers.at(pwallet->GetName())->StopMixing();
privateSendClientManagers.at(pwallet->GetName())->StopMixing(); } else if (fAutoStart) {
} else if (fAutoStart) { privateSendClientManagers.at(pwallet->GetName())->StartMixing(pwallet);
privateSendClientManagers.at(pwallet->GetName())->StartMixing(pwallet);
}
} }
} }
privateSendClientOptions.fPrivateSendMultiSession = gArgs.GetBoolArg("-privatesendmultisession", DEFAULT_PRIVATESEND_MULTISESSION); LogPrintf("PrivateSend: autostart=%d, multisession=%d," /* Continued */
privateSendClientOptions.nPrivateSendSessions = std::min(std::max((int)gArgs.GetArg("-privatesendsessions", DEFAULT_PRIVATESEND_SESSIONS), MIN_PRIVATESEND_SESSIONS), MAX_PRIVATESEND_SESSIONS); "sessions=%d, rounds=%d, amount=%d, denoms_goal=%d, denoms_hardcap=%d\n",
privateSendClientOptions.nPrivateSendRounds = std::min(std::max((int)gArgs.GetArg("-privatesendrounds", DEFAULT_PRIVATESEND_ROUNDS), MIN_PRIVATESEND_ROUNDS), MAX_PRIVATESEND_ROUNDS); fAutoStart, CPrivateSendClientOptions::IsMultiSessionEnabled(),
privateSendClientOptions.nPrivateSendAmount = std::min(std::max((int)gArgs.GetArg("-privatesendamount", DEFAULT_PRIVATESEND_AMOUNT), MIN_PRIVATESEND_AMOUNT), MAX_PRIVATESEND_AMOUNT); CPrivateSendClientOptions::GetSessions(), CPrivateSendClientOptions::GetRounds(),
privateSendClientOptions.nPrivateSendDenomsGoal = std::min(std::max((int)gArgs.GetArg("-privatesenddenomsgoal", DEFAULT_PRIVATESEND_DENOMS_GOAL), MIN_PRIVATESEND_DENOMS_GOAL), MAX_PRIVATESEND_DENOMS_GOAL); CPrivateSendClientOptions::GetAmount(), CPrivateSendClientOptions::GetDenomsGoal(),
privateSendClientOptions.nPrivateSendDenomsHardCap = std::min(std::max((int)gArgs.GetArg("-privatesenddenomshardcap", DEFAULT_PRIVATESEND_DENOMS_HARDCAP), MIN_PRIVATESEND_DENOMS_HARDCAP), MAX_PRIVATESEND_DENOMS_HARDCAP); CPrivateSendClientOptions::GetDenomsHardCap());
if (privateSendClientOptions.fEnablePrivateSend) {
LogPrintf("PrivateSend: autostart=%d, multisession=%d," /* Continued */
"sessions=%d, rounds=%d, amount=%d, denoms_goal=%d, denoms_hardcap=%d\n",
fAutoStart, privateSendClientOptions.fPrivateSendMultiSession,
privateSendClientOptions.nPrivateSendSessions, privateSendClientOptions.nPrivateSendRounds,
privateSendClientOptions.nPrivateSendAmount,
privateSendClientOptions.nPrivateSendDenomsGoal, privateSendClientOptions.nPrivateSendDenomsHardCap);
}
} }
void WalletInit::InitKeePass() void WalletInit::InitKeePass()

View File

@ -2682,7 +2682,7 @@ UniValue setprivatesendrounds(const JSONRPCRequest& request)
if (nRounds > MAX_PRIVATESEND_ROUNDS || nRounds < MIN_PRIVATESEND_ROUNDS) if (nRounds > MAX_PRIVATESEND_ROUNDS || nRounds < MIN_PRIVATESEND_ROUNDS)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid number of rounds"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid number of rounds");
privateSendClientOptions.nPrivateSendRounds = nRounds; CPrivateSendClientOptions::SetRounds(nRounds);
return NullUniValue; return NullUniValue;
} }
@ -2710,7 +2710,7 @@ UniValue setprivatesendamount(const JSONRPCRequest& request)
if (nAmount > MAX_PRIVATESEND_AMOUNT || nAmount < MIN_PRIVATESEND_AMOUNT) if (nAmount > MAX_PRIVATESEND_AMOUNT || nAmount < MIN_PRIVATESEND_AMOUNT)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount of " + CURRENCY_UNIT + " as mixing goal amount"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount of " + CURRENCY_UNIT + " as mixing goal amount");
privateSendClientOptions.nPrivateSendAmount = nAmount; CPrivateSendClientOptions::SetAmount(nAmount);
return NullUniValue; return NullUniValue;
} }

View File

@ -1662,7 +1662,7 @@ int CWallet::GetCappedOutpointPrivateSendRounds(const COutPoint& outpoint) const
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
int realPrivateSendRounds = GetRealOutpointPrivateSendRounds(outpoint); int realPrivateSendRounds = GetRealOutpointPrivateSendRounds(outpoint);
return realPrivateSendRounds > privateSendClientOptions.nPrivateSendRounds ? privateSendClientOptions.nPrivateSendRounds : realPrivateSendRounds; return realPrivateSendRounds > CPrivateSendClientOptions::GetRounds() ? CPrivateSendClientOptions::GetRounds() : realPrivateSendRounds;
} }
bool CWallet::IsDenominated(const COutPoint& outpoint) const bool CWallet::IsDenominated(const COutPoint& outpoint) const
@ -2364,7 +2364,7 @@ CAmount CWalletTx::GetAnonymizedCredit(bool fUseCache) const
if (pwallet->IsSpent(hashTx, i) || !CPrivateSend::IsDenominatedAmount(txout.nValue)) continue; if (pwallet->IsSpent(hashTx, i) || !CPrivateSend::IsDenominatedAmount(txout.nValue)) continue;
const int nRounds = pwallet->GetCappedOutpointPrivateSendRounds(outpoint); const int nRounds = pwallet->GetCappedOutpointPrivateSendRounds(outpoint);
if (nRounds >= privateSendClientOptions.nPrivateSendRounds){ if (nRounds >= CPrivateSendClientOptions::GetRounds()) {
nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE); nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE);
if (!MoneyRange(nCredit)) if (!MoneyRange(nCredit))
throw std::runtime_error(std::string(__func__) + ": value out of range"); throw std::runtime_error(std::string(__func__) + ": value out of range");
@ -2573,7 +2573,7 @@ CAmount CWallet::GetBalance() const
CAmount CWallet::GetAnonymizableBalance(bool fSkipDenominated, bool fSkipUnconfirmed) const CAmount CWallet::GetAnonymizableBalance(bool fSkipDenominated, bool fSkipUnconfirmed) const
{ {
if(!privateSendClientOptions.fEnablePrivateSend) return 0; if (!CPrivateSendClientOptions::IsEnabled()) return 0;
std::vector<CompactTallyItem> vecTally; std::vector<CompactTallyItem> vecTally;
if(!SelectCoinsGroupedByAddresses(vecTally, fSkipDenominated, true, fSkipUnconfirmed)) return 0; if(!SelectCoinsGroupedByAddresses(vecTally, fSkipDenominated, true, fSkipUnconfirmed)) return 0;
@ -2595,7 +2595,7 @@ CAmount CWallet::GetAnonymizableBalance(bool fSkipDenominated, bool fSkipUnconfi
CAmount CWallet::GetAnonymizedBalance() const CAmount CWallet::GetAnonymizedBalance() const
{ {
if(!privateSendClientOptions.fEnablePrivateSend) return 0; if (!CPrivateSendClientOptions::IsEnabled()) return 0;
CAmount nTotal = 0; CAmount nTotal = 0;
@ -2612,7 +2612,7 @@ CAmount CWallet::GetAnonymizedBalance() const
// that's ok as long as we use it for informational purposes only // that's ok as long as we use it for informational purposes only
float CWallet::GetAverageAnonymizedRounds() const float CWallet::GetAverageAnonymizedRounds() const
{ {
if(!privateSendClientOptions.fEnablePrivateSend) return 0; if (!CPrivateSendClientOptions::IsEnabled()) return 0;
int nTotal = 0; int nTotal = 0;
int nCount = 0; int nCount = 0;
@ -2634,7 +2634,7 @@ float CWallet::GetAverageAnonymizedRounds() const
// that's ok as long as we use it for informational purposes only // that's ok as long as we use it for informational purposes only
CAmount CWallet::GetNormalizedAnonymizedBalance() const CAmount CWallet::GetNormalizedAnonymizedBalance() const
{ {
if(!privateSendClientOptions.fEnablePrivateSend) return 0; if (!CPrivateSendClientOptions::IsEnabled()) return 0;
CAmount nTotal = 0; CAmount nTotal = 0;
@ -2648,7 +2648,7 @@ CAmount CWallet::GetNormalizedAnonymizedBalance() const
if (it->second.GetDepthInMainChain() < 0) continue; if (it->second.GetDepthInMainChain() < 0) continue;
int nRounds = GetCappedOutpointPrivateSendRounds(outpoint); int nRounds = GetCappedOutpointPrivateSendRounds(outpoint);
nTotal += nValue * nRounds / privateSendClientOptions.nPrivateSendRounds; nTotal += nValue * nRounds / CPrivateSendClientOptions::GetRounds();
} }
return nTotal; return nTotal;
@ -2656,7 +2656,7 @@ CAmount CWallet::GetNormalizedAnonymizedBalance() const
CAmount CWallet::GetDenominatedBalance(bool unconfirmed) const CAmount CWallet::GetDenominatedBalance(bool unconfirmed) const
{ {
if(!privateSendClientOptions.fEnablePrivateSend) return 0; if (!CPrivateSendClientOptions::IsEnabled()) return 0;
CAmount nTotal = 0; CAmount nTotal = 0;
@ -2831,11 +2831,11 @@ void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, const
if (nCoinType == CoinType::ONLY_FULLY_MIXED) { if (nCoinType == CoinType::ONLY_FULLY_MIXED) {
if (!CPrivateSend::IsDenominatedAmount(pcoin->tx->vout[i].nValue)) continue; if (!CPrivateSend::IsDenominatedAmount(pcoin->tx->vout[i].nValue)) continue;
int nRounds = GetCappedOutpointPrivateSendRounds(COutPoint(wtxid, i)); int nRounds = GetCappedOutpointPrivateSendRounds(COutPoint(wtxid, i));
found = nRounds >= privateSendClientOptions.nPrivateSendRounds; found = nRounds >= CPrivateSendClientOptions::GetRounds();
} else if(nCoinType == CoinType::ONLY_READY_TO_MIX) { } else if(nCoinType == CoinType::ONLY_READY_TO_MIX) {
if (!CPrivateSend::IsDenominatedAmount(pcoin->tx->vout[i].nValue)) continue; if (!CPrivateSend::IsDenominatedAmount(pcoin->tx->vout[i].nValue)) continue;
int nRounds = GetCappedOutpointPrivateSendRounds(COutPoint(wtxid, i)); int nRounds = GetCappedOutpointPrivateSendRounds(COutPoint(wtxid, i));
found = nRounds < privateSendClientOptions.nPrivateSendRounds; found = nRounds < CPrivateSendClientOptions::GetRounds();
} else if(nCoinType == CoinType::ONLY_NONDENOMINATED) { } else if(nCoinType == CoinType::ONLY_NONDENOMINATED) {
if (CPrivateSend::IsCollateralAmount(pcoin->tx->vout[i].nValue)) continue; // do not use collateral amounts if (CPrivateSend::IsCollateralAmount(pcoin->tx->vout[i].nValue)) continue; // do not use collateral amounts
found = !CPrivateSend::IsDenominatedAmount(pcoin->tx->vout[i].nValue); found = !CPrivateSend::IsDenominatedAmount(pcoin->tx->vout[i].nValue);
@ -3217,7 +3217,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
// Make sure to include mixed preset inputs only, // Make sure to include mixed preset inputs only,
// even if some non-mixed inputs were manually selected via CoinControl // even if some non-mixed inputs were manually selected via CoinControl
int nRounds = GetRealOutpointPrivateSendRounds(outpoint); int nRounds = GetRealOutpointPrivateSendRounds(outpoint);
if (nRounds < privateSendClientOptions.nPrivateSendRounds) continue; if (nRounds < CPrivateSendClientOptions::GetRounds()) continue;
} }
nValueFromPresetInputs += pcoin->tx->vout[outpoint.n].nValue; nValueFromPresetInputs += pcoin->tx->vout[outpoint.n].nValue;
setPresetCoins.insert(CInputCoin(pcoin, outpoint.n)); setPresetCoins.insert(CInputCoin(pcoin, outpoint.n));
@ -3420,7 +3420,7 @@ bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTa
// otherwise they will just lead to higher fee / lower priority // otherwise they will just lead to higher fee / lower priority
if(wtx.tx->vout[i].nValue <= nSmallestDenom/10) continue; if(wtx.tx->vout[i].nValue <= nSmallestDenom/10) continue;
// ignore mixed // ignore mixed
if(GetCappedOutpointPrivateSendRounds(COutPoint(outpoint.hash, i)) >= privateSendClientOptions.nPrivateSendRounds) continue; if (GetCappedOutpointPrivateSendRounds(COutPoint(outpoint.hash, i)) >= CPrivateSendClientOptions::GetRounds()) continue;
} }
if (itTallyItem == mapTally.end()) { if (itTallyItem == mapTally.end()) {