Skip to content

Commit 4112414

Browse files
authored
Introduce getprivatesendinfo and deprecate getpoolinfo (#3140)
* Introduce getprivatesendinfo and deprecate getpoolinfo * s/ToJson/GetJsonInfo/ * s/queues/queue_size/ * Add TODO to explain `denomination` string convertion * s/entries/entries_count/ * Use `CURRENCY_UNIT` * Who needs safety belts after all
1 parent 152c10b commit 4112414

File tree

5 files changed

+139
-32
lines changed

5 files changed

+139
-32
lines changed

src/privatesend/privatesend-client.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "wallet/coincontrol.h"
2020

2121
#include <memory>
22+
#include <univalue.h>
2223

2324
CPrivateSendClientManager privateSendClient;
2425

@@ -1667,3 +1668,54 @@ void CPrivateSendClientManager::DoMaintenance(CConnman& connman)
16671668
nDoAutoNextRun = nTick + PRIVATESEND_AUTO_TIMEOUT_MIN + GetRandInt(PRIVATESEND_AUTO_TIMEOUT_MAX - PRIVATESEND_AUTO_TIMEOUT_MIN);
16681669
}
16691670
}
1671+
1672+
void CPrivateSendClientSession::GetJsonInfo(UniValue& obj) const
1673+
{
1674+
obj.clear();
1675+
obj.setObject();
1676+
if (mixingMasternode != nullptr) {
1677+
assert(mixingMasternode->pdmnState);
1678+
obj.push_back(Pair("protxhash", mixingMasternode->proTxHash.ToString()));
1679+
obj.push_back(Pair("outpoint", mixingMasternode->collateralOutpoint.ToStringShort()));
1680+
obj.push_back(Pair("service", mixingMasternode->pdmnState->addr.ToString()));
1681+
}
1682+
CAmount amount{0};
1683+
if (nSessionDenom) {
1684+
// TODO: GetDenominationsToString has few issues:
1685+
// - it returns a string of denomination amounts concatenated via "+" if there are many of them
1686+
// - it uses FormatMoney which drops trailing zeros
1687+
// We no longer use multiple denominations in one session and this thing should be refactored
1688+
// together with other similar functions in CPrivatesend.
1689+
// For now, we just use a workaround here to convert a string into CAmount and convert it to a
1690+
// proper format via ValueFromAmount later.
1691+
ParseFixedPoint(CPrivateSend::GetDenominationsToString(nSessionDenom), 8, &amount);
1692+
}
1693+
obj.push_back(Pair("denomination", ValueFromAmount(amount)));
1694+
obj.push_back(Pair("state", GetStateString()));
1695+
obj.push_back(Pair("entries_count", GetEntriesCount()));
1696+
}
1697+
1698+
void CPrivateSendClientManager::GetJsonInfo(UniValue& obj) const
1699+
{
1700+
LOCK(cs_deqsessions);
1701+
obj.clear();
1702+
obj.setObject();
1703+
obj.push_back(Pair("enabled", fEnablePrivateSend));
1704+
obj.push_back(Pair("running", fPrivateSendRunning));
1705+
obj.push_back(Pair("multisession", fPrivateSendMultiSession));
1706+
obj.push_back(Pair("max_sessions", nPrivateSendSessions));
1707+
obj.push_back(Pair("max_rounds", nPrivateSendRounds));
1708+
obj.push_back(Pair("max_amount", nPrivateSendAmount));
1709+
obj.push_back(Pair("max_denoms", nPrivateSendDenoms));
1710+
obj.push_back(Pair("queue_size", GetQueueSize()));
1711+
1712+
UniValue arrSessions(UniValue::VARR);
1713+
for (const auto& session : deqSessions) {
1714+
if (session.GetState() != POOL_STATE_IDLE) {
1715+
UniValue objSession(UniValue::VOBJ);
1716+
session.GetJsonInfo(objSession);
1717+
arrSessions.push_back(objSession);
1718+
}
1719+
}
1720+
obj.push_back(Pair("sessions", arrSessions));
1721+
}

src/privatesend/privatesend-client.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class CPrivateSendClientManager;
1515
class CConnman;
1616
class CNode;
17-
17+
class UniValue;
1818

1919
static const int MIN_PRIVATESEND_SESSIONS = 1;
2020
static const int MIN_PRIVATESEND_ROUNDS = 2;
@@ -162,6 +162,8 @@ class CPrivateSendClientSession : public CPrivateSendBaseSession
162162
bool ProcessPendingDsaRequest(CConnman& connman);
163163

