Changeset View
Changeset View
Standalone View
Standalone View
src/test/mempool_tests.cpp
Show First 20 Lines • Show All 377 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest) { | ||||
/* highest fee */ | /* highest fee */ | ||||
CMutableTransaction tx2 = CMutableTransaction(); | CMutableTransaction tx2 = CMutableTransaction(); | ||||
tx2.vout.resize(1); | tx2.vout.resize(1); | ||||
tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx2.vout[0].nValue = 2 * COIN; | tx2.vout[0].nValue = 2 * COIN; | ||||
pool.addUnchecked(tx2.GetId(), | pool.addUnchecked(tx2.GetId(), | ||||
entry.Fee(Amount(20000LL)).Priority(9.0).FromTx(tx2)); | entry.Fee(Amount(20000LL)).Priority(9.0).FromTx(tx2)); | ||||
uint64_t tx2Size = GetTransactionSize(tx2); | uint64_t tx2Size = CTransaction(tx2).GetTotalSize(); | ||||
/* lowest fee */ | /* lowest fee */ | ||||
CMutableTransaction tx3 = CMutableTransaction(); | CMutableTransaction tx3 = CMutableTransaction(); | ||||
tx3.vout.resize(1); | tx3.vout.resize(1); | ||||
tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx3.vout[0].nValue = 5 * COIN; | tx3.vout[0].nValue = 5 * COIN; | ||||
pool.addUnchecked(tx3.GetId(), | pool.addUnchecked(tx3.GetId(), | ||||
entry.Fee(Amount(0LL)).Priority(100.0).FromTx(tx3)); | entry.Fee(Amount(0LL)).Priority(100.0).FromTx(tx3)); | ||||
Show All 33 Lines | BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest) { | ||||
CheckSort<ancestor_score>(pool, sortedOrder); | CheckSort<ancestor_score>(pool, sortedOrder); | ||||
/* low fee parent with high fee child */ | /* low fee parent with high fee child */ | ||||
/* tx6 (0) -> tx7 (high) */ | /* tx6 (0) -> tx7 (high) */ | ||||
CMutableTransaction tx6 = CMutableTransaction(); | CMutableTransaction tx6 = CMutableTransaction(); | ||||
tx6.vout.resize(1); | tx6.vout.resize(1); | ||||
tx6.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx6.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx6.vout[0].nValue = 20 * COIN; | tx6.vout[0].nValue = 20 * COIN; | ||||
uint64_t tx6Size = GetTransactionSize(tx6); | uint64_t tx6Size = CTransaction(tx6).GetTotalSize(); | ||||
pool.addUnchecked(tx6.GetId(), entry.Fee(Amount(0LL)).FromTx(tx6)); | pool.addUnchecked(tx6.GetId(), entry.Fee(Amount(0LL)).FromTx(tx6)); | ||||
BOOST_CHECK_EQUAL(pool.size(), 6UL); | BOOST_CHECK_EQUAL(pool.size(), 6UL); | ||||
// Ties are broken by hash | // Ties are broken by hash | ||||
if (tx3.GetId() < tx6.GetId()) { | if (tx3.GetId() < tx6.GetId()) { | ||||
sortedOrder.push_back(tx6.GetId().ToString()); | sortedOrder.push_back(tx6.GetId().ToString()); | ||||
} else { | } else { | ||||
sortedOrder.insert(sortedOrder.end() - 1, tx6.GetId().ToString()); | sortedOrder.insert(sortedOrder.end() - 1, tx6.GetId().ToString()); | ||||
} | } | ||||
CheckSort<ancestor_score>(pool, sortedOrder); | CheckSort<ancestor_score>(pool, sortedOrder); | ||||
CMutableTransaction tx7 = CMutableTransaction(); | CMutableTransaction tx7 = CMutableTransaction(); | ||||
tx7.vin.resize(1); | tx7.vin.resize(1); | ||||
tx7.vin[0].prevout = COutPoint(tx6.GetId(), 0); | tx7.vin[0].prevout = COutPoint(tx6.GetId(), 0); | ||||
tx7.vin[0].scriptSig = CScript() << OP_11; | tx7.vin[0].scriptSig = CScript() << OP_11; | ||||
tx7.vout.resize(1); | tx7.vout.resize(1); | ||||
tx7.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx7.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx7.vout[0].nValue = 10 * COIN; | tx7.vout[0].nValue = 10 * COIN; | ||||
uint64_t tx7Size = GetTransactionSize(tx7); | uint64_t tx7Size = CTransaction(tx7).GetTotalSize(); | ||||
/* set the fee to just below tx2's feerate when including ancestor */ | /* set the fee to just below tx2's feerate when including ancestor */ | ||||
Amount fee((20000 / tx2Size) * (tx7Size + tx6Size) - 1); | Amount fee((20000 / tx2Size) * (tx7Size + tx6Size) - 1); | ||||
// CTxMemPoolEntry entry7(tx7, fee, 2, 10.0, 1, true); | // CTxMemPoolEntry entry7(tx7, fee, 2, 10.0, 1, true); | ||||
pool.addUnchecked(tx7.GetId(), entry.Fee(Amount(fee)).FromTx(tx7)); | pool.addUnchecked(tx7.GetId(), entry.Fee(Amount(fee)).FromTx(tx7)); | ||||
BOOST_CHECK_EQUAL(pool.size(), 7UL); | BOOST_CHECK_EQUAL(pool.size(), 7UL); | ||||
sortedOrder.insert(sortedOrder.begin() + 1, tx7.GetId().ToString()); | sortedOrder.insert(sortedOrder.begin() + 1, tx7.GetId().ToString()); | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest) { | ||||
// tx3 should pay for tx2 (CPFP) | // tx3 should pay for tx2 (CPFP) | ||||
pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4); | pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4); | ||||
BOOST_CHECK(!pool.exists(tx1.GetId())); | BOOST_CHECK(!pool.exists(tx1.GetId())); | ||||
BOOST_CHECK(pool.exists(tx2.GetId())); | BOOST_CHECK(pool.exists(tx2.GetId())); | ||||
BOOST_CHECK(pool.exists(tx3.GetId())); | BOOST_CHECK(pool.exists(tx3.GetId())); | ||||
// mempool is limited to tx1's size in memory usage, so nothing fits | // mempool is limited to tx1's size in memory usage, so nothing fits | ||||
pool.TrimToSize(GetTransactionSize(tx1)); | pool.TrimToSize(CTransaction(tx1).GetTotalSize()); | ||||
BOOST_CHECK(!pool.exists(tx1.GetId())); | BOOST_CHECK(!pool.exists(tx1.GetId())); | ||||
BOOST_CHECK(!pool.exists(tx2.GetId())); | BOOST_CHECK(!pool.exists(tx2.GetId())); | ||||
BOOST_CHECK(!pool.exists(tx3.GetId())); | BOOST_CHECK(!pool.exists(tx3.GetId())); | ||||
CFeeRate maxFeeRateRemoved( | CFeeRate maxFeeRateRemoved(Amount(25000), | ||||
Amount(25000), GetTransactionSize(tx3) + GetTransactionSize(tx2)); | CTransaction(tx3).GetTotalSize() + | ||||
CTransaction(tx2).GetTotalSize()); | |||||
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), | BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), | ||||
maxFeeRateRemoved.GetFeePerK() + Amount(1000)); | maxFeeRateRemoved.GetFeePerK() + Amount(1000)); | ||||
CMutableTransaction tx4 = CMutableTransaction(); | CMutableTransaction tx4 = CMutableTransaction(); | ||||
tx4.vin.resize(2); | tx4.vin.resize(2); | ||||
tx4.vin[0].prevout.SetNull(); | tx4.vin[0].prevout.SetNull(); | ||||
tx4.vin[0].scriptSig = CScript() << OP_4; | tx4.vin[0].scriptSig = CScript() << OP_4; | ||||
tx4.vin[1].prevout.SetNull(); | tx4.vin[1].prevout.SetNull(); | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |