Branch data Line data Source code
1 : : // Copyright (c) 2012-2022 The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : #include <common/bloom.h>
6 : :
7 : : #include <clientversion.h>
8 : : #include <common/system.h>
9 : : #include <key.h>
10 : : #include <key_io.h>
11 : : #include <merkleblock.h>
12 : : #include <primitives/block.h>
13 : : #include <random.h>
14 : : #include <serialize.h>
15 : : #include <streams.h>
16 : : #include <test/util/random.h>
17 : : #include <test/util/setup_common.h>
18 : : #include <uint256.h>
19 : : #include <util/strencodings.h>
20 : :
21 : : #include <vector>
22 : :
23 : : #include <boost/test/unit_test.hpp>
24 : :
25 : : using namespace util::hex_literals;
26 : :
27 : : namespace bloom_tests {
28 : 24 : struct BloomTest : public BasicTestingSetup {
29 : : std::vector<unsigned char> RandomData();
30 : : };
31 : : } // namespace bloom_tests
32 : :
33 : : BOOST_FIXTURE_TEST_SUITE(bloom_tests, BloomTest)
34 : :
35 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
36 : : {
37 : 1 : CBloomFilter filter(3, 0.01, 0, BLOOM_UPDATE_ALL);
38 : :
39 [ + - + - : 1 : BOOST_CHECK_MESSAGE( !filter.contains("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter should be empty!");
+ - ]
40 [ + - ]: 1 : filter.insert("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8);
41 [ + - + - : 2 : BOOST_CHECK_MESSAGE( filter.contains("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter doesn't contain just-inserted object!");
+ - + - ]
42 : : // One bit different in first byte
43 [ + - + - : 2 : BOOST_CHECK_MESSAGE(!filter.contains("19108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter contains something it shouldn't!");
+ - + - ]
44 : :
45 [ + - ]: 1 : filter.insert("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"_hex_u8);
46 [ + - + - : 2 : BOOST_CHECK_MESSAGE(filter.contains("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"_hex_u8), "Bloom filter doesn't contain just-inserted object (2)!");
+ - + - ]
47 : :
48 [ + - ]: 1 : filter.insert("b9300670b4c5366e95b2699e8b18bc75e5f729c5"_hex_u8);
49 [ + - + - : 2 : BOOST_CHECK_MESSAGE(filter.contains("b9300670b4c5366e95b2699e8b18bc75e5f729c5"_hex_u8), "Bloom filter doesn't contain just-inserted object (3)!");
+ - + - ]
50 : :
51 : 1 : DataStream stream{};
52 [ + - ]: 1 : stream << filter;
53 : :
54 : 1 : constexpr auto expected{"03614e9b050000000000000001"_hex};
55 [ + - + - : 2 : BOOST_CHECK_EQUAL_COLLECTIONS(stream.begin(), stream.end(), expected.begin(), expected.end());
+ - + - ]
56 : :
57 [ + - + - : 2 : BOOST_CHECK_MESSAGE( filter.contains("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter doesn't contain just-inserted object!");
+ - ]
58 : 1 : }
59 : :
60 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize_with_tweak)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
61 : : {
62 : : // Same test as bloom_create_insert_serialize, but we add a nTweak of 100
63 : 1 : CBloomFilter filter(3, 0.01, 2147483649UL, BLOOM_UPDATE_ALL);
64 : :
65 [ + - ]: 1 : filter.insert("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8);
66 [ + - + - : 2 : BOOST_CHECK_MESSAGE( filter.contains("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter doesn't contain just-inserted object!");
+ - + - ]
67 : : // One bit different in first byte
68 [ + - + - : 2 : BOOST_CHECK_MESSAGE(!filter.contains("19108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter contains something it shouldn't!");
+ - + - ]
69 : :
70 [ + - ]: 1 : filter.insert("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"_hex_u8);
71 [ + - + - : 2 : BOOST_CHECK_MESSAGE(filter.contains("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"_hex_u8), "Bloom filter doesn't contain just-inserted object (2)!");
+ - + - ]
72 : :
73 [ + - ]: 1 : filter.insert("b9300670b4c5366e95b2699e8b18bc75e5f729c5"_hex_u8);
74 [ + - + - : 2 : BOOST_CHECK_MESSAGE(filter.contains("b9300670b4c5366e95b2699e8b18bc75e5f729c5"_hex_u8), "Bloom filter doesn't contain just-inserted object (3)!");
+ - + - ]
75 : :
76 : 1 : DataStream stream{};
77 [ + - ]: 1 : stream << filter;
78 : :
79 : 1 : constexpr auto expected{"03ce4299050000000100008001"_hex};
80 [ + - + - : 2 : BOOST_CHECK_EQUAL_COLLECTIONS(stream.begin(), stream.end(), expected.begin(), expected.end());
+ - ]
81 : 1 : }
82 : :
83 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(bloom_create_insert_key)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
84 : : {
85 : 1 : std::string strSecret = std::string("5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C");
86 [ + - ]: 1 : CKey key = DecodeSecret(strSecret);
87 [ + - ]: 1 : CPubKey pubkey = key.GetPubKey();
88 [ + - ]: 1 : std::vector<unsigned char> vchPubKey(pubkey.begin(), pubkey.end());
89 : :
90 [ + - ]: 1 : CBloomFilter filter(2, 0.001, 0, BLOOM_UPDATE_ALL);
91 [ + - ]: 1 : filter.insert(vchPubKey);
92 [ + - ]: 1 : uint160 hash = pubkey.GetID();
93 [ + - ]: 1 : filter.insert(hash);
94 : :
95 : 1 : DataStream stream{};
96 [ + - ]: 1 : stream << filter;
97 : :
98 : 1 : constexpr auto expected{"038fc16b080000000000000001"_hex};
99 [ + - + - : 2 : BOOST_CHECK_EQUAL_COLLECTIONS(stream.begin(), stream.end(), expected.begin(), expected.end());
+ - ]
100 : 1 : }
101 : :
102 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(bloom_match)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
103 : : {
104 : : // Random real transaction (b4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b)
105 : 1 : DataStream stream{
106 : 1 : "01000000010b26e9b7735eb6aabdf358bab62f9816a21ba9ebdb719d5299e88607d722c190000000008b4830450220070aca44506c5cef3a16ed519d7c3c39f8aab192c4e1c90d065f37b8a4af6141022100a8e160b856c2d43d27d8fba71e5aef6405b8643ac4cb7cb3c462aced7f14711a0141046d11fee51b0e60666d5049a9101a72741df480b96ee26488a4d3466b95c9a40ac5eeef87e10a5cd336c19a84565f80fa6c547957b7700ff4dfbdefe76036c339ffffffff021bff3d11000000001976a91404943fdd508053c75000106d3bc6e2754dbcff1988ac2f15de00000000001976a914a266436d2965547608b9e15d9032a7b9d64fa43188ac00000000"_hex,
107 : 1 : };
108 [ + - ]: 1 : CTransaction tx(deserialize, TX_WITH_WITNESS, stream);
109 : :
110 : : // and one which spends it (e2769b09e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436)
111 : 1 : unsigned char ch[] = {0x01, 0x00, 0x00, 0x00, 0x01, 0x6b, 0xff, 0x7f, 0xcd, 0x4f, 0x85, 0x65, 0xef, 0x40, 0x6d, 0xd5, 0xd6, 0x3d, 0x4f, 0xf9, 0x4f, 0x31, 0x8f, 0xe8, 0x20, 0x27, 0xfd, 0x4d, 0xc4, 0x51, 0xb0, 0x44, 0x74, 0x01, 0x9f, 0x74, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x49, 0x30, 0x46, 0x02, 0x21, 0x00, 0xda, 0x0d, 0xc6, 0xae, 0xce, 0xfe, 0x1e, 0x06, 0xef, 0xdf, 0x05, 0x77, 0x37, 0x57, 0xde, 0xb1, 0x68, 0x82, 0x09, 0x30, 0xe3, 0xb0, 0xd0, 0x3f, 0x46, 0xf5, 0xfc, 0xf1, 0x50, 0xbf, 0x99, 0x0c, 0x02, 0x21, 0x00, 0xd2, 0x5b, 0x5c, 0x87, 0x04, 0x00, 0x76, 0xe4, 0xf2, 0x53, 0xf8, 0x26, 0x2e, 0x76, 0x3e, 0x2d, 0xd5, 0x1e, 0x7f, 0xf0, 0xbe, 0x15, 0x77, 0x27, 0xc4, 0xbc, 0x42, 0x80, 0x7f, 0x17, 0xbd, 0x39, 0x01, 0x41, 0x04, 0xe6, 0xc2, 0x6e, 0xf6, 0x7d, 0xc6, 0x10, 0xd2, 0xcd, 0x19, 0x24, 0x84, 0x78, 0x9a, 0x6c, 0xf9, 0xae, 0xa9, 0x93, 0x0b, 0x94, 0x4b, 0x7e, 0x2d, 0xb5, 0x34, 0x2b, 0x9d, 0x9e, 0x5b, 0x9f, 0xf7, 0x9a, 0xff, 0x9a, 0x2e, 0xe1, 0x97, 0x8d, 0xd7, 0xfd, 0x01, 0xdf, 0xc5, 0x22, 0xee, 0x02, 0x28, 0x3d, 0x3b, 0x06, 0xa9, 0xd0, 0x3a, 0xcf, 0x80, 0x96, 0x96, 0x8d, 0x7d, 0xbb, 0x0f, 0x91, 0x78, 0xff, 0xff, 0xff, 0xff, 0x02, 0x8b, 0xa7, 0x94, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xba, 0xde, 0xec, 0xfd, 0xef, 0x05, 0x07, 0x24, 0x7f, 0xc8, 0xf7, 0x42, 0x41, 0xd7, 0x3b, 0xc0, 0x39, 0x97, 0x2d, 0x7b, 0x88, 0xac, 0x40, 0x94, 0xa8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xc1, 0x09, 0x32, 0x48, 0x3f, 0xec, 0x93, 0xed, 0x51, 0xf5, 0xfe, 0x95, 0xe7, 0x25, 0x59, 0xf2, 0xcc, 0x70, 0x43, 0xf9, 0x88, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00};
112 [ + - ]: 1 : std::vector<unsigned char> vch(ch, ch + sizeof(ch) -1);
113 [ + - ]: 1 : DataStream spendStream{vch};
114 [ + - ]: 1 : CTransaction spendingTx(deserialize, TX_WITH_WITNESS, spendStream);
115 : :
116 [ + - ]: 1 : CBloomFilter filter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
117 [ + - ]: 1 : filter.insert(uint256{"b4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b"});
118 [ + - + - : 2 : BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match tx hash");
+ - + - ]
119 : :
120 [ + - ]: 1 : filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
121 : : // byte-reversed tx hash
122 [ + - ]: 1 : filter.insert("6bff7fcd4f8565ef406dd5d63d4ff94f318fe82027fd4dc451b04474019f74b4"_hex_u8);
123 [ + - + - : 2 : BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match manually serialized tx hash");
+ - + - ]
124 : :
125 [ + - ]: 1 : filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
126 [ + - ]: 1 : filter.insert("30450220070aca44506c5cef3a16ed519d7c3c39f8aab192c4e1c90d065f37b8a4af6141022100a8e160b856c2d43d27d8fba71e5aef6405b8643ac4cb7cb3c462aced7f14711a01"_hex_u8);
127 [ + - + - : 2 : BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match input signature");
+ - + - ]
128 : :
129 [ + - ]: 1 : filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
130 [ + - ]: 1 : filter.insert("046d11fee51b0e60666d5049a9101a72741df480b96ee26488a4d3466b95c9a40ac5eeef87e10a5cd336c19a84565f80fa6c547957b7700ff4dfbdefe76036c339"_hex_u8);
131 [ + - + - : 2 : BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match input pub key");
+ - + - ]
132 : :
133 [ + - ]: 1 : filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
134 [ + - ]: 1 : filter.insert("04943fdd508053c75000106d3bc6e2754dbcff19"_hex_u8);
135 [ + - + - : 2 : BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match output address");
+ - + - ]
136 [ + - + - : 2 : BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(spendingTx), "Simple Bloom filter didn't add output");
+ - + - ]
137 : :
138 [ + - ]: 1 : filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
139 [ + - ]: 1 : filter.insert("a266436d2965547608b9e15d9032a7b9d64fa431"_hex_u8);
140 [ + - + - : 2 : BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match output address");
+ - + - ]
141 : :
142 [ + - ]: 1 : filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
143 [ + - + - ]: 2 : filter.insert(COutPoint(Txid::FromHex("90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b").value(), 0));
144 [ + - + - : 2 : BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match COutPoint");
+ - + - ]
145 : :
146 [ + - ]: 1 : filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
147 [ + - + - ]: 2 : COutPoint prevOutPoint(Txid::FromHex("90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b").value(), 0);
148 : 1 : {
149 [ + - ]: 1 : std::vector<unsigned char> data(32 + sizeof(unsigned int));
150 [ + - ]: 1 : memcpy(data.data(), prevOutPoint.hash.begin(), 32);
151 : 1 : memcpy(data.data()+32, &prevOutPoint.n, sizeof(unsigned int));
152 [ + - ]: 1 : filter.insert(data);
153 : 0 : }
154 [ + - + - : 2 : BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match manually serialized COutPoint");
+ - + - ]
155 : :
156 [ + - ]: 1 : filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
157 [ + - ]: 1 : filter.insert(uint256{"00000009e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436"});
158 [ + - + - : 2 : BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched random tx hash");
+ - + - ]
159 : :
160 [ + - ]: 1 : filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
161 [ + - ]: 1 : filter.insert("0000006d2965547608b9e15d9032a7b9d64fa431"_hex_u8);
162 [ + - + - : 2 : BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched random address");
+ - + - ]
163 : :
164 [ + - ]: 1 : filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
165 [ + - + - ]: 2 : filter.insert(COutPoint(Txid::FromHex("90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b").value(), 1));
166 [ + - + - : 2 : BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched COutPoint for an output we didn't care about");
+ - + - ]
167 : :
168 [ + - ]: 1 : filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
169 [ + - + - ]: 2 : filter.insert(COutPoint(Txid::FromHex("000000d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b").value(), 0));
170 [ + - + - : 2 : BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched COutPoint for an output we didn't care about");
+ - ]
171 : 3 : }
172 : :
173 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(merkle_block_1)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
174 : : {
175 : 1 : CBlock block = getBlock13b8a();
176 [ + - ]: 1 : CBloomFilter filter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
177 : : // Match the last transaction
178 [ + - ]: 1 : filter.insert(uint256{"74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"});
179 : :
180 [ + - ]: 1 : CMerkleBlock merkleBlock(block, filter);
181 [ + - + - : 1 : BOOST_CHECK_EQUAL(merkleBlock.header.GetHash().GetHex(), block.GetHash().GetHex());
+ - + - +
- + - ]
182 : :
183 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(merkleBlock.vMatchedTxn.size(), 1U);
184 [ + - ]: 1 : std::pair<unsigned int, uint256> pair = merkleBlock.vMatchedTxn[0];
185 : :
186 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256{"74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"});
+ - ]
187 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 8);
+ - ]
188 : :
189 : 1 : std::vector<uint256> vMatched;
190 : 1 : std::vector<unsigned int> vIndex;
191 [ + - + - : 2 : BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
+ - + - ]
192 [ + - + - ]: 2 : BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
193 [ + + ]: 2 : for (unsigned int i = 0; i < vMatched.size(); i++)
194 [ + - + - ]: 2 : BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second);
195 : :
196 : : // Also match the 8th transaction
197 [ + - ]: 1 : filter.insert(uint256{"dd1fd2a6fc16404faf339881a90adbde7f4f728691ac62e8f168809cdfae1053"});
198 [ + - ]: 1 : merkleBlock = CMerkleBlock(block, filter);
199 [ + - + - : 2 : BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
+ - + - +
- ]
200 : :
201 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 2);
+ - ]
202 : :
203 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[1] == pair);
+ - ]
204 : :
205 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256{"dd1fd2a6fc16404faf339881a90adbde7f4f728691ac62e8f168809cdfae1053"});
+ - ]
206 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 7);
+ - ]
207 : :
208 [ + - + - : 2 : BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
+ - + - ]
209 [ + - + - ]: 2 : BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
210 [ + + ]: 3 : for (unsigned int i = 0; i < vMatched.size(); i++)
211 [ + - + - ]: 4 : BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second);
212 : 1 : }
213 : :
214 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(merkle_block_2)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
215 : : {
216 : : // Random real block (000000005a4ded781e667e06ceefafb71410b511fe0d5adc3e5a27ecbec34ae6)
217 : : // With 4 txes
218 : 1 : CBlock block;
219 : 1 : DataStream stream{
220 [ + - ]: 1 : "0100000075616236cc2126035fadb38deb65b9102cc2c41c09cdf29fc051906800000000fe7d5e12ef0ff901f6050211249919b1c0653771832b3a80c66cea42847f0ae1d4d26e49ffff001d00f0a4410401000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d029105ffffffff0100f2052a010000004341046d8709a041d34357697dfcb30a9d05900a6294078012bf3bb09c6f9b525f1d16d5503d7905db1ada9501446ea00728668fc5719aa80be2fdfc8a858a4dbdd4fbac00000000010000000255605dc6f5c3dc148b6da58442b0b2cd422be385eab2ebea4119ee9c268d28350000000049483045022100aa46504baa86df8a33b1192b1b9367b4d729dc41e389f2c04f3e5c7f0559aae702205e82253a54bf5c4f65b7428551554b2045167d6d206dfe6a2e198127d3f7df1501ffffffff55605dc6f5c3dc148b6da58442b0b2cd422be385eab2ebea4119ee9c268d2835010000004847304402202329484c35fa9d6bb32a55a70c0982f606ce0e3634b69006138683bcd12cbb6602200c28feb1e2555c3210f1dddb299738b4ff8bbe9667b68cb8764b5ac17b7adf0001ffffffff0200e1f505000000004341046a0765b5865641ce08dd39690aade26dfbf5511430ca428a3089261361cef170e3929a68aee3d8d4848b0c5111b0a37b82b86ad559fd2a745b44d8e8d9dfdc0cac00180d8f000000004341044a656f065871a353f216ca26cef8dde2f03e8c16202d2e8ad769f02032cb86a5eb5e56842e92e19141d60a01928f8dd2c875a390f67c1f6c94cfc617c0ea45afac0000000001000000025f9a06d3acdceb56be1bfeaa3e8a25e62d182fa24fefe899d1c17f1dad4c2028000000004847304402205d6058484157235b06028c30736c15613a28bdb768ee628094ca8b0030d4d6eb0220328789c9a2ec27ddaec0ad5ef58efded42e6ea17c2e1ce838f3d6913f5e95db601ffffffff5f9a06d3acdceb56be1bfeaa3e8a25e62d182fa24fefe899d1c17f1dad4c2028010000004a493046022100c45af050d3cea806cedd0ab22520c53ebe63b987b8954146cdca42487b84bdd6022100b9b027716a6b59e640da50a864d6dd8a0ef24c76ce62391fa3eabaf4d2886d2d01ffffffff0200e1f505000000004341046a0765b5865641ce08dd39690aade26dfbf5511430ca428a3089261361cef170e3929a68aee3d8d4848b0c5111b0a37b82b86ad559fd2a745b44d8e8d9dfdc0cac00180d8f000000004341046a0765b5865641ce08dd39690aade26dfbf5511430ca428a3089261361cef170e3929a68aee3d8d4848b0c5111b0a37b82b86ad559fd2a745b44d8e8d9dfdc0cac000000000100000002e2274e5fea1bf29d963914bd301aa63b64daaf8a3e88f119b5046ca5738a0f6b0000000048473044022016e7a727a061ea2254a6c358376aaa617ac537eb836c77d646ebda4c748aac8b0220192ce28bf9f2c06a6467e6531e27648d2b3e2e2bae85159c9242939840295ba501ffffffffe2274e5fea1bf29d963914bd301aa63b64daaf8a3e88f119b5046ca5738a0f6b010000004a493046022100b7a1a755588d4190118936e15cd217d133b0e4a53c3c15924010d5648d8925c9022100aaef031874db2114f2d869ac2de4ae53908fbfea5b2b1862e181626bb9005c9f01ffffffff0200e1f505000000004341044a656f065871a353f216ca26cef8dde2f03e8c16202d2e8ad769f02032cb86a5eb5e56842e92e19141d60a01928f8dd2c875a390f67c1f6c94cfc617c0ea45afac00180d8f000000004341046a0765b5865641ce08dd39690aade26dfbf5511430ca428a3089261361cef170e3929a68aee3d8d4848b0c5111b0a37b82b86ad559fd2a745b44d8e8d9dfdc0cac00000000"_hex,
221 [ + - ]: 1 : };
222 [ + - ]: 1 : stream >> TX_WITH_WITNESS(block);
223 : :
224 [ + - ]: 1 : CBloomFilter filter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
225 : : // Match the first transaction
226 [ + - ]: 1 : filter.insert(uint256{"e980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df5b47aecb93b70"});
227 : :
228 [ + - ]: 1 : CMerkleBlock merkleBlock(block, filter);
229 [ + - + - : 2 : BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
+ - + - +
- ]
230 : :
231 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1);
+ - ]
232 [ + - ]: 1 : std::pair<unsigned int, uint256> pair = merkleBlock.vMatchedTxn[0];
233 : :
234 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256{"e980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df5b47aecb93b70"});
+ - ]
235 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 0);
+ - ]
236 : :
237 : 1 : std::vector<uint256> vMatched;
238 : 1 : std::vector<unsigned int> vIndex;
239 [ + - + - : 2 : BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
+ - + - ]
240 [ + - + - ]: 2 : BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
241 [ + + ]: 2 : for (unsigned int i = 0; i < vMatched.size(); i++)
242 [ + - + - ]: 2 : BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second);
243 : :
244 : : // Match an output from the second transaction (the pubkey for address 1DZTzaBHUDM7T3QvUKBz4qXMRpkg8jsfB5)
245 : : // This should match the third transaction because it spends the output matched
246 : : // It also matches the fourth transaction, which spends to the pubkey again
247 [ + - ]: 1 : filter.insert("044a656f065871a353f216ca26cef8dde2f03e8c16202d2e8ad769f02032cb86a5eb5e56842e92e19141d60a01928f8dd2c875a390f67c1f6c94cfc617c0ea45af"_hex_u8);
248 : :
249 [ + - ]: 1 : merkleBlock = CMerkleBlock(block, filter);
250 [ + - + - : 2 : BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
+ - + - +
- ]
251 : :
252 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 4);
+ - ]
253 : :
254 [ + - + - : 2 : BOOST_CHECK(pair == merkleBlock.vMatchedTxn[0]);
+ - ]
255 : :
256 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[1].second == uint256{"28204cad1d7fc1d199e8ef4fa22f182de6258a3eaafe1bbe56ebdcacd3069a5f"});
+ - ]
257 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[1].first == 1);
+ - ]
258 : :
259 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[2].second == uint256{"6b0f8a73a56c04b519f1883e8aafda643ba61a30bd1439969df21bea5f4e27e2"});
+ - ]
260 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[2].first == 2);
+ - ]
261 : :
262 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[3].second == uint256{"3c1d7e82342158e4109df2e0b6348b6e84e403d8b4046d7007663ace63cddb23"});
+ - ]
263 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[3].first == 3);
+ - ]
264 : :
265 [ + - + - : 2 : BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
+ - + - ]
266 [ + - + - ]: 2 : BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
267 [ + + ]: 5 : for (unsigned int i = 0; i < vMatched.size(); i++)
268 [ + - + - ]: 8 : BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second);
269 : 1 : }
270 : :
271 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(merkle_block_2_with_update_none)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
272 : : {
273 : : // Random real block (000000005a4ded781e667e06ceefafb71410b511fe0d5adc3e5a27ecbec34ae6)
274 : : // With 4 txes
275 : 1 : CBlock block;
276 : 1 : DataStream stream{
277 [ + - ]: 1 : "0100000075616236cc2126035fadb38deb65b9102cc2c41c09cdf29fc051906800000000fe7d5e12ef0ff901f6050211249919b1c0653771832b3a80c66cea42847f0ae1d4d26e49ffff001d00f0a4410401000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d029105ffffffff0100f2052a010000004341046d8709a041d34357697dfcb30a9d05900a6294078012bf3bb09c6f9b525f1d16d5503d7905db1ada9501446ea00728668fc5719aa80be2fdfc8a858a4dbdd4fbac00000000010000000255605dc6f5c3dc148b6da58442b0b2cd422be385eab2ebea4119ee9c268d28350000000049483045022100aa46504baa86df8a33b1192b1b9367b4d729dc41e389f2c04f3e5c7f0559aae702205e82253a54bf5c4f65b7428551554b2045167d6d206dfe6a2e198127d3f7df1501ffffffff55605dc6f5c3dc148b6da58442b0b2cd422be385eab2ebea4119ee9c268d2835010000004847304402202329484c35fa9d6bb32a55a70c0982f606ce0e3634b69006138683bcd12cbb6602200c28feb1e2555c3210f1dddb299738b4ff8bbe9667b68cb8764b5ac17b7adf0001ffffffff0200e1f505000000004341046a0765b5865641ce08dd39690aade26dfbf5511430ca428a3089261361cef170e3929a68aee3d8d4848b0c5111b0a37b82b86ad559fd2a745b44d8e8d9dfdc0cac00180d8f000000004341044a656f065871a353f216ca26cef8dde2f03e8c16202d2e8ad769f02032cb86a5eb5e56842e92e19141d60a01928f8dd2c875a390f67c1f6c94cfc617c0ea45afac0000000001000000025f9a06d3acdceb56be1bfeaa3e8a25e62d182fa24fefe899d1c17f1dad4c2028000000004847304402205d6058484157235b06028c30736c15613a28bdb768ee628094ca8b0030d4d6eb0220328789c9a2ec27ddaec0ad5ef58efded42e6ea17c2e1ce838f3d6913f5e95db601ffffffff5f9a06d3acdceb56be1bfeaa3e8a25e62d182fa24fefe899d1c17f1dad4c2028010000004a493046022100c45af050d3cea806cedd0ab22520c53ebe63b987b8954146cdca42487b84bdd6022100b9b027716a6b59e640da50a864d6dd8a0ef24c76ce62391fa3eabaf4d2886d2d01ffffffff0200e1f505000000004341046a0765b5865641ce08dd39690aade26dfbf5511430ca428a3089261361cef170e3929a68aee3d8d4848b0c5111b0a37b82b86ad559fd2a745b44d8e8d9dfdc0cac00180d8f000000004341046a0765b5865641ce08dd39690aade26dfbf5511430ca428a3089261361cef170e3929a68aee3d8d4848b0c5111b0a37b82b86ad559fd2a745b44d8e8d9dfdc0cac000000000100000002e2274e5fea1bf29d963914bd301aa63b64daaf8a3e88f119b5046ca5738a0f6b0000000048473044022016e7a727a061ea2254a6c358376aaa617ac537eb836c77d646ebda4c748aac8b0220192ce28bf9f2c06a6467e6531e27648d2b3e2e2bae85159c9242939840295ba501ffffffffe2274e5fea1bf29d963914bd301aa63b64daaf8a3e88f119b5046ca5738a0f6b010000004a493046022100b7a1a755588d4190118936e15cd217d133b0e4a53c3c15924010d5648d8925c9022100aaef031874db2114f2d869ac2de4ae53908fbfea5b2b1862e181626bb9005c9f01ffffffff0200e1f505000000004341044a656f065871a353f216ca26cef8dde2f03e8c16202d2e8ad769f02032cb86a5eb5e56842e92e19141d60a01928f8dd2c875a390f67c1f6c94cfc617c0ea45afac00180d8f000000004341046a0765b5865641ce08dd39690aade26dfbf5511430ca428a3089261361cef170e3929a68aee3d8d4848b0c5111b0a37b82b86ad559fd2a745b44d8e8d9dfdc0cac00000000"_hex,
278 [ + - ]: 1 : };
279 [ + - ]: 1 : stream >> TX_WITH_WITNESS(block);
280 : :
281 [ + - ]: 1 : CBloomFilter filter(10, 0.000001, 0, BLOOM_UPDATE_NONE);
282 : : // Match the first transaction
283 [ + - ]: 1 : filter.insert(uint256{"e980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df5b47aecb93b70"});
284 : :
285 [ + - ]: 1 : CMerkleBlock merkleBlock(block, filter);
286 [ + - + - : 2 : BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
+ - + - +
- ]
287 : :
288 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1);
+ - ]
289 [ + - ]: 1 : std::pair<unsigned int, uint256> pair = merkleBlock.vMatchedTxn[0];
290 : :
291 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256{"e980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df5b47aecb93b70"});
+ - ]
292 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 0);
+ - ]
293 : :
294 : 1 : std::vector<uint256> vMatched;
295 : 1 : std::vector<unsigned int> vIndex;
296 [ + - + - : 2 : BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
+ - + - ]
297 [ + - + - ]: 2 : BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
298 [ + + ]: 2 : for (unsigned int i = 0; i < vMatched.size(); i++)
299 [ + - + - ]: 2 : BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second);
300 : :
301 : : // Match an output from the second transaction (the pubkey for address 1DZTzaBHUDM7T3QvUKBz4qXMRpkg8jsfB5)
302 : : // This should not match the third transaction though it spends the output matched
303 : : // It will match the fourth transaction, which has another pay-to-pubkey output to the same address
304 [ + - ]: 1 : filter.insert("044a656f065871a353f216ca26cef8dde2f03e8c16202d2e8ad769f02032cb86a5eb5e56842e92e19141d60a01928f8dd2c875a390f67c1f6c94cfc617c0ea45af"_hex_u8);
305 : :
306 [ + - ]: 1 : merkleBlock = CMerkleBlock(block, filter);
307 [ + - + - : 2 : BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
+ - + - +
- ]
308 : :
309 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 3);
+ - ]
310 : :
311 [ + - + - : 2 : BOOST_CHECK(pair == merkleBlock.vMatchedTxn[0]);
+ - ]
312 : :
313 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[1].second == uint256{"28204cad1d7fc1d199e8ef4fa22f182de6258a3eaafe1bbe56ebdcacd3069a5f"});
+ - ]
314 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[1].first == 1);
+ - ]
315 : :
316 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[2].second == uint256{"3c1d7e82342158e4109df2e0b6348b6e84e403d8b4046d7007663ace63cddb23"});
+ - ]
317 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[2].first == 3);
+ - ]
318 : :
319 [ + - + - : 2 : BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
+ - + - ]
320 [ + - + - ]: 2 : BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
321 [ + + ]: 4 : for (unsigned int i = 0; i < vMatched.size(); i++)
322 [ + - + - ]: 6 : BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second);
323 : 1 : }
324 : :
325 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(merkle_block_3_and_serialize)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
326 : : {
327 : : // Random real block (000000000000dab0130bbcc991d3d7ae6b81aa6f50a798888dfe62337458dc45)
328 : : // With one tx
329 : 1 : CBlock block;
330 : 1 : DataStream stream{
331 [ + - ]: 1 : "0100000079cda856b143d9db2c1caff01d1aecc8630d30625d10e8b4b8b0000000000000b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f196367291b4d4c86041b8fa45d630101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff08044c86041b020a02ffffffff0100f2052a01000000434104ecd3229b0571c3be876feaac0442a9f13c5a572742927af1dc623353ecf8c202225f64868137a18cdd85cbbb4c74fbccfd4f49639cf1bdc94a5672bb15ad5d4cac00000000"_hex,
332 [ + - ]: 1 : };
333 [ + - ]: 1 : stream >> TX_WITH_WITNESS(block);
334 : :
335 [ + - ]: 1 : CBloomFilter filter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
336 : : // Match the only transaction
337 [ + - ]: 1 : filter.insert(uint256{"63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5"});
338 : :
339 [ + - ]: 1 : CMerkleBlock merkleBlock(block, filter);
340 [ + - + - : 2 : BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
+ - + - +
- ]
341 : :
342 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1);
+ - ]
343 : :
344 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256{"63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5"});
+ - ]
345 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 0);
+ - ]
346 : :
347 : 1 : std::vector<uint256> vMatched;
348 : 1 : std::vector<unsigned int> vIndex;
349 [ + - + - : 2 : BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
+ - + - ]
350 [ + - + - ]: 2 : BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
351 [ + + ]: 2 : for (unsigned int i = 0; i < vMatched.size(); i++)
352 [ + - + - ]: 2 : BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second);
353 : :
354 : 1 : DataStream merkleStream{};
355 [ + - ]: 1 : merkleStream << merkleBlock;
356 : :
357 : 1 : constexpr auto expected{"0100000079cda856b143d9db2c1caff01d1aecc8630d30625d10e8b4b8b0000000000000b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f196367291b4d4c86041b8fa45d630100000001b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f19630101"_hex};
358 [ + - + - : 2 : BOOST_CHECK_EQUAL_COLLECTIONS(merkleStream.begin(), merkleStream.end(), expected.begin(), expected.end());
+ - ]
359 : 1 : }
360 : :
361 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(merkle_block_4)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
362 : : {
363 : : // Random real block (000000000000b731f2eef9e8c63173adfb07e41bd53eb0ef0a6b720d6cb6dea4)
364 : : // With 7 txes
365 : 1 : CBlock block;
366 : 1 : DataStream stream{
367 [ + - ]: 1 : "0100000082bb869cf3a793432a66e826e05a6fc37469f8efb7421dc880670100000000007f16c5962e8bd963659c793ce370d95f093bc7e367117b3c30c1f8fdd0d9728776381b4d4c86041b554b85290701000000010000000000000000000000000000000000000000000000000000000000000000ffffffff07044c86041b0136ffffffff0100f2052a01000000434104eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c876f2c01ec0f0dd5b2e86e7168cefe0d81113c3807420ce13ad1357231a2252247d97a46a91ac000000000100000001bcad20a6a29827d1424f08989255120bf7f3e9e3cdaaa6bb31b0737fe048724300000000494830450220356e834b046cadc0f8ebb5a8a017b02de59c86305403dad52cd77b55af062ea10221009253cd6c119d4729b77c978e1e2aa19f5ea6e0e52b3f16e32fa608cd5bab753901ffffffff02008d380c010000001976a9142b4b8072ecbba129b6453c63e129e643207249ca88ac0065cd1d000000001976a9141b8dd13b994bcfc787b32aeadf58ccb3615cbd5488ac000000000100000003fdacf9b3eb077412e7a968d2e4f11b9a9dee312d666187ed77ee7d26af16cb0b000000008c493046022100ea1608e70911ca0de5af51ba57ad23b9a51db8d28f82c53563c56a05c20f5a87022100a8bdc8b4a8acc8634c6b420410150775eb7f2474f5615f7fccd65af30f310fbf01410465fdf49e29b06b9a1582287b6279014f834edc317695d125ef623c1cc3aaece245bd69fcad7508666e9c74a49dc9056d5fc14338ef38118dc4afae5fe2c585caffffffff309e1913634ecb50f3c4f83e96e70b2df071b497b8973a3e75429df397b5af83000000004948304502202bdb79c596a9ffc24e96f4386199aba386e9bc7b6071516e2b51dda942b3a1ed022100c53a857e76b724fc14d45311eac5019650d415c3abb5428f3aae16d8e69bec2301ffffffff2089e33491695080c9edc18a428f7d834db5b6d372df13ce2b1b0e0cbcb1e6c10000000049483045022100d4ce67c5896ee251c810ac1ff9ceccd328b497c8f553ab6e08431e7d40bad6b5022033119c0c2b7d792d31f1187779c7bd95aefd93d90a715586d73801d9b47471c601ffffffff0100714460030000001976a914c7b55141d097ea5df7a0ed330cf794376e53ec8d88ac0000000001000000045bf0e214aa4069a3e792ecee1e1bf0c1d397cde8dd08138f4b72a00681743447000000008b48304502200c45de8c4f3e2c1821f2fc878cba97b1e6f8807d94930713aa1c86a67b9bf1e40221008581abfef2e30f957815fc89978423746b2086375ca8ecf359c85c2a5b7c88ad01410462bb73f76ca0994fcb8b4271e6fb7561f5c0f9ca0cf6485261c4a0dc894f4ab844c6cdfb97cd0b60ffb5018ffd6238f4d87270efb1d3ae37079b794a92d7ec95ffffffffd669f7d7958d40fc59d2253d88e0f248e29b599c80bbcec344a83dda5f9aa72c000000008a473044022078124c8beeaa825f9e0b30bff96e564dd859432f2d0cb3b72d3d5d93d38d7e930220691d233b6c0f995be5acb03d70a7f7a65b6bc9bdd426260f38a1346669507a3601410462bb73f76ca0994fcb8b4271e6fb7561f5c0f9ca0cf6485261c4a0dc894f4ab844c6cdfb97cd0b60ffb5018ffd6238f4d87270efb1d3ae37079b794a92d7ec95fffffffff878af0d93f5229a68166cf051fd372bb7a537232946e0a46f53636b4dafdaa4000000008c493046022100c717d1714551663f69c3c5759bdbb3a0fcd3fab023abc0e522fe6440de35d8290221008d9cbe25bffc44af2b18e81c58eb37293fd7fe1c2e7b46fc37ee8c96c50ab1e201410462bb73f76ca0994fcb8b4271e6fb7561f5c0f9ca0cf6485261c4a0dc894f4ab844c6cdfb97cd0b60ffb5018ffd6238f4d87270efb1d3ae37079b794a92d7ec95ffffffff27f2b668859cd7f2f894aa0fd2d9e60963bcd07c88973f425f999b8cbfd7a1e2000000008c493046022100e00847147cbf517bcc2f502f3ddc6d284358d102ed20d47a8aa788a62f0db780022100d17b2d6fa84dcaf1c95d88d7e7c30385aecf415588d749afd3ec81f6022cecd701410462bb73f76ca0994fcb8b4271e6fb7561f5c0f9ca0cf6485261c4a0dc894f4ab844c6cdfb97cd0b60ffb5018ffd6238f4d87270efb1d3ae37079b794a92d7ec95ffffffff0100c817a8040000001976a914b6efd80d99179f4f4ff6f4dd0a007d018c385d2188ac000000000100000001834537b2f1ce8ef9373a258e10545ce5a50b758df616cd4356e0032554ebd3c4000000008b483045022100e68f422dd7c34fdce11eeb4509ddae38201773dd62f284e8aa9d96f85099d0b002202243bd399ff96b649a0fad05fa759d6a882f0af8c90cf7632c2840c29070aec20141045e58067e815c2f464c6a2a15f987758374203895710c2d452442e28496ff38ba8f5fd901dc20e29e88477167fe4fc299bf818fd0d9e1632d467b2a3d9503b1aaffffffff0280d7e636030000001976a914f34c3e10eb387efe872acb614c89e78bfca7815d88ac404b4c00000000001976a914a84e272933aaf87e1715d7786c51dfaeb5b65a6f88ac00000000010000000143ac81c8e6f6ef307dfe17f3d906d999e23e0189fda838c5510d850927e03ae7000000008c4930460221009c87c344760a64cb8ae6685a3eec2c1ac1bed5b88c87de51acd0e124f266c16602210082d07c037359c3a257b5c63ebd90f5a5edf97b2ac1c434b08ca998839f346dd40141040ba7e521fa7946d12edbb1d1e95a15c34bd4398195e86433c92b431cd315f455fe30032ede69cad9d1e1ed6c3c4ec0dbfced53438c625462afb792dcb098544bffffffff0240420f00000000001976a9144676d1b820d63ec272f1900d59d43bc6463d96f888ac40420f00000000001976a914648d04341d00d7968b3405c034adc38d4d8fb9bd88ac00000000010000000248cc917501ea5c55f4a8d2009c0567c40cfe037c2e71af017d0a452ff705e3f1000000008b483045022100bf5fdc86dc5f08a5d5c8e43a8c9d5b1ed8c65562e280007b52b133021acd9acc02205e325d613e555f772802bf413d36ba807892ed1a690a77811d3033b3de226e0a01410429fa713b124484cb2bd7b5557b2c0b9df7b2b1fee61825eadc5ae6c37a9920d38bfccdc7dc3cb0c47d7b173dbc9db8d37db0a33ae487982c59c6f8606e9d1791ffffffff41ed70551dd7e841883ab8f0b16bf04176b7d1480e4f0af9f3d4c3595768d068000000008b4830450221008513ad65187b903aed1102d1d0c47688127658c51106753fed0151ce9c16b80902201432b9ebcb87bd04ceb2de66035fbbaf4bf8b00d1cfe41f1a1f7338f9ad79d210141049d4cf80125bf50be1709f718c07ad15d0fc612b7da1f5570dddc35f2a352f0f27c978b06820edca9ef982c35fda2d255afba340068c5035552368bc7200c1488ffffffff0100093d00000000001976a9148edb68822f1ad580b043c7b3df2e400f8699eb4888ac00000000"_hex,
368 [ + - ]: 1 : };
369 [ + - ]: 1 : stream >> TX_WITH_WITNESS(block);
370 : :
371 [ + - ]: 1 : CBloomFilter filter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
372 : : // Match the last transaction
373 [ + - ]: 1 : filter.insert(uint256{"0a2a92f0bda4727d0a13eaddf4dd9ac6b5c61a1429e6b2b818f19b15df0ac154"});
374 : :
375 [ + - ]: 1 : CMerkleBlock merkleBlock(block, filter);
376 [ + - + - : 2 : BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
+ - + - +
- ]
377 : :
378 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1);
+ - ]
379 [ + - ]: 1 : std::pair<unsigned int, uint256> pair = merkleBlock.vMatchedTxn[0];
380 : :
381 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256{"0a2a92f0bda4727d0a13eaddf4dd9ac6b5c61a1429e6b2b818f19b15df0ac154"});
+ - ]
382 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 6);
+ - ]
383 : :
384 : 1 : std::vector<uint256> vMatched;
385 : 1 : std::vector<unsigned int> vIndex;
386 [ + - + - : 2 : BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
+ - + - ]
387 [ + - + - ]: 2 : BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
388 [ + + ]: 2 : for (unsigned int i = 0; i < vMatched.size(); i++)
389 [ + - + - ]: 2 : BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second);
390 : :
391 : : // Also match the 4th transaction
392 [ + - ]: 1 : filter.insert(uint256{"02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041"});
393 [ + - ]: 1 : merkleBlock = CMerkleBlock(block, filter);
394 [ + - + - : 2 : BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
+ - + - +
- ]
395 : :
396 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 2);
+ - ]
397 : :
398 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256{"02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041"});
+ - ]
399 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 3);
+ - ]
400 : :
401 [ + - + - : 2 : BOOST_CHECK(merkleBlock.vMatchedTxn[1] == pair);
+ - ]
402 : :
403 [ + - + - : 2 : BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
+ - + - ]
404 [ + - + - ]: 2 : BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
405 [ + + ]: 3 : for (unsigned int i = 0; i < vMatched.size(); i++)
406 [ + - + - ]: 4 : BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second);
407 : 1 : }
408 : :
409 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(merkle_block_4_test_p2pubkey_only)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
410 : : {
411 : : // Random real block (000000000000b731f2eef9e8c63173adfb07e41bd53eb0ef0a6b720d6cb6dea4)
412 : : // With 7 txes
413 : 1 : CBlock block;
414 : 1 : DataStream stream{
415 [ + - ]: 1 : "0100000082bb869cf3a793432a66e826e05a6fc37469f8efb7421dc880670100000000007f16c5962e8bd963659c793ce370d95f093bc7e367117b3c30c1f8fdd0d9728776381b4d4c86041b554b85290701000000010000000000000000000000000000000000000000000000000000000000000000ffffffff07044c86041b0136ffffffff0100f2052a01000000434104eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c876f2c01ec0f0dd5b2e86e7168cefe0d81113c3807420ce13ad1357231a2252247d97a46a91ac000000000100000001bcad20a6a29827d1424f08989255120bf7f3e9e3cdaaa6bb31b0737fe048724300000000494830450220356e834b046cadc0f8ebb5a8a017b02de59c86305403dad52cd77b55af062ea10221009253cd6c119d4729b77c978e1e2aa19f5ea6e0e52b3f16e32fa608cd5bab753901ffffffff02008d380c010000001976a9142b4b8072ecbba129b6453c63e129e643207249ca88ac0065cd1d000000001976a9141b8dd13b994bcfc787b32aeadf58ccb3615cbd5488ac000000000100000003fdacf9b3eb077412e7a968d2e4f11b9a9dee312d666187ed77ee7d26af16cb0b000000008c493046022100ea1608e70911ca0de5af51ba57ad23b9a51db8d28f82c53563c56a05c20f5a87022100a8bdc8b4a8acc8634c6b420410150775eb7f2474f5615f7fccd65af30f310fbf01410465fdf49e29b06b9a1582287b6279014f834edc317695d125ef623c1cc3aaece245bd69fcad7508666e9c74a49dc9056d5fc14338ef38118dc4afae5fe2c585caffffffff309e1913634ecb50f3c4f83e96e70b2df071b497b8973a3e75429df397b5af83000000004948304502202bdb79c596a9ffc24e96f4386199aba386e9bc7b6071516e2b51dda942b3a1ed022100c53a857e76b724fc14d45311eac5019650d415c3abb5428f3aae16d8e69bec2301ffffffff2089e33491695080c9edc18a428f7d834db5b6d372df13ce2b1b0e0cbcb1e6c10000000049483045022100d4ce67c5896ee251c810ac1ff9ceccd328b497c8f553ab6e08431e7d40bad6b5022033119c0c2b7d792d31f1187779c7bd95aefd93d90a715586d73801d9b47471c601ffffffff0100714460030000001976a914c7b55141d097ea5df7a0ed330cf794376e53ec8d88ac0000000001000000045bf0e214aa4069a3e792ecee1e1bf0c1d397cde8dd08138f4b72a00681743447000000008b48304502200c45de8c4f3e2c1821f2fc878cba97b1e6f8807d94930713aa1c86a67b9bf1e40221008581abfef2e30f957815fc89978423746b2086375ca8ecf359c85c2a5b7c88ad01410462bb73f76ca0994fcb8b4271e6fb7561f5c0f9ca0cf6485261c4a0dc894f4ab844c6cdfb97cd0b60ffb5018ffd6238f4d87270efb1d3ae37079b794a92d7ec95ffffffffd669f7d7958d40fc59d2253d88e0f248e29b599c80bbcec344a83dda5f9aa72c000000008a473044022078124c8beeaa825f9e0b30bff96e564dd859432f2d0cb3b72d3d5d93d38d7e930220691d233b6c0f995be5acb03d70a7f7a65b6bc9bdd426260f38a1346669507a3601410462bb73f76ca0994fcb8b4271e6fb7561f5c0f9ca0cf6485261c4a0dc894f4ab844c6cdfb97cd0b60ffb5018ffd6238f4d87270efb1d3ae37079b794a92d7ec95fffffffff878af0d93f5229a68166cf051fd372bb7a537232946e0a46f53636b4dafdaa4000000008c493046022100c717d1714551663f69c3c5759bdbb3a0fcd3fab023abc0e522fe6440de35d8290221008d9cbe25bffc44af2b18e81c58eb37293fd7fe1c2e7b46fc37ee8c96c50ab1e201410462bb73f76ca0994fcb8b4271e6fb7561f5c0f9ca0cf6485261c4a0dc894f4ab844c6cdfb97cd0b60ffb5018ffd6238f4d87270efb1d3ae37079b794a92d7ec95ffffffff27f2b668859cd7f2f894aa0fd2d9e60963bcd07c88973f425f999b8cbfd7a1e2000000008c493046022100e00847147cbf517bcc2f502f3ddc6d284358d102ed20d47a8aa788a62f0db780022100d17b2d6fa84dcaf1c95d88d7e7c30385aecf415588d749afd3ec81f6022cecd701410462bb73f76ca0994fcb8b4271e6fb7561f5c0f9ca0cf6485261c4a0dc894f4ab844c6cdfb97cd0b60ffb5018ffd6238f4d87270efb1d3ae37079b794a92d7ec95ffffffff0100c817a8040000001976a914b6efd80d99179f4f4ff6f4dd0a007d018c385d2188ac000000000100000001834537b2f1ce8ef9373a258e10545ce5a50b758df616cd4356e0032554ebd3c4000000008b483045022100e68f422dd7c34fdce11eeb4509ddae38201773dd62f284e8aa9d96f85099d0b002202243bd399ff96b649a0fad05fa759d6a882f0af8c90cf7632c2840c29070aec20141045e58067e815c2f464c6a2a15f987758374203895710c2d452442e28496ff38ba8f5fd901dc20e29e88477167fe4fc299bf818fd0d9e1632d467b2a3d9503b1aaffffffff0280d7e636030000001976a914f34c3e10eb387efe872acb614c89e78bfca7815d88ac404b4c00000000001976a914a84e272933aaf87e1715d7786c51dfaeb5b65a6f88ac00000000010000000143ac81c8e6f6ef307dfe17f3d906d999e23e0189fda838c5510d850927e03ae7000000008c4930460221009c87c344760a64cb8ae6685a3eec2c1ac1bed5b88c87de51acd0e124f266c16602210082d07c037359c3a257b5c63ebd90f5a5edf97b2ac1c434b08ca998839f346dd40141040ba7e521fa7946d12edbb1d1e95a15c34bd4398195e86433c92b431cd315f455fe30032ede69cad9d1e1ed6c3c4ec0dbfced53438c625462afb792dcb098544bffffffff0240420f00000000001976a9144676d1b820d63ec272f1900d59d43bc6463d96f888ac40420f00000000001976a914648d04341d00d7968b3405c034adc38d4d8fb9bd88ac00000000010000000248cc917501ea5c55f4a8d2009c0567c40cfe037c2e71af017d0a452ff705e3f1000000008b483045022100bf5fdc86dc5f08a5d5c8e43a8c9d5b1ed8c65562e280007b52b133021acd9acc02205e325d613e555f772802bf413d36ba807892ed1a690a77811d3033b3de226e0a01410429fa713b124484cb2bd7b5557b2c0b9df7b2b1fee61825eadc5ae6c37a9920d38bfccdc7dc3cb0c47d7b173dbc9db8d37db0a33ae487982c59c6f8606e9d1791ffffffff41ed70551dd7e841883ab8f0b16bf04176b7d1480e4f0af9f3d4c3595768d068000000008b4830450221008513ad65187b903aed1102d1d0c47688127658c51106753fed0151ce9c16b80902201432b9ebcb87bd04ceb2de66035fbbaf4bf8b00d1cfe41f1a1f7338f9ad79d210141049d4cf80125bf50be1709f718c07ad15d0fc612b7da1f5570dddc35f2a352f0f27c978b06820edca9ef982c35fda2d255afba340068c5035552368bc7200c1488ffffffff0100093d00000000001976a9148edb68822f1ad580b043c7b3df2e400f8699eb4888ac00000000"_hex,
416 [ + - ]: 1 : };
417 [ + - ]: 1 : stream >> TX_WITH_WITNESS(block);
418 : :
419 [ + - ]: 1 : CBloomFilter filter(10, 0.000001, 0, BLOOM_UPDATE_P2PUBKEY_ONLY);
420 : : // Match the generation pubkey
421 [ + - ]: 1 : filter.insert("04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c876f2c01ec0f0dd5b2e86e7168cefe0d81113c3807420ce13ad1357231a2252247d97a46a91"_hex_u8);
422 : : // ...and the output address of the 4th transaction
423 [ + - ]: 1 : filter.insert("b6efd80d99179f4f4ff6f4dd0a007d018c385d21"_hex_u8);
424 : :
425 [ + - ]: 1 : CMerkleBlock merkleBlock(block, filter);
426 [ + - + - : 2 : BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
+ - + - +
- ]
427 : :
428 : : // We should match the generation outpoint
429 [ + - + - : 3 : BOOST_CHECK(filter.contains(COutPoint(Txid::FromHex("147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b").value(), 0)));
+ - + - +
- ]
430 : : // ... but not the 4th transaction's output (its not pay-2-pubkey)
431 [ + - + - : 3 : BOOST_CHECK(!filter.contains(COutPoint(Txid::FromHex("02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041").value(), 0)));
+ - + - ]
432 : 1 : }
433 : :
434 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(merkle_block_4_test_update_none)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
435 : : {
436 : : // Random real block (000000000000b731f2eef9e8c63173adfb07e41bd53eb0ef0a6b720d6cb6dea4)
437 : : // With 7 txes
438 : 1 : CBlock block;
439 : 1 : DataStream stream{
440 [ + - ]: 1 : "0100000082bb869cf3a793432a66e826e05a6fc37469f8efb7421dc880670100000000007f16c5962e8bd963659c793ce370d95f093bc7e367117b3c30c1f8fdd0d9728776381b4d4c86041b554b85290701000000010000000000000000000000000000000000000000000000000000000000000000ffffffff07044c86041b0136ffffffff0100f2052a01000000434104eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c876f2c01ec0f0dd5b2e86e7168cefe0d81113c3807420ce13ad1357231a2252247d97a46a91ac000000000100000001bcad20a6a29827d1424f08989255120bf7f3e9e3cdaaa6bb31b0737fe048724300000000494830450220356e834b046cadc0f8ebb5a8a017b02de59c86305403dad52cd77b55af062ea10221009253cd6c119d4729b77c978e1e2aa19f5ea6e0e52b3f16e32fa608cd5bab753901ffffffff02008d380c010000001976a9142b4b8072ecbba129b6453c63e129e643207249ca88ac0065cd1d000000001976a9141b8dd13b994bcfc787b32aeadf58ccb3615cbd5488ac000000000100000003fdacf9b3eb077412e7a968d2e4f11b9a9dee312d666187ed77ee7d26af16cb0b000000008c493046022100ea1608e70911ca0de5af51ba57ad23b9a51db8d28f82c53563c56a05c20f5a87022100a8bdc8b4a8acc8634c6b420410150775eb7f2474f5615f7fccd65af30f310fbf01410465fdf49e29b06b9a1582287b6279014f834edc317695d125ef623c1cc3aaece245bd69fcad7508666e9c74a49dc9056d5fc14338ef38118dc4afae5fe2c585caffffffff309e1913634ecb50f3c4f83e96e70b2df071b497b8973a3e75429df397b5af83000000004948304502202bdb79c596a9ffc24e96f4386199aba386e9bc7b6071516e2b51dda942b3a1ed022100c53a857e76b724fc14d45311eac5019650d415c3abb5428f3aae16d8e69bec2301ffffffff2089e33491695080c9edc18a428f7d834db5b6d372df13ce2b1b0e0cbcb1e6c10000000049483045022100d4ce67c5896ee251c810ac1ff9ceccd328b497c8f553ab6e08431e7d40bad6b5022033119c0c2b7d792d31f1187779c7bd95aefd93d90a715586d73801d9b47471c601ffffffff0100714460030000001976a914c7b55141d097ea5df7a0ed330cf794376e53ec8d88ac0000000001000000045bf0e214aa4069a3e792ecee1e1bf0c1d397cde8dd08138f4b72a00681743447000000008b48304502200c45de8c4f3e2c1821f2fc878cba97b1e6f8807d94930713aa1c86a67b9bf1e40221008581abfef2e30f957815fc89978423746b2086375ca8ecf359c85c2a5b7c88ad01410462bb73f76ca0994fcb8b4271e6fb7561f5c0f9ca0cf6485261c4a0dc894f4ab844c6cdfb97cd0b60ffb5018ffd6238f4d87270efb1d3ae37079b794a92d7ec95ffffffffd669f7d7958d40fc59d2253d88e0f248e29b599c80bbcec344a83dda5f9aa72c000000008a473044022078124c8beeaa825f9e0b30bff96e564dd859432f2d0cb3b72d3d5d93d38d7e930220691d233b6c0f995be5acb03d70a7f7a65b6bc9bdd426260f38a1346669507a3601410462bb73f76ca0994fcb8b4271e6fb7561f5c0f9ca0cf6485261c4a0dc894f4ab844c6cdfb97cd0b60ffb5018ffd6238f4d87270efb1d3ae37079b794a92d7ec95fffffffff878af0d93f5229a68166cf051fd372bb7a537232946e0a46f53636b4dafdaa4000000008c493046022100c717d1714551663f69c3c5759bdbb3a0fcd3fab023abc0e522fe6440de35d8290221008d9cbe25bffc44af2b18e81c58eb37293fd7fe1c2e7b46fc37ee8c96c50ab1e201410462bb73f76ca0994fcb8b4271e6fb7561f5c0f9ca0cf6485261c4a0dc894f4ab844c6cdfb97cd0b60ffb5018ffd6238f4d87270efb1d3ae37079b794a92d7ec95ffffffff27f2b668859cd7f2f894aa0fd2d9e60963bcd07c88973f425f999b8cbfd7a1e2000000008c493046022100e00847147cbf517bcc2f502f3ddc6d284358d102ed20d47a8aa788a62f0db780022100d17b2d6fa84dcaf1c95d88d7e7c30385aecf415588d749afd3ec81f6022cecd701410462bb73f76ca0994fcb8b4271e6fb7561f5c0f9ca0cf6485261c4a0dc894f4ab844c6cdfb97cd0b60ffb5018ffd6238f4d87270efb1d3ae37079b794a92d7ec95ffffffff0100c817a8040000001976a914b6efd80d99179f4f4ff6f4dd0a007d018c385d2188ac000000000100000001834537b2f1ce8ef9373a258e10545ce5a50b758df616cd4356e0032554ebd3c4000000008b483045022100e68f422dd7c34fdce11eeb4509ddae38201773dd62f284e8aa9d96f85099d0b002202243bd399ff96b649a0fad05fa759d6a882f0af8c90cf7632c2840c29070aec20141045e58067e815c2f464c6a2a15f987758374203895710c2d452442e28496ff38ba8f5fd901dc20e29e88477167fe4fc299bf818fd0d9e1632d467b2a3d9503b1aaffffffff0280d7e636030000001976a914f34c3e10eb387efe872acb614c89e78bfca7815d88ac404b4c00000000001976a914a84e272933aaf87e1715d7786c51dfaeb5b65a6f88ac00000000010000000143ac81c8e6f6ef307dfe17f3d906d999e23e0189fda838c5510d850927e03ae7000000008c4930460221009c87c344760a64cb8ae6685a3eec2c1ac1bed5b88c87de51acd0e124f266c16602210082d07c037359c3a257b5c63ebd90f5a5edf97b2ac1c434b08ca998839f346dd40141040ba7e521fa7946d12edbb1d1e95a15c34bd4398195e86433c92b431cd315f455fe30032ede69cad9d1e1ed6c3c4ec0dbfced53438c625462afb792dcb098544bffffffff0240420f00000000001976a9144676d1b820d63ec272f1900d59d43bc6463d96f888ac40420f00000000001976a914648d04341d00d7968b3405c034adc38d4d8fb9bd88ac00000000010000000248cc917501ea5c55f4a8d2009c0567c40cfe037c2e71af017d0a452ff705e3f1000000008b483045022100bf5fdc86dc5f08a5d5c8e43a8c9d5b1ed8c65562e280007b52b133021acd9acc02205e325d613e555f772802bf413d36ba807892ed1a690a77811d3033b3de226e0a01410429fa713b124484cb2bd7b5557b2c0b9df7b2b1fee61825eadc5ae6c37a9920d38bfccdc7dc3cb0c47d7b173dbc9db8d37db0a33ae487982c59c6f8606e9d1791ffffffff41ed70551dd7e841883ab8f0b16bf04176b7d1480e4f0af9f3d4c3595768d068000000008b4830450221008513ad65187b903aed1102d1d0c47688127658c51106753fed0151ce9c16b80902201432b9ebcb87bd04ceb2de66035fbbaf4bf8b00d1cfe41f1a1f7338f9ad79d210141049d4cf80125bf50be1709f718c07ad15d0fc612b7da1f5570dddc35f2a352f0f27c978b06820edca9ef982c35fda2d255afba340068c5035552368bc7200c1488ffffffff0100093d00000000001976a9148edb68822f1ad580b043c7b3df2e400f8699eb4888ac00000000"_hex,
441 [ + - ]: 1 : };
442 [ + - ]: 1 : stream >> TX_WITH_WITNESS(block);
443 : :
444 [ + - ]: 1 : CBloomFilter filter(10, 0.000001, 0, BLOOM_UPDATE_NONE);
445 : : // Match the generation pubkey
446 [ + - ]: 1 : filter.insert("04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c876f2c01ec0f0dd5b2e86e7168cefe0d81113c3807420ce13ad1357231a2252247d97a46a91"_hex_u8);
447 : : // ...and the output address of the 4th transaction
448 [ + - ]: 1 : filter.insert("b6efd80d99179f4f4ff6f4dd0a007d018c385d21"_hex_u8);
449 : :
450 [ + - ]: 1 : CMerkleBlock merkleBlock(block, filter);
451 [ + - + - : 2 : BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
+ - + - +
- ]
452 : :
453 : : // We shouldn't match any outpoints (UPDATE_NONE)
454 [ + - + - : 3 : BOOST_CHECK(!filter.contains(COutPoint(Txid::FromHex("147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b").value(), 0)));
+ - + - +
- ]
455 [ + - + - : 3 : BOOST_CHECK(!filter.contains(COutPoint(Txid::FromHex("02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041").value(), 0)));
+ - + - ]
456 : 1 : }
457 : :
458 : 11398 : std::vector<unsigned char> BloomTest::RandomData()
459 : : {
460 : 11398 : uint256 r = m_rng.rand256();
461 : 11398 : return std::vector<unsigned char>(r.begin(), r.end());
462 : : }
463 : :
464 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(rolling_bloom)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
465 : : {
466 : 1 : SeedRandomForTest(SeedRand::ZEROS);
467 : :
468 : : // last-100-entry, 1% false positive:
469 : 1 : CRollingBloomFilter rb1(100, 0.01);
470 : :
471 : : // Overfill:
472 : 1 : static const int DATASIZE=399;
473 : 399 : std::vector<unsigned char> data[DATASIZE];
474 [ + + ]: 400 : for (int i = 0; i < DATASIZE; i++) {
475 [ + - ]: 399 : data[i] = RandomData();
476 [ + - ]: 399 : rb1.insert(data[i]);
477 : : }
478 : : // Last 100 guaranteed to be remembered:
479 [ + + ]: 101 : for (int i = 299; i < DATASIZE; i++) {
480 [ + - + - : 200 : BOOST_CHECK(rb1.contains(data[i]));
+ - ]
481 : : }
482 : :
483 : : // false positive rate is 1%, so we should get about 100 hits if
484 : : // testing 10,000 random keys. We get worst-case false positive
485 : : // behavior when the filter is as full as possible, which is
486 : : // when we've inserted one minus an integer multiple of nElement*2.
487 : 1 : unsigned int nHits = 0;
488 [ + + ]: 10001 : for (int i = 0; i < 10000; i++) {
489 [ + - + - : 10000 : if (rb1.contains(RandomData()))
+ + ]
490 : 71 : ++nHits;
491 : : }
492 : : // Expect about 100 hits
493 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(nHits, 71U);
494 : :
495 [ + - + - : 2 : BOOST_CHECK(rb1.contains(data[DATASIZE-1]));
+ - + - ]
496 [ + - ]: 1 : rb1.reset();
497 [ + - + - : 2 : BOOST_CHECK(!rb1.contains(data[DATASIZE-1]));
+ - ]
498 : :
499 : : // Now roll through data, make sure last 100 entries
500 : : // are always remembered:
501 [ + + ]: 400 : for (int i = 0; i < DATASIZE; i++) {
502 [ + + ]: 399 : if (i >= 100)
503 [ + - + - : 598 : BOOST_CHECK(rb1.contains(data[i-100]));
+ - ]
504 [ + - ]: 399 : rb1.insert(data[i]);
505 [ + - + - : 798 : BOOST_CHECK(rb1.contains(data[i]));
+ - ]
506 : : }
507 : :
508 : : // Insert 999 more random entries:
509 [ + + ]: 1000 : for (int i = 0; i < 999; i++) {
510 [ + - ]: 999 : std::vector<unsigned char> d = RandomData();
511 [ + - ]: 999 : rb1.insert(d);
512 [ + - + - : 1998 : BOOST_CHECK(rb1.contains(d));
+ - ]
513 : 999 : }
514 : : // Sanity check to make sure the filter isn't just filling up:
515 : 1 : nHits = 0;
516 [ + + ]: 400 : for (int i = 0; i < DATASIZE; i++) {
517 [ + - + + ]: 399 : if (rb1.contains(data[i]))
518 : 3 : ++nHits;
519 : : }
520 : : // Expect about 5 false positives
521 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(nHits, 3U);
522 : :
523 : : // last-1000-entry, 0.01% false positive:
524 [ + - ]: 1 : CRollingBloomFilter rb2(1000, 0.001);
525 [ + + ]: 400 : for (int i = 0; i < DATASIZE; i++) {
526 [ + - ]: 399 : rb2.insert(data[i]);
527 : : }
528 : : // ... room for all of them:
529 [ + + ]: 400 : for (int i = 0; i < DATASIZE; i++) {
530 [ + - + - : 798 : BOOST_CHECK(rb2.contains(data[i]));
+ - ]
531 : : }
532 [ + + - - ]: 401 : }
533 : :
534 : : BOOST_AUTO_TEST_SUITE_END()
|