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();
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;
116 if (!replacement_tx) {
119 replacement_tx->vin.resize(1);
120 replacement_tx->vin[0].prevout =
g_outpoints.at(iter++);
123 int32_t replacement_weight = replacement_entry.GetAdjustedWeight();
125 int64_t running_vsize_total{replacement_entry.GetTxSize()};
134 parent.
vin.resize(1);
138 mempool_txs.emplace_back(parent);
140 running_vsize_total += parent_entry.GetTxSize();
143 mempool_txs.pop_back();
146 assert(!pool.GetIter(parent_entry.GetTx().GetHash()));
151 if(!pool.GetIter(parent_entry.GetTx().GetHash())) {
152 mempool_txs.pop_back();
156 child.
vin[0].prevout =
COutPoint{mempool_txs.back().GetHash(), 0};
157 mempool_txs.emplace_back(child);
159 running_vsize_total += child_entry.GetTxSize();
162 mempool_txs.pop_back();
165 if (!pool.GetIter(child_entry.GetTx().GetHash())) {
169 if(!pool.GetIter(child_entry.GetTx().GetHash())) {
170 mempool_txs.pop_back();
182 for (
auto& tx : mempool_txs) {
184 direct_conflicts.insert(*pool.GetIter(tx.GetHash()));
190 for (
auto& txiter : direct_conflicts) {
191 pool.CalculateDescendants(txiter, all_conflicts);
195 auto changeset = pool.GetChangeSet();
196 for (
auto& txiter : all_conflicts) {
197 changeset->StageRemoval(txiter);
199 changeset->StageAddition(replacement_entry.GetSharedTx(), replacement_fees,
200 replacement_entry.GetTime().count(), replacement_entry.GetHeight(),
201 replacement_entry.GetSequence(), replacement_entry.GetSpendsCoinbase(),
202 replacement_entry.GetSigOpCost(), replacement_entry.GetLockPoints());
204 auto calc_results{changeset->CalculateChunksForRBF()};
206 if (calc_results.has_value()) {
211 for (
size_t i = 0; i < calc_results->first.size(); ++i) {
212 first_sum += calc_results->first[i];
213 if (i)
assert(!(calc_results->first[i - 1] << calc_results->first[i]));
216 for (
size_t i = 0; i < calc_results->second.size(); ++i) {
217 second_sum += calc_results->second[i];
218 if (i)
assert(!(calc_results->second[i - 1] << calc_results->second[i]));
222 for (
auto txiter : all_conflicts) {
223 replaced.
fee += txiter->GetModifiedFee();
224 replaced.
size += txiter->GetAdjustedWeight();
228 assert((first_sum - replaced) == (second_sum -
FeeFrac{replacement_fees, replacement_weight}));
233 if (!calc_results.has_value()) {
237 auto old_sum = std::accumulate(calc_results->first.begin(), calc_results->first.end(),
FeeFrac{});
238 auto new_sum = std::accumulate(calc_results->second.begin(), calc_results->second.end(),
FeeFrac{});
239 if (!err_tuple.has_value()) {
241 assert(old_sum.fee <= new_sum.fee);
242 }
else if (old_sum.fee > new_sum.fee) {
int64_t CAmount
Amount in satoshis (Can be negative)
TryAddToMempool(pool, CTxMemPoolEntry(TxGraph::Ref(), tx, fee, 0, 1, 0, false, 4, lp))
#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)
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
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.
FuzzedDataProvider & fuzzed_data_provider