diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 9f4b8c7f143f..1d842b2da1b4 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -606,8 +606,8 @@ void CMasternodePayments::CheckAndRemove() LOCK2(cs_mapMasternodePayeeVotes, cs_mapMasternodeBlocks); - // keep a bit more for historical sake but at least 4000 - int nLimit = std::max(int(mnodeman.size()*1.25), 4000); + // keep a bit more for historical sake but at least minBlocksToStore + int nLimit = std::max(int(mnodeman.size() * nStorageCoeff), nMinBlocksToStore); std::map::iterator it = mapMasternodePayeeVotes.begin(); while(it != mapMasternodePayeeVotes.end()) { @@ -836,6 +836,18 @@ int CMasternodePayments::GetNewestBlock() return nNewestBlock; } +bool CMasternodePayments::IsEnoughData(int nMnCount) { + if(GetBlockCount() > nMnCount * nStorageCoeff || GetBlockCount() > nMinBlocksToStore) + { + float nAverageVotes = (MNPAYMENTS_SIGNATURES_TOTAL + MNPAYMENTS_SIGNATURES_REQUIRED) / 2; + if(GetVoteCount() > nMnCount * nStorageCoeff * nAverageVotes || GetVoteCount() > nMinBlocksToStore * nAverageVotes) + { + return true; + } + } + return false; +} + void CMasternodePayments::UpdatedBlockTip(const CBlockIndex *pindex) { pCurrentBlockIndex = pindex; diff --git a/src/masternode-payments.h b/src/masternode-payments.h index d40cbfa9a055..79063ae656ef 100644 --- a/src/masternode-payments.h +++ b/src/masternode-payments.h @@ -224,7 +224,9 @@ class CMasternodePaymentWinner class CMasternodePayments { private: - int nSyncedFromPeer; + int nMinBlocksToStore; + float nStorageCoeff; + // Keep track of current block index const CBlockIndex *pCurrentBlockIndex; @@ -234,7 +236,8 @@ class CMasternodePayments std::map mapMasternodesLastVote; //Hash(BEGIN(prevout.hash), END(prevout.n)), nBlockHeight CMasternodePayments() { - nSyncedFromPeer = 0; + nMinBlocksToStore = 4000; + nStorageCoeff = 1.25; } void Clear() { @@ -286,6 +289,8 @@ class CMasternodePayments return mapMasternodePayeeVotes.size(); } + bool IsEnoughData(int nMnCount); + ADD_SERIALIZE_METHODS; template diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index f1c2319acac4..fe0e74da816d 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -329,16 +329,10 @@ void CMasternodeSync::Process() return; } - // target blocks count - // we store nMnCount*1.25 payments blocks so nMnCount*1.2 should be enough most of the time - if(mnpayments.GetBlockCount() > nMnCount*1.2) - { - // target votes, max ten per item. 6 average should be fine - if(mnpayments.GetVoteCount() > nMnCount*1.2*6) - { - GetNextAsset(); - return; - } + // if mnpayments already has enough blocks and votes, move to the next asset + if(mnpayments.IsEnoughData(nMnCount)) { + GetNextAsset(); + return; } // requesting is the last thing we do (incase we needed to move to the next asset and we've requested from each peer already) @@ -346,7 +340,6 @@ void CMasternodeSync::Process() if(pnode->HasFulfilledRequest("masternode-winner-sync")) continue; pnode->FulfilledRequest("masternode-winner-sync"); - int nMnCount = mnodeman.CountEnabled(); pnode->PushMessage(NetMsgType::MNWINNERSSYNC, nMnCount); //sync payees RequestedMasternodeAttempt++;