Skip to content

Commit cdab948

Browse files
committed
refactor: inline constant return value of CDBWrapper::Write
1 parent d1847cf commit cdab948

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

src/dbwrapper.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,11 @@ class CDBWrapper
230230
}
231231

232232
template <typename K, typename V>
233-
bool Write(const K& key, const V& value, bool fSync = false)
233+
void Write(const K& key, const V& value, bool fSync = false)
234234
{
235235
CDBBatch batch(*this);
236236
batch.Write(key, value);
237237
WriteBatch(batch, fSync);
238-
return true;
239238
}
240239

241240
//! @returns filesystem path to the on-disk data.

src/index/blockfilterindex.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,7 @@ bool BlockFilterIndex::Write(const BlockFilter& filter, uint32_t block_height, c
291291
value.second.header = filter_header;
292292
value.second.pos = m_next_filter_pos;
293293

294-
if (!m_db->Write(DBHeightKey(block_height), value)) {
295-
return false;
296-
}
294+
m_db->Write(DBHeightKey(block_height), value);
297295

298296
m_next_filter_pos.nPos += bytes_written;
299297
return true;

src/index/coinstatsindex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
226226

227227
// Intentionally do not update DB_MUHASH here so it stays in sync with
228228
// DB_BEST_BLOCK, and the index is not corrupted if there is an unclean shutdown.
229-
return m_db->Write(DBHeightKey(block.height), value);
229+
m_db->Write(DBHeightKey(block.height), value);
230+
return true;
230231
}
231232

232233
[[nodiscard]] static bool CopyHeightIndexToHashIndex(CDBIterator& db_it, CDBBatch& batch,

src/node/blockstorage.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ bool BlockTreeDB::ReadBlockFileInfo(int nFile, CBlockFileInfo& info)
6262
bool BlockTreeDB::WriteReindexing(bool fReindexing)
6363
{
6464
if (fReindexing) {
65-
return Write(DB_REINDEX_FLAG, uint8_t{'1'});
65+
Write(DB_REINDEX_FLAG, uint8_t{'1'});
66+
return true;
6667
} else {
6768
return Erase(DB_REINDEX_FLAG);
6869
}
@@ -94,7 +95,8 @@ bool BlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockFi
9495

9596
bool BlockTreeDB::WriteFlag(const std::string& name, bool fValue)
9697
{
97-
return Write(std::make_pair(DB_FLAG, name), fValue ? uint8_t{'1'} : uint8_t{'0'});
98+
Write(std::make_pair(DB_FLAG, name), fValue ? uint8_t{'1'} : uint8_t{'0'});
99+
return true;
98100
}
99101

100102
bool BlockTreeDB::ReadFlag(const std::string& name, bool& fValue)

src/test/dbwrapper_tests.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper)
3939
for (uint8_t k{0}; k < 10; ++k) {
4040
uint8_t key{k};
4141
uint256 value{m_rng.rand256()};
42-
BOOST_CHECK(dbw.Write(key, value));
42+
dbw.Write(key, value);
4343
key_values.emplace_back(key, value);
4444
}
4545
}
@@ -86,52 +86,52 @@ BOOST_AUTO_TEST_CASE(dbwrapper_basic_data)
8686
std::string key_block = "b" + m_rng.rand256().ToString();
8787

8888
uint256 in_block = m_rng.rand256();
89-
BOOST_CHECK(dbw.Write(key_block, in_block));
89+
dbw.Write(key_block, in_block);
9090
BOOST_CHECK(dbw.Read(key_block, res));
9191
BOOST_CHECK_EQUAL(res.ToString(), in_block.ToString());
9292

9393
//Simulate file raw data - "f + file_number"
9494
std::string key_file = strprintf("f%04x", m_rng.rand32());
9595

9696
uint256 in_file_info = m_rng.rand256();
97-
BOOST_CHECK(dbw.Write(key_file, in_file_info));
97+
dbw.Write(key_file, in_file_info);
9898
BOOST_CHECK(dbw.Read(key_file, res));
9999
BOOST_CHECK_EQUAL(res.ToString(), in_file_info.ToString());
100100

101101
//Simulate transaction raw data - "t + transaction hash"
102102
std::string key_transaction = "t" + m_rng.rand256().ToString();
103103

104104
uint256 in_transaction = m_rng.rand256();
105-
BOOST_CHECK(dbw.Write(key_transaction, in_transaction));
105+
dbw.Write(key_transaction, in_transaction);
106106
BOOST_CHECK(dbw.Read(key_transaction, res));
107107
BOOST_CHECK_EQUAL(res.ToString(), in_transaction.ToString());
108108

109109
//Simulate UTXO raw data - "c + transaction hash"
110110
std::string key_utxo = "c" + m_rng.rand256().ToString();
111111

112112
uint256 in_utxo = m_rng.rand256();
113-
BOOST_CHECK(dbw.Write(key_utxo, in_utxo));
113+
dbw.Write(key_utxo, in_utxo);
114114
BOOST_CHECK(dbw.Read(key_utxo, res));
115115
BOOST_CHECK_EQUAL(res.ToString(), in_utxo.ToString());
116116

