Skip to content

Commit 69e66ef

Browse files
committed
Merge bitcoin/bitcoin#32882: index: remove unnecessary locator cleaning in BaseIndex::Init()
facd01e refactor: remove redundant locator cleanup in BaseIndex::Init() (Hao Xu) Pull request description: Leverage locator.IsNull() to simplify ReadBestBlock() and remove unnecessary SetNull(). ACKs for top commit: l0rinc: ACK facd01e furszy: utACK facd01e sedited: ACK facd01e Tree-SHA512: ca418a3d4c72b9bfdb194e03d5acfacf7b567850ab385ad3a1ec6d070eedef4aea2bb8335f8bfe0316e84c22583111fc202f7603044c5d4d05754db23f75b47f
2 parents 6581ac5 + facd01e commit 69e66ef

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/index/base.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,16 @@ BaseIndex::DB::DB(const fs::path& path, size_t n_cache_size, bool f_memory, bool
7373
.options = [] { DBOptions options; node::ReadDatabaseArgs(gArgs, options); return options; }()}}
7474
{}
7575

76-
bool BaseIndex::DB::ReadBestBlock(CBlockLocator& locator) const
76+
CBlockLocator BaseIndex::DB::ReadBestBlock() const
7777
{
78+
CBlockLocator locator;
79+
7880
bool success = Read(DB_BEST_BLOCK, locator);
7981
if (!success) {
8082
locator.SetNull();
8183
}
82-
return success;
84+
85+
return locator;
8386
}
8487

8588
void BaseIndex::DB::WriteBestBlock(CDBBatch& batch, const CBlockLocator& locator)
@@ -111,10 +114,7 @@ bool BaseIndex::Init()
111114
// callbacks are not missed once m_synced is true.
112115
m_chain->context()->validation_signals->RegisterValidationInterface(this);
113116

114-
CBlockLocator locator;
115-
if (!GetDB().ReadBestBlock(locator)) {
116-
locator.SetNull();
117-
}
117+
const auto locator{GetDB().ReadBestBlock()};
118118

119119
LOCK(cs_main);
120120
CChain& index_chain = m_chainstate->m_chain;

src/index/base.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class BaseIndex : public CValidationInterface
6868
bool f_memory = false, bool f_wipe = false, bool f_obfuscate = false);
6969

7070
/// Read block locator of the chain that the index is in sync with.
71-
bool ReadBestBlock(CBlockLocator& locator) const;
71+
/// Note, the returned locator will be empty if no record exists.
72+
CBlockLocator ReadBestBlock() const;
7273

7374
/// Write block locator of the chain that the index is in sync with.
7475
void WriteBestBlock(CDBBatch& batch, const CBlockLocator& locator);

0 commit comments

Comments
 (0)