12#include <boost/test/unit_test.hpp>
27 txParent.
vin.resize(1);
29 txParent.
vout.resize(3);
30 for (
int i = 0; i < 3; i++)
33 txParent.
vout[i].nValue = 33000LL;
36 for (
int i = 0; i < 3; i++)
38 txChild[i].
vin.resize(1);
40 txChild[i].
vin[0].prevout.hash = txParent.
GetHash();
41 txChild[i].
vin[0].prevout.n = i;
42 txChild[i].
vout.resize(1);
44 txChild[i].
vout[0].nValue = 11000LL;
47 for (
int i = 0; i < 3; i++)
49 txGrandChild[i].
vin.resize(1);
51 txGrandChild[i].
vin[0].prevout.hash = txChild[i].
GetHash();
52 txGrandChild[i].
vin[0].prevout.n = 0;
53 txGrandChild[i].
vout.resize(1);
55 txGrandChild[i].
vout[0].nValue = 11000LL;
63 unsigned int poolSize = testPool.
size();
69 poolSize = testPool.
size();
75 for (
int i = 0; i < 3; i++)
81 poolSize = testPool.
size();
85 poolSize = testPool.
size();
88 poolSize = testPool.
size();
92 poolSize = testPool.
size();
98 for (
int i = 0; i < 3; i++)
105 poolSize = testPool.
size();
111template<
typename name>
115 typename CTxMemPool::indexed_transaction_set::index<name>::type::iterator it = pool.mapTx.get<
name>().begin();
117 for (; it != pool.mapTx.get<
name>().end(); ++it, ++
count) {
165 std::vector<std::string> sortedOrder;
166 sortedOrder.resize(5);
172 CheckSort<descendant_score>(pool, sortedOrder);
184 CheckSort<descendant_score>(pool, sortedOrder);
187 setAncestors.insert(pool.mapTx.find(tx6.
GetHash()));
201 BOOST_CHECK(setAncestorsCalculated == setAncestors);
207 sortedOrder.erase(sortedOrder.begin());
210 CheckSort<descendant_score>(pool, sortedOrder);
220 setAncestors.insert(pool.mapTx.find(tx7.
GetHash()));
225 CheckSort<descendant_score>(pool, sortedOrder);
240 CheckSort<descendant_score>(pool, sortedOrder);
242 std::vector<std::string> snapshotOrder = sortedOrder;
244 setAncestors.insert(pool.mapTx.find(tx8.
GetHash()));
245 setAncestors.insert(pool.mapTx.find(tx9.
GetHash()));
257 setAncestorsCalculated.clear();
259 BOOST_CHECK(setAncestorsCalculated == setAncestors);
278 sortedOrder.erase(sortedOrder.begin(), sortedOrder.begin()+2);
282 CheckSort<descendant_score>(pool, sortedOrder);
289 CheckSort<descendant_score>(pool, snapshotOrder);
338 std::vector<std::string> sortedOrder;
339 sortedOrder.resize(5);
354 CheckSort<ancestor_score>(pool, sortedOrder);
372 CheckSort<ancestor_score>(pool, sortedOrder);
384 CAmount fee = (20000/tx2Size)*(tx7Size + tx6Size) - 1;
389 CheckSort<ancestor_score>(pool, sortedOrder);
392 std::vector<CTransactionRef> vtx;
396 sortedOrder.erase(sortedOrder.begin()+1);
399 sortedOrder.pop_back();
401 sortedOrder.erase(sortedOrder.end()-2);
403 CheckSort<ancestor_score>(pool, sortedOrder);
420 CheckSort<ancestor_score>(pool, sortedOrder);
479 tx4.
vin[0].prevout.SetNull();
481 tx4.
vin[1].prevout.SetNull();
493 tx5.
vin[1].prevout.SetNull();
505 tx6.
vin[1].prevout.SetNull();
549 std::vector<CTransactionRef> vtx;
576inline CTransactionRef make_tx(std::vector<CAmount>&& output_values, std::vector<CTransactionRef>&& inputs=std::vector<CTransactionRef>(), std::vector<uint32_t>&& input_indices=std::vector<uint32_t>())
579 tx.
vin.resize(inputs.size());
580 tx.
vout.resize(output_values.size());
581 for (
size_t i = 0; i < inputs.size(); ++i) {
582 tx.
vin[i].prevout.hash = inputs[i]->GetHash();
583 tx.
vin[i].prevout.n = input_indices.size() > i ? input_indices[i] : 0;
585 for (
size_t i = 0; i < output_values.size(); ++i) {
587 tx.
vout[i].nValue = output_values[i];
595 size_t ancestors, descendants;
695 for (uint64_t i = 0; i < 5; i++) {
697 tyi =
make_tx( {v}, i > 0 ? std::vector<CTransactionRef>{*ty[i - 1]} : std::vector<CTransactionRef>{});
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Fee rate in satoshis per kilobyte: CAmount / kB.
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
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.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
CFeeRate GetMinFee(size_t sizelimit) const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
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...
void TrimToSize(size_t sizelimit, std::vector< COutPoint > *pvNoSpendsRemaining=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove transactions from the mempool until its dynamic size is <= sizelimit.
size_t DynamicMemoryUsage() const
void GetTransactionAncestry(const uint256 &txid, size_t &ancestors, size_t &descendants, size_t *ancestorsize=nullptr, CAmount *ancestorfees=nullptr) const
Calculate the ancestor and descendant count for the given transaction.
bool CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents=true) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Try to calculate all in-mempool ancestors of entry.
static const int ROLLING_FEE_HALFLIFE
std::set< txiter, CompareIteratorByHash > setEntries
void removeForBlock(const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs)
Called when a block is connected.
bool exists(const GenTxid >xid) const
unsigned long size() const
static GenTxid Txid(const uint256 &hash)
std::string ToString() const
BOOST_AUTO_TEST_SUITE_END()
CTransactionRef make_tx(std::vector< CAmount > &&output_values, std::vector< CTransactionRef > &&inputs=std::vector< CTransactionRef >(), std::vector< uint32_t > &&input_indices=std::vector< uint32_t >())
static void CheckSort(CTxMemPool &pool, std::vector< std::string > &sortedOrder) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
static constexpr auto REMOVAL_REASON_DUMMY
BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
static constexpr CAmount CENT
A mutable version of CTransaction.
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
std::vector< CTxOut > vout
TestMemPoolEntryHelper & Time(int64_t _time)
CTxMemPoolEntry FromTx(const CMutableTransaction &tx) const
TestMemPoolEntryHelper & Fee(CAmount _fee)
Testing setup that configures a complete environment.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.