117117
//Simulate last block file number - "l"
118118
uint8_t key_last_blockfile_number{'l'};
119119
uint32_t lastblockfilenumber = m_rng.rand32();
120-
BOOST_CHECK(dbw.Write(key_last_blockfile_number, lastblockfilenumber));
120+
dbw.Write(key_last_blockfile_number, lastblockfilenumber);
121121
BOOST_CHECK(dbw.Read(key_last_blockfile_number, res_uint_32));
122122
BOOST_CHECK_EQUAL(lastblockfilenumber, res_uint_32);
123123

124124
//Simulate Is Reindexing - "R"
125125
uint8_t key_IsReindexing{'R'};
126126
bool isInReindexing = m_rng.randbool();
127-
BOOST_CHECK(dbw.Write(key_IsReindexing, isInReindexing));
127+
dbw.Write(key_IsReindexing, isInReindexing);
128128
BOOST_CHECK(dbw.Read(key_IsReindexing, res_bool));
129129
BOOST_CHECK_EQUAL(isInReindexing, res_bool);
130130

131131
//Simulate last block hash up to which UXTO covers - 'B'
132132
uint8_t key_lastblockhash_uxto{'B'};
133133
uint256 lastblock_hash = m_rng.rand256();
134-
BOOST_CHECK(dbw.Write(key_lastblockhash_uxto, lastblock_hash));
134+
dbw.Write(key_lastblockhash_uxto, lastblock_hash);
135135
BOOST_CHECK(dbw.Read(key_lastblockhash_uxto, res));
136136
BOOST_CHECK_EQUAL(lastblock_hash, res);
137137

@@ -142,7 +142,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_basic_data)
142142
std::string key_file_option = strprintf("%s%01x%s", file_option_tag, filename_length, filename);
143143

144144
bool in_file_bool = m_rng.randbool();
145-
BOOST_CHECK(dbw.Write(key_file_option, in_file_bool));
145+
dbw.Write(key_file_option, in_file_bool);
146146
BOOST_CHECK(dbw.Read(key_file_option, res_bool));
147147
BOOST_CHECK_EQUAL(res_bool, in_file_bool);
148148
}
@@ -195,10 +195,10 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator)
195195
// The two keys are intentionally chosen for ordering
196196
uint8_t key{'j'};
197197
uint256 in = m_rng.rand256();
198-
BOOST_CHECK(dbw.Write(key, in));
198+
dbw.Write(key, in);
199199
uint8_t key2{'k'};
200200
uint256 in2 = m_rng.rand256();
201-
BOOST_CHECK(dbw.Write(key2, in2));
201+
dbw.Write(key2, in2);
202202

203203
std::unique_ptr<CDBIterator> it(const_cast<CDBWrapper&>(dbw).NewIterator());
204204

@@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
238238
uint256 in = m_rng.rand256();
239239
uint256 res;
240240

241-
BOOST_CHECK(dbw->Write(key, in));
241+
dbw->Write(key, in);
242242
BOOST_CHECK(dbw->Read(key, res));
243243
BOOST_CHECK_EQUAL(res.ToString(), in.ToString());
244244

@@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
261261
uint256 res3;
262262

263263
// Check that we can write successfully
264-
BOOST_CHECK(odbw.Write(key, in2));
264+
odbw.Write(key, in2);
265265
BOOST_CHECK(odbw.Read(key, res3));
266266
BOOST_CHECK_EQUAL(res3.ToString(), in2.ToString());
267267
}
@@ -279,7 +279,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex)
279279
uint256 in = m_rng.rand256();
280280
uint256 res;
281281

282-
BOOST_CHECK(dbw->Write(key, in));
282+
dbw->Write(key, in);
283283
BOOST_CHECK(dbw->Read(key, res));
284284
BOOST_CHECK_EQUAL(res.ToString(), in.ToString());
285285

@@ -298,7 +298,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex)
298298
uint256 res3;
299299

300300
// Check that we can write successfully
301-
BOOST_CHECK(odbw.Write(key, in2));
301+
odbw.Write(key, in2);
302302
BOOST_CHECK(odbw.Read(key, res3));
303303
BOOST_CHECK_EQUAL(res3.ToString(), in2.ToString());
304304
}
@@ -310,7 +310,7 @@ BOOST_AUTO_TEST_CASE(iterator_ordering)
310310
for (int x=0x00; x<256; ++x) {
311311
uint8_t key = x;
312312
uint32_t value = x*x;
313-
if (!(x & 1)) BOOST_CHECK(dbw.Write(key, value));
313+
if (!(x & 1)) dbw.Write(key, value);
314314
}
315315

316316
// Check that creating an iterator creates a snapshot
@@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE(iterator_ordering)
319319
for (unsigned int x=0x00; x<256; ++x) {
320320
uint8_t key = x;
321321
uint32_t value = x*x;
322-
if (x & 1) BOOST_CHECK(dbw.Write(key, value));
322+
if (x & 1) dbw.Write(key, value);
323323
}
324324

325325
for (const int seek_start : {0x00, 0x80}) {
@@ -381,7 +381,7 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering)
381381
for (int z = 0; z < y; ++z)
382382
key += key;
383383
uint32_t value = x*x;
384-
BOOST_CHECK(dbw.Write(StringContentsSerializer{key}, value));
384+
dbw.Write(StringContentsSerializer{key}, value);
385385
}
386386
}
387387

0 commit comments

Comments
 (0)