diff --git a/src/test/mempool_tests.cpp b/src/test/mempool_tests.cpp --- a/src/test/mempool_tests.cpp +++ b/src/test/mempool_tests.cpp @@ -502,127 +502,6 @@ CheckSort(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 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(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(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(pool, sortedOrder, - "MempoolAncestorIndexingTest3"); - - /* after tx6 is mined, tx7 should move up in the sort */ - std::vector 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(pool, sortedOrder, - "MempoolAncestorIndexingTest4"); -} - BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest) { CTxMemPool pool; TestMemPoolEntryHelper entry; diff --git a/src/txmempool.h b/src/txmempool.h --- a/src/txmempool.h +++ b/src/txmempool.h @@ -325,32 +325,10 @@ } }; -class CompareTxMemPoolEntryByAncestorFee { -public: - bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const { - double aFees = a.GetModFeesWithAncestors() / SATOSHI; - double aSize = a.GetSizeWithAncestors(); - - double bFees = b.GetModFeesWithAncestors() / SATOSHI; - double bSize = b.GetSizeWithAncestors(); - - // Avoid division by rewriting (a/b > c/d) as (a*d > c*b). - double f1 = aFees * bSize; - double f2 = aSize * bFees; - - if (f1 == f2) { - return a.GetTx().GetId() < b.GetTx().GetId(); - } - - return f1 > f2; - } -}; - // Multi_index tag names struct descendant_score {}; struct entry_time {}; struct mining_score {}; -struct ancestor_score {}; struct txid_index {}; struct insertion_order {}; @@ -530,11 +508,6 @@ boost::multi_index::tag, boost::multi_index::identity, CompareTxMemPoolEntryByScore>, - // sorted by fee rate with ancestors - boost::multi_index::ordered_non_unique< - boost::multi_index::tag, - boost::multi_index::identity, - CompareTxMemPoolEntryByAncestorFee>, boost::multi_index::sequenced< boost::multi_index::tag>>> indexed_transaction_set;