mirror of https://github.com/bitcoin/bitcoin
index: blockfilter, decouple header lookup into its own function
This commit is contained in:
parent
331f044e3b
commit
a6756ecdb2
|
@ -222,6 +222,22 @@ size_t BlockFilterIndex::WriteFilterToDisk(FlatFilePos& pos, const BlockFilter&
|
||||||
return data_size;
|
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)
|
bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
|
||||||
{
|
{
|
||||||
CBlockUndo block_undo;
|
CBlockUndo block_undo;
|
||||||
|
@ -235,19 +251,9 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<uint256, DBVal> read_out;
|
auto op_prev_header = ReadFilterHeader(block.height - 1, *Assert(block.prev_hash));
|
||||||
if (!m_db->Read(DBHeightKey(block.height - 1), read_out)) {
|
if (!op_prev_header) return false;
|
||||||
return false;
|
prev_header = *op_prev_header;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockFilter filter(m_filter_type, *Assert(block.data), block_undo);
|
BlockFilter filter(m_filter_type, *Assert(block.data), block_undo);
|
||||||
|
|
|
@ -46,6 +46,8 @@ private:
|
||||||
|
|
||||||
bool Write(const BlockFilter& filter, uint32_t block_height, const uint256& filter_header);
|
bool Write(const BlockFilter& filter, uint32_t block_height, const uint256& filter_header);
|
||||||
|
|
||||||
|
std::optional<uint256> ReadFilterHeader(int height, const uint256& expected_block_hash);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool CustomInit(const std::optional<interfaces::BlockKey>& block) override;
|
bool CustomInit(const std::optional<interfaces::BlockKey>& block) override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue