Branch data Line data Source code
1 : : // Copyright (c) 2017-2021 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 <consensus/validation.h>
6 : : #include <key_io.h>
7 : : #include <policy/packages.h>
8 : : #include <policy/policy.h>
9 : : #include <policy/ephemeral_policy.h>
10 : : #include <policy/truc_policy.h>
11 : : #include <primitives/transaction.h>
12 : : #include <random.h>
13 : : #include <script/script.h>
14 : : #include <test/util/setup_common.h>
15 : : #include <test/util/txmempool.h>
16 : : #include <validation.h>
17 : :
18 : : #include <boost/test/unit_test.hpp>
19 : :
20 : :
21 : : BOOST_AUTO_TEST_SUITE(txvalidation_tests)
22 : :
23 : : /**
24 : : * Ensure that the mempool won't accept coinbase transactions.
25 : : */
26 [ + - + - : 7 : BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup)
+ - + - -
+ + - + -
+ - + - +
- + - - +
+ - + - +
- + - + -
+ - - + +
- + - + -
+ - + - +
- + - - +
+ - + - +
- + - + -
+ - - + +
- ]
27 : : {
28 [ + - + - : 2 : CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
+ - ]
29 [ + - ]: 1 : CMutableTransaction coinbaseTx;
30 : :
31 : 1 : coinbaseTx.version = 1;
32 [ + - ]: 1 : coinbaseTx.vin.resize(1);
33 [ + - ]: 1 : coinbaseTx.vout.resize(1);
34 [ + - + - ]: 1 : coinbaseTx.vin[0].scriptSig = CScript() << OP_11 << OP_EQUAL;
35 : 1 : coinbaseTx.vout[0].nValue = 1 * CENT;
36 : 1 : coinbaseTx.vout[0].scriptPubKey = scriptPubKey;
37 : :
38 [ + - + - : 3 : BOOST_CHECK(CTransaction(coinbaseTx).IsCoinBase());
+ - + - ]
39 : :
40 [ + - ]: 1 : LOCK(cs_main);
41 : :
42 [ + - ]: 1 : unsigned int initialPoolSize = m_node.mempool->size();
43 [ + - + - ]: 2 : const MempoolAcceptResult result = m_node.chainman->ProcessTransaction(MakeTransactionRef(coinbaseTx));
44 : :
45 [ + - + - : 2 : BOOST_CHECK(result.m_result_type == MempoolAcceptResult::ResultType::INVALID);
+ - ]
46 : :
47 : : // Check that the transaction hasn't been added to mempool.
48 [ + - + - : 1 : BOOST_CHECK_EQUAL(m_node.mempool->size(), initialPoolSize);
+ - ]
49 : :
50 : : // Check that the validation state reflects the unsuccessful attempt.
51 [ + - + - : 2 : BOOST_CHECK(result.m_state.IsInvalid());
+ - ]
52 [ + - - + : 2 : BOOST_CHECK_EQUAL(result.m_state.GetRejectReason(), "coinbase");
+ - ]
53 [ + - + - ]: 2 : BOOST_CHECK(result.m_state.GetResult() == TxValidationResult::TX_CONSENSUS);
54 [ + - ]: 3 : }
55 : :
56 : : // Generate a number of random, nonexistent outpoints.
57 : 10 : static inline std::vector<COutPoint> random_outpoints(size_t num_outpoints) {
58 : 10 : std::vector<COutPoint> outpoints;
59 [ + + ]: 129 : for (size_t i{0}; i < num_outpoints; ++i) {
60 [ + - ]: 119 : outpoints.emplace_back(Txid::FromUint256(GetRandHash()), 0);
61 : : }
62 : 10 : return outpoints;
63 : 0 : }
64 : :
65 : 1 : static inline std::vector<CPubKey> random_keys(size_t num_keys) {
66 : 1 : std::vector<CPubKey> keys;
67 [ + - ]: 1 : keys.reserve(num_keys);
68 [ + + ]: 3 : for (size_t i{0}; i < num_keys; ++i) {
69 : 2 : CKey key;
70 [ + - ]: 2 : key.MakeNewKey(true);
71 [ + - + - ]: 2 : keys.emplace_back(key.GetPubKey());
72 : 2 : }
73 : 1 : return keys;
74 : 0 : }
75 : :
76 : : // Creates a placeholder tx (not valid) with 25 outputs. Specify the version and the inputs.
77 : 28 : static inline CTransactionRef make_tx(const std::vector<COutPoint>& inputs, int32_t version)
78 : : {
79 : 28 : CMutableTransaction mtx = CMutableTransaction{};
80 : 28 : mtx.version = version;
81 [ - + + - ]: 28 : mtx.vin.resize(inputs.size());
82 [ + - ]: 28 : mtx.vout.resize(25);
83 [ - + + + ]: 168 : for (size_t i{0}; i < inputs.size(); ++i) {
84 : 140 : mtx.vin[i].prevout = inputs[i];
85 : : }
86 [ + + ]: 728 : for (auto i{0}; i < 25; ++i) {
87 [ + - ]: 700 : mtx.vout[i].scriptPubKey = CScript() << OP_TRUE;
88 : 700 : mtx.vout[i].nValue = 10000;
89 : : }
90 [ + - ]: 56 : return MakeTransactionRef(mtx);
91 : 28 : }
92 : :
93 : : static constexpr auto NUM_EPHEMERAL_TX_OUTPUTS = 3;
94 : : static constexpr auto EPHEMERAL_DUST_INDEX = NUM_EPHEMERAL_TX_OUTPUTS - 1;
95 : :
96 : : // Same as make_tx but adds 2 normal outputs and 0-value dust to end of vout
97 : 4 : static inline CTransactionRef make_ephemeral_tx(const std::vector<COutPoint>& inputs, int32_t version)
98 : : {
99 : 4 : CMutableTransaction mtx = CMutableTransaction{};
100 : 4 : mtx.version = version;
101 [ - + + - ]: 4 : mtx.vin.resize(inputs.size());
102 [ - + + + ]: 9 : for (size_t i{0}; i < inputs.size(); ++i) {
103 : 5 : mtx.vin[i].prevout = inputs[i];
104 : : }
105 [ + - ]: 4 : mtx.vout.resize(NUM_EPHEMERAL_TX_OUTPUTS);
106 [ + + ]: 16 : for (auto i{0}; i < NUM_EPHEMERAL_TX_OUTPUTS; ++i) {
107 [ + - ]: 12 : mtx.vout[i].scriptPubKey = CScript() << OP_TRUE;
108 [ + + ]: 20 : mtx.vout[i].nValue = (i == EPHEMERAL_DUST_INDEX) ? 0 : 10000;
109 : : }
110 [ + - ]: 8 : return MakeTransactionRef(mtx);
111 : 4 : }
112 : :
113 [ + - + - : 7 : BOOST_FIXTURE_TEST_CASE(ephemeral_tests, RegTestingSetup)
+ - + - -
+ + - + -
+ - + - +
- + - - +
+ - + - +
- + - + -
+ - - + +
- + - + -
+ - + - +
- + - - +
+ - + - +
- + - + -
+ - - + +
- ]
114 : : {
115 [ - + ]: 1 : CTxMemPool& pool = *Assert(m_node.mempool);
116 [ + - ]: 1 : LOCK2(cs_main, pool.cs);
117 : 1 : TestMemPoolEntryHelper entry;
118 : :
119 [ + - ]: 1 : TxValidationState child_state;
120 [ + - ]: 1 : Wtxid child_wtxid;
121 : :
122 : : // Arbitrary non-0 feerate for these tests
123 [ + - ]: 1 : CFeeRate dustrelay(DUST_RELAY_TX_FEE);
124 : :
125 : : // Basic transaction with dust
126 [ + - + - ]: 1 : auto grandparent_tx_1 = make_ephemeral_tx(random_outpoints(1), /*version=*/2);
127 [ + - ]: 1 : const auto dust_txid = grandparent_tx_1->GetHash();
128 : :
129 : : // Child transaction spending dust
130 [ + - + - : 2 : auto dust_spend = make_tx({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX}}, /*version=*/2);
+ - ]
131 : :
132 : : // We first start with nothing "in the mempool", using package checks
133 : :
134 : : // Trivial single transaction with no dust
135 [ + - + - : 4 : BOOST_CHECK(CheckEphemeralSpends({dust_spend}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
136 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
137 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
138 : :
139 : : // Now with dust, ok because the tx has no dusty parents
140 [ + - + - : 4 : BOOST_CHECK(CheckEphemeralSpends({grandparent_tx_1}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
141 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
142 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
143 : :
144 : : // Dust checks pass
145 [ + - + - : 5 : BOOST_CHECK(CheckEphemeralSpends({grandparent_tx_1, dust_spend}, CFeeRate(0), pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
146 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
147 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
148 [ + - + - : 5 : BOOST_CHECK(CheckEphemeralSpends({grandparent_tx_1, dust_spend}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
149 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
150 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
151 : :
152 [ + - + - : 2 : auto dust_non_spend = make_tx({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX - 1}}, /*version=*/2);
+ - ]
153 : :
154 : : // Child spending non-dust only from parent should be disallowed even if dust otherwise spent
155 [ + - ]: 1 : const auto dust_non_spend_wtxid{dust_non_spend->GetWitnessHash()};
156 [ + - + - : 6 : BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, dust_non_spend, dust_spend}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
157 [ + - + - : 2 : BOOST_CHECK(!child_state.IsValid());
+ - ]
158 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, dust_non_spend_wtxid);
159 : 1 : child_state = TxValidationState();
160 [ + - ]: 1 : child_wtxid = Wtxid();
161 : :
162 [ + - + - : 6 : BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, dust_spend, dust_non_spend}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
163 [ + - + - : 2 : BOOST_CHECK(!child_state.IsValid());
+ - ]
164 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, dust_non_spend_wtxid);
165 : 1 : child_state = TxValidationState();
166 [ + - ]: 1 : child_wtxid = Wtxid();
167 : :
168 [ + - + - : 5 : BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, dust_non_spend}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
169 [ + - + - : 2 : BOOST_CHECK(!child_state.IsValid());
+ - ]
170 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, dust_non_spend_wtxid);
171 : 1 : child_state = TxValidationState();
172 [ + - ]: 1 : child_wtxid = Wtxid();
173 : :
174 [ + - + - ]: 1 : auto grandparent_tx_2 = make_ephemeral_tx(random_outpoints(1), /*version=*/2);
175 [ + - ]: 1 : const auto dust_txid_2 = grandparent_tx_2->GetHash();
176 : :
177 : : // Spend dust from one but not another is ok, as long as second grandparent has no child
178 [ + - + - : 6 : BOOST_CHECK(CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, dust_spend}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
179 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
180 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
181 : :
182 [ + - + - : 2 : auto dust_non_spend_both_parents = make_tx({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX}, COutPoint{dust_txid_2, EPHEMERAL_DUST_INDEX - 1}}, /*version=*/2);
+ - ]
183 : : // But if we spend from the parent, it must spend dust
184 [ + - + - : 6 : BOOST_CHECK(!CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, dust_non_spend_both_parents}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
185 [ + - + - : 2 : BOOST_CHECK(!child_state.IsValid());
+ - ]
186 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, dust_non_spend_both_parents->GetWitnessHash());
187 : 1 : child_state = TxValidationState();
188 [ + - ]: 1 : child_wtxid = Wtxid();
189 : :
190 [ + - + - : 2 : auto dust_spend_both_parents = make_tx({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX}, COutPoint{dust_txid_2, EPHEMERAL_DUST_INDEX}}, /*version=*/2);
+ - ]
191 [ + - + - : 6 : BOOST_CHECK(CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, dust_spend_both_parents}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
192 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
193 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
194 : :
195 : : // Spending other outputs is also correct, as long as the dusty one is spent
196 [ + - ]: 1 : const std::vector<COutPoint> all_outpoints{COutPoint(dust_txid, 0), COutPoint(dust_txid, 1), COutPoint(dust_txid, 2),
197 [ + - ]: 1 : COutPoint(dust_txid_2, 0), COutPoint(dust_txid_2, 1), COutPoint(dust_txid_2, 2)};
198 [ + - ]: 1 : auto dust_spend_all_outpoints = make_tx(all_outpoints, /*version=*/2);
199 [ + - + - : 6 : BOOST_CHECK(CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, dust_spend_all_outpoints}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
200 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
201 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
202 : :
203 : : // 2 grandparents with dust <- 1 dust-spending parent with dust <- child with no dust
204 [ + - + - : 2 : auto parent_with_dust = make_ephemeral_tx({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX}, COutPoint{dust_txid_2, EPHEMERAL_DUST_INDEX}}, /*version=*/2);
+ - ]
205 : : // Ok for parent to have dust
206 [ + - + - : 6 : BOOST_CHECK(CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, parent_with_dust}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
207 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
208 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
209 [ + - + - : 2 : auto child_no_dust = make_tx({COutPoint{parent_with_dust->GetHash(), EPHEMERAL_DUST_INDEX}}, /*version=*/2);
+ - ]
210 [ + - + - : 7 : BOOST_CHECK(CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_no_dust}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
211 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
212 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
213 : :
214 : : // 2 grandparents with dust <- 1 dust-spending parent with dust <- child with dust
215 [ + - + - : 2 : auto child_with_dust = make_ephemeral_tx({COutPoint{parent_with_dust->GetHash(), EPHEMERAL_DUST_INDEX}}, /*version=*/2);
+ - ]
216 [ + - + - : 7 : BOOST_CHECK(CheckEphemeralSpends({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_with_dust}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
217 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
218 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
219 : :
220 : : // Tests with parents in mempool
221 : :
222 : : // Nothing in mempool, this should pass for any transaction
223 [ + - + - : 4 : BOOST_CHECK(CheckEphemeralSpends({grandparent_tx_1}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
224 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
225 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
226 : :
227 : : // Add first grandparent to mempool and fetch entry
228 [ + - + - ]: 1 : TryAddToMempool(pool, entry.FromTx(grandparent_tx_1));
229 : :
230 : : // Ignores ancestors that aren't direct parents
231 [ + - + - : 4 : BOOST_CHECK(CheckEphemeralSpends({child_no_dust}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
232 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
233 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
234 : :
235 : : // Valid spend of dust with grandparent in mempool
236 [ + - + - : 4 : BOOST_CHECK(CheckEphemeralSpends({parent_with_dust}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
237 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
238 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
239 : :
240 : : // Second grandparent in same package
241 [ + - + - : 5 : BOOST_CHECK(CheckEphemeralSpends({parent_with_dust, grandparent_tx_2}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
242 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
243 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
244 : :
245 : : // Order in package doesn't matter
246 [ + - + - : 5 : BOOST_CHECK(CheckEphemeralSpends({grandparent_tx_2, parent_with_dust}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
247 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
248 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
249 : :
250 : : // Add second grandparent to mempool
251 [ + - + - ]: 1 : TryAddToMempool(pool, entry.FromTx(grandparent_tx_2));
252 : :
253 : : // Only spends single dust out of two direct parents
254 [ + - + - : 4 : BOOST_CHECK(!CheckEphemeralSpends({dust_non_spend_both_parents}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
255 [ + - + - : 2 : BOOST_CHECK(!child_state.IsValid());
+ - ]
256 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, dust_non_spend_both_parents->GetWitnessHash());
257 : 1 : child_state = TxValidationState();
258 [ + - ]: 1 : child_wtxid = Wtxid();
259 : :
260 : : // Spends both parents' dust
261 [ + - + - : 4 : BOOST_CHECK(CheckEphemeralSpends({parent_with_dust}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
262 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
263 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
264 : :
265 : : // Now add dusty parent to mempool
266 [ + - + - ]: 1 : TryAddToMempool(pool, entry.FromTx(parent_with_dust));
267 : :
268 : : // Passes dust checks even with non-parent ancestors
269 [ + - + - : 4 : BOOST_CHECK(CheckEphemeralSpends({child_no_dust}, dustrelay, pool, child_state, child_wtxid));
+ - + - +
+ + - - -
- - ]
270 [ + - + - : 2 : BOOST_CHECK(child_state.IsValid());
+ - ]
271 [ + - + - : 1 : BOOST_CHECK_EQUAL(child_wtxid, Wtxid());
+ - ]
272 [ + - + - : 82 : }
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
273 : :
274 [ + - + - : 7 : BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
+ - + - -
+ + - + -
+ - + - +
- + - - +
+ - + - +
- + - + -
+ - - + +
- + - + -
+ - + - +
- + - - +
+ - + - +
- + - + -
+ - - + +
- ]
275 : : {
276 : : // Test TRUC policy helper functions
277 [ - + ]: 1 : CTxMemPool& pool = *Assert(m_node.mempool);
278 [ + - ]: 1 : LOCK2(cs_main, pool.cs);
279 : 1 : TestMemPoolEntryHelper entry;
280 [ + - ]: 1 : std::set<Txid> empty_conflicts_set;
281 : 1 : std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef> empty_parents;
282 : :
283 [ + - + - ]: 1 : auto mempool_tx_v3 = make_tx(random_outpoints(1), /*version=*/3);
284 [ + - + - ]: 1 : TryAddToMempool(pool, entry.FromTx(mempool_tx_v3));
285 [ + - + - ]: 1 : auto mempool_tx_v2 = make_tx(random_outpoints(1), /*version=*/2);
286 [ + - + - ]: 1 : TryAddToMempool(pool, entry.FromTx(mempool_tx_v2));
287 : :
288 : : // Cannot spend from an unconfirmed TRUC transaction unless this tx is also TRUC.
289 : 1 : {
290 : : // mempool_tx_v3
291 : : // ^
292 : : // tx_v2_from_v3
293 [ + - + - : 2 : auto tx_v2_from_v3 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 0}}, /*version=*/2);
+ - ]
294 [ + - + - ]: 1 : auto parents_v2_from_v3 = pool.GetParents(entry.FromTx(tx_v2_from_v3));
295 [ + - ]: 1 : const auto expected_error_str{strprintf("non-version=3 tx %s (wtxid=%s) cannot spend from version=3 tx %s (wtxid=%s)",
296 [ + - + - ]: 2 : tx_v2_from_v3->GetHash().ToString(), tx_v2_from_v3->GetWitnessHash().ToString(),
297 [ + - + - : 3 : mempool_tx_v3->GetHash().ToString(), mempool_tx_v3->GetWitnessHash().ToString())};
+ - + - ]
298 [ + - + - ]: 1 : auto result_v2_from_v3{SingleTRUCChecks(pool, tx_v2_from_v3, parents_v2_from_v3, empty_conflicts_set, GetVirtualTransactionSize(*tx_v2_from_v3))};
299 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_v2_from_v3->first, expected_error_str);
300 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_v2_from_v3->second, nullptr);
301 : :
302 [ + + + - : 3 : Package package_v3_v2{mempool_tx_v3, tx_v2_from_v3};
- - - - ]
303 [ + - + - : 1 : BOOST_CHECK_EQUAL(*PackageTRUCChecks(pool, tx_v2_from_v3, GetVirtualTransactionSize(*tx_v2_from_v3), package_v3_v2, empty_parents), expected_error_str);
+ - + - ]
304 [ + - + - : 3 : BOOST_CHECK_EQUAL(*PackageTRUCChecks(pool, tx_v2_from_v3, GetVirtualTransactionSize(*tx_v2_from_v3), {tx_v2_from_v3}, parents_v2_from_v3), expected_error_str);
+ - + - +
+ + - - -
- - ]
305 : :
306 : : // mempool_tx_v3 mempool_tx_v2
307 : : // ^ ^
308 : : // tx_v2_from_v2_and_v3
309 [ + - + - : 2 : auto tx_v2_from_v2_and_v3 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 0}, COutPoint{mempool_tx_v2->GetHash(), 0}}, /*version=*/2);
+ - ]
310 [ + - + - ]: 1 : auto parents_2_from_both{pool.GetParents(entry.FromTx(tx_v2_from_v2_and_v3))};
311 [ + - ]: 1 : const auto expected_error_str_2{strprintf("non-version=3 tx %s (wtxid=%s) cannot spend from version=3 tx %s (wtxid=%s)",
312 [ + - + - ]: 2 : tx_v2_from_v2_and_v3->GetHash().ToString(), tx_v2_from_v2_and_v3->GetWitnessHash().ToString(),
313 [ + - + - : 3 : mempool_tx_v3->GetHash().ToString(), mempool_tx_v3->GetWitnessHash().ToString())};
+ - + - ]
314 [ + - + - ]: 1 : auto result_v2_from_both{SingleTRUCChecks(pool, tx_v2_from_v2_and_v3, parents_2_from_both, empty_conflicts_set, GetVirtualTransactionSize(*tx_v2_from_v2_and_v3))};
315 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_v2_from_both->first, expected_error_str_2);
316 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_v2_from_both->second, nullptr);
317 : :
318 [ + + + - : 4 : Package package_v3_v2_v2{mempool_tx_v3, mempool_tx_v2, tx_v2_from_v2_and_v3};
- - - - ]
319 [ + - + - : 1 : BOOST_CHECK_EQUAL(*PackageTRUCChecks(pool, tx_v2_from_v2_and_v3, GetVirtualTransactionSize(*tx_v2_from_v2_and_v3), package_v3_v2_v2, empty_parents), expected_error_str_2);
+ - + - ]
320 [ + - + - ]: 2 : }
321 : :
322 : : // TRUC cannot spend from an unconfirmed non-TRUC transaction.
323 : 1 : {
324 : : // mempool_tx_v2
325 : : // ^
326 : : // tx_v3_from_v2
327 [ + - + - : 2 : auto tx_v3_from_v2 = make_tx({COutPoint{mempool_tx_v2->GetHash(), 0}}, /*version=*/3);
+ - ]
328 [ + - + - ]: 1 : auto parents_v3_from_v2{pool.GetParents(entry.FromTx(tx_v3_from_v2))};
329 [ + - ]: 1 : const auto expected_error_str{strprintf("version=3 tx %s (wtxid=%s) cannot spend from non-version=3 tx %s (wtxid=%s)",
330 [ + - + - ]: 2 : tx_v3_from_v2->GetHash().ToString(), tx_v3_from_v2->GetWitnessHash().ToString(),
331 [ + - + - : 3 : mempool_tx_v2->GetHash().ToString(), mempool_tx_v2->GetWitnessHash().ToString())};
+ - + - ]
332 [ + - + - ]: 1 : auto result_v3_from_v2{SingleTRUCChecks(pool, tx_v3_from_v2, parents_v3_from_v2, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_from_v2))};
333 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_v3_from_v2->first, expected_error_str);
334 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_v3_from_v2->second, nullptr);
335 : :
336 [ + + + - : 3 : Package package_v2_v3{mempool_tx_v2, tx_v3_from_v2};
- - - - ]
337 [ + - + - : 1 : BOOST_CHECK_EQUAL(*PackageTRUCChecks(pool, tx_v3_from_v2, GetVirtualTransactionSize(*tx_v3_from_v2), package_v2_v3, empty_parents), expected_error_str);
+ - + - ]
338 [ + - + - : 3 : BOOST_CHECK_EQUAL(*PackageTRUCChecks(pool, tx_v3_from_v2, GetVirtualTransactionSize(*tx_v3_from_v2), {tx_v3_from_v2}, parents_v3_from_v2), expected_error_str);
+ - + - +
+ + - - -
- - ]
339 : :
340 : : // mempool_tx_v3 mempool_tx_v2
341 : : // ^ ^
342 : : // tx_v3_from_v2_and_v3
343 [ + - + - : 2 : auto tx_v3_from_v2_and_v3 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 0}, COutPoint{mempool_tx_v2->GetHash(), 0}}, /*version=*/3);
+ - ]
344 [ + - + - ]: 1 : auto parents_v3_from_both{pool.GetParents(entry.FromTx(tx_v3_from_v2_and_v3))};
345 [ + - ]: 1 : const auto expected_error_str_2{strprintf("version=3 tx %s (wtxid=%s) cannot spend from non-version=3 tx %s (wtxid=%s)",
346 [ + - + - ]: 2 : tx_v3_from_v2_and_v3->GetHash().ToString(), tx_v3_from_v2_and_v3->GetWitnessHash().ToString(),
347 [ + - + - : 3 : mempool_tx_v2->GetHash().ToString(), mempool_tx_v2->GetWitnessHash().ToString())};
+ - + - ]
348 [ + - + - ]: 1 : auto result_v3_from_both{SingleTRUCChecks(pool, tx_v3_from_v2_and_v3, parents_v3_from_both, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_from_v2_and_v3))};
349 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_v3_from_both->first, expected_error_str_2);
350 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_v3_from_both->second, nullptr);
351 : :
352 : : // tx_v3_from_v2_and_v3 also violates TRUC_ANCESTOR_LIMIT.
353 [ + - ]: 1 : const auto expected_error_str_3{strprintf("tx %s (wtxid=%s) would have too many ancestors",
354 [ + - + - : 2 : tx_v3_from_v2_and_v3->GetHash().ToString(), tx_v3_from_v2_and_v3->GetWitnessHash().ToString())};
+ - ]
355 [ + + + - : 4 : Package package_v3_v2_v3{mempool_tx_v3, mempool_tx_v2, tx_v3_from_v2_and_v3};
- - - - ]
356 [ + - + - : 1 : BOOST_CHECK_EQUAL(*PackageTRUCChecks(pool, tx_v3_from_v2_and_v3, GetVirtualTransactionSize(*tx_v3_from_v2_and_v3), package_v3_v2_v3, empty_parents), expected_error_str_3);
+ - + - ]
357 [ + - + - ]: 2 : }
358 : : // V3 from V3 is ok, and non-V3 from non-V3 is ok.
359 : 1 : {
360 : : // mempool_tx_v3
361 : : // ^
362 : : // tx_v3_from_v3
363 [ + - + - : 2 : auto tx_v3_from_v3 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 0}}, /*version=*/3);
+ - ]
364 [ + - + - ]: 1 : auto parents_v3{pool.GetParents(entry.FromTx(tx_v3_from_v3))};
365 [ + - + - : 2 : BOOST_CHECK(SingleTRUCChecks(pool, tx_v3_from_v3, parents_v3, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_from_v3))
+ - + - +
- ]
366 : : == std::nullopt);
367 : :
368 [ + + + - : 3 : Package package_v3_v3{mempool_tx_v3, tx_v3_from_v3};
- - - - ]
369 [ + - + - : 2 : BOOST_CHECK(PackageTRUCChecks(pool, tx_v3_from_v3, GetVirtualTransactionSize(*tx_v3_from_v3), package_v3_v3, empty_parents) == std::nullopt);
+ - + - +
- ]
370 : :
371 : : // mempool_tx_v2
372 : : // ^
373 : : // tx_v2_from_v2
374 [ + - + - : 2 : auto tx_v2_from_v2 = make_tx({COutPoint{mempool_tx_v2->GetHash(), 0}}, /*version=*/2);
+ - ]
375 [ + - + - ]: 1 : auto parents_v2{pool.GetParents(entry.FromTx(tx_v2_from_v2))};
376 [ + - + - : 2 : BOOST_CHECK(SingleTRUCChecks(pool, tx_v2_from_v2, parents_v2, empty_conflicts_set, GetVirtualTransactionSize(*tx_v2_from_v2))
+ - + - +
- ]
377 : : == std::nullopt);
378 : :
379 [ + + + - : 3 : Package package_v2_v2{mempool_tx_v2, tx_v2_from_v2};
- - - - ]
380 [ + - + - : 2 : BOOST_CHECK(PackageTRUCChecks(pool, tx_v2_from_v2, GetVirtualTransactionSize(*tx_v2_from_v2), package_v2_v2, empty_parents) == std::nullopt);
+ - + - ]
381 [ + - + - ]: 2 : }
382 : :
383 : : // Tx spending TRUC cannot have too many mempool ancestors
384 : : // Configuration where the tx has multiple direct parents.
385 : 1 : {
386 : 1 : Package package_multi_parents;
387 : 1 : std::vector<COutPoint> mempool_outpoints;
388 [ + - ]: 1 : mempool_outpoints.emplace_back(mempool_tx_v3->GetHash(), 0);
389 [ + - ]: 1 : package_multi_parents.emplace_back(mempool_tx_v3);
390 [ + + ]: 3 : for (size_t i{0}; i < 2; ++i) {
391 [ + - + - ]: 2 : auto mempool_tx = make_tx(random_outpoints(i + 1), /*version=*/3);
392 [ + - + - ]: 2 : TryAddToMempool(pool, entry.FromTx(mempool_tx));
393 [ + - ]: 2 : mempool_outpoints.emplace_back(mempool_tx->GetHash(), 0);
394 [ + - ]: 2 : package_multi_parents.emplace_back(mempool_tx);
395 : 2 : }
396 [ + - ]: 1 : auto tx_v3_multi_parent = make_tx(mempool_outpoints, /*version=*/3);
397 [ + - ]: 1 : package_multi_parents.emplace_back(tx_v3_multi_parent);
398 [ + - + - ]: 1 : auto parents{pool.GetParents(entry.FromTx(tx_v3_multi_parent))};
399 [ + - - + : 1 : BOOST_CHECK_EQUAL(parents.size(), 3);
+ - ]
400 [ + - ]: 1 : const auto expected_error_str{strprintf("tx %s (wtxid=%s) would have too many ancestors",
401 [ + - + - : 2 : tx_v3_multi_parent->GetHash().ToString(), tx_v3_multi_parent->GetWitnessHash().ToString())};
+ - ]
402 [ + - + - ]: 1 : auto result{SingleTRUCChecks(pool, tx_v3_multi_parent, parents, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_multi_parent))};
403 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result->first, expected_error_str);
404 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result->second, nullptr);
405 : :
406 [ + - + - : 1 : BOOST_CHECK_EQUAL(*PackageTRUCChecks(pool, tx_v3_multi_parent, GetVirtualTransactionSize(*tx_v3_multi_parent), package_multi_parents, empty_parents),
+ - + - ]
407 : : expected_error_str);
408 [ + - ]: 2 : }
409 : :
410 : : // Configuration where the tx is in a multi-generation chain.
411 : 1 : {
412 : 1 : Package package_multi_gen;
413 : 1 : CTransactionRef middle_tx;
414 [ + - ]: 1 : auto last_outpoint{random_outpoints(1)[0]};
415 [ + + ]: 3 : for (size_t i{0}; i < 2; ++i) {
416 [ + - + - : 4 : auto mempool_tx = make_tx({last_outpoint}, /*version=*/3);
+ - ]
417 [ + - + - ]: 2 : TryAddToMempool(pool, entry.FromTx(mempool_tx));
418 [ + - ]: 2 : last_outpoint = COutPoint{mempool_tx->GetHash(), 0};
419 [ + - ]: 2 : package_multi_gen.emplace_back(mempool_tx);
420 [ + + ]: 2 : if (i == 1) middle_tx = mempool_tx;
421 : 2 : }
422 [ + - + - : 2 : auto tx_v3_multi_gen = make_tx({last_outpoint}, /*version=*/3);
+ - ]
423 [ + - ]: 1 : package_multi_gen.emplace_back(tx_v3_multi_gen);
424 [ + - + - ]: 1 : auto parents{pool.GetParents(entry.FromTx(tx_v3_multi_gen))};
425 [ + - ]: 1 : const auto expected_error_str{strprintf("tx %s (wtxid=%s) would have too many ancestors",
426 [ + - + - : 2 : tx_v3_multi_gen->GetHash().ToString(), tx_v3_multi_gen->GetWitnessHash().ToString())};
+ - ]
427 [ + - + - ]: 1 : auto result{SingleTRUCChecks(pool, tx_v3_multi_gen, parents, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_multi_gen))};
428 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result->first, expected_error_str);
429 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result->second, nullptr);
430 : :
431 : : // Middle tx is what triggers a failure for the grandchild:
432 [ + - + - : 1 : BOOST_CHECK_EQUAL(*PackageTRUCChecks(pool, middle_tx, GetVirtualTransactionSize(*middle_tx), package_multi_gen, empty_parents), expected_error_str);
+ - + - ]
433 [ + - + - : 2 : BOOST_CHECK(PackageTRUCChecks(pool, tx_v3_multi_gen, GetVirtualTransactionSize(*tx_v3_multi_gen), package_multi_gen, empty_parents) == std::nullopt);
+ - + - ]
434 [ + - + - ]: 3 : }
435 : :
436 : : // Tx spending TRUC cannot be too large in virtual size.
437 [ + - ]: 1 : auto many_inputs{random_outpoints(100)};
438 [ + - ]: 1 : many_inputs.emplace_back(mempool_tx_v3->GetHash(), 0);
439 : 1 : {
440 [ + - ]: 1 : auto tx_v3_child_big = make_tx(many_inputs, /*version=*/3);
441 [ + - ]: 1 : const auto vsize{GetVirtualTransactionSize(*tx_v3_child_big)};
442 [ + - + - ]: 1 : auto parents{pool.GetParents(entry.FromTx(tx_v3_child_big))};
443 [ + - ]: 1 : const auto expected_error_str{strprintf("version=3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
444 [ + - + - : 2 : tx_v3_child_big->GetHash().ToString(), tx_v3_child_big->GetWitnessHash().ToString(), vsize, TRUC_CHILD_MAX_VSIZE)};
+ - ]
445 [ + - + - ]: 1 : auto result{SingleTRUCChecks(pool, tx_v3_child_big, parents, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_child_big))};
446 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result->first, expected_error_str);
447 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result->second, nullptr);
448 : :
449 [ + + + - : 3 : Package package_child_big{mempool_tx_v3, tx_v3_child_big};
- - - - ]
450 [ + - + - : 1 : BOOST_CHECK_EQUAL(*PackageTRUCChecks(pool, tx_v3_child_big, GetVirtualTransactionSize(*tx_v3_child_big), package_child_big, empty_parents),
+ - + - ]
451 : : expected_error_str);
452 [ + - ]: 1 : }
453 : :
454 : : // Tx spending TRUC cannot have too many sigops.
455 : : // This child has 10 P2WSH multisig inputs.
456 [ + - ]: 1 : auto multisig_outpoints{random_outpoints(10)};
457 [ + - ]: 1 : multisig_outpoints.emplace_back(mempool_tx_v3->GetHash(), 0);
458 [ + - ]: 1 : auto keys{random_keys(2)};
459 : 1 : CScript script_multisig;
460 [ + - ]: 1 : script_multisig << OP_1;
461 [ + + ]: 3 : for (const auto& key : keys) {
462 [ + - ]: 4 : script_multisig << ToByteVector(key);
463 : : }
464 [ + - + - ]: 1 : script_multisig << OP_2 << OP_CHECKMULTISIG;
465 : 1 : {
466 [ + - ]: 1 : CMutableTransaction mtx_many_sigops = CMutableTransaction{};
467 : 1 : mtx_many_sigops.version = TRUC_VERSION;
468 [ + + ]: 12 : for (const auto& outpoint : multisig_outpoints) {
469 [ + - ]: 11 : mtx_many_sigops.vin.emplace_back(outpoint);
470 [ + - + - ]: 22 : mtx_many_sigops.vin.back().scriptWitness.stack.emplace_back(script_multisig.begin(), script_multisig.end());
471 : : }
472 [ + - ]: 1 : mtx_many_sigops.vout.resize(1);
473 [ + - ]: 1 : mtx_many_sigops.vout.back().scriptPubKey = CScript() << OP_TRUE;
474 : 1 : mtx_many_sigops.vout.back().nValue = 10000;
475 [ + - ]: 1 : auto tx_many_sigops{MakeTransactionRef(mtx_many_sigops)};
476 : :
477 [ + - + - ]: 1 : auto parents{pool.GetParents(entry.FromTx(tx_many_sigops))};
478 : : // legacy uses fAccurate = false, and the maximum number of multisig keys is used
479 [ - + + - ]: 1 : const int64_t total_sigops{static_cast<int64_t>(tx_many_sigops->vin.size()) * static_cast<int64_t>(script_multisig.GetSigOpCount(/*fAccurate=*/false))};
480 [ + - - + : 1 : BOOST_CHECK_EQUAL(total_sigops, tx_many_sigops->vin.size() * MAX_PUBKEYS_PER_MULTISIG);
+ - ]
481 [ + - ]: 1 : const int64_t bip141_vsize{GetVirtualTransactionSize(*tx_many_sigops)};
482 : : // Weight limit is not reached...
483 [ + - + - : 2 : BOOST_CHECK(SingleTRUCChecks(pool, tx_many_sigops, parents, empty_conflicts_set, bip141_vsize) == std::nullopt);
+ - + - ]
484 : : // ...but sigop limit is.
485 : 1 : const auto expected_error_str{strprintf("version=3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
486 [ + - + - ]: 2 : tx_many_sigops->GetHash().ToString(), tx_many_sigops->GetWitnessHash().ToString(),
487 [ + - + - ]: 2 : total_sigops * DEFAULT_BYTES_PER_SIGOP / WITNESS_SCALE_FACTOR, TRUC_CHILD_MAX_VSIZE)};
488 : 1 : auto result{SingleTRUCChecks(pool, tx_many_sigops, parents, empty_conflicts_set,
489 [ + - + - ]: 1 : GetVirtualTransactionSize(*tx_many_sigops, /*nSigOpCost=*/total_sigops, /*bytes_per_sigop=*/ DEFAULT_BYTES_PER_SIGOP))};
490 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result->first, expected_error_str);
491 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result->second, nullptr);
492 : :
493 [ + + + - : 3 : Package package_child_sigops{mempool_tx_v3, tx_many_sigops};
- - - - ]
494 [ + - + - : 1 : BOOST_CHECK_EQUAL(*PackageTRUCChecks(pool, tx_many_sigops, total_sigops * DEFAULT_BYTES_PER_SIGOP / WITNESS_SCALE_FACTOR, package_child_sigops, empty_parents),
+ - ]
495 : : expected_error_str);
496 [ + - ]: 2 : }
497 : :
498 : : // Parent + child with TRUC in the mempool. Child is allowed as long as it is under TRUC_CHILD_MAX_VSIZE.
499 [ + - + - : 2 : auto tx_mempool_v3_child = make_tx({COutPoint{mempool_tx_v3->GetHash(), 0}}, /*version=*/3);
+ - ]
500 : 1 : {
501 [ + - + - : 2 : BOOST_CHECK(GetTransactionWeight(*tx_mempool_v3_child) <= TRUC_CHILD_MAX_VSIZE * WITNESS_SCALE_FACTOR);
+ - ]
502 [ + - + - ]: 1 : auto parents{pool.GetParents(entry.FromTx(tx_mempool_v3_child))};
503 [ + - + - : 2 : BOOST_CHECK(SingleTRUCChecks(pool, tx_mempool_v3_child, parents, empty_conflicts_set, GetVirtualTransactionSize(*tx_mempool_v3_child)) == std::nullopt);
+ - + - +
- ]
504 [ + - + - ]: 1 : TryAddToMempool(pool, entry.FromTx(tx_mempool_v3_child));
505 : :
506 [ + + + - : 3 : Package package_v3_1p1c{mempool_tx_v3, tx_mempool_v3_child};
- - - - ]
507 [ + - + - : 2 : BOOST_CHECK(PackageTRUCChecks(pool, tx_mempool_v3_child, GetVirtualTransactionSize(*tx_mempool_v3_child), package_v3_1p1c, empty_parents) == std::nullopt);
+ - + - ]
508 : 1 : }
509 : :
510 : : // A TRUC transaction cannot have more than 1 descendant. Sibling is returned when exactly 1 exists.
511 : 1 : {
512 [ + - + - : 2 : auto tx_v3_child2 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 1}}, /*version=*/3);
+ - ]
513 : : // Configuration where parent already has 1 other child in mempool
514 [ + - + - ]: 1 : auto parents_1sibling{pool.GetParents(entry.FromTx(tx_v3_child2))};
515 [ + - ]: 1 : const auto expected_error_str{strprintf("tx %s (wtxid=%s) would exceed descendant count limit",
516 [ + - + - : 2 : mempool_tx_v3->GetHash().ToString(), mempool_tx_v3->GetWitnessHash().ToString())};
+ - ]
517 [ + - + - ]: 1 : auto result_with_sibling_eviction{SingleTRUCChecks(pool, tx_v3_child2, parents_1sibling, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_child2))};
518 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_with_sibling_eviction->first, expected_error_str);
519 : : // The other mempool child is returned to allow for sibling eviction.
520 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_with_sibling_eviction->second, tx_mempool_v3_child);
521 : :
522 : : // If directly replacing the child, make sure there is no double-counting.
523 [ + - + - : 2 : BOOST_CHECK(SingleTRUCChecks(pool, tx_v3_child2, parents_1sibling, {tx_mempool_v3_child->GetHash()}, GetVirtualTransactionSize(*tx_v3_child2))
+ - + - +
- + - ]
524 : : == std::nullopt);
525 : :
526 [ + + + - : 4 : Package package_v3_1p2c{mempool_tx_v3, tx_mempool_v3_child, tx_v3_child2};
- - - - ]
527 [ + - + - : 1 : BOOST_CHECK_EQUAL(*PackageTRUCChecks(pool, tx_v3_child2, GetVirtualTransactionSize(*tx_v3_child2), package_v3_1p2c, empty_parents),
+ - + - ]
528 : : expected_error_str);
529 : :
530 : : // Configuration where parent already has 2 other children in mempool (no sibling eviction allowed). This may happen as the result of a reorg.
531 [ + - + - ]: 1 : TryAddToMempool(pool, entry.FromTx(tx_v3_child2));
532 [ + - + - : 2 : auto tx_v3_child3 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 24}}, /*version=*/3);
+ - ]
533 [ + - ]: 1 : auto entry_mempool_parent = pool.GetIter(mempool_tx_v3->GetHash()).value();
534 [ + - + - : 1 : BOOST_CHECK_EQUAL(pool.GetDescendantCount(entry_mempool_parent), 3);
+ - ]
535 [ + - + - ]: 1 : auto parents_2siblings{pool.GetParents(entry.FromTx(tx_v3_child3))};
536 : :
537 [ + - + - ]: 1 : auto result_2children{SingleTRUCChecks(pool, tx_v3_child3, parents_2siblings, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_child3))};
538 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_2children->first, expected_error_str);
539 : : // The other mempool child is not returned because sibling eviction is not allowed.
540 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_2children->second, nullptr);
541 [ + - + - ]: 2 : }
542 : :
543 : : // Sibling eviction: parent already has 1 other child, which also has its own child (no sibling eviction allowed). This may happen as the result of a reorg.
544 : 1 : {
545 [ + - + - ]: 1 : auto tx_mempool_grandparent = make_tx(random_outpoints(1), /*version=*/3);
546 [ + - + - : 2 : auto tx_mempool_sibling = make_tx({COutPoint{tx_mempool_grandparent->GetHash(), 0}}, /*version=*/3);
+ - ]
547 [ + - + - : 2 : auto tx_mempool_nibling = make_tx({COutPoint{tx_mempool_sibling->GetHash(), 0}}, /*version=*/3);
+ - ]
548 [ + - + - : 2 : auto tx_to_submit = make_tx({COutPoint{tx_mempool_grandparent->GetHash(), 1}}, /*version=*/3);
+ - ]
549 : :
550 [ + - + - ]: 1 : TryAddToMempool(pool, entry.FromTx(tx_mempool_grandparent));
551 [ + - + - ]: 1 : TryAddToMempool(pool, entry.FromTx(tx_mempool_sibling));
552 [ + - + - ]: 1 : TryAddToMempool(pool, entry.FromTx(tx_mempool_nibling));
553 : :
554 [ + - + - ]: 1 : auto parents_3gen{pool.GetParents(entry.FromTx(tx_to_submit))};
555 [ + - ]: 1 : const auto expected_error_str{strprintf("tx %s (wtxid=%s) would exceed descendant count limit",
556 [ + - + - : 2 : tx_mempool_grandparent->GetHash().ToString(), tx_mempool_grandparent->GetWitnessHash().ToString())};
+ - ]
557 [ + - + - ]: 1 : auto result_3gen{SingleTRUCChecks(pool, tx_to_submit, parents_3gen, empty_conflicts_set, GetVirtualTransactionSize(*tx_to_submit))};
558 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_3gen->first, expected_error_str);
559 : : // The other mempool child is not returned because sibling eviction is not allowed.
560 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result_3gen->second, nullptr);
561 [ + - + - : 5 : }
+ - + - +
- ]
562 : :
563 : : // Configuration where tx has multiple generations of descendants is not tested because that is
564 : : // equivalent to the tx with multiple generations of ancestors.
565 [ + - + - : 42 : }
- + + - +
- + - + -
+ - - + +
- + - - +
+ - + - +
- + - + -
- + + - +
- - + + -
+ - - + +
- + - - +
+ - + - -
+ + - + -
- + + - +
- + - - +
+ - + - +
- + - ]
566 : :
567 : : BOOST_AUTO_TEST_SUITE_END()
|