refactor: inline constant return value of BlockTreeDB::WriteBatchSync and BlockManager::WriteBlockIndexDB and BlockTreeDB::WriteFlag

This commit is contained in:
Lőrinc committed 2025-08-13 15:47:48 -07:00
1 parent e030240e90
commit 743abbcbde
4 files changed
+9 -16

No files matched your search

+4 -9
View File
@@ -78,7 +78,7 @@ bool BlockTreeDB::ReadLastBlockFile(int& nFile)
return Read(DB_LAST_BLOCK, nFile); return Read(DB_LAST_BLOCK, nFile);
} }
bool BlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*>>& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo) void BlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*>>& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo)
{ {
CDBBatch batch(*this); CDBBatch batch(*this);
for (const auto& [file, info] : fileInfo) { for (const auto& [file, info] : fileInfo) {
@@ -89,13 +89,11 @@ bool BlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockFi
batch.Write(std::make_pair(DB_BLOCK_INDEX, bi->GetBlockHash()), CDiskBlockIndex{bi}); batch.Write(std::make_pair(DB_BLOCK_INDEX, bi->GetBlockHash()), CDiskBlockIndex{bi});
} }
WriteBatch(batch, true); 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'}); 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) bool BlockTreeDB::ReadFlag(const std::string& name, bool& fValue)
@@ -478,7 +476,7 @@ bool BlockManager::LoadBlockIndex(const std::optional<uint256>& snapshot_blockha
return true; return true;
} }
bool BlockManager::WriteBlockIndexDB() void BlockManager::WriteBlockIndexDB()
{ {
AssertLockHeld(::cs_main); AssertLockHeld(::cs_main);
std::vector<std::pair<int, const CBlockFileInfo*>> vFiles; std::vector<std::pair<int, const CBlockFileInfo*>> vFiles;
@@ -494,10 +492,7 @@ bool BlockManager::WriteBlockIndexDB()
m_dirty_blockindex.erase(it++); m_dirty_blockindex.erase(it++);
} }
int max_blockfile = WITH_LOCK(cs_LastBlockFile, return this->MaxBlockfileNum()); int max_blockfile = WITH_LOCK(cs_LastBlockFile, return this->MaxBlockfileNum());
if (!m_block_tree_db->WriteBatchSync(vFiles, max_blockfile, vBlocks)) { m_block_tree_db->WriteBatchSync(vFiles, max_blockfile, vBlocks);
return false;
}
return true;
} }
bool BlockManager::LoadBlockIndexDB(const std::optional<uint256>& snapshot_blockhash) bool BlockManager::LoadBlockIndexDB(const std::optional<uint256>& snapshot_blockhash)
+3 -3
View File
@@ -52,12 +52,12 @@ class BlockTreeDB : public CDBWrapper
{ {
public: public:
using CDBWrapper::CDBWrapper; using CDBWrapper::CDBWrapper;
bool WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*>>& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo); void WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*>>& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo);
bool ReadBlockFileInfo(int nFile, CBlockFileInfo& info); bool ReadBlockFileInfo(int nFile, CBlockFileInfo& info);
bool ReadLastBlockFile(int& nFile); bool ReadLastBlockFile(int& nFile);
void WriteReindexing(bool fReindexing); void WriteReindexing(bool fReindexing);
void ReadReindexing(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 ReadFlag(const std::string& name, bool& fValue);
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, const util::SignalInterrupt& interrupt) bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, const util::SignalInterrupt& interrupt)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main); EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
@@ -300,7 +300,7 @@ public:
std::unique_ptr<BlockTreeDB> m_block_tree_db GUARDED_BY(::cs_main); std::unique_ptr<BlockTreeDB> 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<uint256>& snapshot_blockhash) bool LoadBlockIndexDB(const std::optional<uint256>& snapshot_blockhash)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main); EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+1 -1
View File
@@ -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. // 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 // We should be able to read every block file info we stored. Its value should correspond to
// what we stored above. // what we stored above.
+1 -3
View File
@@ -2851,9 +2851,7 @@ bool Chainstate::FlushStateToDisk(
{ {
LOG_TIME_MILLIS_WITH_CATEGORY("write block index to disk", BCLog::BENCH); LOG_TIME_MILLIS_WITH_CATEGORY("write block index to disk", BCLog::BENCH);
if (!m_blockman.WriteBlockIndexDB()) { m_blockman.WriteBlockIndexDB();
return FatalError(m_chainman.GetNotifications(), state, _("Failed to write to block index database."));
}
} }
// Finally remove any pruned files // Finally remove any pruned files
if (fFlushForPrune) { if (fFlushForPrune) {