mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-10 06:48:07 +00:00
bf3ec900d0
correct branch to force them to go to the right chain.
142 lines
5.2 KiB
C++
142 lines
5.2 KiB
C++
// Copyright (c) 2009-2012 The Bitcoin developers
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <boost/assign/list_of.hpp> // for 'map_list_of()'
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include "checkpoints.h"
|
|
|
|
#include "main.h"
|
|
#include "uint256.h"
|
|
|
|
namespace Checkpoints
|
|
{
|
|
typedef std::map<int, uint256> MapCheckpoints;
|
|
|
|
// How many times we expect transactions after the last checkpoint to
|
|
// be slower. 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.
|
|
static const double fSigcheckVerificationFactor = 5.0;
|
|
|
|
struct CCheckpointData {
|
|
const MapCheckpoints *mapCheckpoints;
|
|
int64 nTimeLastCheckpoint;
|
|
int64 nTransactionsLastCheckpoint;
|
|
double fTransactionsPerDay;
|
|
};
|
|
|
|
bool fEnabled = true;
|
|
|
|
// What makes a good checkpoint block?
|
|
// + Is surrounded by blocks with reasonable timestamps
|
|
// (no blocks before with a timestamp after, none after with
|
|
// timestamp before)
|
|
// + Contains no strange transactions
|
|
static MapCheckpoints mapCheckpoints =
|
|
boost::assign::map_list_of
|
|
( 121, uint256("0xcfdd9b4eb621c93163af7b730b3590b7a90c3d5e233569d76a1c0363527c92ae"))
|
|
( 13081, uint256("0x5125dc1f6a3b8f1c463baf3e078d8af9f1b35aa4b34fb441e3a7ee391f8727c6"))
|
|
( 18000, uint256("0xa3cab01c0e3e9b17b2a63b3cc93d258112f5ad753df1df7bd45e37a5c60814a9"))
|
|
( 18050, uint256("0xef0d4c9e318a952dd45fcb1c867996df309a0fb586811479c08cf18a176a8864"))
|
|
( 18973, uint256("0x5f3f60fec53ac03434907ca980b5349875822794a4a0b50b78bcf0411d0c95fe"))
|
|
;
|
|
static const CCheckpointData data = {
|
|
&mapCheckpoints,
|
|
1389556451, // * UNIX timestamp of last checkpoint block
|
|
22193, // * total number of transactions between genesis and last checkpoint
|
|
// (the tx=... number in the SetBestChain debug.log lines)
|
|
144.0 // * estimated number of transactions per day after checkpoint
|
|
};
|
|
|
|
static MapCheckpoints mapCheckpointsTestnet =
|
|
boost::assign::map_list_of
|
|
( 546, uint256("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70"))
|
|
;
|
|
static const CCheckpointData dataTestnet = {
|
|
&mapCheckpointsTestnet,
|
|
1338180505,
|
|
16341,
|
|
300
|
|
};
|
|
|
|
const CCheckpointData &Checkpoints() {
|
|
if (TestNet())
|
|
return dataTestnet;
|
|
else
|
|
return data;
|
|
}
|
|
|
|
bool CheckBlock(int nHeight, const uint256& hash)
|
|
{
|
|
if (!fEnabled)
|
|
return true;
|
|
|
|
const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
|
|
|
|
MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
|
|
if (i == checkpoints.end()) return true;
|
|
return hash == i->second;
|
|
}
|
|
|
|
// 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 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 checkoint, and
|
|
// fSigcheckVerificationFactor per transaction after.
|
|
|
|
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);
|
|
}
|
|
|
|
int GetTotalBlocksEstimate()
|
|
{
|
|
if (!fEnabled)
|
|
return 0;
|
|
|
|
const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
|
|
|
|
return checkpoints.rbegin()->first;
|
|
}
|
|
|
|
CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
|
|
{
|
|
if (!fEnabled)
|
|
return NULL;
|
|
|
|
const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
|
|
|
|
BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
|
|
{
|
|
const uint256& hash = i.second;
|
|
std::map<uint256, CBlockIndex*>::const_iterator t = mapBlockIndex.find(hash);
|
|
if (t != mapBlockIndex.end())
|
|
return t->second;
|
|
}
|
|
return NULL;
|
|
}
|
|
}
|