From a930363366e5a0f1f94fc3ea77d0fbf2b88d9d07 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 11 Jan 2017 03:00:06 +0400 Subject: [PATCH] RequestLowDataPaymentBlocks should request unknown payment blocks too (#1255) --- src/masternode-payments.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 07e7cb492..89a1edfa8 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -843,15 +843,36 @@ void CMasternodePayments::Sync(CNode* pnode, int nCountNeeded) pnode->PushMessage(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_MNW, nInvCount); } -// Request low data payment blocks in batches directly from some node instead of/after preliminary Sync. +// Request low data/unknown payment blocks in batches directly from some node instead of/after preliminary Sync. void CMasternodePayments::RequestLowDataPaymentBlocks(CNode* pnode) { // Old nodes can't process this if(pnode->nVersion < 70202) return; + if(!pCurrentBlockIndex) return; LOCK2(cs_main, cs_mapMasternodeBlocks); std::vector vToFetch; + int nLimit = GetStorageLimit(); + + const CBlockIndex *pindex = pCurrentBlockIndex; + + while(pCurrentBlockIndex->nHeight - pindex->nHeight < nLimit) { + if(!mapMasternodeBlocks.count(pindex->nHeight)) { + // We have no idea about this block height, let's ask + vToFetch.push_back(CInv(MSG_MASTERNODE_PAYMENT_BLOCK, pindex->GetBlockHash())); + // We should not violate GETDATA rules + if(vToFetch.size() == MAX_INV_SZ) { + LogPrintf("CMasternodePayments::SyncLowDataPaymentBlocks -- asking peer %d for %d blocks\n", pnode->id, MAX_INV_SZ); + pnode->PushMessage(NetMsgType::GETDATA, vToFetch); + // Start filling new batch + vToFetch.clear(); + } + } + if(!pindex->pprev) break; + pindex = pindex->pprev; + } + std::map::iterator it = mapMasternodeBlocks.begin(); while(it != mapMasternodeBlocks.end()) {