From d774276da139344e8bef6da75c757d8c847e23af Mon Sep 17 00:00:00 2001 From: James Stewart Date: Fri, 17 Apr 2020 09:05:35 -0500 Subject: [PATCH] [RPC][Bug] Fix masternodecurrent: return next winner, not rank-1 mn --- src/rpc/masternode.cpp | 11 +++++++---- src/sync.h | 11 +++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 91e22e99f8..3470153134 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -198,21 +198,24 @@ UniValue masternodecurrent (const UniValue& params, bool fHelp) if (fHelp || (params.size() != 0)) throw std::runtime_error( "masternodecurrent\n" - "\nGet current masternode winner\n" + "\nGet current masternode winner (scheduled to be paid next).\n" "\nResult:\n" "{\n" " \"protocol\": xxxx, (numeric) Protocol version\n" " \"txhash\": \"xxxx\", (string) Collateral transaction hash\n" " \"pubkey\": \"xxxx\", (string) MN Public key\n" - " \"lastseen\": xxx, (numeric) Time since epoch of last seen\n" - " \"activeseconds\": xxx, (numeric) Seconds MN has been active\n" + " \"lastseen\": xxx, (numeric) Time since epoch of last seen\n" + " \"activeseconds\": xxx, (numeric) Seconds MN has been active\n" "}\n" "\nExamples:\n" + HelpExampleCli("masternodecurrent", "") + HelpExampleRpc("masternodecurrent", "")); - CMasternode* winner = mnodeman.GetCurrentMasterNode(1); + const int nHeight = WITH_LOCK(cs_main, return chainActive.Height() + 1); + int nCount = 0; + CMasternode* winner = mnodeman.GetNextMasternodeInQueueForPayment(nHeight, true, nCount); + if (winner) { UniValue obj(UniValue::VOBJ); diff --git a/src/sync.h b/src/sync.h index 9035cc40e8..656ff64fbc 100644 --- a/src/sync.h +++ b/src/sync.h @@ -189,6 +189,17 @@ class SCOPED_LOCKABLE CCriticalBlock LeaveCritical(); \ } +//! Run code while locking a mutex. +//! +//! Examples: +//! +//! WITH_LOCK(cs, shared_val = shared_val + 1); +//! +//! int val = WITH_LOCK(cs, return shared_val); +//! +#define WITH_LOCK(cs, code) [&] { LOCK(cs); code; }() + + class CSemaphore { private: