13 #include <boost/test/unit_test.hpp> 34 txParent.
vin.resize(1);
36 txParent.
vout.resize(3);
37 for (
int i = 0; i < 3; i++)
40 txParent.
vout[i].nValue = 33000LL;
43 for (
int i = 0; i < 3; i++)
45 txChild[i].
vin.resize(1);
47 txChild[i].
vin[0].prevout.hash = txParent.
GetHash();
48 txChild[i].
vin[0].prevout.n = i;
49 txChild[i].
vout.resize(1);
51 txChild[i].
vout[0].nValue = 11000LL;
54 for (
int i = 0; i < 3; i++)
56 txGrandChild[i].
vin.resize(1);
58 txGrandChild[i].
vin[0].prevout.hash = txChild[i].
GetHash();
59 txGrandChild[i].
vin[0].prevout.n = 0;
60 txGrandChild[i].
vout.resize(1);
62 txGrandChild[i].
vout[0].nValue = 11000LL;
70 unsigned int poolSize = testPool.
size();
76 poolSize = testPool.
size();
82 for (
int i = 0; i < 3; i++)
88 poolSize = testPool.
size();
92 poolSize = testPool.
size();
95 poolSize = testPool.
size();
99 poolSize = testPool.
size();
105 for (
int i = 0; i < 3; i++)
112 poolSize = testPool.
size();
118 template <
typename name>
122 typename CTxMemPool::indexed_transaction_set::index<name>::type::iterator it = pool.mapTx.get<
name>().begin();
124 for (; it != pool.mapTx.get<
name>().end(); ++it, ++
count) {
146 tx2.vout[0].nValue = 2 *
COIN;
153 tx3.vout[0].nValue = 5 *
COIN;
160 tx4.vout[0].nValue = 6 *
COIN;
167 tx5.vout[0].nValue = 11 *
COIN;
172 std::vector<std::string> sortedOrder;
173 sortedOrder.resize(5);
174 sortedOrder[0] = tx3.GetHash().ToString();
175 sortedOrder[1] = tx5.GetHash().ToString();
177 sortedOrder[3] = tx4.GetHash().ToString();
178 sortedOrder[4] = tx2.GetHash().ToString();
179 CheckSort<descendant_score>(pool, sortedOrder);
186 tx6.vout[0].nValue = 20 *
COIN;
190 sortedOrder.insert(sortedOrder.begin(), tx6.GetHash().ToString());
191 CheckSort<descendant_score>(pool, sortedOrder);
194 setAncestors.insert(pool.GetIter(tx6.GetHash()).value());
207 BOOST_REQUIRE(ancestors_calculated.has_value());
208 BOOST_CHECK(*ancestors_calculated == setAncestors);
215 sortedOrder.erase(sortedOrder.begin());
216 sortedOrder.push_back(tx6.GetHash().ToString());
218 CheckSort<descendant_score>(pool, sortedOrder);
227 tx8.vout[0].nValue = 10 *
COIN;
228 setAncestors.insert(pool.GetIter(tx7.
GetHash()).value());
232 sortedOrder.insert(sortedOrder.begin(), tx8.GetHash().ToString());
233 CheckSort<descendant_score>(pool, sortedOrder);
242 tx9.vout[0].nValue = 1 *
COIN;
247 sortedOrder.insert(sortedOrder.begin(), tx9.GetHash().ToString());
248 CheckSort<descendant_score>(pool, sortedOrder);
250 std::vector<std::string> snapshotOrder = sortedOrder;
252 setAncestors.insert(pool.GetIter(tx8.GetHash()).value());
253 setAncestors.insert(pool.GetIter(tx9.GetHash()).value());
267 BOOST_REQUIRE(ancestors_calculated);
268 BOOST_CHECK(*ancestors_calculated == setAncestors);
288 sortedOrder.erase(sortedOrder.begin(), sortedOrder.begin()+2);
289 sortedOrder.insert(sortedOrder.begin()+5, tx9.GetHash().ToString());
290 sortedOrder.insert(sortedOrder.begin()+6, tx8.GetHash().ToString());
292 CheckSort<descendant_score>(pool, sortedOrder);
299 CheckSort<descendant_score>(pool, snapshotOrder);
322 tx2.vout[0].nValue = 2 *
COIN;
337 tx4.vout[0].nValue = 6 *
COIN;
344 tx5.vout[0].nValue = 11 *
COIN;
348 std::vector<std::string> sortedOrder;
349 sortedOrder.resize(5);
350 sortedOrder[0] = tx2.GetHash().ToString();
351 sortedOrder[1] = tx4.GetHash().ToString();
355 if (tx1.
GetHash() < tx5.GetHash()) {
357 sortedOrder[3] = tx5.GetHash().ToString();
359 sortedOrder[2] = tx5.GetHash().ToString();
364 CheckSort<ancestor_score>(pool, sortedOrder);
371 tx6.vout[0].nValue = 20 *
COIN;
377 if (tx3.
GetHash() < tx6.GetHash())
378 sortedOrder.push_back(tx6.GetHash().ToString());
380 sortedOrder.insert(sortedOrder.end()-1,tx6.GetHash().ToString());
382 CheckSort<ancestor_score>(pool, sortedOrder);
386 tx7.vin[0].prevout =
COutPoint(tx6.GetHash(), 0);
390 tx7.vout[0].nValue = 10 *
COIN;
394 CAmount fee = (20000/tx2Size)*(tx7Size + tx6Size) - 1;
398 sortedOrder.insert(sortedOrder.begin()+1, tx7.GetHash().ToString());
399 CheckSort<ancestor_score>(pool, sortedOrder);
402 std::vector<CTransactionRef> vtx;
404 pool.removeForBlock(vtx, 1);
406 sortedOrder.erase(sortedOrder.begin()+1);
408 if (tx3.
GetHash() < tx6.GetHash())
409 sortedOrder.pop_back();
411 sortedOrder.erase(sortedOrder.end()-2);
412 sortedOrder.insert(sortedOrder.begin(), tx7.GetHash().ToString());
413 CheckSort<ancestor_score>(pool, sortedOrder);
419 tx8.vin[0].prevout =
COutPoint(tx7.GetHash(), 0);
423 tx8.vout[0].nValue = 10*
COIN;
429 sortedOrder.insert(sortedOrder.end()-1, tx8.GetHash().ToString());
430 CheckSort<ancestor_score>(pool, sortedOrder);
453 tx2.vout[0].nValue = 10 *
COIN;
456 pool.TrimToSize(pool.DynamicMemoryUsage());
460 pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4);
467 tx3.vin[0].prevout =
COutPoint(tx2.GetHash(), 0);
471 tx3.vout[0].nValue = 10 *
COIN;
474 pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4);
489 tx4.vin[0].prevout.SetNull();
491 tx4.vin[1].prevout.SetNull();
495 tx4.vout[0].nValue = 10 *
COIN;
497 tx4.vout[1].nValue = 10 *
COIN;
503 tx5.
vin[1].prevout.SetNull();
515 tx6.
vin[1].prevout.SetNull();
541 pool.TrimToSize(pool.DynamicMemoryUsage() - 1);
550 pool.TrimToSize(pool.DynamicMemoryUsage() / 2);
559 std::vector<CTransactionRef> vtx;
564 pool.removeForBlock(vtx, 1);
586 inline 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>())
589 tx.
vin.resize(inputs.size());
590 tx.
vout.resize(output_values.size());
591 for (
size_t i = 0; i < inputs.size(); ++i) {
592 tx.
vin[i].prevout.hash = inputs[i]->GetHash();
593 tx.
vin[i].prevout.n = input_indices.size() > i ? input_indices[i] : 0;
595 for (
size_t i = 0; i < output_values.size(); ++i) {
597 tx.
vout[i].nValue = output_values[i];
605 size_t ancestors, descendants;
705 for (uint64_t i = 0; i < 5; i++) {
707 tyi =
make_tx({v}, i > 0 ? std::vector<CTransactionRef>{*ty[i - 1]} : std::vector<CTransactionRef>{});
764 size_t ancestors, descendants;
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...
TestMemPoolEntryHelper & Fee(CAmount _fee)
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
unsigned long size() const
std::set< txiter, CompareIteratorByHash > setEntries
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
CTxMemPoolEntry FromTx(const CMutableTransaction &tx) const
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transa...
CFeeRate GetMinFee() const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
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 >())
std::unique_ptr< CTxMemPool > mempool
int64_t CAmount
Amount in satoshis (Can be negative)
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
static constexpr auto REMOVAL_REASON_DUMMY
BOOST_AUTO_TEST_SUITE_END()
std::string ToString() const
static const int ROLLING_FEE_HALFLIFE
Txid GetHash() const
Compute the hash of this CMutableTransaction.
AddToMempool(pool, CTxMemPoolEntry(tx, fee, nTime, nHeight, sequence, spendsCoinbase, sigOpCost, lp))
An outpoint - a combination of a transaction hash and an index n into its vout.
std::vector< CTxOut > vout
static CTransactionRef MakeTransactionRef(Tx &&txIn)
#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.
TestMemPoolEntryHelper & Time(NodeSeconds tp)
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.
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
static void CheckSort(CTxMemPool &pool, std::vector< std::string > &sortedOrder) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
A mutable version of CTransaction.
static constexpr CAmount CENT
BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
static constexpr MemPoolLimits NoLimits()
The basic transaction that is broadcasted on the network and contained in blocks. ...
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
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.