Bitcoin ABC  0.23.2
P2P Digital Currency
blockindexworkcomparator.h
Go to the documentation of this file.
1 // Copyright (c) 2018-2019 The Bitcoin 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 #ifndef BITCOIN_BLOCKINDEXWORKCOMPARATOR_H
6 #define BITCOIN_BLOCKINDEXWORKCOMPARATOR_H
7 
8 #include <blockindex.h>
9 
11  bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const {
12  // First sort by most total work, ...
13  if (pa->nChainWork > pb->nChainWork) {
14  return false;
15  }
16  if (pa->nChainWork < pb->nChainWork) {
17  return true;
18  }
19 
20  // ... then by earliest time received, ...
21  if (pa->nSequenceId < pb->nSequenceId) {
22  return false;
23  }
24  if (pa->nSequenceId > pb->nSequenceId) {
25  return true;
26  }
27 
28  // Use pointer address as tie breaker (should only happen with blocks
29  // loaded from disk, as those all have id 0).
30  if (pa < pb) {
31  return false;
32  }
33  if (pa > pb) {
34  return true;
35  }
36 
37  // Identical blocks.
38  return false;
39  }
40 };
41 
42 #endif // BITCOIN_BLOCKINDEXWORKCOMPARATOR_H
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
Definition: blockindex.h:49
int32_t nSequenceId
(memory only) Sequential id assigned to distinguish order in which blocks are received.
Definition: blockindex.h:87
bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: blockindex.h:23