34 static const auto testing_setup = MakeNoLogFileContext<>();
35 g_setup = testing_setup.get();
40 static const auto testing_setup = MakeNoLogFileContext<>();
41 g_setup = testing_setup.get();
57 std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider,
TX_WITH_WITNESS);
68 const std::optional<CMutableTransaction> another_mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider,
TX_WITH_WITNESS);
73 if (fuzzed_data_provider.
ConsumeBool() && !mtx->vin.empty()) {
74 mtx->
vin[0].prevout =
COutPoint{another_tx.GetHash(), 0};
77 if (!pool.GetIter(another_tx.GetHash())) {
84 if (!pool.GetIter(tx.GetHash())) {
110 std::vector<CTransaction> mempool_txs;
115 std::optional<CMutableTransaction> replacement_tx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider,
TX_WITH_WITNESS);
116 if (!replacement_tx) {
120 replacement_tx->vin.resize(1);
121 replacement_tx->vin[0].prevout =
g_outpoints[iter++];
124 int32_t replacement_vsize = replacement_entry.GetTxSize();
125 int64_t running_vsize_total{replacement_vsize};
134 parent.
vin.resize(1);
138 mempool_txs.emplace_back(parent);
140 running_vsize_total += parent_entry.GetTxSize();
141 if (running_vsize_total > std::numeric_limits<int32_t>::max()) {
143 mempool_txs.pop_back();
146 assert(!pool.GetIter(parent_entry.GetTx().GetHash()));
149 child.
vin[0].prevout =
COutPoint{mempool_txs.back().GetHash(), 0};
151 mempool_txs.emplace_back(child);
153 running_vsize_total += child_entry.GetTxSize();
154 if (running_vsize_total > std::numeric_limits<int32_t>::max()) {
156 mempool_txs.pop_back();
159 if (!pool.GetIter(child_entry.GetTx().GetHash())) {
164 pool.PrioritiseTransaction(mempool_txs.back().GetHash().ToUint256(), fuzzed_data_provider.
ConsumeIntegralInRange<int32_t>(-100000, 100000));
170 for (
auto& tx : mempool_txs) {
172 direct_conflicts.insert(*pool.GetIter(tx.GetHash()));
178 for (
auto& txiter : direct_conflicts) {
179 pool.CalculateDescendants(txiter, all_conflicts);
183 auto changeset = pool.GetChangeSet();
184 for (
auto& txiter : all_conflicts) {
185 changeset->StageRemoval(txiter);
187 changeset->StageAddition(replacement_entry.GetSharedTx(), replacement_fees,
188 replacement_entry.GetTime().count(), replacement_entry.GetHeight(),
189 replacement_entry.GetSequence(), replacement_entry.GetSpendsCoinbase(),
190 replacement_entry.GetSigOpCost(), replacement_entry.GetLockPoints());
192 auto calc_results{changeset->CalculateChunksForRBF()};
194 if (calc_results.has_value()) {
199 for (
size_t i = 0; i < calc_results->first.size(); ++i) {
200 first_sum += calc_results->first[i];
201 if (i)
assert(!(calc_results->first[i - 1] << calc_results->first[i]));
204 for (
size_t i = 0; i < calc_results->second.size(); ++i) {
205 second_sum += calc_results->second[i];
206 if (i)
assert(!(calc_results->second[i - 1] << calc_results->second[i]));
210 for (
auto txiter : all_conflicts) {
211 replaced.
fee += txiter->GetModifiedFee();
212 replaced.
size += txiter->GetTxSize();
216 assert((first_sum - replaced) == (second_sum -
FeeFrac{replacement_fees, replacement_vsize}));
221 if (!calc_results.has_value()) {
225 auto old_sum = std::accumulate(calc_results->first.begin(), calc_results->first.end(),
FeeFrac{});
226 auto new_sum = std::accumulate(calc_results->second.begin(), calc_results->second.end(),
FeeFrac{});
227 if (!err_tuple.has_value()) {
229 assert(old_sum.fee <= new_sum.fee);
230 }
else if (old_sum.fee > new_sum.fee) {
int64_t CAmount
Amount in satoshis (Can be negative)
#define Assert(val)
Identity function.
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
const std::vector< CTxIn > vin
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
std::set< txiter, CompareIteratorByHash > setEntries
T ConsumeIntegralInRange(T min, T max)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
AddToMempool(pool, CTxMemPoolEntry(tx, fee, nTime, nHeight, sequence, spendsCoinbase, sigOpCost, lp))
std::optional< std::pair< DiagramCheckError, std::string > > ImprovesFeerateDiagram(CTxMemPool::ChangeSet &changeset)
The replacement transaction must improve the feerate diagram of the mempool.
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...
@ FAILURE
New diagram wasn't strictly superior
@ UNCALCULABLE
Unable to calculate due to topology or other reason.
static constexpr TransactionSerParams TX_WITH_WITNESS
A mutable version of CTransaction.
std::vector< CTxOut > vout
Data structure storing a fee and size, ordered by increasing fee/size.
FUZZ_TARGET(rbf,.init=initialize_rbf)
std::vector< COutPoint > g_outpoints
void initialize_package_rbf()
CTxMemPoolEntry ConsumeTxMemPoolEntry(FuzzedDataProvider &fuzzed_data_provider, const CTransaction &tx) noexcept
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
@ ZEROS
Seed with a compile time constant of zeros.
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.