Improved lastpaid and fixed votes calculation

This commit is contained in:
Evan Duffield 2015-07-21 16:57:21 -07:00
parent b2c4e14ee8
commit cbe2bae130
2 changed files with 19 additions and 6 deletions

View File

@ -123,7 +123,7 @@ public:
bool HasPayeeWithVotes(CScript payee, int nVotesReq) bool HasPayeeWithVotes(CScript payee, int nVotesReq)
{ {
BOOST_FOREACH(CMasternodePayee& p, vecPayments){ BOOST_FOREACH(CMasternodePayee& p, vecPayments){
if(p.nVotes > nVotesReq && p.scriptPubKey == payee) return true; if(p.nVotes >= nVotesReq && p.scriptPubKey == payee) return true;
} }
return false; return false;

View File

@ -237,17 +237,30 @@ int64_t CMasternode::GetLastPaid() {
// use a deterministic offset to break a tie -- 2.5 minutes // use a deterministic offset to break a tie -- 2.5 minutes
int64_t nOffset = hash.GetCompact(false) % 150; int64_t nOffset = hash.GetCompact(false) % 150;
for(int64_t h = pindexPrev->nHeight-mnodeman.CountEnabled()*0.95; h <= pindexPrev->nHeight+10; h++){ if (chainActive.Tip() == NULL) return false;
if(masternodePayments.mapMasternodeBlocks.count(h)){
const CBlockIndex *BlockReading = chainActive.Tip();
int nMnCount = mnodeman.CountEnabled()*1.1;
int n = 0;
for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) {
if(n >= nMnCount){
return 0;
}
n++;
if(masternodePayments.mapMasternodeBlocks.count(BlockReading->nHeight)){
/* /*
Search for this payee, with at least 2 votes. This will aid in consensus allowing the network Search for this payee, with at least 2 votes. This will aid in consensus allowing the network
to converge on the same payees quickly, then keep the same schedule. to converge on the same payees quickly, then keep the same schedule.
*/ */
if(masternodePayments.mapMasternodeBlocks[h].HasPayeeWithVotes(mnpayee, 2)){ if(masternodePayments.mapMasternodeBlocks[BlockReading->nHeight].HasPayeeWithVotes(mnpayee, 2)){
int64_t nTimeEstimate = pindexPrev->nTime - (pindexPrev->nHeight - h)*2.5; return BlockReading->nTime + nOffset;
return nTimeEstimate + nOffset;
} }
} }
if (BlockReading->pprev == NULL) { assert(BlockReading); break; }
BlockReading = BlockReading->pprev;
} }
return 0; return 0;