Skip to content

Commit

Permalink
Improving the listtransactions performance
Browse files Browse the repository at this point in the history
  • Loading branch information
a-bezrukov committed Apr 19, 2021
1 parent d76b2c5 commit 6338b4c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ bool CDeterministicMNManager::IsDIP3Enforced(int nHeight)

void CDeterministicMNManager::CleanupCache(int nHeight)
{
LOCK(cs);
AssertLockHeld(cs);

std::vector<uint256> toDelete;
for (const auto& p : mnListsCache) {
Expand Down
2 changes: 1 addition & 1 deletion src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ class CDeterministicMNManager
void UpgradeDBIfNeeded();
static bool IsDIP3Active(int height);

public:
private:
void CleanupCache(int nHeight);
};

Expand Down
8 changes: 0 additions & 8 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,6 @@ bool CMasternodePayments::GetBlockTxOuts(int nBlockHeight, CAmount blockReward,
return true;
}

bool CMasternodePayments::GetBlockTxOutsWipeCache(int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet) const
{
bool result = GetBlockTxOuts(nBlockHeight, blockReward, voutMasternodePaymentsRet);
AssertLockHeld(cs_main);
deterministicMNManager->CleanupCache(chainActive.Height());
return result;
}

// Is this masternode scheduled to get paid soon?
// -- Only look ahead up to 8 blocks to allow for propagation of the latest 2 blocks of votes
bool CMasternodePayments::IsScheduled(const CDeterministicMNCPtr& dmnIn, int nNotBlockHeight) const
Expand Down
1 change: 0 additions & 1 deletion src/masternode-payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class CMasternodePayments
{
public:
bool GetBlockTxOuts(int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet) const;
bool GetBlockTxOutsWipeCache(int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet) const;
bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward) const;
bool IsScheduled(const CDeterministicMNCPtr& dmn, int nNotBlockHeight) const;

Expand Down
16 changes: 10 additions & 6 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,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)
void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter, bool omitNmPayments)
{
CAmount nFee;
string strSentAccount;
Expand Down Expand Up @@ -1555,7 +1555,7 @@ void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const strin
bool its_znode_payment = false;
if (!fSkipMnpayoutCheck) {
std::vector<CTxOut> voutMasternodePaymentsRet;
mnpayments.GetBlockTxOutsWipeCache(txHeight, CAmount(), voutMasternodePaymentsRet);
mnpayments.GetBlockTxOuts(txHeight, CAmount(), voutMasternodePaymentsRet);
//compare address of payee to addr.
for(CTxOut const & out : voutMasternodePaymentsRet) {
CTxDestination payeeDest;
Expand Down Expand Up @@ -1617,7 +1617,7 @@ UniValue listtransactions(const JSONRPCRequest& request)
return NullUniValue;
}

if (request.fHelp || request.params.size() > 4)
if (request.fHelp || request.params.size() > 5)
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 @@ -1626,6 +1626,7 @@ 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 @@ -1692,6 +1693,9 @@ 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 @@ -1707,7 +1711,7 @@ UniValue listtransactions(const JSONRPCRequest& request)
{
CWalletTx *const pwtx = (*it).second.first;
if (pwtx != 0)
ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter);
ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter, omitNmPayments);
CAccountingEntry *const pacentry = (*it).second.second;
if (pacentry != 0)
AcentryToJSON(*pacentry, strAccount, ret);
Expand Down Expand Up @@ -1916,7 +1920,7 @@ UniValue listsinceblock(const JSONRPCRequest& request)
CWalletTx tx = pairWtx.second;

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

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

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

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

0 comments on commit 6338b4c

Please sign in to comment.