Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
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