diff --git a/src/bench/mempool_eviction.cpp b/src/bench/mempool_eviction.cpp --- a/src/bench/mempool_eviction.cpp +++ b/src/bench/mempool_eviction.cpp @@ -16,8 +16,7 @@ bool spendsCoinbase = false; unsigned int nSigOpCount = 1; LockPoints lp; - pool.addUnchecked(tx->GetId(), - CTxMemPoolEntry(tx, nFee, nTime, nHeight, spendsCoinbase, + pool.addUnchecked(CTxMemPoolEntry(tx, nFee, nTime, nHeight, spendsCoinbase, nSigOpCount, lp)); } diff --git a/src/bench/rpc_mempool.cpp b/src/bench/rpc_mempool.cpp --- a/src/bench/rpc_mempool.cpp +++ b/src/bench/rpc_mempool.cpp @@ -15,10 +15,10 @@ static void AddTx(const CTransactionRef &tx, const Amount &fee, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs) { LockPoints lp; - pool.addUnchecked(tx->GetId(), CTxMemPoolEntry(tx, fee, /* time */ 0, - /* height */ 1, - /* spendsCoinbase */ false, - /* sigOpCount */ 1, lp)); + pool.addUnchecked(CTxMemPoolEntry(tx, fee, /* time */ 0, + /* height */ 1, + /* spendsCoinbase */ false, + /* sigOpCount */ 1, lp)); } static void RpcMempool(benchmark::State &state) { diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp --- a/src/test/blockencodings_tests.cpp +++ b/src/test/blockencodings_tests.cpp @@ -73,7 +73,7 @@ CBlock block(BuildBlockTestCase()); LOCK2(cs_main, pool.cs); - pool.addUnchecked(block.vtx[2]->GetId(), entry.FromTx(block.vtx[2])); + pool.addUnchecked(entry.FromTx(block.vtx[2])); BOOST_CHECK_EQUAL( pool.mapTx.find(block.vtx[2]->GetId())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0); @@ -184,7 +184,7 @@ CBlock block(BuildBlockTestCase()); LOCK2(cs_main, pool.cs); - pool.addUnchecked(block.vtx[2]->GetId(), entry.FromTx(block.vtx[2])); + pool.addUnchecked(entry.FromTx(block.vtx[2])); BOOST_CHECK_EQUAL( pool.mapTx.find(block.vtx[2]->GetId())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0); @@ -279,7 +279,7 @@ CBlock block(BuildBlockTestCase()); LOCK2(cs_main, pool.cs); - pool.addUnchecked(block.vtx[1]->GetId(), entry.FromTx(block.vtx[1])); + pool.addUnchecked(entry.FromTx(block.vtx[1])); BOOST_CHECK_EQUAL( pool.mapTx.find(block.vtx[1]->GetId())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0); 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 @@ -35,8 +35,7 @@ parentOfAll.vout.emplace_back(10 * SATOSHI, CScript() << OP_TRUE); } TxId parentOfAllId = parentOfAll.GetId(); - testPool.addUnchecked(parentOfAllId, - entry.SigOpCount(0).FromTx(parentOfAll)); + testPool.addUnchecked(entry.SigOpCount(0).FromTx(parentOfAll)); // Add some outpoints to the tracking vector for (size_t i = 0; i < maxOutputs; i++) { @@ -105,7 +104,7 @@ int randSigOpCount = InsecureRandRange(5); testPool.addUnchecked( - curId, entry.Fee(randFee).SigOpCount(randSigOpCount).FromTx(tx)); + entry.Fee(randFee).SigOpCount(randSigOpCount).FromTx(tx)); // Add this transaction to the totals. minAncestors += 1; @@ -184,17 +183,16 @@ BOOST_CHECK_EQUAL(testPool.size(), poolSize); // Just the parent: - testPool.addUnchecked(txParent.GetId(), entry.FromTx(txParent)); + testPool.addUnchecked(entry.FromTx(txParent)); poolSize = testPool.size(); testPool.removeRecursive(CTransaction(txParent)); BOOST_CHECK_EQUAL(testPool.size(), poolSize - 1); // Parent, children, grandchildren: - testPool.addUnchecked(txParent.GetId(), entry.FromTx(txParent)); + testPool.addUnchecked(entry.FromTx(txParent)); for (int i = 0; i < 3; i++) { - testPool.addUnchecked(txChild[i].GetId(), entry.FromTx(txChild[i])); - testPool.addUnchecked(txGrandChild[i].GetId(), - entry.FromTx(txGrandChild[i])); + testPool.addUnchecked(entry.FromTx(txChild[i])); + testPool.addUnchecked(entry.FromTx(txGrandChild[i])); } // Remove Child[0], GrandChild[0] should be removed: poolSize = testPool.size(); @@ -216,9 +214,8 @@ // Add children and grandchildren, but NOT the parent (simulate the parent // being in a block) for (int i = 0; i < 3; i++) { - testPool.addUnchecked(txChild[i].GetId(), entry.FromTx(txChild[i])); - testPool.addUnchecked(txGrandChild[i].GetId(), - entry.FromTx(txGrandChild[i])); + testPool.addUnchecked(entry.FromTx(txChild[i])); + testPool.addUnchecked(entry.FromTx(txGrandChild[i])); } // Now remove the parent, as might happen if a block-re-org occurs but the @@ -251,7 +248,7 @@ BOOST_CHECK_EQUAL(testPool.size(), 0UL); // Add the transaction - testPool.addUnchecked(txParent.GetId(), entry.FromTx(txParent)); + testPool.addUnchecked(entry.FromTx(txParent)); BOOST_CHECK_EQUAL(testPool.size(), 1UL); BOOST_CHECK_EQUAL(testPool.mapTx.size(), 1UL); BOOST_CHECK_EQUAL(testPool.mapNextTx.size(), 1UL); @@ -292,28 +289,28 @@ 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).FromTx(tx1)); + pool.addUnchecked(entry.Fee(10000 * SATOSHI).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).FromTx(tx2)); + pool.addUnchecked(entry.Fee(20000 * SATOSHI).FromTx(tx2)); /* 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()).FromTx(tx3)); + pool.addUnchecked(entry.Fee(Amount::zero()).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).FromTx(tx4)); + pool.addUnchecked(entry.Fee(15000 * SATOSHI).FromTx(tx4)); /* equal fee rate to tx1, but newer */ CMutableTransaction tx5 = CMutableTransaction(); @@ -321,7 +318,7 @@ tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; tx5.vout[0].nValue = 11 * COIN; entry.nTime = 1; - pool.addUnchecked(tx5.GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx5)); + pool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tx5)); BOOST_CHECK_EQUAL(pool.size(), 5UL); std::vector sortedOrder; @@ -339,7 +336,7 @@ tx6.vout.resize(1); tx6.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; tx6.vout[0].nValue = 20 * COIN; - pool.addUnchecked(tx6.GetId(), entry.Fee(Amount::zero()).FromTx(tx6)); + pool.addUnchecked(entry.Fee(Amount::zero()).FromTx(tx6)); BOOST_CHECK_EQUAL(pool.size(), 6UL); // Check that at this point, tx6 is sorted low sortedOrder.insert(sortedOrder.begin(), tx6.GetId().ToString()); @@ -366,7 +363,7 @@ true); BOOST_CHECK(setAncestorsCalculated == setAncestors); - pool.addUnchecked(tx7.GetId(), entry.FromTx(tx7), setAncestors); + pool.addUnchecked(entry.FromTx(tx7), setAncestors); BOOST_CHECK_EQUAL(pool.size(), 7UL); // Now tx6 should be sorted higher (high fee child): tx7, tx6, tx2, ... @@ -384,8 +381,7 @@ tx8.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; tx8.vout[0].nValue = 10 * COIN; setAncestors.insert(pool.mapTx.find(tx7.GetId())); - pool.addUnchecked(tx8.GetId(), - entry.Fee(Amount::zero()).Time(2).FromTx(tx8), + pool.addUnchecked(entry.Fee(Amount::zero()).Time(2).FromTx(tx8), setAncestors); // Now tx8 should be sorted low, but tx6/tx both high @@ -400,8 +396,7 @@ tx9.vout.resize(1); tx9.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; tx9.vout[0].nValue = 1 * COIN; - pool.addUnchecked(tx9.GetId(), - entry.Fee(Amount::zero()).Time(3).FromTx(tx9), + pool.addUnchecked(entry.Fee(Amount::zero()).Time(3).FromTx(tx9), setAncestors); // tx9 should be sorted low @@ -432,7 +427,7 @@ true); BOOST_CHECK(setAncestorsCalculated == setAncestors); - pool.addUnchecked(tx10.GetId(), entry.FromTx(tx10), setAncestors); + pool.addUnchecked(entry.FromTx(tx10), setAncestors); /** * tx8 and tx9 should both now be sorted higher @@ -478,14 +473,14 @@ 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).FromTx(tx1)); + pool.addUnchecked(entry.Fee(10000 * SATOSHI).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).FromTx(tx2)); + pool.addUnchecked(entry.Fee(20000 * SATOSHI).FromTx(tx2)); uint64_t tx2Size = CTransaction(tx2).GetTotalSize(); /* lowest fee */ @@ -493,21 +488,21 @@ 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()).FromTx(tx3)); + pool.addUnchecked(entry.Fee(Amount::zero()).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).FromTx(tx4)); + pool.addUnchecked(entry.Fee(15000 * SATOSHI).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)); + pool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tx5)); BOOST_CHECK_EQUAL(pool.size(), 5UL); std::vector sortedOrder; @@ -537,7 +532,7 @@ tx6.vout[0].nValue = 20 * COIN; uint64_t tx6Size = CTransaction(tx6).GetTotalSize(); - pool.addUnchecked(tx6.GetId(), entry.Fee(Amount::zero()).FromTx(tx6)); + pool.addUnchecked(entry.Fee(Amount::zero()).FromTx(tx6)); BOOST_CHECK_EQUAL(pool.size(), 6UL); // Ties are broken by hash if (tx3.GetId() < tx6.GetId()) { @@ -562,7 +557,7 @@ 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)); + pool.addUnchecked(entry.Fee(Amount(fee)).FromTx(tx7)); BOOST_CHECK_EQUAL(pool.size(), 7UL); sortedOrder.insert(sortedOrder.begin() + 1, tx7.GetId().ToString()); CheckSort(pool, sortedOrder, @@ -597,8 +592,7 @@ // Check that we sort by min(feerate, ancestor_feerate): // set the fee so that the ancestor feerate is above tx1/5, // but the transaction's own feerate is lower - pool.addUnchecked(tx8.GetId(), - entry.Fee(Amount(5000 * SATOSHI)).FromTx(tx8)); + pool.addUnchecked(entry.Fee(Amount(5000 * SATOSHI)).FromTx(tx8)); sortedOrder.insert(sortedOrder.end() - 1, tx8.GetId().ToString()); CheckSort(pool, sortedOrder, "MempoolAncestorIndexingTest5"); @@ -616,7 +610,7 @@ tx1.vout.resize(1); tx1.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL; tx1.vout[0].nValue = 10 * COIN; - pool.addUnchecked(tx1.GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx1)); + pool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tx1)); CMutableTransaction tx2 = CMutableTransaction(); tx2.vin.resize(1); @@ -624,7 +618,7 @@ tx2.vout.resize(1); tx2.vout[0].scriptPubKey = CScript() << OP_2 << OP_EQUAL; tx2.vout[0].nValue = 10 * COIN; - pool.addUnchecked(tx2.GetId(), entry.Fee(5000 * SATOSHI).FromTx(tx2)); + pool.addUnchecked(entry.Fee(5000 * SATOSHI).FromTx(tx2)); // should do nothing pool.TrimToSize(pool.DynamicMemoryUsage()); @@ -636,7 +630,7 @@ BOOST_CHECK(pool.exists(tx1.GetId())); BOOST_CHECK(!pool.exists(tx2.GetId())); - pool.addUnchecked(tx2.GetId(), entry.FromTx(tx2)); + pool.addUnchecked(entry.FromTx(tx2)); CMutableTransaction tx3 = CMutableTransaction(); tx3.vin.resize(1); tx3.vin[0].prevout = COutPoint(tx2.GetId(), 0); @@ -644,7 +638,7 @@ tx3.vout.resize(1); tx3.vout[0].scriptPubKey = CScript() << OP_3 << OP_EQUAL; tx3.vout[0].nValue = 10 * COIN; - pool.addUnchecked(tx3.GetId(), entry.Fee(20000 * SATOSHI).FromTx(tx3)); + pool.addUnchecked(entry.Fee(20000 * SATOSHI).FromTx(tx3)); // tx3 should pay for tx2 (CPFP) pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4); @@ -712,10 +706,10 @@ tx7.vout[1].scriptPubKey = CScript() << OP_7 << OP_EQUAL; tx7.vout[1].nValue = 10 * COIN; - pool.addUnchecked(tx4.GetId(), entry.Fee(7000 * SATOSHI).FromTx(tx4)); - pool.addUnchecked(tx5.GetId(), entry.Fee(1000 * SATOSHI).FromTx(tx5)); - pool.addUnchecked(tx6.GetId(), entry.Fee(1100 * SATOSHI).FromTx(tx6)); - pool.addUnchecked(tx7.GetId(), entry.Fee(9000 * SATOSHI).FromTx(tx7)); + pool.addUnchecked(entry.Fee(7000 * SATOSHI).FromTx(tx4)); + pool.addUnchecked(entry.Fee(1000 * SATOSHI).FromTx(tx5)); + pool.addUnchecked(entry.Fee(1100 * SATOSHI).FromTx(tx6)); + pool.addUnchecked(entry.Fee(9000 * SATOSHI).FromTx(tx7)); // we only require this to remove, at max, 2 txn, because it's not clear // what we're really optimizing for aside from that @@ -725,8 +719,8 @@ BOOST_CHECK(!pool.exists(tx7.GetId())); if (!pool.exists(tx5.GetId())) - pool.addUnchecked(tx5.GetId(), entry.Fee(1000 * SATOSHI).FromTx(tx5)); - pool.addUnchecked(tx7.GetId(), entry.Fee(9000 * SATOSHI).FromTx(tx7)); + pool.addUnchecked(entry.Fee(1000 * SATOSHI).FromTx(tx5)); + pool.addUnchecked(entry.Fee(9000 * SATOSHI).FromTx(tx7)); // should maximize mempool size by only removing 5/7 pool.TrimToSize(pool.DynamicMemoryUsage() / 2); @@ -735,8 +729,8 @@ BOOST_CHECK(pool.exists(tx6.GetId())); BOOST_CHECK(!pool.exists(tx7.GetId())); - pool.addUnchecked(tx5.GetId(), entry.Fee(1000 * SATOSHI).FromTx(tx5)); - pool.addUnchecked(tx7.GetId(), entry.Fee(9000 * SATOSHI).FromTx(tx7)); + pool.addUnchecked(entry.Fee(1000 * SATOSHI).FromTx(tx5)); + pool.addUnchecked(entry.Fee(9000 * SATOSHI).FromTx(tx7)); std::vector vtx; SetMockTime(42); @@ -846,7 +840,7 @@ // Add all unconfirmed transactions in testPool for (auto tx : unconfTxns) { TestMemPoolEntryHelper entry; - testPool.addUnchecked(tx->GetId(), entry.FromTx(*tx)); + testPool.addUnchecked(entry.FromTx(*tx)); } } @@ -900,7 +894,7 @@ // [tx1] // CTransactionRef tx1 = make_tx(MK_OUTPUTS(10 * COIN)); - pool.addUnchecked(tx1->GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx1)); + pool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tx1)); // Ancestors / descendants should be 1 / 1 (itself / itself) pool.GetTransactionAncestry(tx1->GetId(), ancestors, descendants); @@ -913,7 +907,7 @@ // CTransactionRef tx2 = make_tx(MK_OUTPUTS(495 * CENT, 5 * COIN), MK_INPUTS(tx1)); - pool.addUnchecked(tx2->GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx2)); + pool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tx2)); // Ancestors / descendants should be: // transaction ancestors descendants @@ -933,7 +927,7 @@ // CTransactionRef tx3 = make_tx(MK_OUTPUTS(290 * CENT, 200 * CENT), MK_INPUTS(tx2)); - pool.addUnchecked(tx3->GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx3)); + pool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tx3)); // Ancestors / descendants should be: // transaction ancestors descendants @@ -959,7 +953,7 @@ // CTransactionRef tx4 = make_tx(MK_OUTPUTS(290 * CENT, 250 * CENT), MK_INPUTS(tx2), MK_INPUT_IDX(1)); - pool.addUnchecked(tx4->GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx4)); + pool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tx4)); // Ancestors / descendants should be: // transaction ancestors descendants @@ -997,13 +991,13 @@ tyi = make_tx(MK_OUTPUTS(v), i > 0 ? MK_INPUTS(*ty[i - 1]) : std::vector()); v -= 50 * CENT; - pool.addUnchecked(tyi->GetId(), entry.Fee(10000 * SATOSHI).FromTx(tyi)); + pool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tyi)); pool.GetTransactionAncestry(tyi->GetId(), ancestors, descendants); BOOST_CHECK_EQUAL(ancestors, i + 1); BOOST_CHECK_EQUAL(descendants, i + 1); } CTransactionRef ty6 = make_tx(MK_OUTPUTS(5 * COIN), MK_INPUTS(tx3, ty5)); - pool.addUnchecked(ty6->GetId(), entry.Fee(10000 * SATOSHI).FromTx(ty6)); + pool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(ty6)); // Ancestors / descendants should be: // transaction ancestors descendants diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -119,29 +119,29 @@ // This tx has a low fee: 1000 satoshis. // Save this txid for later use. TxId parentTxId = tx.GetId(); - g_mempool.addUnchecked(parentTxId, entry.Fee(1000 * SATOSHI) - .Time(GetTime()) - .SpendsCoinbase(true) - .FromTx(tx)); + g_mempool.addUnchecked(entry.Fee(1000 * SATOSHI) + .Time(GetTime()) + .SpendsCoinbase(true) + .FromTx(tx)); // This tx has a medium fee: 10000 satoshis. tx.vin[0].prevout = COutPoint(txFirst[1]->GetId(), 0); tx.vout[0].nValue = int64_t(5000000000LL - 10000) * SATOSHI; TxId mediumFeeTxId = tx.GetId(); - g_mempool.addUnchecked(mediumFeeTxId, entry.Fee(10000 * SATOSHI) - .Time(GetTime()) - .SpendsCoinbase(true) - .FromTx(tx)); + g_mempool.addUnchecked(entry.Fee(10000 * SATOSHI) + .Time(GetTime()) + .SpendsCoinbase(true) + .FromTx(tx)); // This tx has a high fee, but depends on the first transaction. tx.vin[0].prevout = COutPoint(parentTxId, 0); // 50k satoshi fee. tx.vout[0].nValue = int64_t(5000000000LL - 1000 - 50000) * SATOSHI; TxId highFeeTxId = tx.GetId(); - g_mempool.addUnchecked(highFeeTxId, entry.Fee(50000 * SATOSHI) - .Time(GetTime()) - .SpendsCoinbase(false) - .FromTx(tx)); + g_mempool.addUnchecked(entry.Fee(50000 * SATOSHI) + .Time(GetTime()) + .SpendsCoinbase(false) + .FromTx(tx)); std::unique_ptr pblocktemplate = AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); @@ -154,7 +154,7 @@ // 0 fee. tx.vout[0].nValue = int64_t(5000000000LL - 1000 - 50000) * SATOSHI; TxId freeTxId = tx.GetId(); - g_mempool.addUnchecked(freeTxId, entry.Fee(Amount::zero()).FromTx(tx)); + g_mempool.addUnchecked(entry.Fee(Amount::zero()).FromTx(tx)); size_t freeTxSize = GetSerializeSize(tx, PROTOCOL_VERSION); // Calculate a fee on child transaction that will put the package just @@ -165,7 +165,7 @@ tx.vout[0].nValue = int64_t(5000000000LL - 1000 - 50000) * SATOSHI - feeToUse; TxId lowFeeTxId = tx.GetId(); - g_mempool.addUnchecked(lowFeeTxId, entry.Fee(feeToUse).FromTx(tx)); + g_mempool.addUnchecked(entry.Fee(feeToUse).FromTx(tx)); pblocktemplate = AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); // Verify that the free tx and the low fee tx didn't get selected. @@ -181,8 +181,7 @@ // Now we should be just over the min relay fee. tx.vout[0].nValue -= 2 * SATOSHI; lowFeeTxId = tx.GetId(); - g_mempool.addUnchecked(lowFeeTxId, - entry.Fee(feeToUse + 2 * SATOSHI).FromTx(tx)); + g_mempool.addUnchecked(entry.Fee(feeToUse + 2 * SATOSHI).FromTx(tx)); pblocktemplate = AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); BOOST_CHECK(pblocktemplate->block.vtx[4]->GetId() == freeTxId); @@ -198,7 +197,7 @@ tx.vout[1].nValue = 100000000 * SATOSHI; TxId freeTxId2 = tx.GetId(); g_mempool.addUnchecked( - freeTxId2, entry.Fee(Amount::zero()).SpendsCoinbase(true).FromTx(tx)); + entry.Fee(Amount::zero()).SpendsCoinbase(true).FromTx(tx)); // This tx can't be mined by itself. tx.vin[0].prevout = COutPoint(freeTxId2, 0); @@ -207,7 +206,7 @@ tx.vout[0].nValue = int64_t(5000000000LL - 100000000) * SATOSHI - feeToUse; TxId lowFeeTxId2 = tx.GetId(); g_mempool.addUnchecked( - lowFeeTxId2, entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx)); + entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx)); pblocktemplate = AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); @@ -222,7 +221,7 @@ tx.vin[0].prevout = COutPoint(freeTxId2, 1); // 10k satoshi fee. tx.vout[0].nValue = (100000000 - 10000) * SATOSHI; - g_mempool.addUnchecked(tx.GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx)); + g_mempool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tx)); pblocktemplate = AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); BOOST_CHECK(pblocktemplate->block.vtx[8]->GetId() == lowFeeTxId2); @@ -347,10 +346,10 @@ bool spendsCoinbase = i == 0; // If we don't set the # of sig ops in the CTxMemPoolEntry, template // creation fails. - g_mempool.addUnchecked(txid, entry.Fee(LOWFEE) - .Time(GetTime()) - .SpendsCoinbase(spendsCoinbase) - .FromTx(tx)); + g_mempool.addUnchecked(entry.Fee(LOWFEE) + .Time(GetTime()) + .SpendsCoinbase(spendsCoinbase) + .FromTx(tx)); tx.vin[0].prevout = COutPoint(txid, 0); } @@ -368,11 +367,11 @@ bool spendsCoinbase = i == 0; // If we do set the # of sig ops in the CTxMemPoolEntry, template // creation passes. - g_mempool.addUnchecked(txid, entry.Fee(LOWFEE) - .Time(GetTime()) - .SpendsCoinbase(spendsCoinbase) - .SigOpCount(20) - .FromTx(tx)); + g_mempool.addUnchecked(entry.Fee(LOWFEE) + .Time(GetTime()) + .SpendsCoinbase(spendsCoinbase) + .SigOpCount(20) + .FromTx(tx)); tx.vin[0].prevout = COutPoint(txid, 0); } @@ -396,10 +395,10 @@ const TxId txid = tx.GetId(); // Only first tx spends coinbase. bool spendsCoinbase = i == 0; - g_mempool.addUnchecked(txid, entry.Fee(LOWFEE) - .Time(GetTime()) - .SpendsCoinbase(spendsCoinbase) - .FromTx(tx)); + g_mempool.addUnchecked(entry.Fee(LOWFEE) + .Time(GetTime()) + .SpendsCoinbase(spendsCoinbase) + .FromTx(tx)); tx.vin[0].prevout = COutPoint(txid, 0); } @@ -408,8 +407,7 @@ g_mempool.clear(); // Orphan in mempool, template creation fails. - TxId txid = tx.GetId(); - g_mempool.addUnchecked(txid, entry.Fee(LOWFEE).Time(GetTime()).FromTx(tx)); + g_mempool.addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).FromTx(tx)); BOOST_CHECK_EXCEPTION( AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-txns-inputs-missingorspent")); @@ -419,9 +417,8 @@ tx.vin[0].scriptSig = CScript() << OP_1; tx.vin[0].prevout = COutPoint(txFirst[1]->GetId(), 0); tx.vout[0].nValue = BLOCKSUBSIDY - HIGHFEE; - txid = tx.GetId(); + TxId txid = tx.GetId(); g_mempool.addUnchecked( - txid, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); tx.vin[0].prevout = COutPoint(txid, 0); tx.vin.resize(2); @@ -431,7 +428,6 @@ tx.vout[0].nValue = tx.vout[0].nValue + BLOCKSUBSIDY - HIGHERFEE; txid = tx.GetId(); g_mempool.addUnchecked( - txid, entry.Fee(HIGHERFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) .CreateNewBlock(scriptPubKey)); @@ -445,7 +441,6 @@ txid = tx.GetId(); // Give it a fee so it'll get mined. g_mempool.addUnchecked( - txid, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); // Should throw bad-tx-coinbase BOOST_CHECK_EXCEPTION( @@ -460,12 +455,10 @@ tx.vout[0].scriptPubKey = CScript() << OP_1; txid = tx.GetId(); g_mempool.addUnchecked( - txid, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); tx.vout[0].scriptPubKey = CScript() << OP_2; txid = tx.GetId(); g_mempool.addUnchecked( - txid, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); BOOST_CHECK_EXCEPTION( AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey), @@ -510,7 +503,6 @@ tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script)); txid = tx.GetId(); g_mempool.addUnchecked( - txid, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); tx.vin[0].prevout = COutPoint(txid, 0); tx.vin[0].scriptSig = CScript() @@ -518,7 +510,6 @@ tx.vout[0].nValue -= LOWFEE; txid = tx.GetId(); g_mempool.addUnchecked( - txid, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); // Should throw blk-bad-inputs BOOST_CHECK_EXCEPTION( @@ -557,7 +548,6 @@ tx.nLockTime = 0; txid = tx.GetId(); g_mempool.addUnchecked( - txid, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); const Consensus::Params ¶ms = chainparams.GetConsensus(); @@ -586,7 +576,7 @@ 1); prevheights[0] = baseheight + 2; txid = tx.GetId(); - g_mempool.addUnchecked(txid, entry.Time(GetTime()).FromTx(tx)); + g_mempool.addUnchecked(entry.Time(GetTime()).FromTx(tx)); { // Locktime passes. @@ -619,7 +609,7 @@ prevheights[0] = baseheight + 3; tx.nLockTime = chainActive.Tip()->nHeight + 1; txid = tx.GetId(); - g_mempool.addUnchecked(txid, entry.Time(GetTime()).FromTx(tx)); + g_mempool.addUnchecked(entry.Time(GetTime()).FromTx(tx)); { // Locktime fails. @@ -647,7 +637,7 @@ prevheights.resize(1); prevheights[0] = baseheight + 4; txid = tx.GetId(); - g_mempool.addUnchecked(txid, entry.Time(GetTime()).FromTx(tx)); + g_mempool.addUnchecked(entry.Time(GetTime()).FromTx(tx)); { // Locktime fails. diff --git a/src/test/policyestimator_tests.cpp b/src/test/policyestimator_tests.cpp --- a/src/test/policyestimator_tests.cpp +++ b/src/test/policyestimator_tests.cpp @@ -44,10 +44,10 @@ tx.vin[0].nSequence = 10000 * blocknum + j; TxId txid = tx.GetId(); mpool.addUnchecked( - txid, entry.Fee((j + 1) * DEFAULT_BLOCK_MIN_TX_FEE_PER_KB) - .Time(GetTime()) - .Height(blocknum) - .FromTx(tx)); + entry.Fee((j + 1) * DEFAULT_BLOCK_MIN_TX_FEE_PER_KB) + .Time(GetTime()) + .Height(blocknum) + .FromTx(tx)); CTransactionRef ptx = mpool.get(txid); block.push_back(ptx); } @@ -78,8 +78,7 @@ // Add new transaction to the mempool with a increasing fee // The average should end up as 1/2 * 100 * // DEFAULT_BLOCK_MIN_TX_FEE_PER_KB - mpool.addUnchecked(tx.GetId(), - entry.Fee((i + 1) * DEFAULT_BLOCK_MIN_TX_FEE_PER_KB) + mpool.addUnchecked(entry.Fee((i + 1) * DEFAULT_BLOCK_MIN_TX_FEE_PER_KB) .Time(GetTime()) .Height(blocknum) .FromTx(tx)); diff --git a/src/txmempool.h b/src/txmempool.h --- a/src/txmempool.h +++ b/src/txmempool.h @@ -603,10 +603,9 @@ // Note that addUnchecked is ONLY called from ATMP outside of tests // and any other callers may break wallet's in-mempool tracking (due to // lack of CValidationInterface::TransactionAddedToMempool callbacks). - void addUnchecked(const TxId &txid, const CTxMemPoolEntry &entry) + void addUnchecked(const CTxMemPoolEntry &entry) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main); - void addUnchecked(const TxId &txid, const CTxMemPoolEntry &entry, - setEntries &setAncestors) + void addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main); void removeRecursive( diff --git a/src/txmempool.cpp b/src/txmempool.cpp --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -387,7 +387,7 @@ nTransactionsUpdated += n; } -void CTxMemPool::addUnchecked(const TxId &txid, const CTxMemPoolEntry &entry, +void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAncestors) { NotifyEntryAdded(entry.GetSharedTx()); // Add to memory pool without checking anything. @@ -1069,13 +1069,13 @@ } } -void CTxMemPool::addUnchecked(const TxId &txid, const CTxMemPoolEntry &entry) { +void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry) { setEntries setAncestors; uint64_t nNoLimit = std::numeric_limits::max(); std::string dummy; CalculateMemPoolAncestors(entry, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy); - return addUnchecked(txid, entry, setAncestors); + return addUnchecked(entry, setAncestors); } void CTxMemPool::UpdateChild(txiter entry, txiter child, bool add) { diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -795,7 +795,7 @@ } // Store transaction in memory. - pool.addUnchecked(txid, entry, setAncestors); + pool.addUnchecked(entry, setAncestors); // Trim mempool and check if tx was trimmed. if (!bypass_limits) {