Bitcoin ABC  0.22.13
P2P Digital Currency
checkpoints.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <checkpoints.h>
6 
7 #include <chainparams.h>
8 #include <reverse_iterator.h>
9 // D6970 moved LookupBlockIndex from chain.h to validation.h TODO: remove this
10 // when LookupBlockIndex is refactored out of validation
11 #include <validation.h>
12 
13 #include <cstdint>
14 
15 namespace Checkpoints {
16 
17 bool CheckBlock(const CCheckpointData &data, int nHeight,
18  const BlockHash &hash) {
19  const MapCheckpoints &checkpoints = data.mapCheckpoints;
20 
21  MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
22  if (i == checkpoints.end()) {
23  return true;
24  }
25  return hash == i->second;
26 }
27 
30  const MapCheckpoints &checkpoints = data.mapCheckpoints;
31 
32  for (const MapCheckpoints::value_type &i : reverse_iterate(checkpoints)) {
33  const BlockHash &hash = i.second;
34  CBlockIndex *pindex = LookupBlockIndex(hash);
35  if (pindex) {
36  return pindex;
37  }
38  }
39 
40  return nullptr;
41 }
42 
43 } // namespace Checkpoints
reverse_range< T > reverse_iterate(T &x)
unsigned int nHeight
Block-chain checkpoints are compiled-in sanity checks.
Definition: checkpoints.cpp:15
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:95
CBlockIndex * GetLastCheckpoint(const CCheckpointData &data) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Returns last CBlockIndex* that is a checkpoint.
Definition: checkpoints.cpp:28
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
MapCheckpoints mapCheckpoints
Definition: chainparams.h:25
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: blockindex.h:23
std::map< int, BlockHash > MapCheckpoints
Definition: chainparams.h:22
CBlockIndex * LookupBlockIndex(const BlockHash &hash)
Definition: validation.cpp:145
bool CheckBlock(const CCheckpointData &data, int nHeight, const BlockHash &hash)
Returns true if block passes checkpoint checks.
Definition: checkpoints.cpp:17