Bitcoin ABC  0.24.10
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
nHeight
unsigned int nHeight
Definition: mempool_eviction.cpp:13
Checkpoints::GetLastCheckpoint
CBlockIndex * GetLastCheckpoint(const CCheckpointData &data) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Returns last CBlockIndex* that is a checkpoint.
Definition: checkpoints.cpp:28
CCheckpointData::mapCheckpoints
MapCheckpoints mapCheckpoints
Definition: chainparams.h:25
chainparams.h
MapCheckpoints
std::map< int, BlockHash > MapCheckpoints
Definition: chainparams.h:22
validation.h
cs_main
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:103
Checkpoints
Block-chain checkpoints are compiled-in sanity checks.
Definition: checkpoints.cpp:15
reverse_iterator.h
CCheckpointData
Definition: chainparams.h:24
checkpoints.h
BlockHash
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
LookupBlockIndex
CBlockIndex * LookupBlockIndex(const BlockHash &hash)
Definition: validation.cpp:150
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:23
reverse_iterate
reverse_range< T > reverse_iterate(T &x)
Definition: reverse_iterator.h:25
Checkpoints::CheckBlock
bool CheckBlock(const CCheckpointData &data, int nHeight, const BlockHash &hash)
Returns true if block passes checkpoint checks.
Definition: checkpoints.cpp:17