Bitcoin Core 31.99.0
P2P Digital Currency
coins_view.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-present 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 <coins.h>
6#include <consensus/amount.h>
11#include <kernel/cs_main.h>
12#include <policy/policy.h>
13#include <primitives/block.h>
15#include <script/interpreter.h>
17#include <test/fuzz/fuzz.h>
18#include <test/fuzz/util.h>
20#include <txdb.h>
21#include <util/hasher.h>
22#include <util/threadpool.h>
23
24#include <cassert>
25#include <algorithm>
26#include <cstdint>
27#include <functional>
28#include <limits>
29#include <memory>
30#include <optional>
31#include <ranges>
32#include <stdexcept>
33#include <string>
34#include <utility>
35#include <vector>
36
37namespace {
38const Coin EMPTY_COIN{};
39
40bool operator==(const Coin& a, const Coin& b)
41{
42 if (a.IsSpent() && b.IsSpent()) return true;
43 return a.fCoinBase == b.fCoinBase && a.nHeight == b.nHeight && a.out == b.out;
44}
45
53class MutationGuardCoinsViewCache final : public CCoinsViewCache
54{
55private:
56 struct CacheCoinSnapshot {
57 COutPoint outpoint;
58 bool dirty{false};
59 bool fresh{false};
60 Coin coin;
61 bool operator==(const CacheCoinSnapshot&) const = default;
62 };
63
64 std::vector<CacheCoinSnapshot> ComputeCacheCoinsSnapshot() const
65 {
66 std::vector<CacheCoinSnapshot> snapshot;
67 snapshot.reserve(cacheCoins.size());
68
69 for (const auto& [outpoint, entry] : cacheCoins) {
70 snapshot.emplace_back(outpoint, entry.IsDirty(), entry.IsFresh(), entry.coin);
71 }
72
73 std::ranges::sort(snapshot, std::less<>{}, &CacheCoinSnapshot::outpoint);
74 return snapshot;
75 }
76
77 mutable std::vector<CacheCoinSnapshot> m_expected_snapshot{ComputeCacheCoinsSnapshot()};
78
79public:
80 void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash) override
81 {
82 // Nothing must modify cacheCoins other than BatchWrite.
83 assert(ComputeCacheCoinsSnapshot() == m_expected_snapshot);
84 CCoinsViewCache::BatchWrite(cursor, block_hash);
85 m_expected_snapshot = ComputeCacheCoinsSnapshot();
86 }
87
89};
90
91// Reuse a single global thread pool across fuzz iterations. Creating and destroying a pool every
92// iteration leaks memory, since iterations can run faster than the OS can tear down the threads.
93std::shared_ptr<ThreadPool> g_thread_pool{std::make_shared<ThreadPool>("view_fuzz")};
94
96{
97 if (!g_thread_pool->WorkersCount()) g_thread_pool->Start(DEFAULT_PREVOUTFETCH_THREADS);
98}
99
102{
103 CBlock block;
104 CMutableTransaction coinbase;
105 coinbase.vin.emplace_back();
106 block.vtx.push_back(MakeTransactionRef(coinbase));
107
108 CCoinsViewCache seed_cache{&view, /*deterministic=*/true};
109 seed_cache.SetBestBlock(uint256::ONE);
110
113 {
116 {
119 : prevhash};
120 const COutPoint outpoint{txid, fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
121 if (auto coin{ConsumeDeserializable<Coin>(fuzzed_data_provider)}; coin && !coin->IsSpent()) {
122 seed_cache.AddCoin(outpoint, std::move(*coin), /*possible_overwrite=*/true);
123 }
124 tx.vin.emplace_back(outpoint);
125 }
126 prevhash = tx.GetHash();
127 block.vtx.push_back(MakeTransactionRef(tx));
128 }
129
130 seed_cache.Flush();
131 return block;
132}
133
134} // namespace
135
137{
138 static const auto testing_setup = MakeNoLogFileContext<>();
139}
140
142{
143 auto* const db{dynamic_cast<CCoinsViewDB*>(backend_coins_view)};
144 auto* const overlay{dynamic_cast<CoinsViewOverlay*>(&coins_view_cache)};
145 const bool is_db{db != nullptr};
146 bool good_data{true};
147 auto* original_backend{backend_coins_view};
148
149 if (is_db) coins_view_cache.SetBestBlock(uint256::ONE);
150 COutPoint random_out_point;
151 Coin random_coin;
152 CMutableTransaction random_mutable_transaction;
153 LIMITED_WHILE (good_data && fuzzed_data_provider.ConsumeBool(), 10'000) {
154 CallOneOf(
156 [&] {
157 if (random_coin.IsSpent()) {
158 return;
159 }
160 COutPoint outpoint{random_out_point};
161 Coin coin{random_coin};
163 // We can only skip the check if no unspent coin exists for this outpoint.
164 const bool possible_overwrite{coins_view_cache.PeekCoin(outpoint) || fuzzed_data_provider.ConsumeBool()};
165 coins_view_cache.AddCoin(outpoint, std::move(coin), possible_overwrite);
166 } else {
167 coins_view_cache.EmplaceCoinInternalDANGER(outpoint, std::move(coin));
168 }
169 },
170 [&] {
171 if (overlay && !overlay->AllInputsConsumed()) return; // CoinsViewOverlay::Flush() must have all inputs consumed before being called
172 coins_view_cache.Flush(/*reallocate_cache=*/fuzzed_data_provider.ConsumeBool());
173 },
174 [&] {
175 if (overlay) return; // CoinsViewOverlay::Sync() is never called in production code
176 coins_view_cache.Sync();
177 },
178 [&] {
179 if (db) WITH_LOCK(::cs_main, (void)db->CompactFullAsync());
180 },
181 [&] {
183 // `CCoinsViewDB::BatchWrite()` requires a non-null best block.
184 if (is_db && best_block.IsNull()) best_block = uint256::ONE;
185 coins_view_cache.SetBestBlock(best_block);
186 },
187 [&] {
188 (void)coins_view_cache.CreateResetGuard();
189 // Reset() clears the best block, so reseed db-backed caches.
190 if (is_db) {
192 if (best_block.IsNull()) {
193 good_data = false;
194 return;
195 }
196 coins_view_cache.SetBestBlock(best_block);
197 }
198 },
199 [&] {
200 Coin move_to;
201 (void)coins_view_cache.SpendCoin(random_out_point, fuzzed_data_provider.ConsumeBool() ? &move_to : nullptr);
202 },
203 [&] {
204 coins_view_cache.Uncache(random_out_point);
205 },
206 [&] {
207 if (overlay) return; // // CoinsViewOverlay::SetBackend() is never called in production code
208 const bool use_original_backend{fuzzed_data_provider.ConsumeBool()};
209 if (use_original_backend && backend_coins_view != original_backend) {
210 // FRESH flags valid against the empty backend may be invalid
211 // against the original backend, so reset before restoring it.
212 (void)coins_view_cache.CreateResetGuard();
213 // Reset() clears the best block; db backends require a non-null hash.
214 if (is_db) coins_view_cache.SetBestBlock(uint256::ONE);
215 }
216 backend_coins_view = use_original_backend ? original_backend : &CoinsViewEmpty::Get();
217 coins_view_cache.SetBackend(*backend_coins_view);
218 },
219 [&] {
220 const std::optional<COutPoint> opt_out_point = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);
221 if (!opt_out_point) {
222 good_data = false;
223 return;
224 }
225 random_out_point = *opt_out_point;
226 },
227 [&] {
228 const std::optional<Coin> opt_coin = ConsumeDeserializable<Coin>(fuzzed_data_provider);
229 if (!opt_coin) {
230 good_data = false;
231 return;
232 }
233 random_coin = *opt_coin;
234 },
235 [&] {
236 const std::optional<CMutableTransaction> opt_mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
237 if (!opt_mutable_transaction) {
238 good_data = false;
239 return;
240 }
241 random_mutable_transaction = *opt_mutable_transaction;
242 },
243 [&] {
244 CoinsCachePair sentinel{};
245 sentinel.second.SelfRef(sentinel);
246 size_t dirty_count{0};
248 CCoinsMap coins_map{0, SaltedOutpointHasher{/*deterministic=*/true}, CCoinsMap::key_equal{}, &resource};
249 LIMITED_WHILE (good_data && fuzzed_data_provider.ConsumeBool(), 10'000) {
250 CCoinsCacheEntry coins_cache_entry;
252 coins_cache_entry.coin = random_coin;
253 } else {
254 const std::optional<Coin> opt_coin = ConsumeDeserializable<Coin>(fuzzed_data_provider);
255 if (!opt_coin) {
256 good_data = false;
257 return;
258 }
259 coins_cache_entry.coin = *opt_coin;
260 }
261 // Avoid setting FRESH for an outpoint that already exists unspent in the parent view.
262 bool fresh{!coins_view_cache.PeekCoin(random_out_point) && fuzzed_data_provider.ConsumeBool()};
263 bool dirty{fresh || fuzzed_data_provider.ConsumeBool()};
264 auto it{coins_map.emplace(random_out_point, std::move(coins_cache_entry)).first};
265 if (dirty) CCoinsCacheEntry::SetDirty(*it, sentinel);
266 if (fresh) CCoinsCacheEntry::SetFresh(*it, sentinel);
267 dirty_count += dirty;
268 }
269 auto cursor{CoinsViewCacheCursor(dirty_count, sentinel, coins_map, /*will_erase=*/true)};
270 uint256 best_block{coins_view_cache.GetBestBlock()};
272 // Set best block hash to non-null to satisfy the assertion in CCoinsViewDB::BatchWrite().
273 if (is_db && best_block.IsNull()) best_block = uint256::ONE;
274 coins_view_cache.BatchWrite(cursor, best_block);
275 });
276 }
277
278 {
279 (void)coins_view_cache.DynamicMemoryUsage();
280 (void)coins_view_cache.EstimateSize();
281 (void)coins_view_cache.GetBestBlock();
282 (void)coins_view_cache.GetCacheSize();
283 (void)coins_view_cache.GetHeadBlocks();
284 (void)coins_view_cache.HaveInputs(CTransaction{random_mutable_transaction});
285 }
286
287 {
288 if (is_db && backend_coins_view == original_backend) {
289 assert(db->Cursor());
290 }
291 (void)backend_coins_view->EstimateSize();
292 (void)backend_coins_view->GetBestBlock();
293 (void)backend_coins_view->GetHeadBlocks();
294 }
295
297 CallOneOf(
299 [&] {
300 const CTransaction transaction{random_mutable_transaction};
301 bool is_spent = false;
302 for (const CTxOut& tx_out : transaction.vout) {
303 if (Coin{tx_out, 0, transaction.IsCoinBase()}.IsSpent()) {
304 is_spent = true;
305 }
306 }
307 if (is_spent) {
308 // Avoid:
309 // coins.cpp:69: void CCoinsViewCache::AddCoin(const COutPoint &, Coin &&, bool): Assertion `!coin.IsSpent()' failed.
310 return;
311 }
312 const int height{int(fuzzed_data_provider.ConsumeIntegral<uint32_t>() >> 1)};
313 const bool check_for_overwrite{transaction.IsCoinBase() || [&] {
314 for (uint32_t i{0}; i < transaction.vout.size(); ++i) {
315 if (coins_view_cache.PeekCoin(COutPoint{transaction.GetHash(), i})) return true;
316 }
318 }()}; // We can only skip the check if the current txid has no unspent outputs
319 AddCoins(coins_view_cache, transaction, height, check_for_overwrite);
320 },
321 [&] {
322 (void)ValidateInputsStandardness(CTransaction{random_mutable_transaction}, coins_view_cache);
323 },
324 [&] {
325 TxValidationState state;
326 CAmount tx_fee_out;
327 const CTransaction transaction{random_mutable_transaction};
328 if (ContainsSpentInput(transaction, coins_view_cache)) {
329 // Avoid:
330 // consensus/tx_verify.cpp:171: bool Consensus::CheckTxInputs(const CTransaction &, TxValidationState &, const CCoinsViewCache &, int, CAmount &): Assertion `!coin.IsSpent()' failed.
331 return;
332 }
333 TxValidationState dummy;
334 if (!CheckTransaction(transaction, dummy)) {
335 // It is not allowed to call CheckTxInputs if CheckTransaction failed
336 return;
337 }
338 if (Consensus::CheckTxInputs(transaction, state, coins_view_cache, fuzzed_data_provider.ConsumeIntegralInRange<int>(0, std::numeric_limits<int>::max()), tx_fee_out)) {
339 assert(MoneyRange(tx_fee_out));
340 }
341 },
342 [&] {
343 const CTransaction transaction{random_mutable_transaction};
344 if (ContainsSpentInput(transaction, coins_view_cache)) {
345 // Avoid:
346 // consensus/tx_verify.cpp:130: unsigned int GetP2SHSigOpCount(const CTransaction &, const CCoinsViewCache &): Assertion `!coin.IsSpent()' failed.
347 return;
348 }
349 (void)GetP2SHSigOpCount(transaction, coins_view_cache);
350 },
351 [&] {
352 const CTransaction transaction{random_mutable_transaction};
353 if (ContainsSpentInput(transaction, coins_view_cache)) {
354 // Avoid:
355 // consensus/tx_verify.cpp:130: unsigned int GetP2SHSigOpCount(const CTransaction &, const CCoinsViewCache &): Assertion `!coin.IsSpent()' failed.
356 return;
357 }
359 if (!transaction.vin.empty() && (flags & SCRIPT_VERIFY_WITNESS) != 0 && (flags & SCRIPT_VERIFY_P2SH) == 0) {
360 // Avoid:
361 // script/interpreter.cpp:1705: size_t CountWitnessSigOps(const CScript &, const CScript &, const CScriptWitness &, unsigned int): Assertion `(flags & SCRIPT_VERIFY_P2SH) != 0' failed.
362 return;
363 }
364 (void)GetTransactionSigOpCost(transaction, coins_view_cache, flags);
365 },
366 [&] {
367 (void)IsWitnessStandard(CTransaction{random_mutable_transaction}, coins_view_cache);
368 });
369 }
370
371 {
372 const Coin& coin_using_access_coin = coins_view_cache.AccessCoin(random_out_point);
373 const bool exists_using_access_coin = !(coin_using_access_coin == EMPTY_COIN);
374 const bool exists_using_have_coin = coins_view_cache.HaveCoin(random_out_point);
375 const bool exists_using_have_coin_in_cache = coins_view_cache.HaveCoinInCache(random_out_point);
376 if (auto coin{coins_view_cache.GetCoin(random_out_point)}) {
377 assert(*coin == coin_using_access_coin);
378 assert(exists_using_access_coin && exists_using_have_coin_in_cache && exists_using_have_coin);
379 } else {
380 assert(!exists_using_access_coin && !exists_using_have_coin_in_cache && !exists_using_have_coin);
381 }
382 // If HaveCoin on the backend is true, it must also be on the cache if the coin wasn't spent.
383 std::optional<Coin> coin_in_backend;
384 bool exists_using_have_coin_in_backend;
385 if (dynamic_cast<CoinsViewOverlay*>(&coins_view_cache)) {
386 // PeekCoin does not mutate cacheCoins, so async workers can keep running.
387 coin_in_backend = backend_coins_view->PeekCoin(random_out_point);
388 exists_using_have_coin_in_backend = coin_in_backend.has_value();
389 } else {
390 exists_using_have_coin_in_backend = backend_coins_view->HaveCoin(random_out_point);
391 coin_in_backend = backend_coins_view->GetCoin(random_out_point);
392 }
393 if (!coin_using_access_coin.IsSpent() && exists_using_have_coin_in_backend) {
394 assert(exists_using_have_coin);
395 }
396 if (coin_in_backend) {
397 assert(exists_using_have_coin_in_backend);
398 // Note we can't assert that `coin_using_get_coin == *coin` because the coin in
399 // the cache may have been modified but not yet flushed.
400 } else {
401 assert(!exists_using_have_coin_in_backend);
402 }
403 }
404}
405
407{
408 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
409 CCoinsViewCache coins_view_cache{&CoinsViewEmpty::Get(), /*deterministic=*/true};
411}
412
414{
415 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
416 auto db_params = DBParams{
417 .path = "",
418 .cache_bytes = 1_MiB,
419 .memory_only = true,
420 };
421 CCoinsViewDB backend_coins_view{std::move(db_params), CoinsViewOptions{}};
422 CCoinsViewCache coins_view_cache{&backend_coins_view, /*deterministic=*/true};
423 TestCoinsView(fuzzed_data_provider, coins_view_cache, &backend_coins_view);
424}
425
426// Creates a CoinsViewOverlay and a MutationGuardCoinsViewCache as the base.
427// This allows us to exercise all methods on a CoinsViewOverlay, while also
428// ensuring that nothing can mutate the underlying cache until Flush or Sync is
429// called.
431{
432 SeedRandomStateForTest(SeedRand::ZEROS); // for SaltedTxidHasher
434 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
435 MutationGuardCoinsViewCache backend_cache{&CoinsViewEmpty::Get(), /*deterministic=*/true};
436 CoinsViewOverlay coins_view_cache{&backend_cache, g_thread_pool, /*deterministic=*/true};
437 CBlock block{BuildRandomBlock(fuzzed_data_provider, backend_cache)};
438 const auto reset_guard{coins_view_cache.StartFetching(block)};
439 TestCoinsView(fuzzed_data_provider, coins_view_cache, &backend_cache);
440}
441
443{
444 SeedRandomStateForTest(SeedRand::ZEROS); // for SaltedTxidHasher
446 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
447 auto db_params = DBParams{
448 .path = "",
449 .cache_bytes = 1_MiB,
450 .memory_only = true,
451 };
452 CCoinsViewDB backend_base_coins_view{std::move(db_params), CoinsViewOptions{}};
453 CCoinsViewCache backend_cache{&backend_base_coins_view, /*deterministic=*/true};
454 TestCoinsView(fuzzed_data_provider, backend_cache, &backend_base_coins_view);
455 CoinsViewOverlay coins_view_cache{&backend_cache, g_thread_pool, /*deterministic=*/true};
456 CBlock block{BuildRandomBlock(fuzzed_data_provider, backend_base_coins_view)};
457 {
458 const auto reset_guard{coins_view_cache.StartFetching(block)};
459 TestCoinsView(fuzzed_data_provider, coins_view_cache, &backend_cache);
460 }
461 TestCoinsView(fuzzed_data_provider, backend_cache, &backend_base_coins_view);
462}
bool MoneyRange(const CAmount &nValue)
Definition: amount.h:27
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
if(!SetupNetworking())
int flags
Definition: bitcoin-tx.cpp:530
static constexpr int32_t DEFAULT_PREVOUTFETCH_THREADS
Definition: block.h:74
std::vector< CTransactionRef > vtx
Definition: block.h:77
void SetBackend(CCoinsView &in_view)
Definition: coins.h:386
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:400
void Sync()
Push the modifications applied to this cache to its base while retaining the contents of this cache (...
Definition: coins.cpp:277
bool SpendCoin(const COutPoint &outpoint, Coin *moveto=nullptr)
Spend a coin.
Definition: coins.cpp:137
ResetGuard CreateResetGuard() noexcept
Create a scoped guard that will call Reset() on this cache when it goes out of scope.
Definition: coins.h:548
void Uncache(const COutPoint &outpoint)
Removes the UTXO with the given outpoint from the cache, if it is not modified.
Definition: coins.cpp:296
void EmplaceCoinInternalDANGER(const COutPoint &outpoint, Coin &&coin)
Emplace a coin into cacheCoins without performing any checks, marking the emplaced coin as dirty.
Definition: coins.cpp:116
void AddCoin(const COutPoint &outpoint, Coin &&coin, bool possible_overwrite)
Add a coin.
Definition: coins.cpp:73
CCoinsViewCache(CCoinsView *in_base, bool deterministic=false)
Definition: coins.cpp:36
virtual void Flush(bool reallocate_cache=true)
Push the modifications applied to this cache to its base and wipe local state.
Definition: coins.cpp:265
void SetBestBlock(const uint256 &block_hash)
Definition: coins.cpp:189
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:183
void BatchWrite(CoinsViewCacheCursor &cursor, const uint256 &block_hash) override
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: coins.cpp:194
std::optional< Coin > PeekCoin(const COutPoint &outpoint) const override
Retrieve the Coin (unspent transaction output) for a given outpoint, without caching results.
Definition: coins.cpp:28
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:37
Pure abstract view on the open txout dataset.
Definition: coins.h:319
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:29
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:281
An output of a transaction.
Definition: transaction.h:140
A UTXO entry.
Definition: coins.h:46
CTxOut out
unspent transaction output
Definition: coins.h:49
bool IsSpent() const
Either this coin never existed (see e.g.
Definition: coins.h:94
bool fCoinBase
whether containing transaction was a coinbase
Definition: coins.h:52
uint32_t nHeight
at which height this containing transaction was included in the active block chain
Definition: coins.h:55
static CoinsViewEmpty & Get()
Definition: coins.cpp:22
CCoinsViewCache subclass that asynchronously fetches most block input prevouts in parallel during Con...
Definition: coins.h:617
T ConsumeIntegralInRange(T min, T max)
static constexpr script_verify_flags from_int(value_type f)
Definition: verify_flags.h:35
static transaction_identifier FromUint256(const uint256 &id)
256-bit opaque blob.
Definition: uint256.h:196
static const uint256 ONE
Definition: uint256.h:205
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check_for_overwrite)
Utility function to add all of a transaction's outputs to a cache.
Definition: coins.cpp:126
std::pair< const COutPoint, CCoinsCacheEntry > CoinsCachePair
Definition: coins.h:104
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher, std::equal_to< COutPoint >, PoolAllocator< CoinsCachePair, sizeof(CoinsCachePair)+sizeof(void *) *4 > > CCoinsMap
PoolAllocator's MAX_BLOCK_SIZE_BYTES parameter here uses sizeof the data, and adds the size of 4 poin...
Definition: coins.h:235
CCoinsMap::allocator_type::ResourceType CCoinsMapMemoryResource
Definition: coins.h:237
void TestCoinsView(FuzzedDataProvider &fuzzed_data_provider, CCoinsViewCache &coins_view_cache, CCoinsView *backend_coins_view)
Definition: coins_view.cpp:141
FUZZ_TARGET(coins_view,.init=initialize_coins_view)
Definition: coins_view.cpp:406
void initialize_coins_view()
Definition: coins_view.cpp:136
LIMITED_WHILE(provider.remaining_bytes(), 10000)
StartPoolIfNeeded()
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:8
bool CheckTxInputs(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &inputs, int nSpendHeight, CAmount &txfee)
Check whether all inputs of this transaction are valid (no double spends and amounts) This does not m...
Definition: tx_verify.cpp:164
Definition: basic.cpp:8
bool operator==(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:603
TxValidationState ValidateInputsStandardness(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check transaction inputs.
Definition: policy.cpp:214
bool IsWitnessStandard(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check if the transaction is over standard P2WSH resources limit: 3600bytes witnessScript size,...
Definition: policy.cpp:265
static constexpr TransactionSerParams TX_WITH_WITNESS
Definition: transaction.h:180
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:404
A Coin in one level of the coins database caching hierarchy.
Definition: coins.h:121
Coin coin
Definition: coins.h:153
static void SetFresh(CoinsCachePair &pair, CoinsCachePair &sentinel) noexcept
Definition: coins.h:184
static void SetDirty(CoinsCachePair &pair, CoinsCachePair &sentinel) noexcept
Definition: coins.h:183
A mutable version of CTransaction.
Definition: transaction.h:358
Txid GetHash() const
Compute the hash of this CMutableTransaction.
Definition: transaction.cpp:69
std::vector< CTxIn > vin
Definition: transaction.h:359
Cursor for iterating over the linked list of flagged entries in CCoinsViewCache.
Definition: coins.h:272
User-controlled performance and debug options.
Definition: txdb.h:28
Application-specific storage settings.
Definition: dbwrapper.h:41
fs::path path
Location in the filesystem where leveldb data will be stored.
Definition: dbwrapper.h:43
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:299
CDBWrapper db
Definition: dbwrapper.cpp:371
SeedRandomStateForTest(SeedRand::ZEROS)
bool ContainsSpentInput(const CTransaction &tx, const CCoinsViewCache &inputs) noexcept
Definition: util.cpp:240
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:195
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
Definition: util.h:37
@ ZEROS
Seed with a compile time constant of zeros.
bool CheckTransaction(const CTransaction &tx, TxValidationState &state)
Definition: tx_check.cpp:11
int64_t GetTransactionSigOpCost(const CTransaction &tx, const CCoinsViewCache &inputs, script_verify_flags flags)
Compute total signature operation cost of a transaction.
Definition: tx_verify.cpp:143
unsigned int GetP2SHSigOpCount(const CTransaction &tx, const CCoinsViewCache &inputs)
Count ECDSA signature operations in pay-to-script-hash inputs.
Definition: tx_verify.cpp:126
assert(!tx.IsCoinBase())
FuzzedDataProvider & fuzzed_data_provider
Definition: fees.cpp:39