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();
56 std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider,
TX_WITH_WITNESS);
67 const std::optional<CMutableTransaction> another_mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider,
TX_WITH_WITNESS);
72 if (fuzzed_data_provider.
ConsumeBool() && !mtx->vin.empty()) {
73 mtx->
vin[0].prevout =
COutPoint{another_tx.GetHash(), 0};
104 std::vector<CTransaction> mempool_txs;
111 int64_t running_vsize_total{replacement_vsize};
120 parent.
vin.resize(1);
124 mempool_txs.emplace_back(parent);
126 running_vsize_total += parent_entry.GetTxSize();
127 if (running_vsize_total > std::numeric_limits<int32_t>::max()) {
129 mempool_txs.pop_back();
132 pool.addUnchecked(parent_entry);
134 child.
vin[0].prevout =
COutPoint{mempool_txs.back().GetHash(), 0};
136 mempool_txs.emplace_back(child);
138 running_vsize_total += child_entry.GetTxSize();
139 if (running_vsize_total > std::numeric_limits<int32_t>::max()) {
141 mempool_txs.pop_back();
144 pool.addUnchecked(child_entry);
147 pool.PrioritiseTransaction(mempool_txs.back().GetHash().ToUint256(), fuzzed_data_provider.
ConsumeIntegralInRange<int32_t>(-100000, 100000));
153 for (
auto& tx : mempool_txs) {
155 direct_conflicts.insert(*pool.GetIter(tx.GetHash()));
161 for (
auto& txiter : direct_conflicts) {
162 pool.CalculateDescendants(txiter, all_conflicts);
167 auto calc_results{pool.CalculateChunksForRBF(replacement_fees, replacement_vsize, direct_conflicts, all_conflicts)};
169 if (calc_results.has_value()) {
174 for (
size_t i = 0; i < calc_results->first.size(); ++i) {
175 first_sum += calc_results->first[i];
176 if (i)
assert(!(calc_results->first[i - 1] << calc_results->first[i]));
179 for (
size_t i = 0; i < calc_results->second.size(); ++i) {
180 second_sum += calc_results->second[i];
181 if (i)
assert(!(calc_results->second[i - 1] << calc_results->second[i]));
185 for (
auto txiter : all_conflicts) {
186 replaced.
fee += txiter->GetModifiedFee();
187 replaced.
size += txiter->GetTxSize();
191 assert((first_sum - replaced) == (second_sum -
FeeFrac{replacement_fees, replacement_vsize}));
195 auto err_tuple{
ImprovesFeerateDiagram(pool, direct_conflicts, all_conflicts, replacement_fees, replacement_vsize)};
196 if (!calc_results.has_value()) {
200 auto old_sum = std::accumulate(calc_results->first.begin(), calc_results->first.end(),
FeeFrac{});
201 auto new_sum = std::accumulate(calc_results->second.begin(), calc_results->second.end(),
FeeFrac{});
202 if (!err_tuple.has_value()) {
204 assert(old_sum.fee <= new_sum.fee);
205 }
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.
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
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
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.