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) {
119 replacement_tx->vin.resize(1);
120 replacement_tx->vin[0].prevout =
g_outpoints.at(iter++);
123 int32_t replacement_vsize = replacement_entry.GetTxSize();
124 int64_t running_vsize_total{replacement_vsize};
133 parent.
vin.resize(1);
137 mempool_txs.emplace_back(parent);
139 running_vsize_total += parent_entry.GetTxSize();
140 if (running_vsize_total > std::numeric_limits<int32_t>::max()) {
142 mempool_txs.pop_back();
145 assert(!pool.GetIter(parent_entry.GetTx().GetHash()));
148 child.
vin[0].prevout =
COutPoint{mempool_txs.back().GetHash(), 0};
150 mempool_txs.emplace_back(child);
152 running_vsize_total += child_entry.GetTxSize();
153 if (running_vsize_total > std::numeric_limits<int32_t>::max()) {
155 mempool_txs.pop_back();
158 if (!pool.GetIter(child_entry.GetTx().GetHash())) {
163 pool.PrioritiseTransaction(mempool_txs.back().GetHash().ToUint256(), fuzzed_data_provider.
ConsumeIntegralInRange<int32_t>(-100000, 100000));
169 for (
auto& tx : mempool_txs) {
171 direct_conflicts.insert(*pool.GetIter(tx.GetHash()));
177 for (
auto& txiter : direct_conflicts) {
178 pool.CalculateDescendants(txiter, all_conflicts);
182 auto changeset = pool.GetChangeSet();
183 for (
auto& txiter : all_conflicts) {
184 changeset->StageRemoval(txiter);
186 changeset->StageAddition(replacement_entry.GetSharedTx(), replacement_fees,
187 replacement_entry.GetTime().count(), replacement_entry.GetHeight(),
188 replacement_entry.GetSequence(), replacement_entry.GetSpendsCoinbase(),
189 replacement_entry.GetSigOpCost(), replacement_entry.GetLockPoints());
191 auto calc_results{changeset->CalculateChunksForRBF()};
193 if (calc_results.has_value()) {
198 for (
size_t i = 0; i < calc_results->first.size(); ++i) {
199 first_sum += calc_results->first[i];
200 if (i)
assert(!(calc_results->first[i - 1] << calc_results->first[i]));
203 for (
size_t i = 0; i < calc_results->second.size(); ++i) {
204 second_sum += calc_results->second[i];
205 if (i)
assert(!(calc_results->second[i - 1] << calc_results->second[i]));
209 for (
auto txiter : all_conflicts) {
210 replaced.
fee += txiter->GetModifiedFee();
211 replaced.
size += txiter->GetTxSize();
215 assert((first_sum - replaced) == (second_sum -
FeeFrac{replacement_fees, replacement_vsize}));
220 if (!calc_results.has_value()) {
224 auto old_sum = std::accumulate(calc_results->first.begin(), calc_results->first.end(),
FeeFrac{});
225 auto new_sum = std::accumulate(calc_results->second.begin(), calc_results->second.end(),
FeeFrac{});
226 if (!err_tuple.has_value()) {
228 assert(old_sum.fee <= new_sum.fee);
229 }
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.