Skip to content

Commit

Permalink
[RPC][Bug] Fix masternodecurrent: return next winner, not rank-1 mn
Browse files Browse the repository at this point in the history
  • Loading branch information
Liquid369 committed Apr 17, 2020
1 parent f09f689 commit d774276
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/rpc/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions src/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d774276

Please sign in to comment.