32 static const auto testing_setup = MakeNoLogFileContext<>();
33 g_setup = testing_setup.get();
38 static const auto testing_setup = MakeNoLogFileContext<>();
39 g_setup = testing_setup.get();
54 std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider,
TX_WITH_WITNESS);
63 const std::optional<CMutableTransaction> another_mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider,
TX_WITH_WITNESS);
68 if (fuzzed_data_provider.
ConsumeBool() && !mtx->vin.empty()) {
69 mtx->
vin[0].prevout =
COutPoint{another_tx.GetHash(), 0};
90 std::optional<CMutableTransaction> child = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider,
TX_WITH_WITNESS);
96 std::vector<CTransaction> mempool_txs;
103 int64_t running_vsize_total{replacement_vsize};
110 std::optional<CMutableTransaction> parent = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider,
TX_WITH_WITNESS);
115 parent->vin.resize(1);
118 mempool_txs.emplace_back(*parent);
120 running_vsize_total += parent_entry.GetTxSize();
121 if (running_vsize_total > std::numeric_limits<int32_t>::max()) {
123 mempool_txs.pop_back();
126 pool.addUnchecked(parent_entry);
127 if (fuzzed_data_provider.
ConsumeBool() && !child->vin.empty()) {
128 child->vin[0].prevout =
COutPoint{mempool_txs.back().GetHash(), 0};
130 mempool_txs.emplace_back(*child);
132 running_vsize_total += child_entry.GetTxSize();
133 if (running_vsize_total > std::numeric_limits<int32_t>::max()) {
135 mempool_txs.pop_back();
138 pool.addUnchecked(child_entry);
141 pool.PrioritiseTransaction(mempool_txs.back().GetHash().ToUint256(), fuzzed_data_provider.
ConsumeIntegralInRange<int32_t>(-100000, 100000));
147 for (
auto& tx : mempool_txs) {
149 direct_conflicts.insert(*pool.GetIter(tx.GetHash()));
155 for (
auto& txiter : direct_conflicts) {
156 pool.CalculateDescendants(txiter, all_conflicts);
161 auto calc_results{pool.CalculateChunksForRBF(replacement_fees, replacement_vsize, direct_conflicts, all_conflicts)};
163 if (calc_results.has_value()) {
168 for (
size_t i = 0; i < calc_results->first.size(); ++i) {
169 first_sum += calc_results->first[i];
170 if (i)
assert(!(calc_results->first[i - 1] << calc_results->first[i]));
173 for (
size_t i = 0; i < calc_results->second.size(); ++i) {
174 second_sum += calc_results->second[i];
175 if (i)
assert(!(calc_results->second[i - 1] << calc_results->second[i]));
179 for (
auto txiter : all_conflicts) {
180 replaced.
fee += txiter->GetModifiedFee();
181 replaced.
size += txiter->GetTxSize();
185 assert((first_sum - replaced) == (second_sum -
FeeFrac{replacement_fees, replacement_vsize}));
189 auto err_tuple{
ImprovesFeerateDiagram(pool, direct_conflicts, all_conflicts, replacement_fees, replacement_vsize)};
190 if (!calc_results.has_value()) {
194 auto old_sum = std::accumulate(calc_results->first.begin(), calc_results->first.end(),
FeeFrac{});
195 auto new_sum = std::accumulate(calc_results->second.begin(), calc_results->second.end(),
FeeFrac{});
196 if (!err_tuple.has_value()) {
198 assert(old_sum.fee <= new_sum.fee);
199 }
else if (old_sum.fee > new_sum.fee) {
int64_t CAmount
Amount in satoshis (Can be negative)
An outpoint - a combination of a transaction hash and an index n into its vout.
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.
std::optional< std::pair< DiagramCheckError, std::string > > ImprovesFeerateDiagram(CTxMemPool &pool, const CTxMemPool::setEntries &direct_conflicts, const CTxMemPool::setEntries &all_conflicts, CAmount replacement_fees, int64_t replacement_vsize)
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
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
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.