12 #include <boost/test/unit_test.hpp> 22 tx.
vin.resize(inputs.size());
23 tx.
vout.resize(output_values.size());
24 for (
size_t i = 0; i < inputs.size(); ++i) {
25 tx.
vin[i].prevout.hash = inputs[i]->GetHash();
26 tx.
vin[i].prevout.n = 0;
29 witness.
stack.push_back(std::vector<unsigned char>(i + 10));
30 tx.
vin[i].scriptWitness = witness;
32 for (
size_t i = 0; i < output_values.size(); ++i) {
34 tx.
vout[i].nValue = output_values[i];
46 auto tx_to_spend = tx;
47 for (int32_t i{0}; i < num_descendants; ++i) {
48 auto next_tx =
make_tx({tx_to_spend}, {(50 - i) *
CENT});
49 pool.addUnchecked(entry.
FromTx(next_tx));
50 tx_to_spend = next_tx;
65 const auto tx1 =
make_tx( {m_coinbase_txns[0]}, {10 *
COIN});
71 const auto tx3 =
make_tx( {m_coinbase_txns[1]}, {1099 *
CENT});
77 const auto tx5 =
make_tx( {m_coinbase_txns[2]}, {1099 *
CENT});
86 const auto tx7 =
make_tx( {m_coinbase_txns[3]}, {999 *
CENT});
88 const auto tx8 =
make_tx( {m_coinbase_txns[4]}, {999 *
CENT});
91 const auto entry1 = pool.
GetIter(tx1->GetHash()).value();
92 const auto entry2 = pool.
GetIter(tx2->GetHash()).value();
93 const auto entry3 = pool.
GetIter(tx3->GetHash()).value();
94 const auto entry4 = pool.
GetIter(tx4->GetHash()).value();
95 const auto entry5 = pool.
GetIter(tx5->GetHash()).value();
96 const auto entry6 = pool.
GetIter(tx6->GetHash()).value();
97 const auto entry7 = pool.
GetIter(tx7->GetHash()).value();
98 const auto entry8 = pool.
GetIter(tx8->GetHash()).value();
120 CFeeRate(entry1->GetModifiedFee() + 1, entry1->GetTxSize() + 2),
121 unused_txid).has_value());
159 BOOST_CHECK(
PaysForRBF(high_fee, high_fee + 1, 2, incremental_relay_feerate, unused_txid).has_value());
160 BOOST_CHECK(
PaysForRBF(high_fee, high_fee + 2, 2, incremental_relay_feerate, unused_txid) == std::nullopt);
162 BOOST_CHECK(
PaysForRBF(high_fee, high_fee + 4, 2, higher_relay_feerate, unused_txid) == std::nullopt);
163 BOOST_CHECK(
PaysForRBF(low_fee, high_fee, 99999999, incremental_relay_feerate, unused_txid).has_value());
164 BOOST_CHECK(
PaysForRBF(low_fee, high_fee + 99999999, 99999999, incremental_relay_feerate, unused_txid) == std::nullopt);
169 const std::vector<CTransactionRef> parent_inputs({m_coinbase_txns[0], m_coinbase_txns[1], m_coinbase_txns[2],
170 m_coinbase_txns[3], m_coinbase_txns[4]});
171 const auto conflicts_with_parents =
make_tx(parent_inputs, {50 *
CENT});
176 all_conflicts) == std::nullopt);
178 auto conflicts_size = all_conflicts.size();
179 all_conflicts.clear();
183 conflicts_size += 23;
185 all_conflicts.clear();
189 conflicts_size += 23;
191 all_conflicts.clear();
195 conflicts_size += 23;
197 all_conflicts.clear();
201 conflicts_size += 23;
204 all_conflicts.clear();
211 const auto spends_unconfirmed =
make_tx({tx1}, {36 *
CENT});
212 for (
const auto& input : spends_unconfirmed->vin) {
218 all_entries) == std::nullopt);
222 const auto spends_new_unconfirmed =
make_tx({tx1, tx8}, {36 *
CENT});
226 const auto spends_conflicting_confirmed =
make_tx({m_coinbase_txns[0], m_coinbase_txns[1]}, {45 *
CENT});
std::optional< std::string > PaysForRBF(CAmount original_fees, CAmount replacement_fees, size_t replacement_vsize, CFeeRate relay_fee, const uint256 &txid)
The replacement transaction must pay more fees than the original transactions.
std::shared_ptr< const CTransaction > CTransactionRef
static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE
Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or rep...
std::optional< std::string > PaysMoreThanConflicts(const CTxMemPool::setEntries &iters_conflicting, CFeeRate replacement_feerate, const uint256 &txid)
Check that the feerate of the replacement transaction(s) is higher than the feerate of each of the tr...
static void add_descendants(const CTransactionRef &tx, int32_t num_descendants, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(
std::optional< std::string > HasNoNewUnconfirmed(const CTransaction &tx, const CTxMemPool &pool, const CTxMemPool::setEntries &iters_conflicting)
The replacement transaction may only include an unconfirmed input if that input was included in one o...
TestMemPoolEntryHelper & Fee(CAmount _fee)
bool exists(const GenTxid >xid) const
uint256 GetRandHash() noexcept
std::optional< std::string > EntriesAndTxidsDisjoint(const CTxMemPool::setEntries &ancestors, const std::set< uint256 > &direct_conflicts, const uint256 &txid)
Check the intersection between two sets of transactions (a set of mempool entries and a set of txids)...
std::vector< std::vector< unsigned char > > stack
std::set< txiter, CompareIteratorByHash > setEntries
BOOST_FIXTURE_TEST_CASE(rbf_helper_functions, TestChain100Setup)
CTxMemPoolEntry FromTx(const CMutableTransaction &tx) const
std::unique_ptr< CTxMemPool > mempool
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimate=true) EXCLUSIVE_LOCKS_REQUIRED(cs
If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transa...
std::optional< std::string > GetEntriesForConflicts(const CTransaction &tx, CTxMemPool &pool, const CTxMemPool::setEntries &iters_conflicting, CTxMemPool::setEntries &all_conflicts)
Get all descendants of iters_conflicting.
int64_t CAmount
Amount in satoshis (Can be negative)
static CTransactionRef make_tx(const std::vector< CTransactionRef > &inputs, const std::vector< CAmount > &output_values)
BOOST_AUTO_TEST_SUITE_END()
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
std::vector< CTxOut > vout
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::optional< txiter > GetIter(const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given hash, if found.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
#define BOOST_CHECK_EQUAL(v1, v2)
Serialized script, used inside transaction inputs and outputs.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
A mutable version of CTransaction.
static constexpr CAmount CENT
void PrioritiseTransaction(const uint256 &hash, const CAmount &nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
Testing setup that configures a complete environment.
static GenTxid Txid(const uint256 &hash)
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it...
#define Assert(val)
Identity function.
#define BOOST_CHECK(expr)
static constexpr CAmount COIN
The amount of satoshis in one BTC.