35 static const auto testing_setup = MakeNoLogFileContext<>();
41 static const auto testing_setup = MakeNoLogFileContext<>();
75 mtx->
vin[0].prevout =
COutPoint{another_tx.GetHash(), 0};
78 if (!pool.GetIter(another_tx.GetHash())) {
85 if (!pool.GetIter(tx.GetHash())) {
111 std::vector<CTransaction> mempool_txs;
117 if (!replacement_tx) {
120 replacement_tx->vin.resize(1);
121 replacement_tx->vin[0].prevout =
g_outpoints.at(iter++);
124 int32_t replacement_weight = replacement_entry.GetAdjustedWeight();
126 int64_t running_vsize_total{replacement_entry.GetTxSize()};
135 parent.
vin.resize(1);
139 mempool_txs.emplace_back(parent);
141 running_vsize_total += parent_entry.GetTxSize();
144 mempool_txs.pop_back();
147 assert(!pool.GetIter(parent_entry.GetTx().GetHash()));
152 if(!pool.GetIter(parent_entry.GetTx().GetHash())) {
153 mempool_txs.pop_back();
157 child.
vin[0].prevout =
COutPoint{mempool_txs.back().GetHash(), 0};
158 mempool_txs.emplace_back(child);
160 running_vsize_total += child_entry.GetTxSize();
163 mempool_txs.pop_back();
166 if (!pool.GetIter(child_entry.GetTx().GetHash())) {
170 if(!pool.GetIter(child_entry.GetTx().GetHash())) {
171 mempool_txs.pop_back();
183 for (
auto& tx : mempool_txs) {
185 direct_conflicts.insert(*pool.GetIter(tx.GetHash()));
191 for (
auto& txiter : direct_conflicts) {
192 pool.CalculateDescendants(txiter, all_conflicts);
196 auto changeset = pool.GetChangeSet();
197 for (
auto& txiter : all_conflicts) {
198 changeset->StageRemoval(txiter);
200 changeset->StageAddition(replacement_entry.GetSharedTx(), replacement_fees,
201 replacement_entry.GetTime().count(), replacement_entry.GetHeight(),
202 replacement_entry.GetSequence(), replacement_entry.GetSpendsCoinbase(),
203 replacement_entry.GetSigOpCost(), replacement_entry.GetLockPoints());
205 auto calc_results{changeset->CalculateChunksForRBF()};
207 if (calc_results.has_value()) {
212 for (
size_t i = 0; i < calc_results->first.size(); ++i) {
213 first_sum += calc_results->first[i];
214 if (i)
assert(!(calc_results->first[i - 1] << calc_results->first[i]));
217 for (
size_t i = 0; i < calc_results->second.size(); ++i) {
218 second_sum += calc_results->second[i];
219 if (i)
assert(!(calc_results->second[i - 1] << calc_results->second[i]));
223 for (
auto txiter : all_conflicts) {
224 replaced.
fee += txiter->GetModifiedFee();
225 replaced.
size += txiter->GetAdjustedWeight();
229 assert((first_sum - replaced) == (second_sum -
FeeFrac{replacement_fees, replacement_weight}));
234 if (!calc_results.has_value()) {
238 auto old_sum = std::accumulate(calc_results->first.begin(), calc_results->first.end(),
FeeFrac{});
239 auto new_sum = std::accumulate(calc_results->second.begin(), calc_results->second.end(),
FeeFrac{});
240 if (!err_tuple.has_value()) {
242 assert(old_sum.fee <= new_sum.fee);
243 }
else if (old_sum.fee > new_sum.fee) {
int64_t CAmount
Amount in satoshis (Can be negative)
TryAddToMempool(pool, CTxMemPoolEntry(tx, fee, 0, 1, 0, false, 4, lp))
const TestingSetup * g_setup
#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)
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
static const int WITNESS_SCALE_FACTOR
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::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, uint32_t max_height) noexcept
NodeSeconds 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)
FuzzedDataProvider & fuzzed_data_provider