Skip to content

Commit

Permalink
db: fix BloomFilter path lifecycle for operator>> (#2751)
Browse files Browse the repository at this point in the history
  • Loading branch information
canepat authored Feb 25, 2025
1 parent 55cd2f6 commit 460516c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions silkworm/db/datastore/snapshots/bloom_filter/bloom_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ BloomFilter::BloomFilter(
if (std::filesystem::file_size(path) == 0) {
throw std::runtime_error("index file " + path.filename().string() + " is empty");
}
std::ifstream file_stream{path, std::ios::in | std::ios::binary};
path_ = std::move(path);
std::ifstream file_stream{path_, std::ios::in | std::ios::binary};
file_stream.exceptions(std::ios::failbit | std::ios::badbit);
file_stream >> *this;

path_ = std::move(path);
data_key_hasher_ = std::move(data_key_hasher);
}

Expand Down Expand Up @@ -216,7 +216,8 @@ std::istream& operator>>(std::istream& is, BloomFilter& filter) {
// Verify that the computed hash checksum does match the expected one
const auto computed_hash = hashing_istream.hash();
if (computed_hash.buffer != sha384_hash.buffer) {
throw std::runtime_error{"hash mismatch: got=" + to_hex(computed_hash.buffer) + " expected=" + to_hex(sha384_hash.buffer)};
throw std::runtime_error{"hash mismatch: got=" + to_hex(computed_hash.buffer) + " expected=" + to_hex(sha384_hash.buffer) +
" in file: " + filter.path().string()};
}

return is;
Expand Down

0 comments on commit 460516c

Please sign in to comment.