Bitcoin Src


SUBMITTED BY: Hobbyistpool

DATE: Sept. 22, 2016, 8:45 p.m.

FORMAT: C

SIZE: 3.4 kB

HITS: 1579

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

comments powered by Disqus