refactor: remove redundant locator cleanup in BaseIndex::Init()
Leverage locator.IsNull() to simplify ReadBestBlock() and remove unnecessary SetNull(). Co-authored-by: furszy <matiasfurszyfer@protonmail.com> Co-authored-by: l0rinc <pap.lorinc@gmail.com> Signed-off-by: Hao Xu <hao.xu@linux.dev>
This commit is contained in:
1 parent
1444ed855f
commit
facd01e6ff
2 files changed
+8
-7
No files matched your search
+6
-6
@@ -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; }()}}
|
.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);
|
bool success = Read(DB_BEST_BLOCK, locator);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
locator.SetNull();
|
locator.SetNull();
|
||||||
}
|
}
|
||||||
return success;
|
|
||||||
|
return locator;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseIndex::DB::WriteBestBlock(CDBBatch& batch, const CBlockLocator& 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.
|
// callbacks are not missed once m_synced is true.
|
||||||
m_chain->context()->validation_signals->RegisterValidationInterface(this);
|
m_chain->context()->validation_signals->RegisterValidationInterface(this);
|
||||||
|
|
||||||
CBlockLocator locator;
|
const auto locator{GetDB().ReadBestBlock()};
|
||||||
if (!GetDB().ReadBestBlock(locator)) {
|
|
||||||
locator.SetNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
CChain& index_chain = m_chainstate->m_chain;
|
CChain& index_chain = m_chainstate->m_chain;
|
||||||
|
|||||||
+2
-1
@@ -56,7 +56,8 @@ protected:
|
|||||||
bool f_memory = false, bool f_wipe = false, bool f_obfuscate = false);
|
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.
|
/// 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.
|
/// Write block locator of the chain that the index is in sync with.
|
||||||
void WriteBestBlock(CDBBatch& batch, const CBlockLocator& locator);
|
void WriteBestBlock(CDBBatch& batch, const CBlockLocator& locator);
|
||||||
|
|||||||
Reference in new issue
Block a user