From 743abbcbde9e5a2db489bca461c98df461eff7d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Tue, 22 Jul 2025 12:37:40 -0700 Subject: [PATCH] refactor: inline constant return value of `BlockTreeDB::WriteBatchSync` and `BlockManager::WriteBlockIndexDB` and `BlockTreeDB::WriteFlag` --- src/node/blockstorage.cpp | 13 ++++--------- src/node/blockstorage.h | 6 +++--- src/test/fuzz/block_index.cpp | 2 +- src/validation.cpp | 4 +--- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 5a54baf2b5e..a72292cb4a9 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -78,7 +78,7 @@ bool BlockTreeDB::ReadLastBlockFile(int& nFile) return Read(DB_LAST_BLOCK, nFile); } -bool BlockTreeDB::WriteBatchSync(const std::vector>& fileInfo, int nLastFile, const std::vector& blockinfo) +void BlockTreeDB::WriteBatchSync(const std::vector>& fileInfo, int nLastFile, const std::vector& blockinfo) { CDBBatch batch(*this); for (const auto& [file, info] : fileInfo) { @@ -89,13 +89,11 @@ bool BlockTreeDB::WriteBatchSync(const std::vectorGetBlockHash()), CDiskBlockIndex{bi}); } WriteBatch(batch, true); - return true; } -bool BlockTreeDB::WriteFlag(const std::string& name, bool fValue) +void BlockTreeDB::WriteFlag(const std::string& name, bool fValue) { Write(std::make_pair(DB_FLAG, name), fValue ? uint8_t{'1'} : uint8_t{'0'}); - return true; } bool BlockTreeDB::ReadFlag(const std::string& name, bool& fValue) @@ -478,7 +476,7 @@ bool BlockManager::LoadBlockIndex(const std::optional& snapshot_blockha return true; } -bool BlockManager::WriteBlockIndexDB() +void BlockManager::WriteBlockIndexDB() { AssertLockHeld(::cs_main); std::vector> vFiles; @@ -494,10 +492,7 @@ bool BlockManager::WriteBlockIndexDB() m_dirty_blockindex.erase(it++); } int max_blockfile = WITH_LOCK(cs_LastBlockFile, return this->MaxBlockfileNum()); - if (!m_block_tree_db->WriteBatchSync(vFiles, max_blockfile, vBlocks)) { - return false; - } - return true; + m_block_tree_db->WriteBatchSync(vFiles, max_blockfile, vBlocks); } bool BlockManager::LoadBlockIndexDB(const std::optional& snapshot_blockhash) diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h index 7d6f78f2532..caf291e9f2d 100644 --- a/src/node/blockstorage.h +++ b/src/node/blockstorage.h @@ -52,12 +52,12 @@ class BlockTreeDB : public CDBWrapper { public: using CDBWrapper::CDBWrapper; - bool WriteBatchSync(const std::vector>& fileInfo, int nLastFile, const std::vector& blockinfo); + void WriteBatchSync(const std::vector>& fileInfo, int nLastFile, const std::vector& blockinfo); bool ReadBlockFileInfo(int nFile, CBlockFileInfo& info); bool ReadLastBlockFile(int& nFile); void WriteReindexing(bool fReindexing); void ReadReindexing(bool& fReindexing); - bool WriteFlag(const std::string& name, bool fValue); + void WriteFlag(const std::string& name, bool fValue); bool ReadFlag(const std::string& name, bool& fValue); bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function insertBlockIndex, const util::SignalInterrupt& interrupt) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); @@ -300,7 +300,7 @@ public: std::unique_ptr m_block_tree_db GUARDED_BY(::cs_main); - bool WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + void WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); bool LoadBlockIndexDB(const std::optional& snapshot_blockhash) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); diff --git a/src/test/fuzz/block_index.cpp b/src/test/fuzz/block_index.cpp index eef8c2efc80..5bc6240cabb 100644 --- a/src/test/fuzz/block_index.cpp +++ b/src/test/fuzz/block_index.cpp @@ -89,7 +89,7 @@ FUZZ_TARGET(block_index, .init = init_block_index) } // Store these files and blocks in the block index. It should not fail. - assert(block_index.WriteBatchSync(files_info, files_count - 1, blocks_info)); + block_index.WriteBatchSync(files_info, files_count - 1, blocks_info); // We should be able to read every block file info we stored. Its value should correspond to // what we stored above. diff --git a/src/validation.cpp b/src/validation.cpp index 7b7c8b2d5bd..c322118574b 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2851,9 +2851,7 @@ bool Chainstate::FlushStateToDisk( { LOG_TIME_MILLIS_WITH_CATEGORY("write block index to disk", BCLog::BENCH); - if (!m_blockman.WriteBlockIndexDB()) { - return FatalError(m_chainman.GetNotifications(), state, _("Failed to write to block index database.")); - } + m_blockman.WriteBlockIndexDB(); } // Finally remove any pruned files if (fFlushForPrune) {