From 0c1679e58c941c6f715c75007fc121f9f607670d Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 27 Sep 2017 20:43:03 +0300 Subject: [PATCH] fix `masternode current` rpc (#1640) GetNextMasternodeInQueueForPayment should not filter scheduled massternodes for it --- src/masternode-payments.cpp | 4 ++-- src/masternodeman.cpp | 10 +++++----- src/masternodeman.h | 4 ++-- src/rpc/masternode.cpp | 7 +++---- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 7d432adff..cce6b0877 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -272,7 +272,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int nBlockH // no masternode detected... int nCount = 0; masternode_info_t mnInfo; - if(!mnodeman.GetNextMasternodeInQueueForPayment(nBlockHeight, true, nCount, mnInfo)) { + if(!mnodeman.GetNextMasternodeInQueueForPayment(nBlockHeight, true, true, nCount, mnInfo)) { // ...and we can't calculate it on our own LogPrintf("CMasternodePayments::FillBlockPayee -- Failed to detect masternode to pay\n"); return; @@ -744,7 +744,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight, CConnman& connman) int nCount = 0; masternode_info_t mnInfo; - if (!mnodeman.GetNextMasternodeInQueueForPayment(nBlockHeight, true, nCount, mnInfo)) { + if (!mnodeman.GetNextMasternodeInQueueForPayment(nBlockHeight, true, true, nCount, mnInfo)) { LogPrintf("CMasternodePayments::ProcessBlock -- ERROR: Failed to find masternode to pay\n"); return false; } diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index d15cd661f..153a0c4dd 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -482,12 +482,12 @@ bool CMasternodeMan::Has(const COutPoint& outpoint) // // Deterministically select the oldest/best masternode to pay on the network // -bool CMasternodeMan::GetNextMasternodeInQueueForPayment(bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet) +bool CMasternodeMan::GetNextMasternodeInQueueForPayment(bool fFilterSigTime, bool fFilterScheduled, int& nCountRet, masternode_info_t& mnInfoRet) { - return GetNextMasternodeInQueueForPayment(nCachedBlockHeight, fFilterSigTime, nCountRet, mnInfoRet); + return GetNextMasternodeInQueueForPayment(nCachedBlockHeight, fFilterSigTime, fFilterScheduled, nCountRet, mnInfoRet); } -bool CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet) +bool CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, bool fFilterScheduled, int& nCountRet, masternode_info_t& mnInfoRet) { mnInfoRet = masternode_info_t(); nCountRet = 0; @@ -515,7 +515,7 @@ bool CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool f if(mnpair.second.nProtocolVersion < mnpayments.GetMinMasternodePaymentsProto()) continue; //it's in the list (up to 8 entries ahead of current block to allow propagation) -- so let's skip it - if(mnpayments.IsScheduled(mnpair.second, nBlockHeight)) continue; + if(fFilterScheduled && mnpayments.IsScheduled(mnpair.second, nBlockHeight)) continue; //it's too new, wait for a cycle if(fFilterSigTime && mnpair.second.sigTime + (nMnCount*2.6*60) > GetAdjustedTime()) continue; @@ -530,7 +530,7 @@ bool CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool f //when the network is in the process of upgrading, don't penalize nodes that recently restarted if(fFilterSigTime && nCountRet < nMnCount/3) - return GetNextMasternodeInQueueForPayment(nBlockHeight, false, nCountRet, mnInfoRet); + return GetNextMasternodeInQueueForPayment(nBlockHeight, false, fFilterScheduled, nCountRet, mnInfoRet); // Sort them low to high sort(vecMasternodeLastPaid.begin(), vecMasternodeLastPaid.end(), CompareLastPaidBlock()); diff --git a/src/masternodeman.h b/src/masternodeman.h index 3231fdfbd..06586d0cf 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -166,9 +166,9 @@ public: bool GetMasternodeInfo(const CScript& payee, masternode_info_t& mnInfoRet); /// Find an entry in the masternode list that is next to be paid - bool GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet); + bool GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, bool fFilterScheduled, int& nCountRet, masternode_info_t& mnInfoRet); /// Same as above but use current block height - bool GetNextMasternodeInQueueForPayment(bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet); + bool GetNextMasternodeInQueueForPayment(bool fFilterSigTime, bool fFilterScheduled, int& nCountRet, masternode_info_t& mnInfoRet); /// Find a random entry masternode_info_t FindRandomNotInVec(const std::vector &vecToExclude, int nProtocolVersion = -1); diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 3b6e16ce8..7ce1593ff 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -125,7 +125,7 @@ UniValue masternode(const UniValue& params, bool fHelp) " status - Print masternode status information\n" " list - Print list of all known masternodes (see masternodelist for more info)\n" " list-conf - Print masternode.conf in JSON format\n" - " winner - Print info on next masternode winner to vote for\n" + " winner - Print info on next masternode winner to vote for (calculated locally)\n" " winners - Print list of masternode winners\n" ); @@ -176,7 +176,7 @@ UniValue masternode(const UniValue& params, bool fHelp) int nCount; masternode_info_t mnInfo; - mnodeman.GetNextMasternodeInQueueForPayment(true, nCount, mnInfo); + mnodeman.GetNextMasternodeInQueueForPayment(true, true, nCount, mnInfo); if (strMode == "qualify") return nCount; @@ -199,8 +199,7 @@ UniValue masternode(const UniValue& params, bool fHelp) } nHeight = pindex->nHeight + (strCommand == "current" ? 1 : 10); mnodeman.UpdateLastPaid(pindex); - - if(!mnodeman.GetNextMasternodeInQueueForPayment(nHeight, true, nCount, mnInfo)) + if (!mnodeman.GetNextMasternodeInQueueForPayment(nHeight, true, false, nCount, mnInfo)) return "unknown"; UniValue obj(UniValue::VOBJ);