From 6b31970f1301d1c3fa05b328aa3b2a89363634c0 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Thu, 20 Aug 2015 08:36:44 -0700 Subject: [PATCH] Fix payment cycle when network is in the process of updating --- configure.ac | 2 +- src/clientversion.h | 2 +- src/masternode-payments.cpp | 4 ++-- src/masternodeman.cpp | 11 ++++++++--- src/masternodeman.h | 2 +- src/rpcmasternode.cpp | 13 ++++++++++--- 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index d55bf9dfd..b59757f33 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 0) define(_CLIENT_VERSION_MINOR, 12) define(_CLIENT_VERSION_REVISION, 0) -define(_CLIENT_VERSION_BUILD, 46) +define(_CLIENT_VERSION_BUILD, 47) define(_CLIENT_VERSION_IS_RELEASE, true) define(_COPYRIGHT_YEAR, 2015) AC_INIT([Dash Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[info@dashpay.io],[dash]) diff --git a/src/clientversion.h b/src/clientversion.h index 4a2bb7927..ebc5785c6 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -17,7 +17,7 @@ #define CLIENT_VERSION_MAJOR 0 #define CLIENT_VERSION_MINOR 12 #define CLIENT_VERSION_REVISION 0 -#define CLIENT_VERSION_BUILD 46 +#define CLIENT_VERSION_BUILD 47 //! Set to true for release, false for prerelease or test build #define CLIENT_VERSION_IS_RELEASE true diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index bd64227d9..a145222ac 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -686,8 +686,8 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight) LogPrintf("CMasternodePayments::ProcessBlock() Start nHeight %d - vin %s. \n", nBlockHeight, activeMasternode.vin.ToString().c_str()); // pay to the oldest MN that still had no payment but its input is old enough and it was active long enough - CMasternode *pmn = mnodeman.GetNextMasternodeInQueueForPayment(nBlockHeight, true); - if(pmn == NULL) pmn = mnodeman.GetNextMasternodeInQueueForPayment(nBlockHeight, false); // if no results, look for any node with a newer sigTime + int nCount = 0; + CMasternode *pmn = mnodeman.GetNextMasternodeInQueueForPayment(nBlockHeight, true, nCount); if(pmn != NULL) { diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 9e4fccb9f..0e92e7726 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -414,9 +414,10 @@ CMasternode *CMasternodeMan::Find(const CPubKey &pubKeyMasternode) // // Deterministically select the oldest/best masternode to pay on the network // -CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime) +CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCount) { LOCK(cs); + nCount = 0; CMasternode *pBestMasternode = NULL; std::vector > vecMasternodeLastPaid; @@ -444,8 +445,12 @@ CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight if(mn.GetMasternodeInputAge() < nMnCount) continue; vecMasternodeLastPaid.push_back(make_pair(mn.SecondsSincePayment(), mn.vin)); + nCount++; } + //when the network is in the process of upgrading, don't penalize nodes that recently restarted + if(fFilterSigTime && nCount < nMnCount/3) return GetNextMasternodeInQueueForPayment(nBlockHeight, false, nCount); + // Sort them low to high sort(vecMasternodeLastPaid.rbegin(), vecMasternodeLastPaid.rend(), CompareLastPaid()); @@ -454,7 +459,7 @@ CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight // -- 1/100 payments should be a double payment on mainnet - (1/(3000/10))*2 // -- (chance per block * chances before IsScheduled will fire) int nTenthNetwork = CountEnabled()/10; - int nCount = 0; + int nCountTenth = 0; uint256 nHigh = 0; BOOST_FOREACH (PAIRTYPE(int64_t, CTxIn)& s, vecMasternodeLastPaid){ CMasternode* pmn = Find(s.second); @@ -465,7 +470,7 @@ CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight nHigh = n; pBestMasternode = pmn; } - nCount++; + nCountTenth++; if(nCount >= nTenthNetwork) break; } return pBestMasternode; diff --git a/src/masternodeman.h b/src/masternodeman.h index 04b22cf92..033f197c9 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -116,7 +116,7 @@ public: CMasternode* Find(const CPubKey& pubKeyMasternode); /// Find an entry in the masternode list that is next to be paid - CMasternode* GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime=true); + CMasternode* GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCount); /// Find a random entry CMasternode* FindRandomNotInVec(std::vector &vecToExclude, int protocolVersion = -1); diff --git a/src/rpcmasternode.cpp b/src/rpcmasternode.cpp index de26049c4..6afe3b2e7 100644 --- a/src/rpcmasternode.cpp +++ b/src/rpcmasternode.cpp @@ -134,7 +134,7 @@ Value masternode(const Array& params, bool fHelp) "1. \"command\" (string or set of strings, required) The command to execute\n" "2. \"passphrase\" (string, optional) The wallet passphrase\n" "\nAvailable commands:\n" - " count - Print number of all known masternodes (optional: 'ds', 'enabled', 'all')\n" + " count - Print number of all known masternodes (optional: 'ds', 'enabled', 'all', 'qualify')\n" " current - Print info on current masternode winner\n" " debug - Print masternode status\n" " genkey - Generate new masternodeprivkey\n" @@ -186,12 +186,19 @@ Value masternode(const Array& params, bool fHelp) } if (params.size() == 2) { + int nCount = 0; + + if(chainActive.Tip()) + mnodeman.GetNextMasternodeInQueueForPayment(chainActive.Tip()->nHeight, true, nCount); + if(params[1] == "ds") return mnodeman.CountEnabled(MIN_POOL_PEER_PROTO_VERSION); if(params[1] == "enabled") return mnodeman.CountEnabled(); - if(params[1] == "all") return strprintf("Total: %d (DS Compatible: %d / Enabled: %d)", + if(params[1] == "qualify") return nCount; + if(params[1] == "all") return strprintf("Total: %d (DS Compatible: %d / Enabled: %d / Qualify: %d)", mnodeman.size(), mnodeman.CountEnabled(MIN_POOL_PEER_PROTO_VERSION), - mnodeman.CountEnabled()); + mnodeman.CountEnabled(), + nCount); } return mnodeman.size(); }