aboutsummaryrefslogtreecommitdiff
path: root/src/index/blockfilterindex.cpp
diff options
context:
space:
mode:
authorMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2024-01-11 18:47:54 +0100
committerMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2024-03-11 13:49:25 +0100
commitfa1d62434843866d242bff9f9c55cb838a4f0d83 (patch)
tree4e3700eee74471773d83528593a6c0a68525544a /src/index/blockfilterindex.cpp
parentfa9a5e80ab86c997102a1c3d4ba017bbe86641d5 (diff)
downloadbitcoin-fa1d62434843866d242bff9f9c55cb838a4f0d83.tar.xz
scripted-diff: return error(...); ==> error(...); return false;
This is needed for the next commit. -BEGIN VERIFY SCRIPT- # Separate sed invocations to replace one-line, and two-line error(...) calls sed -i --regexp-extended 's!( +)return (error\(.*\);)!\1\2\n\1return false;!g' $( git grep -l 'return error(' ) sed -i --null-data --regexp-extended 's!( +)return (error\([^\n]*\n[^\n]*\);)!\1\2\n\1return false;!g' $( git grep -l 'return error(' ) -END VERIFY SCRIPT-
Diffstat (limited to 'src/index/blockfilterindex.cpp')
-rw-r--r--src/index/blockfilterindex.cpp36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp
index 226d9a178e..de6bd833c3 100644
--- a/src/index/blockfilterindex.cpp
+++ b/src/index/blockfilterindex.cpp
@@ -119,8 +119,9 @@ bool BlockFilterIndex::CustomInit(const std::optional<interfaces::BlockKey>& blo
// indicate database corruption or a disk failure, and starting the index would cause
// further corruption.
if (m_db->Exists(DB_FILTER_POS)) {
- return error("%s: Cannot read current %s state; index may be corrupted",
+ error("%s: Cannot read current %s state; index may be corrupted",
__func__, GetName());
+ return false;
}
// If the DB_FILTER_POS is not set, then initialize to the first location.
@@ -137,10 +138,12 @@ bool BlockFilterIndex::CustomCommit(CDBBatch& batch)
// Flush current filter file to disk.
AutoFile file{m_filter_fileseq->Open(pos)};
if (file.IsNull()) {
- return error("%s: Failed to open filter file %d", __func__, pos.nFile);
+ error("%s: Failed to open filter file %d", __func__, pos.nFile);
+ return false;
}
if (!FileCommit(file.Get())) {
- return error("%s: Failed to commit filter file %d", __func__, pos.nFile);
+ error("%s: Failed to commit filter file %d", __func__, pos.nFile);
+ return false;
}
batch.Write(DB_FILTER_POS, pos);
@@ -160,12 +163,14 @@ bool BlockFilterIndex::ReadFilterFromDisk(const FlatFilePos& pos, const uint256&
try {
filein >> block_hash >> encoded_filter;
if (Hash(encoded_filter) != hash) {
- return error("Checksum mismatch in filter decode.");
+ error("Checksum mismatch in filter decode.");
+ return false;
}
filter = BlockFilter(GetFilterType(), block_hash, std::move(encoded_filter), /*skip_decode_check=*/true);
}
catch (const std::exception& e) {
- return error("%s: Failed to deserialize block filter from disk: %s", __func__, e.what());
+ error("%s: Failed to deserialize block filter from disk: %s", __func__, e.what());
+ return false;
}
return true;
@@ -237,8 +242,9 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
uint256 expected_block_hash = *Assert(block.prev_hash);
if (read_out.first != expected_block_hash) {
- return error("%s: previous block header belongs to unexpected block %s; expected %s",
+ error("%s: previous block header belongs to unexpected block %s; expected %s",
__func__, read_out.first.ToString(), expected_block_hash.ToString());
+ return false;
}
prev_header = read_out.second.header;
@@ -272,14 +278,16 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
for (int height = start_height; height <= stop_height; ++height) {
if (!db_it.GetKey(key) || key.height != height) {
- return error("%s: unexpected key in %s: expected (%c, %d)",
+ error("%s: unexpected key in %s: expected (%c, %d)",
__func__, index_name, DB_BLOCK_HEIGHT, height);
+ return false;
}
std::pair<uint256, DBVal> value;
if (!db_it.GetValue(value)) {
- return error("%s: unable to read value in %s at key (%c, %d)",
+ error("%s: unable to read value in %s at key (%c, %d)",
__func__, index_name, DB_BLOCK_HEIGHT, height);
+ return false;
}
batch.Write(DBHashKey(value.first), std::move(value.second));
@@ -332,11 +340,13 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start
const CBlockIndex* stop_index, std::vector<DBVal>& results)
{
if (start_height < 0) {
- return error("%s: start height (%d) is negative", __func__, start_height);
+ error("%s: start height (%d) is negative", __func__, start_height);
+ return false;
}
if (start_height > stop_index->nHeight) {
- return error("%s: start height (%d) is greater than stop height (%d)",
+ error("%s: start height (%d) is greater than stop height (%d)",
__func__, start_height, stop_index->nHeight);
+ return false;
}
size_t results_size = static_cast<size_t>(stop_index->nHeight - start_height + 1);
@@ -352,8 +362,9 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start
size_t i = static_cast<size_t>(height - start_height);
if (!db_it->GetValue(values[i])) {
- return error("%s: unable to read value in %s at key (%c, %d)",
+ error("%s: unable to read value in %s at key (%c, %d)",
__func__, index_name, DB_BLOCK_HEIGHT, height);
+ return false;
}
db_it->Next();
@@ -375,8 +386,9 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start
}
if (!db.Read(DBHashKey(block_hash), results[i])) {
- return error("%s: unable to read value in %s at key (%c, %s)",
+ error("%s: unable to read value in %s at key (%c, %s)",
__func__, index_name, DB_BLOCK_HASH, block_hash.ToString());
+ return false;
}
}