aboutsummaryrefslogtreecommitdiff
path: root/src/index/blockfilterindex.cpp
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2023-01-30 17:51:16 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2024-03-12 09:31:39 -0300
commita6756ecdb2f1ac960433412807aa377d1ee80d05 (patch)
tree2a10852adace9ccd793e4d5beaa166303a75e484 /src/index/blockfilterindex.cpp
parent331f044e3b49223cedd16803d123c0da9d91d6a2 (diff)
downloadbitcoin-a6756ecdb2f1ac960433412807aa377d1ee80d05.tar.xz
index: blockfilter, decouple header lookup into its own function
Diffstat (limited to 'src/index/blockfilterindex.cpp')
-rw-r--r--src/index/blockfilterindex.cpp32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp
index 1085b4da77..204e5d7e18 100644
--- a/src/index/blockfilterindex.cpp
+++ b/src/index/blockfilterindex.cpp
@@ -222,6 +222,22 @@ size_t BlockFilterIndex::WriteFilterToDisk(FlatFilePos& pos, const BlockFilter&
return data_size;
}
+std::optional<uint256> BlockFilterIndex::ReadFilterHeader(int height, const uint256& expected_block_hash)
+{
+ std::pair<uint256, DBVal> read_out;
+ if (!m_db->Read(DBHeightKey(height), read_out)) {
+ return std::nullopt;
+ }
+
+ if (read_out.first != expected_block_hash) {
+ LogError("%s: previous block header belongs to unexpected block %s; expected %s\n",
+ __func__, read_out.first.ToString(), expected_block_hash.ToString());
+ return std::nullopt;
+ }
+
+ return read_out.second.header;
+}
+
bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
{
CBlockUndo block_undo;
@@ -235,19 +251,9 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
return false;
}
- std::pair<uint256, DBVal> read_out;
- if (!m_db->Read(DBHeightKey(block.height - 1), read_out)) {
- return false;
- }
-
- uint256 expected_block_hash = *Assert(block.prev_hash);
- if (read_out.first != expected_block_hash) {
- LogError("%s: previous block header belongs to unexpected block %s; expected %s\n",
- __func__, read_out.first.ToString(), expected_block_hash.ToString());
- return false;
- }
-
- prev_header = read_out.second.header;
+ auto op_prev_header = ReadFilterHeader(block.height - 1, *Assert(block.prev_hash));
+ if (!op_prev_header) return false;
+ prev_header = *op_prev_header;
}
BlockFilter filter(m_filter_type, *Assert(block.data), block_undo);