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")};
94Mutex g_thread_pool_mutex;
95
96void StartPoolIfNeeded() EXCLUSIVE_LOCKS_REQUIRED(!g_thread_pool_mutex)
97{
98 LOCK(g_thread_pool_mutex);
99 if (!g_thread_pool->WorkersCount()) g_thread_pool->Start(DEFAULT_PREVOUTFETCH_THREADS);
100}
101
104{
105 CBlock block;
106 CMutableTransaction coinbase;
107 coinbase.vin.emplace_back();
108 block.vtx.push_back(MakeTransactionRef(coinbase));
109
110 CCoinsViewCache seed_cache{&view, /*deterministic=*/true};
111 seed_cache.SetBestBlock(uint256::ONE);
112
115 {
118 {
121 : prevhash};
122 const COutPoint outpoint{txid, fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
123 if (auto coin{ConsumeDeserializable<Coin>(fuzzed_data_provider)}; coin && !coin->IsSpent()) {
124 seed_cache.AddCoin(outpoint, std::move(*coin), /*possible_overwrite=*/true);
125 }
126 tx.vin.emplace_back(outpoint);
127 }
128 prevhash = tx.GetHash();
129 block.vtx.push_back(MakeTransactionRef(tx));
130 }
131
132 seed_cache.Flush();
133 return block;
134}
135
136} // namespace
137
139{
140 static const auto testing_setup = MakeNoLogFileContext<>();
141}
142
144{
145 auto* const db{dynamic_cast<CCoinsViewDB*>(backend_coins_view)};
146 auto* const overlay{dynamic_cast<CoinsViewOverlay*>(&coins_view_cache)};
147 const bool is_db{db != nullptr};
148 bool good_data{true};
149 auto* original_backend{backend_coins_view};
150
151 if (is_db) coins_view_cache.SetBestBlock(uint256::ONE);
152 COutPoint random_out_point;
153 Coin random_coin;
154 CMutableTransaction random_mutable_transaction;
155 LIMITED_WHILE(good_data && fuzzed_data_provider.ConsumeBool(), 10'000)
156 {
157 CallOneOf(
159 [&] {
160 if (random_coin.IsSpent()) {
161 return;
162 }
163 COutPoint outpoint{random_out_point};
164 Coin coin{random_coin};
166 // We can only skip the check if no unspent coin exists for this outpoint.
167 const bool possible_overwrite{coins_view_cache.PeekCoin(outpoint) || fuzzed_data_provider.ConsumeBool()};
168 coins_view_cache.AddCoin(outpoint, std::move(coin), possible_overwrite);
169 } else {
170 coins_view_cache.EmplaceCoinInternalDANGER(std::move(outpoint), std::move(coin));
171 }
172 },
173 [&] {
174 if (overlay && !overlay->AllInputsConsumed()) return; // CoinsViewOverlay::Flush() must have all inputs consumed before being called
175 coins_view_cache.Flush(/*reallocate_cache=*/fuzzed_data_provider.ConsumeBool());
176 },
177 [&] {
178 if (overlay) return; // CoinsViewOverlay::Sync() is never called in production code
179 coins_view_cache.Sync();
180 },
181 [&] {
182 if (db) WITH_LOCK(::cs_main, (void)db->CompactFullAsync());
183 },
184 [&] {
186 // `CCoinsViewDB::BatchWrite()` requires a non-null best block.
187 if (is_db && best_block.IsNull()) best_block = uint256::ONE;
188 coins_view_cache.SetBestBlock(best_block);
189 },
190 [&] {
191 (void)coins_view_cache.CreateResetGuard();
192 // Reset() clears the best block, so reseed db-backed caches.
193 if (is_db) {
195 if (best_block.IsNull()) {
196 good_data = false;
197 return;
198 }
199 coins_view_cache.SetBestBlock(best_block);
200 }
201 },
202 [&] {
203 Coin move_to;
204 (void)coins_view_cache.SpendCoin(random_out_point, fuzzed_data_provider.ConsumeBool() ? &move_to : nullptr);
205 },
206 [&] {
207 coins_view_cache.Uncache(random_out_point);
208 },
209 [&] {
210 if (overlay) return; // // CoinsViewOverlay::SetBackend() is never called in production code
211 const bool use_original_backend{fuzzed_data_provider.ConsumeBool()};
212 if (use_original_backend && backend_coins_view != original_backend) {
213 // FRESH flags valid against the empty backend may be invalid
214 // against the original backend, so reset before restoring it.
215 (void)coins_view_cache.CreateResetGuard();
216 // Reset() clears the best block; db backends require a non-null hash.
217 if (is_db) coins_view_cache.SetBestBlock(uint256::ONE);
218 }
219 backend_coins_view = use_original_backend ? original_backend : &CoinsViewEmpty::Get();
220 coins_view_cache.SetBackend(*backend_coins_view);
221 },
222 [&] {
223 const std::optional<COutPoint> opt_out_point = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);
224 if (!opt_out_point) {
225 good_data = false;
226 return;
227 }
228 random_out_point = *opt_out_point;
229 },
230 [&] {
231 const std::optional<Coin> opt_coin = ConsumeDeserializable<Coin>(fuzzed_data_provider);
232 if (!opt_coin) {
233 good_data = false;
234 return;
235 }
236 random_coin = *opt_coin;
237 },
238 [&] {
239 const std::optional<CMutableTransaction> opt_mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
240 if (!opt_mutable_transaction) {
241 good_data = false;
242 return;
243 }
244 random_mutable_transaction = *opt_mutable_transaction;
245 },
246 [&] {
247 CoinsCachePair sentinel{};
248 sentinel.second.SelfRef(sentinel);
249 size_t dirty_count{0};
251 CCoinsMap coins_map{0, SaltedOutpointHasher{/*deterministic=*/true}, CCoinsMap::key_equal{}, &resource};
252 LIMITED_WHILE(good_data && fuzzed_data_provider.ConsumeBool(), 10'000)
253 {
254 CCoinsCacheEntry coins_cache_entry;
256 coins_cache_entry.coin = random_coin;
257 } else {
258 const std::optional<Coin> opt_coin = ConsumeDeserializable<Coin>(fuzzed_data_provider);
259 if (!opt_coin) {
260 good_data = false;
261 return;
262 }
263 coins_cache_entry.coin = *opt_coin;
264 }
265 // Avoid setting FRESH for an outpoint that already exists unspent in the parent view.
266 bool fresh{!coins_view_cache.PeekCoin(random_out_point) && fuzzed_data_provider.ConsumeBool()};
267 bool dirty{fresh || fuzzed_data_provider.ConsumeBool()};
268 auto it{coins_map.emplace(random_out_point, std::move(coins_cache_entry)).first};
269 if (dirty) CCoinsCacheEntry::SetDirty(*it, sentinel);
270 if (fresh) CCoinsCacheEntry::SetFresh(*it, sentinel);
271 dirty_count += dirty;
272 }
273 auto cursor{CoinsViewCacheCursor(dirty_count, sentinel, coins_map, /*will_erase=*/true)};
274 uint256 best_block{coins_view_cache.GetBestBlock()};
276 // Set best block hash to non-null to satisfy the assertion in CCoinsViewDB::BatchWrite().
277 if (is_db && best_block.IsNull()) best_block = uint256::ONE;
278 coins_view_cache.BatchWrite(cursor, best_block);
279 });
280 }
281
282 {
283 bool expected_code_path = false;
284 try {
285 (void)coins_view_cache.Cursor();
286 } catch (const std::logic_error&) {
287 expected_code_path = true;
288 }
289 assert(expected_code_path);
290 (void)coins_view_cache.DynamicMemoryUsage();
291 (void)coins_view_cache.EstimateSize();
292 (void)coins_view_cache.GetBestBlock();
293 (void)coins_view_cache.GetCacheSize();
294 (void)coins_view_cache.GetHeadBlocks();
295 (void)coins_view_cache.HaveInputs(CTransaction{random_mutable_transaction});
296 }
297
298 {
299 if (is_db && backend_coins_view == original_backend) {
300 assert(backend_coins_view->Cursor());
301 }
302 (void)backend_coins_view->EstimateSize();
303 (void)backend_coins_view->GetBestBlock();
304 (void)backend_coins_view->GetHeadBlocks();
305 }
306
308 CallOneOf(
310 [&] {
311 const CTransaction transaction{random_mutable_transaction};
312 bool is_spent = false;
313 for (const CTxOut& tx_out : transaction.vout) {
314 if (Coin{tx_out, 0, transaction.IsCoinBase()}.IsSpent()) {
315 is_spent = true;
316 }
317 }
318 if (is_spent) {
319 // Avoid:
320 // coins.cpp:69: void CCoinsViewCache::AddCoin(const COutPoint &, Coin &&, bool): Assertion `!coin.IsSpent()' failed.
321 return;
322 }
323 const int height{int(fuzzed_data_provider.ConsumeIntegral<uint32_t>() >> 1)};
324 const bool check_for_overwrite{transaction.IsCoinBase() || [&] {
325 for (uint32_t i{0}; i < transaction.vout.size(); ++i) {
326 if (coins_view_cache.PeekCoin(COutPoint{transaction.GetHash(), i})) return true;
327 }
329 }()}; // We can only skip the check if the current txid has no unspent outputs
330 AddCoins(coins_view_cache, transaction, height, check_for_overwrite);
331 },
332 [&] {
333 (void)ValidateInputsStandardness(CTransaction{random_mutable_transaction}, coins_view_cache);
334 },
335 [&] {
336 TxValidationState state;
337 CAmount tx_fee_out;
338 const CTransaction transaction{random_mutable_transaction};
339 if (ContainsSpentInput(transaction, coins_view_cache)) {
340 // Avoid:
341 // consensus/tx_verify.cpp:171: bool Consensus::CheckTxInputs(const CTransaction &, TxValidationState &, const CCoinsViewCache &, int, CAmount &): Assertion `!coin.IsSpent()' failed.
342 return;
343 }
344 TxValidationState dummy;
345 if (!CheckTransaction(transaction, dummy)) {
346 // It is not allowed to call CheckTxInputs if CheckTransaction failed
347 return;
348 }
349 if (Consensus::CheckTxInputs(transaction, state, coins_view_cache, fuzzed_data_provider.ConsumeIntegralInRange<int>(0, std::numeric_limits<int>::max()), tx_fee_out)) {
350 assert(MoneyRange(tx_fee_out));
351 }
352 },
353 [&] {
354 const CTransaction transaction{random_mutable_transaction};
355 if (ContainsSpentInput(transaction, coins_view_cache)) {
356 // Avoid:
357 // consensus/tx_verify.cpp:130: unsigned int GetP2SHSigOpCount(const CTransaction &, const CCoinsViewCache &): Assertion `!coin.IsSpent()' failed.
358 return;
359 }
360 (void)GetP2SHSigOpCount(transaction, coins_view_cache);
361 },
362 [&] {
363 const CTransaction transaction{random_mutable_transaction};
364 if (ContainsSpentInput(transaction, coins_view_cache)) {
365 // Avoid:
366 // consensus/tx_verify.cpp:130: unsigned int GetP2SHSigOpCount(const CTransaction &, const CCoinsViewCache &): Assertion `!coin.IsSpent()' failed.
367 return;
368 }
370 if (!transaction.vin.empty() && (flags & SCRIPT_VERIFY_WITNESS) != 0 && (flags & SCRIPT_VERIFY_P2SH) == 0) {
371 // Avoid:
372 // script/interpreter.cpp:1705: size_t CountWitnessSigOps(const CScript &, const CScript &, const CScriptWitness &, unsigned int): Assertion `(flags & SCRIPT_VERIFY_P2SH) != 0' failed.
373 return;
374 }
375 (void)GetTransactionSigOpCost(transaction, coins_view_cache, flags);
376 },
377 [&] {
378 (void)IsWitnessStandard(CTransaction{random_mutable_transaction}, coins_view_cache);
379 });
380 }
381
382 {
383 const Coin& coin_using_access_coin = coins_view_cache.AccessCoin(random_out_point);
384 const bool exists_using_access_coin = !(coin_using_access_coin == EMPTY_COIN);
385 const bool exists_using_have_coin = coins_view_cache.HaveCoin(random_out_point);
386 const bool exists_using_have_coin_in_cache = coins_view_cache.HaveCoinInCache(random_out_point);
387 if (auto coin{coins_view_cache.GetCoin(random_out_point)}) {
388 assert(*coin == coin_using_access_coin);
389 assert(exists_using_access_coin && exists_using_have_coin_in_cache && exists_using_have_coin);
390 } else {
391 assert(!exists_using_access_coin && !exists_using_have_coin_in_cache && !exists_using_have_coin);
392 }
393 // If HaveCoin on the backend is true, it must also be on the cache if the coin wasn't spent.
394 std::optional<Coin> coin_in_backend;
395 bool exists_using_have_coin_in_backend;
396 if (dynamic_cast<CoinsViewOverlay*>(&coins_view_cache)) {
397 // PeekCoin does not mutate cacheCoins, so async workers can keep running.
398 coin_in_backend = backend_coins_view->PeekCoin(random_out_point);
399 exists_using_have_coin_in_backend = coin_in_backend.has_value();
400 } else {
401 exists_using_have_coin_in_backend = backend_coins_view->HaveCoin(random_out_point);
402 coin_in_backend = backend_coins_view->GetCoin(random_out_point);
403 }
404 if (!coin_using_access_coin.IsSpent() && exists_using_have_coin_in_backend) {
405 assert(exists_using_have_coin);
406 }
407 if (coin_in_backend) {
408 assert(exists_using_have_coin_in_backend);
409 // Note we can't assert that `coin_using_get_coin == *coin` because the coin in
410 // the cache may have been modified but not yet flushed.
411 } else {
412 assert(!exists_using_have_coin_in_backend);
413 }
414 }
415}
416
418{
419 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
420 CCoinsViewCache coins_view_cache{&CoinsViewEmpty::Get(), /*deterministic=*/true};
422}
423
425{
426 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
427 auto db_params = DBParams{
428 .path = "",
429 .cache_bytes = 1_MiB,
430 .memory_only = true,
431 };
432 CCoinsViewDB backend_coins_view{std::move(db_params), CoinsViewOptions{}};
433 CCoinsViewCache coins_view_cache{&backend_coins_view, /*deterministic=*/true};
434 TestCoinsView(fuzzed_data_provider, coins_view_cache, &backend_coins_view);
435}
436
437// Creates a CoinsViewOverlay and a MutationGuardCoinsViewCache as the base.
438// This allows us to exercise all methods on a CoinsViewOverlay, while also
439// ensuring that nothing can mutate the underlying cache until Flush or Sync is
440// called.
441FUZZ_TARGET(coins_view_overlay, .init = initialize_coins_view) EXCLUSIVE_LOCKS_REQUIRED(!g_thread_pool_mutex)
442{
443 SeedRandomStateForTest(SeedRand::ZEROS); // for SaltedTxidHasher
445 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
446 MutationGuardCoinsViewCache backend_cache{&CoinsViewEmpty::Get(), /*deterministic=*/true};
447 CoinsViewOverlay coins_view_cache{&backend_cache, g_thread_pool, /*deterministic=*/true};
448 CBlock block{BuildRandomBlock(fuzzed_data_provider, backend_cache)};
449 const auto reset_guard{coins_view_cache.StartFetching(block)};
450 TestCoinsView(fuzzed_data_provider, coins_view_cache, &backend_cache);
451}
452
453FUZZ_TARGET(coins_view_stacked, .init = initialize_coins_view) EXCLUSIVE_LOCKS_REQUIRED(!g_thread_pool_mutex)
454{
455 SeedRandomStateForTest(SeedRand::ZEROS); // for SaltedTxidHasher
457 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
458 auto db_params = DBParams{
459 .path = "",
460 .cache_bytes = 1_MiB,
461 .memory_only = true,
462 };
463 CCoinsViewDB backend_base_coins_view{std::move(db_params), CoinsViewOptions{}};
464 CCoinsViewCache backend_cache{&backend_base_coins_view, /*deterministic=*/true};
465 TestCoinsView(fuzzed_data_provider, backend_cache, &backend_base_coins_view);
466 CoinsViewOverlay coins_view_cache{&backend_cache, g_thread_pool, /*deterministic=*/true};
467 CBlock block{BuildRandomBlock(fuzzed_data_provider, backend_base_coins_view)};
468 {
469 const auto reset_guard{coins_view_cache.StartFetching(block)};
470 TestCoinsView(fuzzed_data_provider, coins_view_cache, &backend_cache);
471 }
472 TestCoinsView(fuzzed_data_provider, backend_cache, &backend_base_coins_view);
473}
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:390
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:405
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:556
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 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
void EmplaceCoinInternalDANGER(COutPoint &&outpoint, Coin &&coin)
Emplace a coin into cacheCoins without performing any checks, marking the emplaced coin as dirty.
Definition: coins.cpp:116
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:625
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:143
FUZZ_TARGET(coins_view,.init=initialize_coins_view)
Definition: coins_view.cpp:417
void initialize_coins_view()
Definition: coins_view.cpp:138
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:8
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition: fuzz.h:22
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 LOCK(cs)
Definition: sync.h:268
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:299
CDBWrapper db
Definition: dbwrapper.cpp:372
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.
static void StartPoolIfNeeded()
Definition: threadpool.cpp:49
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
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