LCOV - code coverage report
Current view: top level - src - checkpoints.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 30 31 96.8 %
Date: 2015-10-12 22:39:14 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2009-2014 The Bitcoin Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include "checkpoints.h"
       6             : 
       7             : #include "chain.h"
       8             : #include "chainparams.h"
       9             : #include "main.h"
      10             : #include "uint256.h"
      11             : 
      12             : #include <stdint.h>
      13             : 
      14             : #include <boost/foreach.hpp>
      15             : 
      16             : namespace Checkpoints {
      17             : 
      18             :     /**
      19             :      * How many times slower we expect checking transactions after the last
      20             :      * checkpoint to be (from checking signatures, which is skipped up to the
      21             :      * last checkpoint). This number is a compromise, as it can't be accurate
      22             :      * for every system. When reindexing from a fast disk with a slow CPU, it
      23             :      * can be up to 20, while when downloading from a slow network with a
      24             :      * fast multicore CPU, it won't be much higher than 1.
      25             :      */
      26             :     static const double SIGCHECK_VERIFICATION_FACTOR = 5.0;
      27             : 
      28             :     //! Guess how far we are in the verification process at the given block index
      29        5720 :     double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex *pindex, bool fSigchecks) {
      30        5720 :         if (pindex==NULL)
      31             :             return 0.0;
      32             : 
      33        5720 :         int64_t nNow = time(NULL);
      34             : 
      35        5720 :         double fSigcheckVerificationFactor = fSigchecks ? SIGCHECK_VERIFICATION_FACTOR : 1.0;
      36        5720 :         double fWorkBefore = 0.0; // Amount of work done before pindex
      37        5720 :         double fWorkAfter = 0.0;  // Amount of work left after pindex (estimated)
      38             :         // Work is defined as: 1.0 per transaction before the last checkpoint, and
      39             :         // fSigcheckVerificationFactor per transaction after.
      40             : 
      41        5720 :         if (pindex->nChainTx <= data.nTransactionsLastCheckpoint) {
      42         134 :             double nCheapBefore = pindex->nChainTx;
      43         134 :             double nCheapAfter = data.nTransactionsLastCheckpoint - pindex->nChainTx;
      44         134 :             double nExpensiveAfter = (nNow - data.nTimeLastCheckpoint)/86400.0*data.fTransactionsPerDay;
      45         134 :             fWorkBefore = nCheapBefore;
      46         134 :             fWorkAfter = nCheapAfter + nExpensiveAfter*fSigcheckVerificationFactor;
      47             :         } else {
      48        5586 :             double nCheapBefore = data.nTransactionsLastCheckpoint;
      49        5586 :             double nExpensiveBefore = pindex->nChainTx - data.nTransactionsLastCheckpoint;
      50       11172 :             double nExpensiveAfter = (nNow - pindex->GetBlockTime())/86400.0*data.fTransactionsPerDay;
      51        5586 :             fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
      52        5586 :             fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
      53             :         }
      54             : 
      55        5720 :         return fWorkBefore / (fWorkBefore + fWorkAfter);
      56             :     }
      57             : 
      58      170595 :     int GetTotalBlocksEstimate(const CCheckpointData& data)
      59             :     {
      60      170595 :         const MapCheckpoints& checkpoints = data.mapCheckpoints;
      61             : 
      62      170595 :         if (checkpoints.empty())
      63             :             return 0;
      64             : 
      65      170595 :         return checkpoints.rbegin()->first;
      66             :     }
      67             : 
      68       13344 :     CBlockIndex* GetLastCheckpoint(const CCheckpointData& data)
      69             :     {
      70       13344 :         const MapCheckpoints& checkpoints = data.mapCheckpoints;
      71             : 
      72      106752 :         BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
      73             :         {
      74       13344 :             const uint256& hash = i.second;
      75       13344 :             BlockMap::const_iterator t = mapBlockIndex.find(hash);
      76       13344 :             if (t != mapBlockIndex.end())
      77       13344 :                 return t->second;
      78             :         }
      79           0 :         return NULL;
      80             :     }
      81             : 
      82         288 : } // namespace Checkpoints

Generated by: LCOV version 1.11