コード例 #1
0
ファイル: checkpoints.cpp プロジェクト: leo-qq/DSValue
    // Guess how far we are in the verification process at the given block index
    double GuessVerificationProgress(CBlockIndex *pindex) {
        if (pindex==NULL)
            return 0.0;

        int64_t nNow = time(NULL);

        double fWorkBefore = 0.0; // Amount of work done before pindex
        double fWorkAfter = 0.0;  // Amount of work left after pindex (estimated)
        // Work is defined as: 1.0 per transaction before the last checkpoint, and
        // fSigcheckVerificationFactor per transaction after.
        LOCK(cs_checkPoint);
        const CCheckpointData &data = Checkpoints();

        if (pindex->nChainTx <= data.nTransactionsLastCheckpoint) {
            double nCheapBefore = pindex->nChainTx;
            double nCheapAfter = data.nTransactionsLastCheckpoint - pindex->nChainTx;
            double nExpensiveAfter = (nNow - data.nTimeLastCheckpoint)/86400.0*data.fTransactionsPerDay;
            fWorkBefore = nCheapBefore;
            fWorkAfter = nCheapAfter + nExpensiveAfter*fSigcheckVerificationFactor;
        } else {
            double nCheapBefore = data.nTransactionsLastCheckpoint;
            double nExpensiveBefore = pindex->nChainTx - data.nTransactionsLastCheckpoint;
            double nExpensiveAfter = (nNow - pindex->nTime)/86400.0*data.fTransactionsPerDay;
            fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
            fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
        }

        return fWorkBefore / (fWorkBefore + fWorkAfter);
    }
コード例 #2
0
ファイル: checkpoints.cpp プロジェクト: leo-qq/DSValue
	bool GetCheckpointByHeight(const int nHeight, std::vector<int> &vCheckpoints) {
		LOCK(cs_checkPoint);
		MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
		std::map<int, uint256>::iterator iterMap = checkpoints.upper_bound(nHeight);
		while (iterMap != checkpoints.end()) {
			vCheckpoints.push_back(iterMap->first);
			++iterMap;
		}
	}
コード例 #3
0
ファイル: checkpoints.cpp プロジェクト: leo-qq/DSValue
    int GetTotalBlocksEstimate()
    {
        if (!fEnabled)
            return 0;

        LOCK(cs_checkPoint);
        const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;

        return checkpoints.rbegin()->first;
    }
コード例 #4
0
ファイル: checkpoints.cpp プロジェクト: leo-qq/DSValue
    bool CheckBlock(int nHeight, const uint256& hash)
    {
        if (!fEnabled)
            return true;
        LOCK(cs_checkPoint);
        const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;

        MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
        if (i == checkpoints.end()) return true;
        return hash == i->second;
    }
コード例 #5
0
ファイル: checkpoints.cpp プロジェクト: leo-qq/DSValue
    CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
    {
        if (!fEnabled)
            return NULL;
        LOCK(cs_checkPoint);
        const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;

        BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
        {
        	LogTrace("bess1","hash=%s,heiht=%d",i.second.ToString(),i.first);
            const uint256& hash = i.second;
            std::map<uint256, CBlockIndex*>::const_iterator t = mapBlockIndex.find(hash);
            if (t != mapBlockIndex.end())
                return t->second;
        }
コード例 #6
0
    // ppcoin: reset synchronized checkpoint to last hardened checkpoint
    bool ResetSyncCheckpoint()
    {
        LOCK(cs_hashSyncCheckpoint);
        const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
        const uint256& hash = checkpoints.rbegin()->second;
        if (mapBlockIndex.count(hash) && !mapBlockIndex[hash]->IsInMainChain())
        {
            // checkpoint block accepted but not yet in main chain
            printf("ResetSyncCheckpoint: SetBestChain to hardened checkpoint %s\n", hash.ToString().c_str());
            CValidationState state;
            if (!SetBestChain(state, mapBlockIndex[hash]))
            {
                return error("ResetSyncCheckpoint: SetBestChain failed for hardened checkpoint %s", hash.ToString().c_str());
            }
        }
        else if(!mapBlockIndex.count(hash))
        {
            // checkpoint block not yet accepted
            hashPendingCheckpoint = hash;
            checkpointMessagePending.SetNull();
            printf("ResetSyncCheckpoint: pending for sync-checkpoint %s\n", hashPendingCheckpoint.ToString().c_str());
        }

        BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
        {
            const uint256& hash = i.second;
            if (mapBlockIndex.count(hash) && mapBlockIndex[hash]->IsInMainChain())
            {
                if (!WriteSyncCheckpoint(hash))
                    return error("ResetSyncCheckpoint: failed to write sync checkpoint %s", hash.ToString().c_str());
                printf("ResetSyncCheckpoint: sync-checkpoint reset to %s\n", hashSyncCheckpoint.ToString().c_str());
                return true;
            }
        }

        // last resort. set sync checkpoint to genesis before downloading any blockchain
        if (WriteSyncCheckpoint(fTestNet ? hashGenesisBlockTestNet : hashGenesisBlock))
        {
            printf("ResetSyncCheckpoint: sync-checkpoint reset to hashGenesisBlock\n");
            return true;
        }
        else
        {
            printf("ResetSyncCheckpoint: failed to reset sync-checkpoint to hashGenesisBlock\n");
            return false;
        }
    }
コード例 #7
0
ファイル: checkpoints.cpp プロジェクト: leo-qq/DSValue
	bool AddCheckpoint(int nHeight, uint256 hash) {
		LOCK(cs_checkPoint);
		MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
		checkpoints.insert(checkpoints.end(), make_pair(nHeight, hash));
		return true;
	}
コード例 #8
0
ファイル: checkpoints.cpp プロジェクト: DSPay/DSValue
 void GetCheckpointMap(std::map<int, uint256> &mapCheckpoints){
 	LOCK(cs_checkPoint);
 	const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
 	mapCheckpoints = checkpoints;
 }