Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint256, CMasternodePaymentWinner>::iterator it = mapMasternodePayeeVotes.begin();
while(it != mapMasternodePayeeVotes.end()) {
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/masternode-payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ class CMasternodePaymentWinner
class CMasternodePayments
{
private:
int nSyncedFromPeer;
int nMinBlocksToStore;
float nStorageCoeff;

// Keep track of current block index
const CBlockIndex *pCurrentBlockIndex;

Expand All @@ -234,7 +236,8 @@ class CMasternodePayments
std::map<uint256, int> mapMasternodesLastVote; //Hash(BEGIN(prevout.hash), END(prevout.n)), nBlockHeight

CMasternodePayments() {
nSyncedFromPeer = 0;
nMinBlocksToStore = 4000;
nStorageCoeff = 1.25;
}

void Clear() {
Expand Down Expand Up @@ -286,6 +289,8 @@ class CMasternodePayments
return mapMasternodePayeeVotes.size();
}

bool IsEnoughData(int nMnCount);

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
Expand Down
15 changes: 4 additions & 11 deletions src/masternode-sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,24 +329,17 @@ 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)

if(pnode->HasFulfilledRequest("masternode-winner-sync")) continue;
pnode->FulfilledRequest("masternode-winner-sync");

int nMnCount = mnodeman.CountEnabled();
pnode->PushMessage(NetMsgType::MNWINNERSSYNC, nMnCount); //sync payees
RequestedMasternodeAttempt++;

Expand Down