Skip to content

Commit

Permalink
Correct startBlock implementation for depth in getmasternodeblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
dcorral committed Dec 6, 2021
1 parent fc021e1 commit a3c3a8e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/masternodes/rpc_masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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());
Expand Down

0 comments on commit a3c3a8e

Please sign in to comment.