@@ -338,16 +338,14 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
338338
339339 if (pfrom->nVersion < GetMinMasternodePaymentsProto ()) return ;
340340
341- if (!pCurrentBlockIndex) return ;
342-
343341 uint256 nHash = vote.GetHash ();
344342
345343 pfrom->setAskFor .erase (nHash);
346344
347345 {
348346 LOCK (cs_mapMasternodePaymentVotes);
349347 if (mapMasternodePaymentVotes.count (nHash)) {
350- LogPrint (" mnpayments" , " MASTERNODEPAYMENTVOTE -- hash=%s, nHeight=%d seen\n " , nHash.ToString (), pCurrentBlockIndex-> nHeight );
348+ LogPrint (" mnpayments" , " MASTERNODEPAYMENTVOTE -- hash=%s, nHeight=%d seen\n " , nHash.ToString (), nCachedBlockHeight );
351349 return ;
352350 }
353351
@@ -358,14 +356,14 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
358356 mapMasternodePaymentVotes[nHash].MarkAsNotVerified ();
359357 }
360358
361- int nFirstBlock = pCurrentBlockIndex-> nHeight - GetStorageLimit ();
362- if (vote.nBlockHeight < nFirstBlock || vote.nBlockHeight > pCurrentBlockIndex-> nHeight +20 ) {
363- LogPrint (" mnpayments" , " MASTERNODEPAYMENTVOTE -- vote out of range: nFirstBlock=%d, nBlockHeight=%d, nHeight=%d\n " , nFirstBlock, vote.nBlockHeight , pCurrentBlockIndex-> nHeight );
359+ int nFirstBlock = nCachedBlockHeight - GetStorageLimit ();
360+ if (vote.nBlockHeight < nFirstBlock || vote.nBlockHeight > nCachedBlockHeight +20 ) {
361+ LogPrint (" mnpayments" , " MASTERNODEPAYMENTVOTE -- vote out of range: nFirstBlock=%d, nBlockHeight=%d, nHeight=%d\n " , nFirstBlock, vote.nBlockHeight , nCachedBlockHeight );
364362 return ;
365363 }
366364
367365 std::string strError = " " ;
368- if (!vote.IsValid (pfrom, pCurrentBlockIndex-> nHeight , strError)) {
366+ if (!vote.IsValid (pfrom, nCachedBlockHeight , strError)) {
369367 LogPrint (" mnpayments" , " MASTERNODEPAYMENTVOTE -- invalid message, error: %s\n " , strError);
370368 return ;
371369 }
@@ -384,7 +382,7 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
384382 }
385383
386384 int nDos = 0 ;
387- if (!vote.CheckSignature (mnInfo.pubKeyMasternode , pCurrentBlockIndex-> nHeight , nDos)) {
385+ if (!vote.CheckSignature (mnInfo.pubKeyMasternode , nCachedBlockHeight , nDos)) {
388386 if (nDos) {
389387 LogPrintf (" MASTERNODEPAYMENTVOTE -- ERROR: invalid signature\n " );
390388 Misbehaving (pfrom->GetId (), nDos);
@@ -406,7 +404,7 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
406404 CBitcoinAddress address2 (address1);
407405
408406 LogPrint (" mnpayments" , " MASTERNODEPAYMENTVOTE -- vote: address=%s, nBlockHeight=%d, nHeight=%d, prevout=%s, hash=%s new\n " ,
409- address2.ToString (), vote.nBlockHeight , pCurrentBlockIndex-> nHeight , vote.vinMasternode .prevout .ToStringShort (), nHash.ToString ());
407+ address2.ToString (), vote.nBlockHeight , nCachedBlockHeight , vote.vinMasternode .prevout .ToStringShort (), nHash.ToString ());
410408
411409 if (AddPaymentVote (vote)){
412410 vote.Relay ();
@@ -450,13 +448,13 @@ bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight)
450448{
451449 LOCK (cs_mapMasternodeBlocks);
452450
453- if (!pCurrentBlockIndex ) return false ;
451+ if (!masternodeSync. IsMasternodeListSynced () ) return false ;
454452
455453 CScript mnpayee;
456454 mnpayee = GetScriptForDestination (mn.pubKeyCollateralAddress .GetID ());
457455
458456 CScript payee;
459- for (int64_t h = pCurrentBlockIndex-> nHeight ; h <= pCurrentBlockIndex-> nHeight + 8 ; h++){
457+ for (int64_t h = nCachedBlockHeight ; h <= nCachedBlockHeight + 8 ; h++){
460458 if (h == nNotBlockHeight) continue ;
461459 if (mapMasternodeBlocks.count (h) && mapMasternodeBlocks[h].GetBestPayee (payee) && mnpayee == payee) {
462460 return true ;
@@ -633,7 +631,7 @@ bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlo
633631
634632void CMasternodePayments::CheckAndRemove ()
635633{
636- if (!pCurrentBlockIndex ) return ;
634+ if (!masternodeSync. IsBlockchainSynced () ) return ;
637635
638636 LOCK2 (cs_mapMasternodeBlocks, cs_mapMasternodePaymentVotes);
639637
@@ -643,7 +641,7 @@ void CMasternodePayments::CheckAndRemove()
643641 while (it != mapMasternodePaymentVotes.end ()) {
644642 CMasternodePaymentVote vote = (*it).second ;
645643
646- if (pCurrentBlockIndex-> nHeight - vote.nBlockHeight > nLimit) {
644+ if (nCachedBlockHeight - vote.nBlockHeight > nLimit) {
647645 LogPrint (" mnpayments" , " CMasternodePayments::CheckAndRemove -- Removing old Masternode payment: nBlockHeight=%d\n " , vote.nBlockHeight );
648646 mapMasternodePaymentVotes.erase (it++);
649647 mapMasternodeBlocks.erase (vote.nBlockHeight );
@@ -824,11 +822,11 @@ void CMasternodePayments::Sync(CNode* pnode)
824822{
825823 LOCK (cs_mapMasternodeBlocks);
826824
827- if (!pCurrentBlockIndex ) return ;
825+ if (!masternodeSync. IsWinnersListSynced () ) return ;
828826
829827 int nInvCount = 0 ;
830828
831- for (int h = pCurrentBlockIndex-> nHeight ; h < pCurrentBlockIndex-> nHeight + 20 ; h++) {
829+ for (int h = nCachedBlockHeight ; h < nCachedBlockHeight + 20 ; h++) {
832830 if (mapMasternodeBlocks.count (h)) {
833831 BOOST_FOREACH (CMasternodePayee& payee, mapMasternodeBlocks[h].vecPayees ) {
834832 std::vector<uint256> vecVoteHashes = payee.GetVoteHashes ();
@@ -848,16 +846,16 @@ void CMasternodePayments::Sync(CNode* pnode)
848846// Request low data/unknown payment blocks in batches directly from some node instead of/after preliminary Sync.
849847void CMasternodePayments::RequestLowDataPaymentBlocks (CNode* pnode)
850848{
851- if (!pCurrentBlockIndex ) return ;
849+ if (!masternodeSync. IsMasternodeListSynced () ) return ;
852850
853851 LOCK2 (cs_main, cs_mapMasternodeBlocks);
854852
855853 std::vector<CInv> vToFetch;
856854 int nLimit = GetStorageLimit ();
857855
858- const CBlockIndex *pindex = pCurrentBlockIndex ;
856+ const CBlockIndex *pindex = chainActive. Tip () ;
859857
860- while (pCurrentBlockIndex-> nHeight - pindex->nHeight < nLimit) {
858+ while (nCachedBlockHeight - pindex->nHeight < nLimit) {
861859 if (!mapMasternodeBlocks.count (pindex->nHeight )) {
862860 // We have no idea about this block height, let's ask
863861 vToFetch.push_back (CInv (MSG_MASTERNODE_PAYMENT_BLOCK, pindex->GetBlockHash ()));
@@ -949,8 +947,10 @@ int CMasternodePayments::GetStorageLimit()
949947
950948void CMasternodePayments::UpdatedBlockTip (const CBlockIndex *pindex)
951949{
952- pCurrentBlockIndex = pindex;
953- LogPrint (" mnpayments" , " CMasternodePayments::UpdatedBlockTip -- pCurrentBlockIndex->nHeight=%d\n " , pCurrentBlockIndex->nHeight );
950+ if (!pindex) return ;
951+
952+ nCachedBlockHeight = pindex->nHeight ;
953+ LogPrint (" mnpayments" , " CMasternodePayments::UpdatedBlockTip -- nCachedBlockHeight=%d\n " , nCachedBlockHeight);
954954
955- ProcessBlock (pindex-> nHeight + 10 );
955+ ProcessBlock (nCachedBlockHeight + 10 );
956956}
0 commit comments