diff options
author | Carl Dong <contact@carldong.me> | 2022-03-15 19:17:36 -0400 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2022-03-15 19:42:43 -0400 |
commit | 12eb05df63f930969115af6dc66e2e5d02f2a517 (patch) | |
tree | 9780c0cc0d3a5c5c51d4bb61d5aa38a8bb450f55 /src/node | |
parent | c600ee38168a460d3026eae0e289c976194aad14 (diff) | |
download | bitcoin-12eb05df63f930969115af6dc66e2e5d02f2a517.tar.xz |
move-only: Move CBlockIndexWorkComparator to blockstorage
...it's declared in blockstorage.h
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/blockstorage.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 5610f6348f..bbdd240692 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -28,6 +28,25 @@ bool fHavePruned = false; bool fPruneMode = false; uint64_t nPruneTarget = 0; +bool CBlockIndexWorkComparator::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; +} + static FILE* OpenUndoFile(const FlatFilePos& pos, bool fReadOnly = false); static FlatFileSeq BlockFileSeq(); static FlatFileSeq UndoFileSeq(); |