@@ -338,16 +338,14 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
338
338
339
339
if (pfrom->nVersion < GetMinMasternodePaymentsProto ()) return ;
340
340
341
- if (!pCurrentBlockIndex) return ;
342
-
343
341
uint256 nHash = vote.GetHash ();
344
342
345
343
pfrom->setAskFor .erase (nHash);
346
344
347
345
{
348
346
LOCK (cs_mapMasternodePaymentVotes);
349
347
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 );
351
349
return ;
352
350
}
353
351
@@ -358,14 +356,14 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
358
356
mapMasternodePaymentVotes[nHash].MarkAsNotVerified ();
359
357
}
360
358
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 );
364
362
return ;
365
363
}
366
364
367
365
std::string strError = " " ;
368
- if (!vote.IsValid (pfrom, pCurrentBlockIndex-> nHeight , strError)) {
366
+ if (!vote.IsValid (pfrom, nCachedBlockHeight , strError)) {
369
367
LogPrint (" mnpayments" , " MASTERNODEPAYMENTVOTE -- invalid message, error: %s\n " , strError);
370
368
return ;
371
369
}
@@ -384,7 +382,7 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
384
382
}
385
383
386
384
int nDos = 0 ;
387
- if (!vote.CheckSignature (mnInfo.pubKeyMasternode , pCurrentBlockIndex-> nHeight , nDos)) {
385
+ if (!vote.CheckSignature (mnInfo.pubKeyMasternode , nCachedBlockHeight , nDos)) {
388
386
if (nDos) {
389
387
LogPrintf (" MASTERNODEPAYMENTVOTE -- ERROR: invalid signature\n " );
390
388
Misbehaving (pfrom->GetId (), nDos);
@@ -406,7 +404,7 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
406
404
CBitcoinAddress address2 (address1);
407
405
408
406
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 ());
410
408
411
409
if (AddPaymentVote (vote)){
412
410
vote.Relay ();
@@ -450,13 +448,13 @@ bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight)
450
448
{
451
449
LOCK (cs_mapMasternodeBlocks);
452
450
453
- if (!pCurrentBlockIndex ) return false ;
451
+ if (!masternodeSync. IsMasternodeListSynced () ) return false ;
454
452
455
453
CScript mnpayee;
456
454
mnpayee = GetScriptForDestination (mn.pubKeyCollateralAddress .GetID ());
457
455
458
456
CScript payee;
459
- for (int64_t h = pCurrentBlockIndex-> nHeight ; h <= pCurrentBlockIndex-> nHeight + 8 ; h++){
457
+ for (int64_t h = nCachedBlockHeight ; h <= nCachedBlockHeight + 8 ; h++){
460
458
if (h == nNotBlockHeight) continue ;
461
459
if (mapMasternodeBlocks.count (h) && mapMasternodeBlocks[h].GetBestPayee (payee) && mnpayee == payee) {
462
460
return true ;
@@ -633,7 +631,7 @@ bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlo
633
631
634
632
void CMasternodePayments::CheckAndRemove ()
635
633
{
636
- if (!pCurrentBlockIndex ) return ;
634
+ if (!masternodeSync. IsBlockchainSynced () ) return ;
637
635
638
636
LOCK2 (cs_mapMasternodeBlocks, cs_mapMasternodePaymentVotes);
639
637
@@ -643,7 +641,7 @@ void CMasternodePayments::CheckAndRemove()
643
641
while (it != mapMasternodePaymentVotes.end ()) {
644
642
CMasternodePaymentVote vote = (*it).second ;
645
643
646
- if (pCurrentBlockIndex-> nHeight - vote.nBlockHeight > nLimit) {
644
+ if (nCachedBlockHeight - vote.nBlockHeight > nLimit) {
647
645
LogPrint (" mnpayments" , " CMasternodePayments::CheckAndRemove -- Removing old Masternode payment: nBlockHeight=%d\n " , vote.nBlockHeight );
648
646
mapMasternodePaymentVotes.erase (it++);
649
647
mapMasternodeBlocks.erase (vote.nBlockHeight );
@@ -824,11 +822,11 @@ void CMasternodePayments::Sync(CNode* pnode)
824
822
{
825
823
LOCK (cs_mapMasternodeBlocks);
826
824
827
- if (!pCurrentBlockIndex ) return ;
825
+ if (!masternodeSync. IsWinnersListSynced () ) return ;
828
826
829
827
int nInvCount = 0 ;
830
828
831
- for (int h = pCurrentBlockIndex-> nHeight ; h < pCurrentBlockIndex-> nHeight + 20 ; h++) {
829
+ for (int h = nCachedBlockHeight ; h < nCachedBlockHeight + 20 ; h++) {
832
830
if (mapMasternodeBlocks.count (h)) {
833
831
BOOST_FOREACH (CMasternodePayee& payee, mapMasternodeBlocks[h].vecPayees ) {
834
832
std::vector<uint256> vecVoteHashes = payee.GetVoteHashes ();
@@ -848,16 +846,16 @@ void CMasternodePayments::Sync(CNode* pnode)
848
846
// Request low data/unknown payment blocks in batches directly from some node instead of/after preliminary Sync.
849
847
void CMasternodePayments::RequestLowDataPaymentBlocks (CNode* pnode)
850
848
{
851
- if (!pCurrentBlockIndex ) return ;
849
+ if (!masternodeSync. IsMasternodeListSynced () ) return ;
852
850
853
851
LOCK2 (cs_main, cs_mapMasternodeBlocks);
854
852
855
853
std::vector<CInv> vToFetch;
856
854
int nLimit = GetStorageLimit ();
857
855
858
- const CBlockIndex *pindex = pCurrentBlockIndex ;
856
+ const CBlockIndex *pindex = chainActive. Tip () ;
859
857
860
- while (pCurrentBlockIndex-> nHeight - pindex->nHeight < nLimit) {
858
+ while (nCachedBlockHeight - pindex->nHeight < nLimit) {
861
859
if (!mapMasternodeBlocks.count (pindex->nHeight )) {
862
860
// We have no idea about this block height, let's ask
863
861
vToFetch.push_back (CInv (MSG_MASTERNODE_PAYMENT_BLOCK, pindex->GetBlockHash ()));
@@ -949,8 +947,10 @@ int CMasternodePayments::GetStorageLimit()
949
947
950
948
void CMasternodePayments::UpdatedBlockTip (const CBlockIndex *pindex)
951
949
{
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);
954
954
955
- ProcessBlock (pindex-> nHeight + 10 );
955
+ ProcessBlock (nCachedBlockHeight + 10 );
956
956
}
0 commit comments