@@ -222,6 +222,22 @@ size_t BlockFilterIndex::WriteFilterToDisk(FlatFilePos& pos, const BlockFilter&
222
222
return data_size;
223
223
}
224
224
225
+ std::optional<uint256> BlockFilterIndex::ReadFilterHeader (int height, const uint256& expected_block_hash)
226
+ {
227
+ std::pair<uint256, DBVal> read_out;
228
+ if (!m_db->Read (DBHeightKey (height), read_out)) {
229
+ return std::nullopt;
230
+ }
231
+
232
+ if (read_out.first != expected_block_hash) {
233
+ LogError (" %s: previous block header belongs to unexpected block %s; expected %s\n " ,
234
+ __func__, read_out.first .ToString (), expected_block_hash.ToString ());
235
+ return std::nullopt;
236
+ }
237
+
238
+ return read_out.second .header ;
239
+ }
240
+
225
241
bool BlockFilterIndex::CustomAppend (const interfaces::BlockInfo& block)
226
242
{
227
243
CBlockUndo block_undo;
@@ -235,19 +251,9 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
235
251
return false ;
236
252
}
237
253
238
- std::pair<uint256, DBVal> read_out;
239
- if (!m_db->Read (DBHeightKey (block.height - 1 ), read_out)) {
240
- return false ;
241
- }
242
-
243
- uint256 expected_block_hash = *Assert (block.prev_hash );
244
- if (read_out.first != expected_block_hash) {
245
- LogError (" %s: previous block header belongs to unexpected block %s; expected %s\n " ,
246
- __func__, read_out.first .ToString (), expected_block_hash.ToString ());
247
- return false ;
248
- }
249
-
250
- prev_header = read_out.second .header ;
254
+ auto op_prev_header = ReadFilterHeader (block.height - 1 , *Assert (block.prev_hash ));
255
+ if (!op_prev_header) return false ;
256
+ prev_header = *op_prev_header;
251
257
}
252
258
253
259
BlockFilter filter (m_filter_type, *Assert (block.data ), block_undo);
0 commit comments