Changeset View
Changeset View
Standalone View
Standalone View
src/test/mempool_tests.cpp
Show First 20 Lines • Show All 496 Lines • ▼ Show 20 Lines | if (tx3.GetId() < tx6.GetId()) { | ||||
sortedOrder.push_back(tx3.GetId().ToString()); | sortedOrder.push_back(tx3.GetId().ToString()); | ||||
} else { | } else { | ||||
sortedOrder.push_back(tx3.GetId().ToString()); | sortedOrder.push_back(tx3.GetId().ToString()); | ||||
sortedOrder.push_back(tx6.GetId().ToString()); | sortedOrder.push_back(tx6.GetId().ToString()); | ||||
} | } | ||||
CheckSort<mining_score>(pool, sortedOrder, "MempoolIndexingTest8"); | CheckSort<mining_score>(pool, sortedOrder, "MempoolIndexingTest8"); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest) { | |||||
CTxMemPool pool; | |||||
TestMemPoolEntryHelper entry; | |||||
/* 3rd highest fee */ | |||||
CMutableTransaction tx1 = CMutableTransaction(); | |||||
tx1.vout.resize(1); | |||||
tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | |||||
tx1.vout[0].nValue = 10 * COIN; | |||||
pool.addUnchecked(tx1.GetId(), | |||||
entry.Fee(10000 * SATOSHI).Priority(10.0).FromTx(tx1)); | |||||
/* highest fee */ | |||||
CMutableTransaction tx2 = CMutableTransaction(); | |||||
tx2.vout.resize(1); | |||||
tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | |||||
tx2.vout[0].nValue = 2 * COIN; | |||||
pool.addUnchecked(tx2.GetId(), | |||||
entry.Fee(20000 * SATOSHI).Priority(9.0).FromTx(tx2)); | |||||
uint64_t tx2Size = CTransaction(tx2).GetTotalSize(); | |||||
/* lowest fee */ | |||||
CMutableTransaction tx3 = CMutableTransaction(); | |||||
tx3.vout.resize(1); | |||||
tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | |||||
tx3.vout[0].nValue = 5 * COIN; | |||||
pool.addUnchecked(tx3.GetId(), | |||||
entry.Fee(Amount::zero()).Priority(100.0).FromTx(tx3)); | |||||
/* 2nd highest fee */ | |||||
CMutableTransaction tx4 = CMutableTransaction(); | |||||
tx4.vout.resize(1); | |||||
tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | |||||
tx4.vout[0].nValue = 6 * COIN; | |||||
pool.addUnchecked(tx4.GetId(), | |||||
entry.Fee(15000 * SATOSHI).Priority(1.0).FromTx(tx4)); | |||||
/* equal fee rate to tx1, but newer */ | |||||
CMutableTransaction tx5 = CMutableTransaction(); | |||||
tx5.vout.resize(1); | |||||
tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | |||||
tx5.vout[0].nValue = 11 * COIN; | |||||
pool.addUnchecked(tx5.GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx5)); | |||||
BOOST_CHECK_EQUAL(pool.size(), 5UL); | |||||
std::vector<std::string> sortedOrder; | |||||
sortedOrder.resize(5); | |||||
sortedOrder[0] = tx2.GetId().ToString(); // 20000 | |||||
sortedOrder[1] = tx4.GetId().ToString(); // 15000 | |||||
// tx1 and tx5 are both 10000 | |||||
// Ties are broken by hash, not timestamp, so determine which hash comes | |||||
// first. | |||||
if (tx1.GetId() < tx5.GetId()) { | |||||
sortedOrder[2] = tx1.GetId().ToString(); | |||||
sortedOrder[3] = tx5.GetId().ToString(); | |||||
} else { | |||||
sortedOrder[2] = tx5.GetId().ToString(); | |||||
sortedOrder[3] = tx1.GetId().ToString(); | |||||
} | |||||
sortedOrder[4] = tx3.GetId().ToString(); // 0 | |||||
LOCK(pool.cs); | |||||
CheckSort<ancestor_score>(pool, sortedOrder, | |||||
"MempoolAncestorIndexingTest1"); | |||||
/* low fee parent with high fee child */ | |||||
/* tx6 (0) -> tx7 (high) */ | |||||
CMutableTransaction tx6 = CMutableTransaction(); | |||||
tx6.vout.resize(1); | |||||
tx6.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | |||||
tx6.vout[0].nValue = 20 * COIN; | |||||
uint64_t tx6Size = CTransaction(tx6).GetTotalSize(); | |||||
pool.addUnchecked(tx6.GetId(), entry.Fee(Amount::zero()).FromTx(tx6)); | |||||
BOOST_CHECK_EQUAL(pool.size(), 6UL); | |||||
// Ties are broken by hash | |||||
if (tx3.GetId() < tx6.GetId()) { | |||||
sortedOrder.push_back(tx6.GetId().ToString()); | |||||
} else { | |||||
sortedOrder.insert(sortedOrder.end() - 1, tx6.GetId().ToString()); | |||||
} | |||||
CheckSort<ancestor_score>(pool, sortedOrder, | |||||
"MempoolAncestorIndexingTest2"); | |||||
CMutableTransaction tx7 = CMutableTransaction(); | |||||
tx7.vin.resize(1); | |||||
tx7.vin[0].prevout = COutPoint(tx6.GetId(), 0); | |||||
tx7.vin[0].scriptSig = CScript() << OP_11; | |||||
tx7.vout.resize(1); | |||||
tx7.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | |||||
tx7.vout[0].nValue = 10 * COIN; | |||||
uint64_t tx7Size = CTransaction(tx7).GetTotalSize(); | |||||
/* set the fee to just below tx2's feerate when including ancestor */ | |||||
Amount fee = int64_t((20000 / tx2Size) * (tx7Size + tx6Size) - 1) * SATOSHI; | |||||
// CTxMemPoolEntry entry7(tx7, fee, 2, 10.0, 1, true); | |||||
pool.addUnchecked(tx7.GetId(), entry.Fee(Amount(fee)).FromTx(tx7)); | |||||
BOOST_CHECK_EQUAL(pool.size(), 7UL); | |||||
sortedOrder.insert(sortedOrder.begin() + 1, tx7.GetId().ToString()); | |||||
CheckSort<ancestor_score>(pool, sortedOrder, | |||||
"MempoolAncestorIndexingTest3"); | |||||
/* after tx6 is mined, tx7 should move up in the sort */ | |||||
std::vector<CTransactionRef> vtx; | |||||
vtx.push_back(MakeTransactionRef(tx6)); | |||||
pool.removeForBlock(vtx, 1); | |||||
sortedOrder.erase(sortedOrder.begin() + 1); | |||||
// Ties are broken by hash | |||||
if (tx3.GetId() < tx6.GetId()) { | |||||
sortedOrder.pop_back(); | |||||
} else { | |||||
sortedOrder.erase(sortedOrder.end() - 2); | |||||
} | |||||
sortedOrder.insert(sortedOrder.begin(), tx7.GetId().ToString()); | |||||
CheckSort<ancestor_score>(pool, sortedOrder, | |||||
"MempoolAncestorIndexingTest4"); | |||||
} | |||||
BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest) { | BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest) { | ||||
CTxMemPool pool; | CTxMemPool pool; | ||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
entry.dPriority = 10.0; | entry.dPriority = 10.0; | ||||
Amount feeIncrement = MEMPOOL_FULL_FEE_INCREMENT.GetFeePerK(); | Amount feeIncrement = MEMPOOL_FULL_FEE_INCREMENT.GetFeePerK(); | ||||
CMutableTransaction tx1 = CMutableTransaction(); | CMutableTransaction tx1 = CMutableTransaction(); | ||||
tx1.vin.resize(1); | tx1.vin.resize(1); | ||||
▲ Show 20 Lines • Show All 258 Lines • Show Last 20 Lines |