Skip to content

Commit 19ca89b

Browse files
committed
node: sort m_dirty_blockindex by block hash
1 parent 94a9e8c commit 19ca89b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/node/blockstorage.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ bool CBlockIndexHeightOnlyComparator::operator()(const CBlockIndex* pa, const CB
179179
return pa->nHeight < pb->nHeight;
180180
}
181181

182+
bool CBlockIndexBlockHashComparator::operator()(const CBlockIndex* pa, const CBlockIndex* pb) const
183+
{
184+
return UintToArith256(pa->GetBlockHash()) < UintToArith256(pb->GetBlockHash());
185+
}
186+
182187
std::vector<CBlockIndex*> BlockManager::GetAllBlockIndices()
183188
{
184189
AssertLockHeld(cs_main);

src/node/blockstorage.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ struct CBlockIndexHeightOnlyComparator {
9595
bool operator()(const CBlockIndex* pa, const CBlockIndex* pb) const;
9696
};
9797

98+
struct CBlockIndexBlockHashComparator {
99+
/* Only used in fuzzing */
100+
bool operator()(const CBlockIndex* pa, const CBlockIndex* pb) const;
101+
};
102+
98103
struct PruneLockInfo {
99104
int height_first{std::numeric_limits<int>::max()}; //! Height of earliest block that should be kept and not pruned
100105
};
@@ -238,7 +243,7 @@ class BlockManager
238243
const Obfuscation m_obfuscation;
239244

240245
/** Dirty block index entries. */
241-
std::set<CBlockIndex*> m_dirty_blockindex;
246+
std::set<CBlockIndex*, CBlockIndexBlockHashComparator> m_dirty_blockindex;
242247

243248
/** Dirty block file entries. */
244249
std::set<int> m_dirty_fileinfo;

0 commit comments

Comments
 (0)