164164
bool CheckTimeout();
165+
166+
void GetJsonInfo(UniValue& obj) const;
165167
};
166168

167169
/** Used to keep track of current status of mixing pool
@@ -249,6 +251,8 @@ class CPrivateSendClientManager : public CPrivateSendBaseManager
249251
void UpdatedBlockTip(const CBlockIndex* pindex);
250252

251253
void DoMaintenance(CConnman& connman);
254+
255+
void GetJsonInfo(UniValue& obj) const;
252256
};
253257

254258
#endif

src/privatesend/privatesend-server.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include "llmq/quorums_instantsend.h"
2222

23+
#include <univalue.h>
24+
2325
CPrivateSendServer privateSendServer;
2426

2527
void CPrivateSendServer::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman)
@@ -941,3 +943,17 @@ void CPrivateSendServer::DoMaintenance(CConnman& connman)
941943
privateSendServer.CheckTimeout(connman);
942944
privateSendServer.CheckForCompleteQueue(connman);
943945
}
946+
947+
void CPrivateSendServer::GetJsonInfo(UniValue& obj) const
948+
{
949+
obj.clear();
950+
obj.setObject();
951+
obj.push_back(Pair("queue_size", GetQueueSize()));
952+
CAmount amount{0};
953+
if (nSessionDenom) {
954+
ParseFixedPoint(CPrivateSend::GetDenominationsToString(nSessionDenom), 8, &amount);
955+
}
956+
obj.push_back(Pair("denomination", ValueFromAmount(amount)));
957+
obj.push_back(Pair("state", GetStateString()));
958+
obj.push_back(Pair("entries_count", GetEntriesCount()));
959+
}

src/privatesend/privatesend-server.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "privatesend.h"
1010

1111
class CPrivateSendServer;
12+
class UniValue;
1213

1314
// The main object for accessing mixing
1415
extern CPrivateSendServer privateSendServer;
@@ -82,6 +83,8 @@ class CPrivateSendServer : public CPrivateSendBaseSession, public CPrivateSendBa
8283
void CheckForCompleteQueue(CConnman& connman);
8384

8485
void DoMaintenance(CConnman& connman);
86+
87+
void GetJsonInfo(UniValue& obj) const;
8588
};
8689

8790
#endif

src/rpc/masternode.cpp

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -93,44 +93,75 @@ UniValue privatesend(const JSONRPCRequest& request)
9393

9494
UniValue getpoolinfo(const JSONRPCRequest& request)
9595
{
96-
if (request.fHelp || request.params.size() != 0)
97-
throw std::runtime_error(
98-
"getpoolinfo\n"
99-
"Returns an object containing mixing pool related information.\n");
96+
throw std::runtime_error(
97+
"getpoolinfo\n"
98+
"DEPRECATED. Please use getprivatesendinfo instead.\n"
99+
);
100+
}
100101

101-
#ifdef ENABLE_WALLET
102-
CPrivateSendBaseManager* pprivateSendBaseManager = fMasternodeMode ? (CPrivateSendBaseManager*)&privateSendServer : (CPrivateSendBaseManager*)&privateSendClient;
102+
UniValue getprivatesendinfo(const JSONRPCRequest& request)
103+
{
104+
if (request.fHelp || request.params.size() != 0) {
105+
throw std::runtime_error(
106+
"getprivatesendinfo\n"
107+
"Returns an object containing an information about PrivateSend settings and state.\n"
108+
"\nResult (for regular nodes):\n"
109+
"{\n"
110+
" \"enabled\": true|false, (bool) Whether mixing functionality is enabled\n"
111+
" \"running\": true|false, (bool) Whether mixing is currently running\n"
112+
" \"multisession\": true|false, (bool) Whether PrivateSend Multisession option is enabled\n"
113+
" \"max_sessions\": xxx, (numeric) How many parallel mixing sessions can there be at once\n"
114+
" \"max_rounds\": xxx, (numeric) How many rounds to mix\n"
115+
" \"max_amount\": xxx, (numeric) How many " + CURRENCY_UNIT + " to keep anonimized\n"
116+
" \"max_denoms\": xxx, (numeric) How many inputs of each denominated amount to create\n"
117+
" \"queue_size\": xxx, (numeric) How many queues there are currently on the network\n"
118+
" \"sessions\": (array of json objects)\n"
119+
" [\n"
120+
" {\n"
121+
" \"protxhash\": \"...\", (string) The ProTxHash of the masternode\n"
122+
" \"outpoint\": \"txid-index\", (string) The outpoint of the masternode\n"
123+
" \"service\": \"host:port\", (string) The IP address and port of the masternode\n"
124+
" \"denomination\": xxx, (numeric) The denomination of the mixing session in " + CURRENCY_UNIT + "\n"
125+
" \"state\": \"...\", (string) Current state of the mixing session\n"
126+
" \"entries_count\": xxx, (numeric) The number of entries in the mixing session\n"
127+
" }\n"
128+
" ,...\n"
129+
" ],\n"
130+
" \"keys_left\": xxx, (numeric) How many new keys are left since last automatic backup\n"
131+
" \"warnings\": \"...\" (string) Warnings if any\n"
132+
"}\n"
133+
"\nResult (for masternodes):\n"
134+
"{\n"
135+
" \"queue_size\": xxx, (numeric) How many queues there are currently on the network\n"
136+
" \"denomination\": xxx, (numeric) The denomination of the mixing session in " + CURRENCY_UNIT + "\n"
137+
" \"state\": \"...\", (string) Current state of the mixing session\n"
138+
" \"entries_count\": xxx, (numeric) The number of entries in the mixing session\n"
139+
"}\n"
140+
"\nExamples:\n"
141+
+ HelpExampleCli("getprivatesendinfo", "")
142+
+ HelpExampleRpc("getprivatesendinfo", "")
143+
);
144+
}
103145

104146
UniValue obj(UniValue::VOBJ);
105-
// TODO:
106-
// obj.push_back(Pair("state", pprivateSendBase->GetStateString()));
107-
obj.push_back(Pair("queue", pprivateSendBaseManager->GetQueueSize()));
108-
// obj.push_back(Pair("entries", pprivateSendBase->GetEntriesCount()));
109-
obj.push_back(Pair("status", privateSendClient.GetStatuses()));
110-
111-
std::vector<CDeterministicMNCPtr> vecDmns;
112-
if (privateSendClient.GetMixingMasternodesInfo(vecDmns)) {
113-
UniValue pools(UniValue::VARR);
114-
for (const auto& dmn : vecDmns) {
115-
UniValue pool(UniValue::VOBJ);
116-
pool.push_back(Pair("outpoint", dmn->collateralOutpoint.ToStringShort()));
117-
pool.push_back(Pair("addr", dmn->pdmnState->addr.ToString()));
118-
pools.push_back(pool);
119-
}
120-
obj.push_back(Pair("pools", pools));
147+
148+
if (fMasternodeMode) {
149+
privateSendServer.GetJsonInfo(obj);
150+
return obj;
121151
}
122152

153+
154+
#ifdef ENABLE_WALLET
155+
privateSendClient.GetJsonInfo(obj);
156+
123157
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
124-
if (pwallet) {
125-
obj.push_back(Pair("keys_left", pwallet->nKeysLeftSinceAutoBackup));
126-
obj.push_back(Pair("warnings", pwallet->nKeysLeftSinceAutoBackup < PRIVATESEND_KEYS_THRESHOLD_WARNING
127-
? "WARNING: keypool is almost depleted!" : ""));
158+
if (!pwallet) {
159+
return obj;
128160
}
129-
#else // ENABLE_WALLET
130-
UniValue obj(UniValue::VOBJ);
131-
obj.push_back(Pair("state", privateSendServer.GetStateString()));
132-
obj.push_back(Pair("queue", privateSendServer.GetQueueSize()));
133-
obj.push_back(Pair("entries", privateSendServer.GetEntriesCount()));
161+
162+
obj.push_back(Pair("keys_left", pwallet->nKeysLeftSinceAutoBackup));
163+
obj.push_back(Pair("warnings", pwallet->nKeysLeftSinceAutoBackup < PRIVATESEND_KEYS_THRESHOLD_WARNING
164+
? "WARNING: keypool is almost depleted!" : ""));
134165
#endif // ENABLE_WALLET
135166

136167
return obj;
@@ -635,6 +666,7 @@ static const CRPCCommand commands[] =
635666
{ "dash", "masternode", &masternode, true, {} },
636667
{ "dash", "masternodelist", &masternodelist, true, {} },
637668
{ "dash", "getpoolinfo", &getpoolinfo, true, {} },
669+
{ "dash", "getprivatesendinfo", &getprivatesendinfo, true, {} },
638670
#ifdef ENABLE_WALLET
639671
{ "dash", "privatesend", &privatesend, false, {} },
640672
#endif // ENABLE_WALLET

0 commit comments

Comments
 (0)