LCOV - code coverage report
Current view: top level - src - checkpoints.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 29 29 100.0 %
Date: 2025-02-23 09:33:43 Functions: 3 3 100.0 %

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

Generated by: LCOV version 1.14