src/vnode-payments.cpp
void CVnodePayments::RequestLowDataPaymentBlocks(CNode* pnode)
{
    if (!pCurrentBlockIndex)
        return;

    LOCK2(cs_main, cs_mapVnodeBlocks);

    std::vector<CInv> vToFetch;
    int nLimit = GetStorageLimit();

    const CBlockIndex* pindex = pCurrentBlockIndex;

    while (pCurrentBlockIndex->nHeight - pindex->nHeight < nLimit) {
        if (!mapVnodeBlocks.count(pindex->nHeight)) {
            // We have no idea about this block height, let's ask
            vToFetch.push_back(CInv(MSG_VNODE_PAYMENT_BLOCK, pindex->GetBlockHash()));
            // We should not violate GETDATA rules
            if (vToFetch.size() == MAX_INV_SZ) {
                LogPrintf("CVnodePayments::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<int, CVnodeBlockPayees>::iterator it = mapVnodeBlocks.begin();

    while (it != mapVnodeBlocks.end()) {
        int nTotalVotes = 0;
        bool fFound = false;
        BOOST_FOREACH (CVnodePayee& payee, it->second.vecPayees) {
            if (payee.GetVoteCount() >= MNPAYMENTS_SIGNATURES_REQUIRED) {
                fFound = true;
                break;
            }
            nTotalVotes += payee.GetVoteCount();
        }
        // A clear winner (MNPAYMENTS_SIGNATURES_REQUIRED+ votes) was found
        // or no clear winner was found but there are at least avg number of votes
        if (fFound || nTotalVotes >= (MNPAYMENTS_SIGNATURES_TOTAL + MNPAYMENTS_SIGNATURES_REQUIRED) / 2) {
            // so just move to the next block
            ++it;
            continue;
        }
        // DEBUG
        //        DBG (
        //            // Let's see why this failed
        //            BOOST_FOREACH(CVnodePayee& payee, it->second.vecPayees) {
        //                CTxDestination address1;
        //                ExtractDestination(payee.GetPayee(), address1);
        //                CBitcoinAddress address2(address1);
        //                printf("payee %s votes %d\n", address2.ToString().c_str(), payee.GetVoteCount());
        //            }
        //            printf("block %d votes total %d\n", it->first, nTotalVotes);
        //        )
        // END DEBUG
        // Low data block found, let's try to sync it
        uint256 hash;
        if (GetBlockHash(hash, it->first)) {
            vToFetch.push_back(CInv(MSG_VNODE_PAYMENT_BLOCK, hash));
        }
        // We should not violate GETDATA rules
        if (vToFetch.size() == MAX_INV_SZ) {
            LogPrintf("CVnodePayments::SyncLowDataPaymentBlocks -- asking peer %d for %d payment blocks\n", pnode->id, MAX_INV_SZ);
            pnode->PushMessage(NetMsgType::GETDATA, vToFetch);
            // Start filling new batch
            vToFetch.clear();
        }
        ++it;
    }
    // Ask for the rest of it
    if (!vToFetch.empty()) {
        LogPrintf("CVnodePayments::SyncLowDataPaymentBlocks -- asking peer %d for %d payment blocks\n", pnode->id, vToFetch.size());
        pnode->PushMessage(NetMsgType::GETDATA, vToFetch);
    }
}
// Request low data/unknown 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.
Request low data / unknown payment blocks in batches directly from some node instead of / after preliminary Sync .
void CVnodePayments::RequestLowDataPaymentBlocks(CNode* pnode)
{
    if (!pCurrentBlockIndex)
        return;
    LOCK2(cs_main, cs_mapVnodeBlocks);
    std::vector<CInv> vToFetch;
    int nLimit = GetStorageLimit();
    const CBlockIndex* pindex = pCurrentBlockIndex;
    while (pCurrentBlockIndex->nHeight - pindex->nHeight < nLimit) {
        if (!mapVnodeBlocks.count(pindex->nHeight)) {
            vToFetch.push_back(CInv(MSG_VNODE_PAYMENT_BLOCK, pindex->GetBlockHash()));
            if (vToFetch.size() == MAX_INV_SZ) {
                LogPrintf("CVnodePayments::SyncLowDataPaymentBlocks -- asking peer %d for %d blocks\n", pnode->id, MAX_INV_SZ);
                pnode->PushMessage(NetMsgType::GETDATA, vToFetch);
                vToFetch.clear();
            }
        }
        if (!pindex->pprev)
            break;
        pindex = pindex->pprev;
    }
    std::map<int, CVnodeBlockPayees>::iterator it = mapVnodeBlocks.begin();
    while (it != mapVnodeBlocks.end()) {
        int nTotalVotes = 0;
        bool fFound = false;
        BOOST_FOREACH (CVnodePayee& payee, it->second.vecPayees) {
            if (payee.GetVoteCount() >= MNPAYMENTS_SIGNATURES_REQUIRED) {
                fFound = true;
                break;
            }
            nTotalVotes += payee.GetVoteCount();
        }
        if (fFound || nTotalVotes >= (MNPAYMENTS_SIGNATURES_TOTAL + MNPAYMENTS_SIGNATURES_REQUIRED) / 2) {
            ++it;
            continue;
        }
        uint256 hash;
        if (GetBlockHash(hash, it->first)) {
            vToFetch.push_back(CInv(MSG_VNODE_PAYMENT_BLOCK, hash));
        }
        if (vToFetch.size() == MAX_INV_SZ) {
            LogPrintf("CVnodePayments::SyncLowDataPaymentBlocks -- asking peer %d for %d payment blocks\n", pnode->id, MAX_INV_SZ);
            pnode->PushMessage(NetMsgType::GETDATA, vToFetch);
            vToFetch.clear();
        }
        ++it;
    }
    if (!vToFetch.empty()) {
        LogPrintf("CVnodePayments::SyncLowDataPaymentBlocks -- asking peer %d for %d payment blocks\n", pnode->id, vToFetch.size());
        pnode->PushMessage(NetMsgType::GETDATA, vToFetch);
    }
}
void CVnodePayments :: RequestLowDataPaymentBlocks ( CNode * pnode ) { if ( ! pCurrentBlockIndex ) return ; LOCK2 ( cs_main , cs_mapVnodeBlocks ) ; std :: vector < CInv > vToFetch ; int nLimit = GetStorageLimit ( ) ; const CBlockIndex * pindex = pCurrentBlockIndex ; while ( pCurrentBlockIndex -> nHeight - pindex -> nHeight < nLimit ) { if ( ! mapVnodeBlocks . count ( pindex -> nHeight ) ) { vToFetch . push_back ( CInv ( MSG_VNODE_PAYMENT_BLOCK , pindex -> GetBlockHash ( ) ) ) ; if ( vToFetch . size ( ) == MAX_INV_SZ ) { LogPrintf ( " \n " , pnode -> id , MAX_INV_SZ ) ; pnode -> PushMessage ( NetMsgType :: GETDATA , vToFetch ) ; vToFetch . clear ( ) ; } } if ( ! pindex -> pprev ) break ; pindex = pindex -> pprev ; } std :: map < int , CVnodeBlockPayees > :: iterator it = mapVnodeBlocks . begin ( ) ; while ( it != mapVnodeBlocks . end ( ) ) { int nTotalVotes = 0 ; bool fFound = false ; BOOST_FOREACH ( CVnodePayee & payee , it -> second . vecPayees ) { if ( payee . GetVoteCount ( ) >= MNPAYMENTS_SIGNATURES_REQUIRED ) { fFound = true ; break ; } nTotalVotes += payee . GetVoteCount ( ) ; } if ( fFound || nTotalVotes >= ( MNPAYMENTS_SIGNATURES_TOTAL + MNPAYMENTS_SIGNATURES_REQUIRED ) / 2 ) { ++ it ; continue ; } uint256 hash ; if ( GetBlockHash ( hash , it -> first ) ) { vToFetch . push_back ( CInv ( MSG_VNODE_PAYMENT_BLOCK , hash ) ) ; } if ( vToFetch . size ( ) == MAX_INV_SZ ) { LogPrintf ( " \n " , pnode -> id , MAX_INV_SZ ) ; pnode -> PushMessage ( NetMsgType :: GETDATA , vToFetch ) ; vToFetch . clear ( ) ; } ++ it ; } if ( ! vToFetch . empty ( ) ) { LogPrintf ( " \n " , pnode -> id , vToFetch . size ( ) ) ; pnode -> PushMessage ( NetMsgType :: GETDATA , vToFetch ) ; } }
Request low data/unknown 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 .
// We have no idea about this block height, let's ask // We should not violate GETDATA rules // Start filling new batch // A clear winner (MNPAYMENTS_SIGNATURES_REQUIRED+ votes) was found // or no clear winner was found but there are at least avg number of votes // so just move to the next block // DEBUG //        DBG ( //            // Let's see why this failed //            BOOST_FOREACH(CVnodePayee& payee, it->second.vecPayees) { //                CTxDestination address1; //                ExtractDestination(payee.GetPayee(), address1); //                CBitcoinAddress address2(address1); //                printf("payee %s votes %d\n", address2.ToString().c_str(), payee.GetVoteCount()); //            } //            printf("block %d votes total %d\n", it->first, nTotalVotes); //        ) // END DEBUG // Low data block found, let's try to sync it // We should not violate GETDATA rules // Start filling new batch // Ask for the rest of it