From a3c3a8ec14252adfc70c3d3e8a4fb3ffd606835e Mon Sep 17 00:00:00 2001 From: Diego del Corral Tercero Date: Mon, 6 Dec 2021 15:52:19 +0100 Subject: [PATCH] Correct startBlock implementation for depth in getmasternodeblocks --- src/masternodes/rpc_masternodes.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/masternodes/rpc_masternodes.cpp b/src/masternodes/rpc_masternodes.cpp index 5b474b2900..ea7737fd3f 100644 --- a/src/masternodes/rpc_masternodes.cpp +++ b/src/masternodes/rpc_masternodes.cpp @@ -803,8 +803,10 @@ UniValue getmasternodeblocks(const JSONRPCRequest& request) { if (!request.params[1].isNull()) { depth = request.params[1].get_int(); } - UniValue ret(UniValue::VOBJ); + auto currentHeight = ::ChainActive().Height(); + depth = std::min(depth, currentHeight); + auto startBlock = currentHeight - depth; auto masternodeBlocks = [&](const uint256& masternodeID, uint32_t blockHeight) { if (masternodeID != mn_id) { @@ -814,6 +816,9 @@ UniValue getmasternodeblocks(const JSONRPCRequest& request) { if (blockHeight <= creationHeight) { return true; } + if (blockHeight <= startBlock) { + return false; + } auto tip = ::ChainActive()[blockHeight]; if (tip && depth > 0) { lastHeight = tip->height; @@ -834,7 +839,7 @@ UniValue getmasternodeblocks(const JSONRPCRequest& request) { auto tip = ::ChainActive()[std::min(lastHeight, uint64_t(Params().GetConsensus().DakotaCrescentHeight)) - 1]; - for (; tip && tip->height > creationHeight && depth > 0; tip = tip->pprev, --depth) { + for (; tip && tip->height > creationHeight && depth > 0 && tip->height > startBlock; tip = tip->pprev, --depth) { auto id = pcustomcsview->GetMasternodeIdByOperator(tip->minterKey()); if (id && *id == mn_id) { ret.pushKV(std::to_string(tip->height), tip->GetBlockHash().ToString());