diff options
author | Patrick Strateman <patrick.strateman@gmail.com> | 2020-06-14 20:14:34 -0400 |
---|---|---|
committer | Calvin Kim <calvin@kcalvinalvin.info> | 2022-05-02 16:04:00 +0900 |
commit | b0a53d50d9142bed51a8372eeb848816bfa94da8 (patch) | |
tree | daa64fb121e1a4d3993bae387fce7be9398417fc /src/blockfilter.cpp | |
parent | 2b5a741e98f186e50d9fbe1ceadcc8b8c91547f7 (diff) | |
download | bitcoin-b0a53d50d9142bed51a8372eeb848816bfa94da8.tar.xz |
Make sanity check in GCSFilter constructor optional
BlockFilterIndex will perform the cheaper check of verifying the filter
hash when reading the filter from disk.
Diffstat (limited to 'src/blockfilter.cpp')
-rw-r--r-- | src/blockfilter.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/blockfilter.cpp b/src/blockfilter.cpp index 63a9ba498f..1ad6872143 100644 --- a/src/blockfilter.cpp +++ b/src/blockfilter.cpp @@ -47,7 +47,7 @@ GCSFilter::GCSFilter(const Params& params) : m_params(params), m_N(0), m_F(0), m_encoded{0} {} -GCSFilter::GCSFilter(const Params& params, std::vector<unsigned char> encoded_filter) +GCSFilter::GCSFilter(const Params& params, std::vector<unsigned char> encoded_filter, bool skip_decode_check) : m_params(params), m_encoded(std::move(encoded_filter)) { SpanReader stream{GCS_SER_TYPE, GCS_SER_VERSION, m_encoded}; @@ -59,6 +59,8 @@ GCSFilter::GCSFilter(const Params& params, std::vector<unsigned char> encoded_fi } m_F = static_cast<uint64_t>(m_N) * static_cast<uint64_t>(m_params.m_M); + if (skip_decode_check) return; + // Verify that the encoded filter contains exactly N elements. If it has too much or too little // data, a std::ios_base::failure exception will be raised. BitStreamReader<SpanReader> bitreader{stream}; @@ -219,14 +221,14 @@ static GCSFilter::ElementSet BasicFilterElements(const CBlock& block, } BlockFilter::BlockFilter(BlockFilterType filter_type, const uint256& block_hash, - std::vector<unsigned char> filter) + std::vector<unsigned char> filter, bool skip_decode_check) : m_filter_type(filter_type), m_block_hash(block_hash) { GCSFilter::Params params; if (!BuildParams(params)) { throw std::invalid_argument("unknown filter_type"); } - m_filter = GCSFilter(params, std::move(filter)); + m_filter = GCSFilter(params, std::move(filter), skip_decode_check); } BlockFilter::BlockFilter(BlockFilterType filter_type, const CBlock& block, const CBlockUndo& block_undo) |