forked from Bitcoin-ABC/bitcoin-abc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblockindexworkcomparator.h
43 lines (36 loc) · 1.22 KB
/
blockindexworkcomparator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2018 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_BLOCKINDEXWORKCOMPARATOR_H
#define BITCOIN_BLOCKINDEXWORKCOMPARATOR_H
// TODO: Split chain.h apart and only include CBlockIndex
#include <chain.h>
struct CBlockIndexWorkComparator {
bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const {
// First sort by most total work, ...
if (pa->nChainWork > pb->nChainWork) {
return false;
}
if (pa->nChainWork < pb->nChainWork) {
return true;
}
// ... then by earliest time received, ...
if (pa->nSequenceId < pb->nSequenceId) {
return false;
}
if (pa->nSequenceId > pb->nSequenceId) {
return true;
}
// Use pointer address as tie breaker (should only happen with blocks
// loaded from disk, as those all have id 0).
if (pa < pb) {
return false;
}
if (pa > pb) {
return true;
}
// Identical blocks.
return false;
}
};
#endif // BITCOIN_BLOCKINDEXWORKCOMPARATOR_H