diff --git a/src/Makefile.am b/src/Makefile.am index 8ad15f646e217..e772d80a51283 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -122,6 +122,7 @@ BITCOIN_CORE_H = \ bloom.h \ cachemap.h \ cachemultimap.h \ + blockfilter.h \ chain.h \ chainparams.h \ chainparamsbase.h \ @@ -281,6 +282,7 @@ libdash_server_a_SOURCES = \ batchedlogger.cpp \ bloom.cpp \ blockencodings.cpp \ + blockfilter.cpp \ chain.cpp \ checkpoints.cpp \ consensus/tx_verify.cpp \ diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include index b5ae95a3bb386..f722769792cd9 100644 --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -27,6 +27,7 @@ bench_bench_dash_SOURCES = \ bench/chacha_poly_aead.cpp \ bench/crypto_hash.cpp \ bench/ccoins_caching.cpp \ + bench/gcs_filter.cpp \ bench/merkle_root.cpp \ bench/mempool_eviction.cpp \ bench/util_time.cpp \ diff --git a/src/Makefile.test.include b/src/Makefile.test.include index ea19019e369c6..ed06a153e00bc 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -10,6 +10,7 @@ TEST_SRCDIR = test TEST_BINARY=test/test_dash$(EXEEXT) JSON_TEST_FILES = \ + test/data/blockfilters.json \ test/data/script_tests.json \ test/data/base58_keys_valid.json \ test/data/base58_encode_decode.json \ @@ -39,6 +40,7 @@ BITCOIN_TESTS =\ test/bip39_tests.cpp \ test/blockchain_tests.cpp \ test/blockencodings_tests.cpp \ + test/blockfilter_tests.cpp \ test/bloom_tests.cpp \ test/bls_tests.cpp \ test/bswap_tests.cpp \ diff --git a/src/bench/gcs_filter.cpp b/src/bench/gcs_filter.cpp new file mode 100644 index 0000000000000..f328b69ca39a4 --- /dev/null +++ b/src/bench/gcs_filter.cpp @@ -0,0 +1,43 @@ +// Copyright (c) 2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include + +static void ConstructGCSFilter(benchmark::State& state) +{ + GCSFilter::ElementSet elements; + for (int i = 0; i < 10000; ++i) { + GCSFilter::Element element(32); + element[0] = static_cast(i); + element[1] = static_cast(i >> 8); + elements.insert(std::move(element)); + } + + uint64_t siphash_k0 = 0; + while (state.KeepRunning()) { + GCSFilter filter(siphash_k0, 0, 20, 1 << 20, elements); + + siphash_k0++; + } +} + +static void MatchGCSFilter(benchmark::State& state) +{ + GCSFilter::ElementSet elements; + for (int i = 0; i < 10000; ++i) { + GCSFilter::Element element(32); + element[0] = static_cast(i); + element[1] = static_cast(i >> 8); + elements.insert(std::move(element)); + } + GCSFilter filter(0, 0, 20, 1 << 20, elements); + + while (state.KeepRunning()) { + filter.Match(GCSFilter::Element()); + } +} + +BENCHMARK(ConstructGCSFilter/*, 1000*/); +BENCHMARK(MatchGCSFilter/*, 50 * 1000*/); diff --git a/src/blockfilter.cpp b/src/blockfilter.cpp new file mode 100644 index 0000000000000..7ada6b025b92e --- /dev/null +++ b/src/blockfilter.cpp @@ -0,0 +1,261 @@ +// Copyright (c) 2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include +#include