diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 1ce841219..927cbaae8 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -763,6 +763,26 @@ std::string CMasternodePayments::ToString() const } + +int CMasternodePayments::GetOldestBlock() +{ + LOCK(cs_masternodepayments); + + int nOldestBlock = std::numeric_limits::max(); + + std::map::iterator it = mapMasternodeBlocks.begin(); + while(it != mapMasternodeBlocks.end()) { + if((*it).first < nOldestBlock) { + nOldestBlock = (*it).first; + } + it++; + } + + return nOldestBlock; +} + + + int CMasternodePayments::GetNewestBlock() { LOCK(cs_masternodepayments); diff --git a/src/masternode-payments.h b/src/masternode-payments.h index 8db591f1e..9a5c1467f 100644 --- a/src/masternode-payments.h +++ b/src/masternode-payments.h @@ -243,6 +243,7 @@ public: std::string GetRequiredPaymentsString(int nBlockHeight); void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees); std::string ToString() const; + int GetOldestBlock(); int GetNewestBlock(); ADD_SERIALIZE_METHODS; diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index 9a48d6313..d12ffae9e 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -174,8 +174,14 @@ void CMasternodeSync::Process() CBlockIndex* pindexPrev = chainActive.Tip(); if(pindexPrev == NULL) return; + int nMnCount = mnodeman.CountEnabled()*1.1; int nCountNeeded = (pindexPrev->nHeight - masternodePayments.GetNewestBlock()); - if(mnodeman.CountEnabled()*1.1 < nCountNeeded) nCountNeeded = mnodeman.CountEnabled()*1.1; + int nHaveBlocks = (pindexPrev->nHeight - masternodePayments.GetOldestBlock()); + if(nHaveBlocks < nMnCount || nCountNeeded > nMnCount) { + //We have less blocks than there are masternodes, we need more history + // - or our cache is old + nCountNeeded = nMnCount; + } pnode->PushMessage("mnget", nCountNeeded); //sync payees RequestedMasternodeAttempt++; diff --git a/src/rpcmasternode.cpp b/src/rpcmasternode.cpp index f419a0399..33e08b283 100644 --- a/src/rpcmasternode.cpp +++ b/src/rpcmasternode.cpp @@ -453,7 +453,7 @@ Value masternode(const Array& params, bool fHelp) int nLast = 10; if (params.size() >= 2){ - nLast = params[1].get_int(); + nLast = atoi(params[1].get_str()); } Object obj;