From cdab9480e9e35656f490878f92dab5427b36f21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Tue, 22 Jul 2025 12:28:44 -0700 Subject: [PATCH] refactor: inline constant return value of `CDBWrapper::Write` --- src/dbwrapper.h | 3 +-- src/index/blockfilterindex.cpp | 4 +--- src/index/coinstatsindex.cpp | 3 ++- src/node/blockstorage.cpp | 6 ++++-- src/test/dbwrapper_tests.cpp | 36 +++++++++++++++++----------------- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 94e452db76b..50be26fb99e 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -230,12 +230,11 @@ public: } template - bool Write(const K& key, const V& value, bool fSync = false) + void Write(const K& key, const V& value, bool fSync = false) { CDBBatch batch(*this); batch.Write(key, value); WriteBatch(batch, fSync); - return true; } //! @returns filesystem path to the on-disk data. diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp index c56d787907a..77bf931d9d0 100644 --- a/src/index/blockfilterindex.cpp +++ b/src/index/blockfilterindex.cpp @@ -291,9 +291,7 @@ bool BlockFilterIndex::Write(const BlockFilter& filter, uint32_t block_height, c value.second.header = filter_header; value.second.pos = m_next_filter_pos; - if (!m_db->Write(DBHeightKey(block_height), value)) { - return false; - } + m_db->Write(DBHeightKey(block_height), value); m_next_filter_pos.nPos += bytes_written; return true; diff --git a/src/index/coinstatsindex.cpp b/src/index/coinstatsindex.cpp index 8f172d706a7..8072167e452 100644 --- a/src/index/coinstatsindex.cpp +++ b/src/index/coinstatsindex.cpp @@ -226,7 +226,8 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block) // Intentionally do not update DB_MUHASH here so it stays in sync with // DB_BEST_BLOCK, and the index is not corrupted if there is an unclean shutdown. - return m_db->Write(DBHeightKey(block.height), value); + m_db->Write(DBHeightKey(block.height), value); + return true; } [[nodiscard]] static bool CopyHeightIndexToHashIndex(CDBIterator& db_it, CDBBatch& batch, diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index f1d4be6b706..7371111ccbc 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -62,7 +62,8 @@ bool BlockTreeDB::ReadBlockFileInfo(int nFile, CBlockFileInfo& info) bool BlockTreeDB::WriteReindexing(bool fReindexing) { if (fReindexing) { - return Write(DB_REINDEX_FLAG, uint8_t{'1'}); + Write(DB_REINDEX_FLAG, uint8_t{'1'}); + return true; } else { return Erase(DB_REINDEX_FLAG); } @@ -94,7 +95,8 @@ bool BlockTreeDB::WriteBatchSync(const std::vector it(const_cast(dbw).NewIterator()); @@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate) uint256 in = m_rng.rand256(); uint256 res; - BOOST_CHECK(dbw->Write(key, in)); + dbw->Write(key, in); BOOST_CHECK(dbw->Read(key, res)); BOOST_CHECK_EQUAL(res.ToString(), in.ToString()); @@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate) uint256 res3; // Check that we can write successfully - BOOST_CHECK(odbw.Write(key, in2)); + odbw.Write(key, in2); BOOST_CHECK(odbw.Read(key, res3)); BOOST_CHECK_EQUAL(res3.ToString(), in2.ToString()); } @@ -279,7 +279,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex) uint256 in = m_rng.rand256(); uint256 res; - BOOST_CHECK(dbw->Write(key, in)); + dbw->Write(key, in); BOOST_CHECK(dbw->Read(key, res)); BOOST_CHECK_EQUAL(res.ToString(), in.ToString()); @@ -298,7 +298,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex) uint256 res3; // Check that we can write successfully - BOOST_CHECK(odbw.Write(key, in2)); + odbw.Write(key, in2); BOOST_CHECK(odbw.Read(key, res3)); BOOST_CHECK_EQUAL(res3.ToString(), in2.ToString()); } @@ -310,7 +310,7 @@ BOOST_AUTO_TEST_CASE(iterator_ordering) for (int x=0x00; x<256; ++x) { uint8_t key = x; uint32_t value = x*x; - if (!(x & 1)) BOOST_CHECK(dbw.Write(key, value)); + if (!(x & 1)) dbw.Write(key, value); } // Check that creating an iterator creates a snapshot @@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE(iterator_ordering) for (unsigned int x=0x00; x<256; ++x) { uint8_t key = x; uint32_t value = x*x; - if (x & 1) BOOST_CHECK(dbw.Write(key, value)); + if (x & 1) dbw.Write(key, value); } for (const int seek_start : {0x00, 0x80}) { @@ -381,7 +381,7 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering) for (int z = 0; z < y; ++z) key += key; uint32_t value = x*x; - BOOST_CHECK(dbw.Write(StringContentsSerializer{key}, value)); + dbw.Write(StringContentsSerializer{key}, value); } }