14#include <boost/test/unit_test.hpp>
35 txParent.
vin.resize(1);
37 txParent.
vout.resize(3);
38 for (
int i = 0; i < 3; i++)
41 txParent.
vout[i].nValue = 33000LL;
44 for (
int i = 0; i < 3; i++)
46 txChild[i].
vin.resize(1);
48 txChild[i].
vin[0].prevout.hash = txParent.
GetHash();
49 txChild[i].
vin[0].prevout.n = i;
50 txChild[i].
vout.resize(1);
52 txChild[i].
vout[0].nValue = 11000LL;
55 for (
int i = 0; i < 3; i++)
57 txGrandChild[i].
vin.resize(1);
59 txGrandChild[i].
vin[0].prevout.hash = txChild[i].
GetHash();
60 txGrandChild[i].
vin[0].prevout.n = 0;
61 txGrandChild[i].
vout.resize(1);
63 txGrandChild[i].
vout[0].nValue = 11000LL;
71 unsigned int poolSize = testPool.
size();
77 poolSize = testPool.
size();
83 for (
int i = 0; i < 3; i++)
89 poolSize = testPool.
size();
93 poolSize = testPool.
size();
96 poolSize = testPool.
size();
100 poolSize = testPool.
size();
106 for (
int i = 0; i < 3; i++)
113 poolSize = testPool.
size();
141 pool.TrimToSize(
pool.DynamicMemoryUsage());
145 pool.TrimToSize(
pool.DynamicMemoryUsage() * 3 / 4);
159 pool.TrimToSize(
pool.DynamicMemoryUsage() * 3 / 4);
174 tx4.
vin[0].prevout.SetNull();
176 tx4.
vin[1].prevout.SetNull();
188 tx5.
vin[1].prevout.SetNull();
200 tx6.
vin[1].prevout.SetNull();
221 auto usage_with_tx4_only =
pool.DynamicMemoryUsage();
230 pool.TrimToSize(
pool.DynamicMemoryUsage() - 1);
244 pool.TrimToSize(usage_with_tx4_only + 1);
254 std::vector<CTransactionRef> vtx;
257 clock_ctx += HALFLIFE;
260 pool.removeForBlock(vtx, 1);
261 clock_ctx += HALFLIFE;
265 clock_ctx += HALFLIFE / 2;
269 clock_ctx += HALFLIFE / 4;
273 clock_ctx += 5 * HALFLIFE;
277 clock_ctx += HALFLIFE;
282inline 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>())
285 tx.
vin.resize(inputs.size());
286 tx.
vout.resize(output_values.size());
287 for (
size_t i = 0; i < inputs.size(); ++i) {
288 tx.
vin[i].prevout.hash = inputs[i]->GetHash();
289 tx.
vin[i].prevout.n = input_indices.size() > i ? input_indices[i] : 0;
291 for (
size_t i = 0; i < output_values.size(); ++i) {
293 tx.
vout[i].nValue = output_values[i];
301 size_t ancestors, clustersize;
315 pool.GetTransactionAncestry(tx1->GetHash(), ancestors, clustersize);
331 pool.GetTransactionAncestry(tx1->GetHash(), ancestors, clustersize);
334 pool.GetTransactionAncestry(tx2->GetHash(), ancestors, clustersize);
351 pool.GetTransactionAncestry(tx1->GetHash(), ancestors, clustersize);
354 pool.GetTransactionAncestry(tx2->GetHash(), ancestors, clustersize);
357 pool.GetTransactionAncestry(tx3->GetHash(), ancestors, clustersize);
377 pool.GetTransactionAncestry(tx1->GetHash(), ancestors, clustersize);
380 pool.GetTransactionAncestry(tx2->GetHash(), ancestors, clustersize);
383 pool.GetTransactionAncestry(tx3->GetHash(), ancestors, clustersize);
386 pool.GetTransactionAncestry(tx4->GetHash(), ancestors, clustersize);
401 for (uint64_t i = 0; i < 5; i++) {
403 tyi =
make_tx({v}, i > 0 ? std::vector<CTransactionRef>{*ty[i - 1]} : std::vector<CTransactionRef>{});
406 pool.GetTransactionAncestry(tyi->GetHash(), ancestors, clustersize);
426 pool.GetTransactionAncestry(tx1->GetHash(), ancestors, clustersize);
429 pool.GetTransactionAncestry(tx2->GetHash(), ancestors, clustersize);
432 pool.GetTransactionAncestry(tx3->GetHash(), ancestors, clustersize);
435 pool.GetTransactionAncestry(tx4->GetHash(), ancestors, clustersize);
438 pool.GetTransactionAncestry(ty1->GetHash(), ancestors, clustersize);
441 pool.GetTransactionAncestry(ty2->GetHash(), ancestors, clustersize);
444 pool.GetTransactionAncestry(ty3->GetHash(), ancestors, clustersize);
447 pool.GetTransactionAncestry(ty4->GetHash(), ancestors, clustersize);
450 pool.GetTransactionAncestry(ty5->GetHash(), ancestors, clustersize);
453 pool.GetTransactionAncestry(ty6->GetHash(), ancestors, clustersize);
460 size_t ancestors, descendants;
489 pool.GetTransactionAncestry(ta->GetHash(), ancestors, descendants);
492 pool.GetTransactionAncestry(tb->GetHash(), ancestors, descendants);
495 pool.GetTransactionAncestry(tc->GetHash(), ancestors, descendants);
498 pool.GetTransactionAncestry(td->GetHash(), ancestors, descendants);
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
TryAddToMempool(pool, CTxMemPoolEntry(tx, fee, 0, 1, 0, false, 4, lp))
#define Assert(val)
Identity function.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
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 ...
CFeeRate GetMinFee() const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
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...
static const int ROLLING_FEE_HALFLIFE
unsigned long size() const
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
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 constexpr auto REMOVAL_REASON_DUMMY
BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
#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 constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE
Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or rep...
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
static constexpr CAmount CENT
A mutable version of CTransaction.
std::vector< CTxOut > vout
Txid GetHash() const
Compute the hash of this CMutableTransaction.
CTxMemPoolEntry FromTx(const CMutableTransaction &tx) const
TestMemPoolEntryHelper & Fee(CAmount _fee)
Testing setup that configures a complete environment.
std::unique_ptr< CTxMemPool > mempool