From 12eb05df63f930969115af6dc66e2e5d02f2a517 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Tue, 15 Mar 2022 19:17:36 -0400 Subject: move-only: Move CBlockIndexWorkComparator to blockstorage ...it's declared in blockstorage.h --- src/node/blockstorage.cpp | 19 +++++++++++++++++++ src/validation.cpp | 18 ------------------ 2 files changed, 19 insertions(+), 18 deletions(-) (limited to 'src') 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(); diff --git a/src/validation.cpp b/src/validation.cpp index ba8925322f..eebb6773d4 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -107,24 +107,6 @@ const std::vector CHECKLEVEL_DOC { "each level includes the checks of the previous levels", }; -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; -} - /** * Mutex to guard access to validation specific variables, such as reading * or changing the chainstate. -- cgit v1.2.3