From d1eb2ceda1a1efc5352cc0aac55a29ed5eb81539 Mon Sep 17 00:00:00 2001 From: Anthony Fieroni Date: Thu, 7 Jan 2021 17:14:38 +0200 Subject: [PATCH] Fix accounthistorycount count on wallet txs Signed-off-by: Anthony Fieroni --- src/masternodes/mn_rpc.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/masternodes/mn_rpc.cpp b/src/masternodes/mn_rpc.cpp index 7d5e2c712d..e6d1b0121b 100644 --- a/src/masternodes/mn_rpc.cpp +++ b/src/masternodes/mn_rpc.cpp @@ -3577,7 +3577,7 @@ UniValue accounthistorycount(const JSONRPCRequest& request) { UniValue ret(UniValue::VARR); uint64_t count = 0; - const auto currentHeight = uint32_t(::ChainActive().Height() + 1); + const auto currentHeight = uint32_t(::ChainActive().Height()); auto shouldContinueToNextAccountHistory = [&](AccountHistoryKey const & key, CLazySerialize valueLazy) -> bool { if (!owner.empty() && owner != key.owner) { @@ -3597,7 +3597,7 @@ UniValue accounthistorycount(const JSONRPCRequest& request) { return true; }; - AccountHistoryKey startAccountKey{owner, currentHeight, 0}; + AccountHistoryKey startAccountKey{owner, currentHeight, std::numeric_limits::max()}; if (isMine) { pcustomcsview->ForEachMineAccountHistory(shouldContinueToNextAccountHistory, startAccountKey); @@ -3607,7 +3607,22 @@ UniValue accounthistorycount(const JSONRPCRequest& request) { if (shouldSearchInWallet) { auto incCount = [&count](COutputEntry const &) { ++count; return true; }; - searchInWallet(pwallet, owner, [&](CWalletTx const *) -> bool { + searchInWallet(pwallet, owner, [&](CWalletTx const * pwtx) -> bool { + if (txs.count(pwtx->GetHash())) { + return true; + } + + auto index = LookupBlockIndex(pwtx->hashBlock); + + // Check we have index before progressing, wallet might be reindexing. + if (!index) { + return true; + } + + if (index->height > currentHeight) { + return true; + } + return false; }, incCount, incCount); }