// 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 // for 'map_list_of()' #include #include "checkpoints.h" #include "txdb.h" #include "main.h" #include "uint256.h" static const int nCheckpointSpan = 500; namespace Checkpoints { typedef std::map MapCheckpoints; // // 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("0x00001123368370feb0997f471423e4445be205b9947e7053c762886317274d2a") ) ( 2, uint256("0x2a95c98075c4ca1ae23f4bdc207be423efb64f347bd7ad7f0568bab5a2ea7f4f") ) // Premine ( 100, uint256("0x58c23d68b43a670f11bc5993c4194347779bde93b1e856ce2d2ec99ca3a0952c") ) ( 1000, uint256("0x4d41cbcf542ef60c8e9acd8229684bf1bbbbfab062c56122dd1a30a2331f45c4") ) ( 142050, uint256("0xf8825a74a619639003719cf0874f6efd200e978ff6645cd1ea61ba006d982750") ) ; // TestNet has no checkpoints static MapCheckpoints mapCheckpointsTestnet; // RegTest has no checkpoints static MapCheckpoints mapCheckpointsRegTest; bool CheckHardened(int nHeight, const uint256& hash) { MapCheckpoints& checkpoints = (TestNet() ? mapCheckpointsTestnet :IsRegTest() ? mapCheckpointsRegTest : mapCheckpoints); MapCheckpoints::const_iterator i = checkpoints.find(nHeight); if (i == checkpoints.end()) return true; return hash == i->second; } int GetTotalBlocksEstimate() { MapCheckpoints& checkpoints = (TestNet() ? mapCheckpointsTestnet : mapCheckpoints); if (checkpoints.empty()) return 0; return checkpoints.rbegin()->first; } CBlockIndex* GetLastCheckpoint(const std::map& mapBlockIndex) { MapCheckpoints& checkpoints = (TestNet() ? mapCheckpointsTestnet : mapCheckpoints); BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints) { const uint256& hash = i.second; std::map::const_iterator t = mapBlockIndex.find(hash); if (t != mapBlockIndex.end()) return t->second; } return NULL; } // Automatically select a suitable sync-checkpoint const CBlockIndex* AutoSelectSyncCheckpoint() { const CBlockIndex *pindex = pindexBest; // Search backward for a block within max span and maturity window while (pindex->pprev && pindex->nHeight + nCheckpointSpan > pindexBest->nHeight) pindex = pindex->pprev; return pindex; } // Check against synchronized checkpoint bool CheckSync(int nHeight) { const CBlockIndex* pindexSync = AutoSelectSyncCheckpoint(); if (nHeight <= pindexSync->nHeight) return false; return true; } }