diff --git a/src/index/base.cpp b/src/index/base.cpp index 82259ac046a..2403989eddb 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -59,13 +59,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) @@ -97,10 +100,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; diff --git a/src/index/base.h b/src/index/base.h index 4131b06cad9..5a8ad8bf1f8 100644 --- a/src/index/base.h +++ b/src/index/base.h @@ -56,7 +56,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);