mirror of
https://github.com/jwinterm/myriadcoin.git
synced 2026-10-19 05:58:38 +02:00
Myriadcoin 0.11 port
This commit is contained in:
+26
-108
@@ -1,118 +1,40 @@
|
||||
// Copyright (c) 2009-2014 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "checkpoints.h"
|
||||
|
||||
#include "chainparams.h"
|
||||
#include "main.h"
|
||||
#include "uint256.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boost/assign/list_of.hpp> // for 'map_list_of()'
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
namespace Checkpoints
|
||||
{
|
||||
typedef std::map<int, uint256> MapCheckpoints;
|
||||
namespace Checkpoints {
|
||||
|
||||
// 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.
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
static const double SIGCHECK_VERIFICATION_FACTOR = 5.0;
|
||||
|
||||
struct CCheckpointData {
|
||||
const MapCheckpoints *mapCheckpoints;
|
||||
int64_t nTimeLastCheckpoint;
|
||||
int64_t 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
|
||||
( 0, uint256("0x00000ffde4c020b5938441a0ea3d314bf619eff0b38f32f78f7583cffa1ea485"))
|
||||
( 9646, uint256("0x0000000000000b0f1372211861f226a3ec06a27d0a5bf36e4244a982da077e8f"))
|
||||
( 27255, uint256("0x00000000000005112a0debf53703eb3dc4ec2d8d68599c90db71423ea14489b7"))
|
||||
( 70623, uint256("0x00000000000004767ff6e509d00772af5c4bedaa82c38c1e95c33adbf5ff84f5"))
|
||||
( 112567, uint256("0x000000000000018c0621bf32ab33d3ca871509f406f08be6dd20facea747b099"))
|
||||
( 141845, uint256("0x00000000000000f62d14d55c2bc3ec0ba94e4f2b3868bbe7be9cb5b681fcc0fb"))
|
||||
( 149540, uint256("0x000000000000061b8f5b8653fe13b5e453347d9386d43d09445ee5e26a8222bb"))
|
||||
( 348178, uint256("0x0000000000000a410c6aff939087769e757132098fa0b0ce89f11d68f935077d"))
|
||||
( 431747, uint256("0x000000000000065616abeccd681f7b4d6d7bed06deef0e1a6e70c905edae3692"))
|
||||
( 490168, uint256("0x000000000000155ce9845e501617f152127e32c2c468edc643809f9988d30327"))
|
||||
( 557719, uint256("0x0000000000000851f690d42129b34408697c88316879debd413049959517d7c6"))
|
||||
( 740001, uint256("0x00000000000002c7aaa3ad688eb5af7d2779f4aa1d9a1b9a5c3cfb4ccad56caa"))
|
||||
( 740576, uint256("0x00000000000043dc047538e724f17a388146f22dd2ecf66f3c88253799912f4d"))
|
||||
( 766081, uint256("0x00000000000001e604a7acc2dd539ff8bd51224a7aac8647736d1af10160427d"))
|
||||
(1007712, uint256("0x00000000000013e0fb1ec8ba2ce0b04b1547d9ae7d9c9e5a2691aeca87559a12"))
|
||||
(1077647, uint256("0x00000000000038b85361a79dd4a04b1f01ec2cc60f4176185363aa4522aab12d"))
|
||||
(1177283, uint256("0x000000000000359b1fb371d92db45de64b449ea72863a51fa78fea6b7ff3989f"))
|
||||
(1336174, uint256("0x00000000000001eafb1051fda69eb842577a0e48e4f0682bd7f33677373d0807"))
|
||||
(1402167, uint256("0x8215cd9feb2db9bf74514361a9d4b4440f054101079df8bb6bf629065db3ab29"))
|
||||
(1449500, uint256("0xef19939e314f239999b9959ac908b20a43b165719d1c35dcfe38ba2566d20765"))
|
||||
;
|
||||
static const CCheckpointData data = {
|
||||
&mapCheckpoints,
|
||||
1446851338, // * UNIX timestamp of last checkpoint block
|
||||
4117140, // * total number of transactions between genesis and last checkpoint
|
||||
// (the tx=... number in the SetBestChain debug.log lines)
|
||||
2880 // * estimated number of transactions per day after checkpoint
|
||||
};
|
||||
|
||||
static MapCheckpoints mapCheckpointsTestnet =
|
||||
boost::assign::map_list_of
|
||||
( 0, uint256("0x0000017ce2a79c8bddafbbe47c004aa92b20678c354b34085f62b762084b9788"))
|
||||
;
|
||||
static const CCheckpointData dataTestnet = {
|
||||
&mapCheckpointsTestnet,
|
||||
1392876393,
|
||||
0,
|
||||
2880
|
||||
};
|
||||
|
||||
static MapCheckpoints mapCheckpointsRegtest =
|
||||
boost::assign::map_list_of
|
||||
( 0, uint256("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"))
|
||||
;
|
||||
static const CCheckpointData dataRegtest = {
|
||||
&mapCheckpointsRegtest,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
const CCheckpointData &Checkpoints() {
|
||||
if (Params().NetworkID() == CChainParams::TESTNET)
|
||||
return dataTestnet;
|
||||
else if (Params().NetworkID() == CChainParams::MAIN)
|
||||
return data;
|
||||
else
|
||||
return dataRegtest;
|
||||
}
|
||||
|
||||
bool CheckBlock(int nHeight, const uint256& hash)
|
||||
bool CheckBlock(const CCheckpointData& data, int nHeight, const uint256& hash)
|
||||
{
|
||||
if (!fEnabled)
|
||||
return true;
|
||||
|
||||
const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
|
||||
const MapCheckpoints& checkpoints = data.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, bool fSigchecks) {
|
||||
//! Guess how far we are in the verification process at the given block index
|
||||
double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex *pindex, bool fSigchecks) {
|
||||
if (pindex==NULL)
|
||||
return 0.0;
|
||||
|
||||
@@ -124,8 +46,6 @@ namespace Checkpoints
|
||||
// Work is defined as: 1.0 per transaction before the last checkpoint, and
|
||||
// fSigcheckVerificationFactor per transaction after.
|
||||
|
||||
const CCheckpointData &data = Checkpoints();
|
||||
|
||||
if (pindex->nChainTx <= data.nTransactionsLastCheckpoint) {
|
||||
double nCheapBefore = pindex->nChainTx;
|
||||
double nCheapAfter = data.nTransactionsLastCheckpoint - pindex->nChainTx;
|
||||
@@ -135,7 +55,7 @@ namespace Checkpoints
|
||||
} else {
|
||||
double nCheapBefore = data.nTransactionsLastCheckpoint;
|
||||
double nExpensiveBefore = pindex->nChainTx - data.nTransactionsLastCheckpoint;
|
||||
double nExpensiveAfter = (nNow - pindex->nTime)/86400.0*data.fTransactionsPerDay;
|
||||
double nExpensiveAfter = (nNow - pindex->GetBlockTime())/86400.0*data.fTransactionsPerDay;
|
||||
fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
|
||||
fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
|
||||
}
|
||||
@@ -143,30 +63,28 @@ namespace Checkpoints
|
||||
return fWorkBefore / (fWorkBefore + fWorkAfter);
|
||||
}
|
||||
|
||||
int GetTotalBlocksEstimate()
|
||||
int GetTotalBlocksEstimate(const CCheckpointData& data)
|
||||
{
|
||||
if (!fEnabled)
|
||||
return 0;
|
||||
const MapCheckpoints& checkpoints = data.mapCheckpoints;
|
||||
|
||||
const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
|
||||
if (checkpoints.empty())
|
||||
return 0;
|
||||
|
||||
return checkpoints.rbegin()->first;
|
||||
}
|
||||
|
||||
CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
|
||||
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data)
|
||||
{
|
||||
if (!fEnabled)
|
||||
return NULL;
|
||||
|
||||
const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
|
||||
const MapCheckpoints& checkpoints = data.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);
|
||||
BlockMap::const_iterator t = mapBlockIndex.find(hash);
|
||||
if (t != mapBlockIndex.end())
|
||||
return t->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Checkpoints
|
||||
|
||||
Reference in New Issue
Block a user