Bitcoin Core  22.99.0
P2P Digital Currency
rbf.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 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 <policy/rbf.h>
7 #include <sync.h>
9 #include <test/fuzz/fuzz.h>
10 #include <test/fuzz/util.h>
11 #include <txmempool.h>
12 
13 #include <cstdint>
14 #include <optional>
15 #include <string>
16 #include <vector>
17 
19 {
20  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
21  SetMockTime(ConsumeTime(fuzzed_data_provider));
22  std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
23  if (!mtx) {
24  return;
25  }
26  CTxMemPool pool;
27  while (fuzzed_data_provider.ConsumeBool()) {
28  const std::optional<CMutableTransaction> another_mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
29  if (!another_mtx) {
30  break;
31  }
32  const CTransaction another_tx{*another_mtx};
33  if (fuzzed_data_provider.ConsumeBool() && !mtx->vin.empty()) {
34  mtx->vin[0].prevout = COutPoint{another_tx.GetHash(), 0};
35  }
36  LOCK2(cs_main, pool.cs);
37  pool.addUnchecked(ConsumeTxMemPoolEntry(fuzzed_data_provider, another_tx));
38  }
39  const CTransaction tx{*mtx};
40  if (fuzzed_data_provider.ConsumeBool()) {
41  LOCK2(cs_main, pool.cs);
42  pool.addUnchecked(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx));
43  }
44  {
45  LOCK(pool.cs);
46  (void)IsRBFOptIn(tx, pool);
47  }
48 }
LOCK2
#define LOCK2(cs1, cs2)
Definition: sync.h:227
CTransaction::vin
const std::vector< CTxIn > vin
Definition: transaction.h:270
sync.h
transaction.h
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:478
util.h
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:259
txmempool.h
ConsumeTime
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
Definition: util.cpp:226
CTxMemPool::cs
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:566
SetMockTime
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:101
ConsumeTxMemPoolEntry
CTxMemPoolEntry ConsumeTxMemPoolEntry(FuzzedDataProvider &fuzzed_data_provider, const CTransaction &tx) noexcept
Definition: util.cpp:347
FuzzedDataProvider.h
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: validation.cpp:116
CTxMemPool::addUnchecked
void check(CChainState &active_chainstate) const EXCLUSIVE_LOCKS_REQUIRED(void addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimate=true) EXCLUSIVE_LOCKS_REQUIRED(cs
If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transa...
Definition: txmempool.h:637
fuzz.h
LOCK
#define LOCK(cs)
Definition: sync.h:226
FuzzedDataProvider
Definition: FuzzedDataProvider.h:31
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
IsRBFOptIn
RBFTransactionState IsRBFOptIn(const CTransaction &tx, const CTxMemPool &pool)
Determine whether an unconfirmed transaction is signaling opt-in to RBF according to BIP 125 This inv...
Definition: rbf.cpp:12
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition: FuzzedDataProvider.h:288
rbf.h
FUZZ_TARGET
FUZZ_TARGET(rbf)
Definition: rbf.cpp:18