mirror of
https://github.com/GOSTSec/gostcoin
synced 2025-01-22 12:34:21 +00:00
150 lines
6.1 KiB
C++
150 lines
6.1 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;
|
|
};
|
|
|
|
// 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
|
|
( 1, uint256("0x0000086f3bfd2ca98fa3f912c41d1c4482ed1f5399c289f4cae4420c9c3a3fda"))
|
|
( 7, uint256("0x00000ae8c47fc4e0498d1c569eeaa05a4c2214ef95cbef2c2906e2daf78c2c6b"))
|
|
( 777, uint256("0x0000062829795a3ffc0ae5e0f7fe5327fb134c9844b3d3755a1619f378be2de4"))
|
|
/* ( 7777, uint256("0xae3094030b34a422c44b9832c84fe602d0d528449d6940374bd43b4472b4df5e"))
|
|
(15420, uint256("0xfded6a374d071f59d738a3009fc4d8461609052c3e7e91aa89146550d179c1b0"))
|
|
(16000, uint256("0x683517a8cae8530f39e636f010ecd1750665c3d91f57ba71d6556535972ab328"))
|
|
(77777, uint256("0xf5c98062cb1ad75c792a1851a388447f0edd7cb2271b67ef1241a03c673b7735"))
|
|
(77778, uint256("0xd13f93f9fdac82ea26ed8f90474ed2449c8c24be50a416e43c323a38573c30e5"))
|
|
(100000, uint256("0xcc4f0b11e9e17f7a406ac4a71e6e192b9b43e32b300ddecba229c789392497eb"))
|
|
(106000, uint256("0xbe27545eb8ea31c74878b54d500161873ed035afc2fa1f4e7cfa7e84a232b8f9"))
|
|
(112800, uint256("0x4dbecbf0368b99c80da8406693f370b754f78a7b6d139a878bc69fb961f86383"))*/
|
|
;
|
|
static const CCheckpointData data = {
|
|
&mapCheckpoints,
|
|
1376885874, // * UNIX timestamp of last checkpoint block
|
|
1859062, // * total number of transactions between genesis and last checkpoint
|
|
// (the tx=... number in the SetBestChain debug.log lines)
|
|
7000.0 // * estimated number of transactions per day after checkpoint
|
|
};
|
|
|
|
static MapCheckpoints mapCheckpointsTestnet =
|
|
boost::assign::map_list_of
|
|
( 5046, uint256("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70"))
|
|
( 35000, uint256("2af959ab4f12111ce947479bfcef16702485f04afd95210aa90fde7d1e4a64ad"))
|
|
;
|
|
static const CCheckpointData dataTestnet = {
|
|
&mapCheckpointsTestnet,
|
|
1369685559,
|
|
37581,
|
|
300
|
|
};
|
|
|
|
const CCheckpointData &Checkpoints() {
|
|
if (fTestNet)
|
|
return dataTestnet;
|
|
else
|
|
return data;
|
|
}
|
|
|
|
bool CheckBlock(int nHeight, const uint256& hash)
|
|
{
|
|
if (fTestNet) return true; // Testnet has no checkpoints
|
|
if (!GetBoolArg("-checkpoints", true))
|
|
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 (fTestNet) return 0; // Testnet has no checkpoints
|
|
if (!GetBoolArg("-checkpoints", true))
|
|
return 0;
|
|
|
|
const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
|
|
|
|
return checkpoints.rbegin()->first;
|
|
}
|
|
|
|
CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
|
|
{
|
|
if (fTestNet) return NULL; // Testnet has no checkpoints
|
|
if (!GetBoolArg("-checkpoints", true))
|
|
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;
|
|
}
|
|
}
|