Files

95 lines
3.6 KiB
C++
Raw Permalink Normal View History

2017-11-09 19:34:51 +01:00
/*
* This file is part of the Flowee project
* Copyright (c) 2009-2015 The Bitcoin Core developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "checkpoints.h"
2015-07-05 14:17:46 +02:00
#include "chain.h"
#include "chainparams.h"
2012-04-15 22:10:54 +02:00
#include "main.h"
#include "uint256.h"
2017-02-14 11:17:46 +01:00
#include "BlocksDB.h"
2012-04-15 22:10:54 +02:00
2013-04-13 00:13:08 -05:00
#include <boost/foreach.hpp>
namespace Checkpoints {
/**
2015-04-28 14:47:17 +00:00
* How many times slower we expect checking transactions after the last
* checkpoint to be (from checking signatures, which is skipped up to the
* last checkpoint). This number is a compromise, as it can't be accurate
* for every system. When reindexing from a fast disk with a slow CPU, it
* can be up to 20, while when downloading from a slow network with a
* fast multicore CPU, it won't be much higher than 1.
*/
2014-03-19 00:26:14 +01:00
static const double SIGCHECK_VERIFICATION_FACTOR = 5.0;
2013-02-10 19:46:42 +01:00
//! Guess how far we are in the verification process at the given block index
double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex *pindex, bool fSigchecks) {
2013-02-10 19:46:42 +01:00
if (pindex==NULL)
return 0.0;
2013-04-13 00:13:08 -05:00
int64_t nNow = time(NULL);
2013-02-10 19:46:42 +01:00
2014-03-19 00:26:14 +01:00
double fSigcheckVerificationFactor = fSigchecks ? SIGCHECK_VERIFICATION_FACTOR : 1.0;
2013-02-10 19:46:42 +01:00
double fWorkBefore = 0.0; // Amount of work done before pindex
double fWorkAfter = 0.0; // Amount of work left after pindex (estimated)
2014-01-17 14:20:43 +02:00
// Work is defined as: 1.0 per transaction before the last checkpoint, and
2013-02-10 19:46:42 +01:00
// fSigcheckVerificationFactor per transaction after.
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;
2014-06-28 23:36:06 +02:00
double nExpensiveAfter = (nNow - pindex->GetBlockTime())/86400.0*data.fTransactionsPerDay;
2013-02-10 19:46:42 +01:00
fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
}
return fWorkBefore / (fWorkBefore + fWorkAfter);
}
int GetTotalBlocksEstimate(const CCheckpointData& data)
{
const MapCheckpoints& checkpoints = data.mapCheckpoints;
if (checkpoints.empty())
return 0;
2012-04-13 14:53:31 -04:00
return checkpoints.rbegin()->first;
}
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data)
{
const MapCheckpoints& checkpoints = data.mapCheckpoints;
2012-04-13 14:53:31 -04:00
BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
{
2018-01-15 15:26:12 +00:00
auto blockIndex = Blocks::Index::get(i.second);
if (blockIndex)
return blockIndex;
}
return NULL;
}
} // namespace Checkpoints