Bitcoin Core  29.1.0
P2P Digital Currency
chain.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020-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 <chain.h>
7 #include <test/fuzz/fuzz.h>
8 #include <test/fuzz/util.h>
9 
10 #include <cstdint>
11 #include <optional>
12 #include <vector>
13 
15 {
16  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
17  std::optional<CDiskBlockIndex> disk_block_index = ConsumeDeserializable<CDiskBlockIndex>(fuzzed_data_provider);
18  if (!disk_block_index) {
19  return;
20  }
21 
22  const uint256 zero{};
23  disk_block_index->phashBlock = &zero;
24  {
25  LOCK(::cs_main);
26  (void)disk_block_index->ConstructBlockHash();
27  (void)disk_block_index->GetBlockPos();
28  (void)disk_block_index->GetBlockTime();
29  (void)disk_block_index->GetBlockTimeMax();
30  (void)disk_block_index->GetMedianTimePast();
31  (void)disk_block_index->GetUndoPos();
32  (void)disk_block_index->HaveNumChainTxs();
33  (void)disk_block_index->IsValid();
34  }
35 
36  const CBlockHeader block_header = disk_block_index->GetBlockHeader();
37  (void)CDiskBlockIndex{*disk_block_index};
38  (void)disk_block_index->BuildSkip();
39 
40  LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
41  const BlockStatus block_status = fuzzed_data_provider.PickValueInArray({
56  });
57  if (block_status & ~BLOCK_VALID_MASK) {
58  continue;
59  }
60  WITH_LOCK(::cs_main, (void)disk_block_index->RaiseValidity(block_status));
61  }
62 
63  CBlockIndex block_index{block_header};
64  block_index.phashBlock = &zero;
65  (void)block_index.GetBlockHash();
66  (void)block_index.ToString();
67 }
descends from failed block
Definition: chain.h:126
Reserved (was BLOCK_VALID_HEADER).
Definition: chain.h:93
FUZZ_TARGET(chain)
Definition: chain.cpp:14
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
Definition: chain.h:97
stage after last reached validness failed
Definition: chain.h:125
Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid...
Definition: chain.h:107
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition: fuzz.h:22
undo data available in rev*.dat
Definition: chain.h:122
Unused.
Definition: chain.h:90
Outputs do not overspend inputs, no double spends, coinbase output ok, no immature coinbase spends...
Definition: chain.h:111
Scripts & signatures ok.
Definition: chain.h:115
#define LOCK(cs)
Definition: sync.h:257
void BuildSkip()
Build the skiplist pointer for this entry.
Definition: chain.cpp:125
Used to marshal pointers into hashes for db storage.
Definition: chain.h:354
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:301
block data in blk*.dat was received with a witness-enforcing client
Definition: chain.h:129
256-bit opaque blob.
Definition: uint256.h:201
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:140
BlockStatus
Definition: chain.h:88
All validity bits.
Definition: chain.h:118
full block available in blk*.dat
Definition: chain.h:121
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: cs_main.cpp:8
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:21