Merge bitcoin/bitcoin#32882: index: remove unnecessary locator cleaning in BaseIndex::Init()

facd01e6ff 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 facd01e6ff
  furszy:
    utACK facd01e6ff
  sedited:
    ACK facd01e6ff

Tree-SHA512: ca418a3d4c72b9bfdb194e03d5acfacf7b567850ab385ad3a1ec6d070eedef4aea2bb8335f8bfe0316e84c22583111fc202f7603044c5d4d05754db23f75b47f
This commit is contained in:
merge-script
2025-12-03 13:47:17 +00:00
2 changed files with 8 additions and 7 deletions

View File

@@ -73,13 +73,16 @@ BaseIndex::DB::DB(const fs::path& path, size_t n_cache_size, bool f_memory, bool
.options = [] { DBOptions options; node::ReadDatabaseArgs(gArgs, options); return options; }()}}
{}
bool BaseIndex::DB::ReadBestBlock(CBlockLocator& locator) const
CBlockLocator BaseIndex::DB::ReadBestBlock() const
{
CBlockLocator locator;
bool success = Read(DB_BEST_BLOCK, locator);
if (!success) {
locator.SetNull();
}
return success;
return locator;
}
void BaseIndex::DB::WriteBestBlock(CDBBatch& batch, const CBlockLocator& locator)
@@ -111,10 +114,7 @@ bool BaseIndex::Init()
// callbacks are not missed once m_synced is true.
m_chain->context()->validation_signals->RegisterValidationInterface(this);
CBlockLocator locator;
if (!GetDB().ReadBestBlock(locator)) {
locator.SetNull();
}
const auto locator{GetDB().ReadBestBlock()};
LOCK(cs_main);
CChain& index_chain = m_chainstate->m_chain;

View File

@@ -68,7 +68,8 @@ protected:
bool f_memory = false, bool f_wipe = false, bool f_obfuscate = false);
/// Read block locator of the chain that the index is in sync with.
bool ReadBestBlock(CBlockLocator& locator) const;
/// Note, the returned locator will be empty if no record exists.
CBlockLocator ReadBestBlock() const;
/// Write block locator of the chain that the index is in sync with.
void WriteBestBlock(CDBBatch& batch, const CBlockLocator& locator);