| 158 | } |
| 159 | |
| 160 | bool BlockFilterIndex::ReadFilterFromDisk(const FlatFilePos& pos, const uint256& hash, BlockFilter& filter) const |
| 161 | { |
| 162 | AutoFile filein{m_filter_fileseq->Open(pos, true)}; |
| 163 | if (filein.IsNull()) { |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | // Check that the hash of the encoded_filter matches the one stored in the db. |
| 168 | uint256 block_hash; |
| 169 | std::vector<uint8_t> encoded_filter; |
| 170 | try { |
| 171 | filein >> block_hash >> encoded_filter; |
| 172 | if (Hash(encoded_filter) != hash) { |
| 173 | LogError("Checksum mismatch in filter decode."); |
| 174 | return false; |
| 175 | } |
| 176 | filter = BlockFilter(GetFilterType(), block_hash, std::move(encoded_filter), /*skip_decode_check=*/true); |
| 177 | } |
| 178 | catch (const std::exception& e) { |
| 179 | LogError("Failed to deserialize block filter from disk: %s", e.what()); |
| 180 | return false; |
| 181 | } |
| 182 | |
| 183 | return true; |
| 184 | } |
| 185 | |
| 186 | size_t BlockFilterIndex::WriteFilterToDisk(FlatFilePos& pos, const BlockFilter& filter) |
| 187 | { |
nothing calls this directly
no test coverage detected