Skip to content

Commit

Permalink
Listtransaciton performance fix (#1018)
Browse files Browse the repository at this point in the history
* Reimplementing ListTransactions with a global flag

* Fixing ListTransaction perf with a global flag

* Improving the listtransactions performance
  • Loading branch information
a-bezrukov committed Apr 27, 2021
1 parent 6f2fa2b commit e0bc12b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-elysiumshowblockconsensushash=<number>", "Calculate and log the consensus hash for the specified block");
#endif

strUsage += HelpMessageOpt("-skipmnpayoutcheck", _("Do not check for masternode payout when handling listtransactions, listsinceblock and gettransaction calls (improves performance)"));

return strUsage;
}

Expand Down Expand Up @@ -1402,6 +1404,7 @@ bool AppInitParameterInteraction()
}
}
}
fSkipMnpayoutCheck = GetBoolArg("-skipmnpayoutcheck", false);
return true;
}

Expand Down
1 change: 0 additions & 1 deletion src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "listtransactions", 1, "count" },
{ "listtransactions", 2, "skip" },
{ "listtransactions", 3, "include_watchonly" },
{ "listtransactions", 4, "skip_mnout_check" },
{ "listaccounts", 0, "minconf" },
{ "listaccounts", 1, "include_watchonly" },
{ "walletpassphrase", 1, "timeout" },
Expand Down
1 change: 1 addition & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS;
bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS;
bool fLogIPs = DEFAULT_LOGIPS;

bool fSkipMnpayoutCheck = false;

std::atomic<bool> fReopenDebugLog(false);
CTranslationInterface translationInterface;
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ extern std::atomic<bool> fReopenElysiumLog;
extern const char * const BITCOIN_CONF_FILENAME;
extern const char * const BITCOIN_PID_FILENAME;

extern bool fSkipMnpayoutCheck;

/**
* Translation function: Call Translate signal on UI interface, which returns a boost::optional result.
Expand Down
17 changes: 6 additions & 11 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest, CBitc
entry.push_back(Pair("address", addr.ToString()));
}

void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter, bool omitNmPayments)
void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter)
{
CAmount nFee;
string strSentAccount;
Expand Down Expand Up @@ -1534,8 +1534,7 @@ void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const strin
int txHeight = chainActive.Height() - wtx.GetDepthInMainChain();

bool its_znode_payment = false;

if (!omitNmPayments) {
if (!fSkipMnpayoutCheck) {
std::vector<CTxOut> voutMasternodePaymentsRet;
mnpayments.GetBlockTxOuts(txHeight, CAmount(), voutMasternodePaymentsRet);
//compare address of payee to addr.
Expand Down Expand Up @@ -1599,7 +1598,7 @@ UniValue listtransactions(const JSONRPCRequest& request)
return NullUniValue;
}

if (request.fHelp || request.params.size() > 5)
if (request.fHelp || request.params.size() > 4)
throw runtime_error(
"listtransactions ( \"account\" count skip include_watchonly)\n"
"\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n"
Expand All @@ -1608,7 +1607,6 @@ UniValue listtransactions(const JSONRPCRequest& request)
"2. count (numeric, optional, default=10) The number of transactions to return\n"
"3. skip (numeric, optional, default=0) The number of transactions to skip\n"
"4. include_watchonly (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')\n"
"5. skip_mnout_check (bool, optional, default=false) Skip checking for masternode payment txout (improves performance)\n"
"\nResult:\n"
"[\n"
" {\n"
Expand Down Expand Up @@ -1675,9 +1673,6 @@ UniValue listtransactions(const JSONRPCRequest& request)
if(request.params.size() > 3)
if(request.params[3].get_bool())
filter = filter | ISMINE_WATCH_ONLY;
bool omitNmPayments = false;
if(request.params.size() > 4)
omitNmPayments = request.params[4].get_bool();

if (nCount < 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count");
Expand All @@ -1693,7 +1688,7 @@ UniValue listtransactions(const JSONRPCRequest& request)
{
CWalletTx *const pwtx = (*it).second.first;
if (pwtx != 0)
ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter, omitNmPayments);
ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter);
CAccountingEntry *const pacentry = (*it).second.second;
if (pacentry != 0)
AcentryToJSON(*pacentry, strAccount, ret);
Expand Down Expand Up @@ -1902,7 +1897,7 @@ UniValue listsinceblock(const JSONRPCRequest& request)
CWalletTx tx = pairWtx.second;

if (depth == -1 || tx.GetDepthInMainChain() < depth)
ListTransactions(pwallet, tx, "*", 0, true, transactions, filter, false);
ListTransactions(pwallet, tx, "*", 0, true, transactions, filter);
}

CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms];
Expand Down Expand Up @@ -1998,7 +1993,7 @@ UniValue gettransaction(const JSONRPCRequest& request)
WalletTxToJSON(wtx, entry);

UniValue details(UniValue::VARR);
ListTransactions(pwallet, wtx, "*", 0, false, details, filter, false);
ListTransactions(pwallet, wtx, "*", 0, false, details, filter);
entry.push_back(Pair("details", details));

string strHex = EncodeHexTx(static_cast<CTransaction>(wtx), RPCSerializationFlags());
Expand Down

0 comments on commit e0bc12b

Please sign in to comment.