Bitcoin ABC 0.30.5
P2P Digital Currency
blockindexcomparators.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_BLOCKINDEXCOMPARATORS_H
6#define BITCOIN_BLOCKINDEXCOMPARATORS_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
46 bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const {
47 return pa->nHeight < pb->nHeight;
48 }
49};
50
51#endif // BITCOIN_BLOCKINDEXCOMPARATORS_H
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:25
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
Definition: blockindex.h:51
int32_t nSequenceId
(memory only) Sequential id assigned to distinguish order in which blocks are received.
Definition: blockindex.h:98
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: blockindex.h:38
bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const
Only compares the height of two block indices, doesn't try to tie-break.
bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const