Branch data Line data Source code
1 : : // Copyright (c) 2021-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 <consensus/validation.h>
6 : : #include <node/context.h>
7 : : #include <node/mempool_args.h>
8 : : #include <node/miner.h>
9 : : #include <policy/truc_policy.h>
10 : : #include <test/fuzz/FuzzedDataProvider.h>
11 : : #include <test/fuzz/fuzz.h>
12 : : #include <test/fuzz/util.h>
13 : : #include <test/fuzz/util/mempool.h>
14 : : #include <test/util/mining.h>
15 : : #include <test/util/script.h>
16 : : #include <test/util/setup_common.h>
17 : : #include <test/util/txmempool.h>
18 : : #include <util/check.h>
19 : : #include <util/rbf.h>
20 : : #include <util/translation.h>
21 : : #include <validation.h>
22 : : #include <validationinterface.h>
23 : :
24 : : using node::BlockAssembler;
25 : : using node::NodeContext;
26 : : using util::ToString;
27 : :
28 : : namespace {
29 : :
30 : : const TestingSetup* g_setup;
31 : : std::vector<COutPoint> g_outpoints_coinbase_init_mature;
32 : : std::vector<COutPoint> g_outpoints_coinbase_init_immature;
33 : :
34 : : struct MockedTxPool : public CTxMemPool {
35 : 313070 : void RollingFeeUpdate() EXCLUSIVE_LOCKS_REQUIRED(!cs)
36 : : {
37 : 313070 : LOCK(cs);
38 [ + - ]: 313070 : lastRollingFeeUpdate = GetTime();
39 [ + - ]: 313070 : blockSinceLastRollingFeeBump = true;
40 : 313070 : }
41 : : };
42 : :
43 : 2 : void initialize_tx_pool()
44 : : {
45 [ + - + - ]: 4 : static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
46 : 2 : g_setup = testing_setup.get();
47 : :
48 : 2 : BlockAssembler::Options options;
49 : 2 : options.coinbase_output_script = P2WSH_OP_TRUE;
50 : :
51 [ + + ]: 402 : for (int i = 0; i < 2 * COINBASE_MATURITY; ++i) {
52 [ + - ]: 400 : COutPoint prevout{MineBlock(g_setup->m_node, options)};
53 : : // Remember the txids to avoid expensive disk access later on
54 [ + + ]: 400 : auto& outpoints = i < COINBASE_MATURITY ?
55 : : g_outpoints_coinbase_init_mature :
56 : : g_outpoints_coinbase_init_immature;
57 [ + - ]: 400 : outpoints.push_back(prevout);
58 : : }
59 [ + - ]: 2 : g_setup->m_node.validation_signals->SyncWithValidationInterfaceQueue();
60 [ + - ]: 4 : }
61 : :
62 : : struct TransactionsDelta final : public CValidationInterface {
63 : : std::set<CTransactionRef>& m_removed;
64 : : std::set<CTransactionRef>& m_added;
65 : :
66 : 155093 : explicit TransactionsDelta(std::set<CTransactionRef>& r, std::set<CTransactionRef>& a)
67 : 155093 : : m_removed{r}, m_added{a} {}
68 : :
69 : 40025 : void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /* mempool_sequence */) override
70 : : {
71 : 40025 : Assert(m_added.insert(tx.info.m_tx).second);
72 : 40025 : }
73 : :
74 : 32729 : void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t /* mempool_sequence */) override
75 : : {
76 : 32729 : Assert(m_removed.insert(tx).second);
77 : 32729 : }
78 : : };
79 : :
80 : 6550 : void SetMempoolConstraints(ArgsManager& args, FuzzedDataProvider& fuzzed_data_provider)
81 : : {
82 [ + - + - ]: 13100 : args.ForceSetArg("-limitancestorcount",
83 [ + - ]: 6550 : ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 50)));
84 [ + - + - ]: 13100 : args.ForceSetArg("-limitancestorsize",
85 [ + - ]: 6550 : ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 202)));
86 [ + - + - ]: 13100 : args.ForceSetArg("-limitdescendantcount",
87 [ + - ]: 6550 : ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 50)));
88 [ + - + - ]: 13100 : args.ForceSetArg("-limitdescendantsize",
89 [ + - ]: 6550 : ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 202)));
90 [ + - + - ]: 13100 : args.ForceSetArg("-maxmempool",
91 [ + - ]: 6550 : ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 200)));
92 [ + - + - ]: 13100 : args.ForceSetArg("-mempoolexpiry",
93 [ + - ]: 6550 : ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 999)));
94 : 6550 : }
95 : :
96 : 6550 : void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, Chainstate& chainstate)
97 : : {
98 [ + - + - ]: 19650 : WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
99 : 6550 : {
100 : 6550 : BlockAssembler::Options options;
101 : 6550 : options.nBlockMaxWeight = fuzzed_data_provider.ConsumeIntegralInRange(0U, MAX_BLOCK_WEIGHT);
102 [ + - ]: 6550 : options.blockMinFeeRate = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
103 [ + - ]: 6550 : auto assembler = BlockAssembler{chainstate, &tx_pool, options};
104 [ + - ]: 6550 : auto block_template = assembler.CreateNewBlock();
105 [ + - ]: 6550 : Assert(block_template->block.vtx.size() >= 1);
106 : 6550 : }
107 : 6550 : const auto info_all = tx_pool.infoAll();
108 [ + + ]: 6550 : if (!info_all.empty()) {
109 [ + - ]: 3586 : const auto& tx_to_remove = *PickValue(fuzzed_data_provider, info_all).tx;
110 [ + - + - ]: 10758 : WITH_LOCK(tx_pool.cs, tx_pool.removeRecursive(tx_to_remove, MemPoolRemovalReason::BLOCK /* dummy */));
111 [ + - - + ]: 3586 : assert(tx_pool.size() < info_all.size());
112 [ + - + - : 10758 : WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
+ - ]
113 : : }
114 [ + - ]: 6550 : g_setup->m_node.validation_signals->SyncWithValidationInterfaceQueue();
115 : 6550 : }
116 : :
117 : 297521 : void MockTime(FuzzedDataProvider& fuzzed_data_provider, const Chainstate& chainstate)
118 : : {
119 : 297521 : const auto time = ConsumeTime(fuzzed_data_provider,
120 [ + - ]: 595042 : chainstate.m_chain.Tip()->GetMedianTimePast() + 1,
121 [ + - ]: 297521 : std::numeric_limits<decltype(chainstate.m_chain.Tip()->nTime)>::max());
122 : 297521 : SetMockTime(time);
123 : 297521 : }
124 : :
125 : 6550 : std::unique_ptr<CTxMemPool> MakeMempool(FuzzedDataProvider& fuzzed_data_provider, const NodeContext& node)
126 : : {
127 : : // Take the default options for tests...
128 : 6550 : CTxMemPool::Options mempool_opts{MemPoolOptionsForTest(node)};
129 : :
130 : : // ...override specific options for this specific fuzz suite
131 : 6550 : mempool_opts.check_ratio = 1;
132 : 6550 : mempool_opts.require_standard = fuzzed_data_provider.ConsumeBool();
133 : :
134 : : // ...and construct a CTxMemPool from it
135 [ + - ]: 6550 : bilingual_str error;
136 [ + - ]: 6550 : auto mempool{std::make_unique<CTxMemPool>(std::move(mempool_opts), error)};
137 : : // ... ignore the error since it might be beneficial to fuzz even when the
138 : : // mempool size is unreasonably small
139 [ + + + - : 8302 : Assert(error.empty() || error.original.starts_with("-maxmempool must be at least "));
+ - ]
140 : 6550 : return mempool;
141 : 6550 : }
142 : :
143 : 155093 : void CheckATMPInvariants(const MempoolAcceptResult& res, bool txid_in_mempool, bool wtxid_in_mempool)
144 : : {
145 : :
146 [ + + - - : 155093 : switch (res.m_result_type) {
- ]
147 : 40025 : case MempoolAcceptResult::ResultType::VALID:
148 : 40025 : {
149 : 40025 : Assert(txid_in_mempool);
150 : 40025 : Assert(wtxid_in_mempool);
151 : 40025 : Assert(res.m_state.IsValid());
152 : 40025 : Assert(!res.m_state.IsInvalid());
153 : 40025 : Assert(res.m_vsize);
154 : 40025 : Assert(res.m_base_fees);
155 : 40025 : Assert(res.m_effective_feerate);
156 : 40025 : Assert(res.m_wtxids_fee_calculations);
157 : 40025 : Assert(!res.m_other_wtxid);
158 : 40025 : break;
159 : : }
160 : 115068 : case MempoolAcceptResult::ResultType::INVALID:
161 : 115068 : {
162 : : // It may be already in the mempool since in ATMP cases we don't set MEMPOOL_ENTRY or DIFFERENT_WITNESS
163 : 115068 : Assert(!res.m_state.IsValid());
164 : 115068 : Assert(res.m_state.IsInvalid());
165 : :
166 : 115068 : const bool is_reconsiderable{res.m_state.GetResult() == TxValidationResult::TX_RECONSIDERABLE};
167 : 115068 : Assert(!res.m_vsize);
168 : 115068 : Assert(!res.m_base_fees);
169 : : // Fee information is provided if the failure is TX_RECONSIDERABLE.
170 : : // In other cases, validation may be unable or unwilling to calculate the fees.
171 : 115068 : Assert(res.m_effective_feerate.has_value() == is_reconsiderable);
172 : 115068 : Assert(res.m_wtxids_fee_calculations.has_value() == is_reconsiderable);
173 : 115068 : Assert(!res.m_other_wtxid);
174 : 115068 : break;
175 : : }
176 : 0 : case MempoolAcceptResult::ResultType::MEMPOOL_ENTRY:
177 : 0 : {
178 : : // ATMP never sets this; only set in package settings
179 : 0 : Assert(false);
180 : 0 : break;
181 : : }
182 : 0 : case MempoolAcceptResult::ResultType::DIFFERENT_WITNESS:
183 : 0 : {
184 : : // ATMP never sets this; only set in package settings
185 : 0 : Assert(false);
186 : 0 : break;
187 : : }
188 : : }
189 : 155093 : }
190 : :
191 [ + - ]: 2330 : FUZZ_TARGET(tx_pool_standard, .init = initialize_tx_pool)
192 : : {
193 : 1898 : SeedRandomStateForTest(SeedRand::ZEROS);
194 : 1898 : FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
195 : 1898 : const auto& node = g_setup->m_node;
196 : 1898 : auto& chainstate{static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
197 : :
198 : 1898 : MockTime(fuzzed_data_provider, chainstate);
199 : :
200 : : // All RBF-spendable outpoints
201 : 1898 : std::set<COutPoint> outpoints_rbf;
202 : : // All outpoints counting toward the total supply (subset of outpoints_rbf)
203 : 1898 : std::set<COutPoint> outpoints_supply;
204 [ + + ]: 191698 : for (const auto& outpoint : g_outpoints_coinbase_init_mature) {
205 [ + - + - ]: 189800 : Assert(outpoints_supply.insert(outpoint).second);
206 : : }
207 [ + - ]: 1898 : outpoints_rbf = outpoints_supply;
208 : :
209 : : // The sum of the values of all spendable outpoints
210 : 1898 : constexpr CAmount SUPPLY_TOTAL{COINBASE_MATURITY * 50 * COIN};
211 : :
212 [ + - ]: 1898 : SetMempoolConstraints(*node.args, fuzzed_data_provider);
213 [ + - ]: 1898 : auto tx_pool_{MakeMempool(fuzzed_data_provider, node)};
214 [ + - ]: 1898 : MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(tx_pool_.get());
215 : :
216 [ + - ]: 1898 : chainstate.SetMempool(&tx_pool);
217 : :
218 : : // Helper to query an amount
219 [ + - + - ]: 5694 : const CCoinsViewMemPool amount_view{WITH_LOCK(::cs_main, return &chainstate.CoinsTip()), tx_pool};
220 : 31972378 : const auto GetAmount = [&](const COutPoint& outpoint) {
221 [ + - ]: 31970480 : auto coin{amount_view.GetCoin(outpoint).value()};
222 : 31970480 : return coin.out.nValue;
223 : 31972378 : };
224 : :
225 [ + + + + ]: 156991 : LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 300)
226 : : {
227 : 155093 : {
228 : : // Total supply is the mempool fee + all outpoints
229 [ + - ]: 310186 : CAmount supply_now{WITH_LOCK(tx_pool.cs, return tx_pool.GetTotalFee())};
230 [ + + ]: 27124793 : for (const auto& op : outpoints_supply) {
231 [ + - ]: 26969700 : supply_now += GetAmount(op);
232 : : }
233 [ + - ]: 155093 : Assert(supply_now == SUPPLY_TOTAL);
234 : : }
235 [ + - ]: 155093 : Assert(!outpoints_supply.empty());
236 : :
237 : : // Create transaction to add to the mempool
238 : 310186 : const CTransactionRef tx = [&] {
239 : 155093 : CMutableTransaction tx_mut;
240 [ + + ]: 155093 : tx_mut.version = fuzzed_data_provider.ConsumeBool() ? TRUC_VERSION : CTransaction::CURRENT_VERSION;
241 [ + + ]: 155093 : tx_mut.nLockTime = fuzzed_data_provider.ConsumeBool() ? 0 : fuzzed_data_provider.ConsumeIntegral<uint32_t>();
242 : 155093 : const auto num_in = fuzzed_data_provider.ConsumeIntegralInRange<int>(1, outpoints_rbf.size());
243 : 155093 : const auto num_out = fuzzed_data_provider.ConsumeIntegralInRange<int>(1, outpoints_rbf.size() * 2);
244 : :
245 : 155093 : CAmount amount_in{0};
246 [ + + ]: 5155873 : for (int i = 0; i < num_in; ++i) {
247 : : // Pop random outpoint
248 : 5000780 : auto pop = outpoints_rbf.begin();
249 : 5000780 : std::advance(pop, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, outpoints_rbf.size() - 1));
250 : 5000780 : const auto outpoint = *pop;
251 : 5000780 : outpoints_rbf.erase(pop);
252 [ + - ]: 5000780 : amount_in += GetAmount(outpoint);
253 : :
254 : : // Create input
255 : 5000780 : const auto sequence = ConsumeSequence(fuzzed_data_provider);
256 : 5000780 : const auto script_sig = CScript{};
257 [ + - + + : 15002340 : const auto script_wit_stack = std::vector<std::vector<uint8_t>>{WITNESS_STACK_ELEM_OP_TRUE};
- - ]
258 : 5000780 : CTxIn in;
259 : 5000780 : in.prevout = outpoint;
260 : 5000780 : in.nSequence = sequence;
261 : 5000780 : in.scriptSig = script_sig;
262 [ + - ]: 5000780 : in.scriptWitness.stack = script_wit_stack;
263 : :
264 [ + - ]: 5000780 : tx_mut.vin.push_back(in);
265 : 5000780 : }
266 : 155093 : const auto amount_fee = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-1000, amount_in);
267 : 155093 : const auto amount_out = (amount_in - amount_fee) / num_out;
268 [ + + ]: 12671397 : for (int i = 0; i < num_out; ++i) {
269 [ + - ]: 12516304 : tx_mut.vout.emplace_back(amount_out, P2WSH_OP_TRUE);
270 : : }
271 [ + - ]: 155093 : auto tx = MakeTransactionRef(tx_mut);
272 : : // Restore previously removed outpoints
273 [ + + ]: 5155873 : for (const auto& in : tx->vin) {
274 [ + - + - ]: 5000780 : Assert(outpoints_rbf.insert(in.prevout).second);
275 : : }
276 : 155093 : return tx;
277 [ + - ]: 5310966 : }();
278 : :
279 [ + + ]: 155093 : if (fuzzed_data_provider.ConsumeBool()) {
280 [ + - ]: 139092 : MockTime(fuzzed_data_provider, chainstate);
281 : : }
282 [ + + ]: 155093 : if (fuzzed_data_provider.ConsumeBool()) {
283 [ + - ]: 106415 : tx_pool.RollingFeeUpdate();
284 : : }
285 [ + + ]: 155093 : if (fuzzed_data_provider.ConsumeBool()) {
286 [ + + ]: 121561 : const auto& txid = fuzzed_data_provider.ConsumeBool() ?
287 : 107725 : tx->GetHash() :
288 : 6918 : PickValue(fuzzed_data_provider, outpoints_rbf).hash;
289 : 114643 : const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
290 [ + - ]: 114643 : tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
291 : : }
292 : :
293 : : // Remember all removed and added transactions
294 [ + - ]: 155093 : std::set<CTransactionRef> removed;
295 : 155093 : std::set<CTransactionRef> added;
296 [ + - ]: 155093 : auto txr = std::make_shared<TransactionsDelta>(removed, added);
297 [ + - + - ]: 310186 : node.validation_signals->RegisterSharedValidationInterface(txr);
298 : 155093 : const bool bypass_limits = fuzzed_data_provider.ConsumeBool();
299 : :
300 : : // Make sure ProcessNewPackage on one transaction works.
301 : : // The result is not guaranteed to be the same as what is returned by ATMP.
302 [ + - + - : 775465 : const auto result_package = WITH_LOCK(::cs_main,
+ - + + +
- - - -
- ]
303 : : return ProcessNewPackage(chainstate, tx_pool, {tx}, true, /*client_maxfeerate=*/{}));
304 : : // If something went wrong due to a package-specific policy, it might not return a
305 : : // validation result for the transaction.
306 [ + - ]: 155093 : if (result_package.m_state.GetResult() != PackageValidationResult::PCKG_POLICY) {
307 : 155093 : auto it = result_package.m_tx_results.find(tx->GetWitnessHash());
308 [ + - ]: 155093 : Assert(it != result_package.m_tx_results.end());
309 [ + + + - : 288164 : Assert(it->second.m_result_type == MempoolAcceptResult::ResultType::VALID ||
+ - ]
310 : : it->second.m_result_type == MempoolAcceptResult::ResultType::INVALID);
311 : : }
312 : :
313 [ + - + - ]: 465279 : const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, tx, GetTime(), bypass_limits, /*test_accept=*/false));
314 : 155093 : const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
315 [ + - ]: 155093 : node.validation_signals->SyncWithValidationInterfaceQueue();
316 [ + - + - ]: 310186 : node.validation_signals->UnregisterSharedValidationInterface(txr);
317 : :
318 [ + - ]: 155093 : bool txid_in_mempool = tx_pool.exists(GenTxid::Txid(tx->GetHash()));
319 [ + - ]: 155093 : bool wtxid_in_mempool = tx_pool.exists(GenTxid::Wtxid(tx->GetWitnessHash()));
320 [ + - ]: 155093 : CheckATMPInvariants(res, txid_in_mempool, wtxid_in_mempool);
321 : :
322 [ + - ]: 155093 : Assert(accepted != added.empty());
323 [ + + ]: 155093 : if (accepted) {
324 [ + - ]: 40025 : Assert(added.size() == 1); // For now, no package acceptance
325 [ + - ]: 40025 : Assert(tx == *added.begin());
326 [ + - ]: 40025 : CheckMempoolTRUCInvariants(tx_pool);
327 : : } else {
328 : : // Do not consider rejected transaction removed
329 : 115068 : removed.erase(tx);
330 : : }
331 : :
332 : : // Helper to insert spent and created outpoints of a tx into collections
333 : 155093 : using Sets = std::vector<std::reference_wrapper<std::set<COutPoint>>>;
334 : 223756 : const auto insert_tx = [](Sets created_by_tx, Sets consumed_by_tx, const auto& tx) {
335 [ + + ]: 798346 : for (size_t i{0}; i < tx.vout.size(); ++i) {
336 [ + + ]: 2092652 : for (auto& set : created_by_tx) {
337 : 1362969 : Assert(set.get().emplace(tx.GetHash(), i).second);
338 : : }
339 : : }
340 [ + + ]: 187577 : for (const auto& in : tx.vin) {
341 [ + + ]: 237828 : for (auto& set : consumed_by_tx) {
342 : 118914 : Assert(set.get().insert(in.prevout).second);
343 : : }
344 : : }
345 : 68663 : };
346 : : // Add created outpoints, remove spent outpoints
347 : 155093 : {
348 : : // Outpoints that no longer exist at all
349 : 155093 : std::set<COutPoint> consumed_erased;
350 : : // Outpoints that no longer count toward the total supply
351 : 155093 : std::set<COutPoint> consumed_supply;
352 [ + + ]: 183731 : for (const auto& removed_tx : removed) {
353 [ + - + - : 57276 : insert_tx(/*created_by_tx=*/{consumed_erased}, /*consumed_by_tx=*/{outpoints_supply}, /*tx=*/*removed_tx);
+ - ]
354 : : }
355 [ + + ]: 195118 : for (const auto& added_tx : added) {
356 [ + - + - : 80050 : insert_tx(/*created_by_tx=*/{outpoints_supply, outpoints_rbf}, /*consumed_by_tx=*/{consumed_supply}, /*tx=*/*added_tx);
+ - ]
357 : : }
358 [ + + ]: 251490 : for (const auto& p : consumed_erased) {
359 [ + - ]: 96397 : Assert(outpoints_supply.erase(p) == 1);
360 [ + - ]: 96397 : Assert(outpoints_rbf.erase(p) == 1);
361 : : }
362 [ + + ]: 228640 : for (const auto& p : consumed_supply) {
363 [ + - ]: 73547 : Assert(outpoints_supply.erase(p) == 1);
364 : : }
365 : 155093 : }
366 [ + - + - ]: 465279 : }
367 [ + - ]: 1898 : Finish(fuzzed_data_provider, tx_pool, chainstate);
368 : 1898 : }
369 : :
370 [ + - ]: 5084 : FUZZ_TARGET(tx_pool, .init = initialize_tx_pool)
371 : : {
372 : 4652 : SeedRandomStateForTest(SeedRand::ZEROS);
373 : 4652 : FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
374 : 4652 : const auto& node = g_setup->m_node;
375 : 4652 : auto& chainstate{static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
376 : :
377 : 4652 : MockTime(fuzzed_data_provider, chainstate);
378 : :
379 : 4652 : std::vector<Txid> txids;
380 [ + - ]: 4652 : txids.reserve(g_outpoints_coinbase_init_mature.size());
381 [ + + ]: 469852 : for (const auto& outpoint : g_outpoints_coinbase_init_mature) {
382 [ + - ]: 465200 : txids.push_back(outpoint.hash);
383 : : }
384 [ + + ]: 23260 : for (int i{0}; i <= 3; ++i) {
385 : : // Add some immature and non-existent outpoints
386 [ + - + - ]: 18608 : txids.push_back(g_outpoints_coinbase_init_immature.at(i).hash);
387 [ + - ]: 18608 : txids.push_back(Txid::FromUint256(ConsumeUInt256(fuzzed_data_provider)));
388 : : }
389 : :
390 [ + - ]: 4652 : SetMempoolConstraints(*node.args, fuzzed_data_provider);
391 [ + - ]: 4652 : auto tx_pool_{MakeMempool(fuzzed_data_provider, node)};
392 : 4652 : MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(tx_pool_.get());
393 : :
394 : 4652 : chainstate.SetMempool(&tx_pool);
395 : :
396 [ + + + + ]: 303731 : LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 300)
397 : : {
398 [ + - ]: 299079 : const auto mut_tx = ConsumeTransaction(fuzzed_data_provider, txids);
399 : :
400 [ + + ]: 299079 : if (fuzzed_data_provider.ConsumeBool()) {
401 [ + - ]: 151879 : MockTime(fuzzed_data_provider, chainstate);
402 : : }
403 [ + + ]: 299079 : if (fuzzed_data_provider.ConsumeBool()) {
404 [ + - ]: 206655 : tx_pool.RollingFeeUpdate();
405 : : }
406 [ + + ]: 299079 : if (fuzzed_data_provider.ConsumeBool()) {
407 [ + + ]: 180565 : const auto txid = fuzzed_data_provider.ConsumeBool() ?
408 [ + - ]: 136089 : mut_tx.GetHash() :
409 : 44476 : PickValue(fuzzed_data_provider, txids);
410 : 180565 : const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
411 [ + - ]: 180565 : tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
412 : : }
413 : :
414 [ + - ]: 299079 : const auto tx = MakeTransactionRef(mut_tx);
415 : 299079 : const bool bypass_limits = fuzzed_data_provider.ConsumeBool();
416 [ + - + - ]: 897237 : const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, tx, GetTime(), bypass_limits, /*test_accept=*/false));
417 : 299079 : const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
418 [ + + ]: 299079 : if (accepted) {
419 [ + - ]: 59616 : txids.push_back(tx->GetHash());
420 [ + - ]: 59616 : CheckMempoolTRUCInvariants(tx_pool);
421 : : }
422 [ + - ]: 897237 : }
423 [ + - ]: 4652 : Finish(fuzzed_data_provider, tx_pool, chainstate);
424 : 4652 : }
425 : : } // namespace
|