mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-30 15:54:03 +02:00
Merge bitcoin/bitcoin#23114: Add minisketch subtree and integrate into build/test
29173d6c6cubsan: add minisketch exceptions (Cory Fields)54b5e1aeabAdd thin Minisketch wrapper to pick best implementation (Pieter Wuille)ee9dc71c1bAdd basic minisketch tests (Pieter Wuille)0659f12b13Add minisketch dependency (Gleb Naumenko)0eb7928ab8Add MSVC build configuration for libminisketch (Pieter Wuille)8bc166d5b1build: add minisketch build file and include it (Cory Fields)b2904ceb85build: add configure checks for minisketch (Cory Fields)b6487dc4efSquashed 'src/minisketch/' content from commit 89629eb2c7 (fanquake) Pull request description: This takes over #21859, which has [recently switched](https://github.com/bitcoin/bitcoin/pull/21859#issuecomment-921899200) to my integration branch. A few more build issues came up (and have been fixed) since, and after discussing with sipa it was decided I would open a PR to shepherd any final changes through. > This adds a `src/minisketch` subtree, taken from the master branch of https://github.com/sipa/minisketch, to prepare for Erlay implementation (see #21515). It gets configured for just supporting 32-bit fields (the only ones we're interested in in the context of Erlay), and some code on top is added: > * A very basic unit test (just to make sure compilation & running works; actual correctness checking is done through minisketch's own tests). > * A wrapper in `minisketchwrapper.{cpp,h}` that runs a benchmark to determine which field implementation to use. Only changes since my last update to the branch in the previous PR have been rebasing on master and fixing an issue with a header in an introduced file. ACKs for top commit: naumenkogs: ACK29173d6c6cTree-SHA512: 1217d3228db1dd0de12c2919314e1c3626c18a416cf6291fec99d37e34fb6eec8e28d9e9fb935f8590273b8836cbadac313a15f05b4fd9f9d3024c8ce2c80d02
This commit is contained in:
49
src/test/minisketch_tests.cpp
Normal file
49
src/test/minisketch_tests.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2021 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 <minisketch.h>
|
||||
#include <minisketchwrapper.h>
|
||||
#include <random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(minisketch_tests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(minisketch_test)
|
||||
{
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
uint32_t errors = 0 + InsecureRandRange(11);
|
||||
uint32_t start_a = 1 + InsecureRandRange(1000000000);
|
||||
uint32_t a_not_b = InsecureRandRange(errors + 1);
|
||||
uint32_t b_not_a = errors - a_not_b;
|
||||
uint32_t both = InsecureRandRange(10000);
|
||||
uint32_t end_a = start_a + a_not_b + both;
|
||||
uint32_t start_b = start_a + a_not_b;
|
||||
uint32_t end_b = start_b + both + b_not_a;
|
||||
|
||||
Minisketch sketch_a = MakeMinisketch32(10);
|
||||
for (uint32_t a = start_a; a < end_a; ++a) sketch_a.Add(a);
|
||||
Minisketch sketch_b = MakeMinisketch32(10);
|
||||
for (uint32_t b = start_b; b < end_b; ++b) sketch_b.Add(b);
|
||||
|
||||
Minisketch sketch_ar = MakeMinisketch32(10);
|
||||
Minisketch sketch_br = MakeMinisketch32(10);
|
||||
sketch_ar.Deserialize(sketch_a.Serialize());
|
||||
sketch_br.Deserialize(sketch_b.Serialize());
|
||||
|
||||
Minisketch sketch_c = std::move(sketch_ar);
|
||||
sketch_c.Merge(sketch_br);
|
||||
auto dec = sketch_c.Decode(errors);
|
||||
BOOST_CHECK(dec.has_value());
|
||||
auto sols = std::move(*dec);
|
||||
std::sort(sols.begin(), sols.end());
|
||||
for (uint32_t i = 0; i < a_not_b; ++i) BOOST_CHECK_EQUAL(sols[i], start_a + i);
|
||||
for (uint32_t i = 0; i < b_not_a; ++i) BOOST_CHECK_EQUAL(sols[i + a_not_b], start_b + both + i);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
Reference in New Issue
Block a user