Skip to content

Commit 743abbc

Browse files
committed
refactor: inline constant return value of BlockTreeDB::WriteBatchSync and BlockManager::WriteBlockIndexDB and BlockTreeDB::WriteFlag
1 parent e030240 commit 743abbc

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

src/node/blockstorage.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ bool BlockTreeDB::ReadLastBlockFile(int& nFile)
7878
return Read(DB_LAST_BLOCK, nFile);
7979
}
8080

81-
bool BlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*>>& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo)
81+
void BlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*>>& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo)
8282
{
8383
CDBBatch batch(*this);
8484
for (const auto& [file, info] : fileInfo) {
@@ -89,13 +89,11 @@ bool BlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockFi
8989
batch.Write(std::make_pair(DB_BLOCK_INDEX, bi->GetBlockHash()), CDiskBlockIndex{bi});
9090
}
9191
WriteBatch(batch, true);
92-
return true;
9392
}
9493

95-
bool BlockTreeDB::WriteFlag(const std::string& name, bool fValue)
94+
void BlockTreeDB::WriteFlag(const std::string& name, bool fValue)
9695
{
9796
Write(std::make_pair(DB_FLAG, name), fValue ? uint8_t{'1'} : uint8_t{'0'});
98-
return true;
9997
}
10098

10199
bool BlockTreeDB::ReadFlag(const std::string& name, bool& fValue)
@@ -478,7 +476,7 @@ bool BlockManager::LoadBlockIndex(const std::optional<uint256>& snapshot_blockha
478476
return true;
479477
}
480478

481-
bool BlockManager::WriteBlockIndexDB()
479+
void BlockManager::WriteBlockIndexDB()
482480
{
483481
AssertLockHeld(::cs_main);
484482
std::vector<std::pair<int, const CBlockFileInfo*>> vFiles;
@@ -494,10 +492,7 @@ bool BlockManager::WriteBlockIndexDB()
494492
m_dirty_blockindex.erase(it++);
495493
}
496494
int max_blockfile = WITH_LOCK(cs_LastBlockFile, return this->MaxBlockfileNum());
497-
if (!m_block_tree_db->WriteBatchSync(vFiles, max_blockfile, vBlocks)) {
498-
return false;
499-
}
500-
return true;
495+
m_block_tree_db->WriteBatchSync(vFiles, max_blockfile, vBlocks);
501496
}
502497

503498
bool BlockManager::LoadBlockIndexDB(const std::optional<uint256>& snapshot_blockhash)

src/node/blockstorage.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ class BlockTreeDB : public CDBWrapper
5252
{
5353
public:
5454
using CDBWrapper::CDBWrapper;
55-
bool WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*>>& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo);
55+
void WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*>>& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo);
5656
bool ReadBlockFileInfo(int nFile, CBlockFileInfo& info);
5757
bool ReadLastBlockFile(int& nFile);
5858
void WriteReindexing(bool fReindexing);
5959
void ReadReindexing(bool& fReindexing);
60-
bool WriteFlag(const std::string& name, bool fValue);
60+
void WriteFlag(const std::string& name, bool fValue);
6161
bool ReadFlag(const std::string& name, bool& fValue);
6262
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, const util::SignalInterrupt& interrupt)
6363
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
@@ -300,7 +300,7 @@ class BlockManager
300300

301301
std::unique_ptr<BlockTreeDB> m_block_tree_db GUARDED_BY(::cs_main);
302302

303-
bool WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
303+
void WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
304304
bool LoadBlockIndexDB(const std::optional<uint256>& snapshot_blockhash)
305305
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
306306

src/test/fuzz/block_index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ FUZZ_TARGET(block_index, .init = init_block_index)
8989
}
9090

9191
// Store these files and blocks in the block index. It should not fail.
92-
assert(block_index.WriteBatchSync(files_info, files_count - 1, blocks_info));
92+
block_index.WriteBatchSync(files_info, files_count - 1, blocks_info);
9393

9494
// We should be able to read every block file info we stored. Its value should correspond to
9595
// what we stored above.

src/validation.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,9 +2851,7 @@ bool Chainstate::FlushStateToDisk(
28512851
{
28522852
LOG_TIME_MILLIS_WITH_CATEGORY("write block index to disk", BCLog::BENCH);
28532853

2854-
if (!m_blockman.WriteBlockIndexDB()) {
2855-
return FatalError(m_chainman.GetNotifications(), state, _("Failed to write to block index database."));
2856-
}
2854+
m_blockman.WriteBlockIndexDB();
28572855
}
28582856
// Finally remove any pruned files
28592857
if (fFlushForPrune) {

0 commit comments

Comments
 (0)