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 @@ -108,7 +108,7 @@ AddTx(tx6, Amount(1100LL), pool); AddTx(tx7, Amount(9000LL), pool); pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4); - pool.TrimToSize(GetTransactionSize(tx1)); + pool.TrimToSize(CTransaction(tx1).GetTotalSize()); } } diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -718,7 +718,7 @@ // transaction(s) have been mined or received. // 100 orphans, each of which is at most 99,999 bytes big is at most 10 // megabytes of orphans and somewhat more byprev index (in the worst case): - unsigned int sz = GetTransactionSize(*tx); + unsigned int sz = tx->GetTotalSize(); if (sz >= MAX_STANDARD_TX_SIZE) { LogPrint(BCLog::MEMPOOL, "ignoring large orphan tx (size: %u, hash: %s)\n", sz, diff --git a/src/policy/policy.cpp b/src/policy/policy.cpp --- a/src/policy/policy.cpp +++ b/src/policy/policy.cpp @@ -55,7 +55,7 @@ // almost as much to process as they cost the sender in fees, because // computing signature hashes is O(ninputs*txsize). Limiting transactions // to MAX_STANDARD_TX_SIZE mitigates CPU exhaustion attacks. - unsigned int sz = GetTransactionSize(tx); + unsigned int sz = tx.GetTotalSize(); if (sz >= MAX_STANDARD_TX_SIZE) { reason = "tx-size"; return false; diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -381,9 +381,6 @@ return std::make_shared(std::forward(txIn)); } -/** Compute the size of a transaction */ -int64_t GetTransactionSize(const CTransaction &tx); - /** Precompute sighash midstate to avoid quadratic hashing */ struct PrecomputedTransactionData { uint256 hashPrevouts, hashSequence, hashOutputs; diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -117,7 +117,7 @@ // for priority. Providing any more cleanup incentive than making additional // inputs free would risk encouraging people to create junk outputs to // redeem later. - if (nTxSize == 0) nTxSize = GetTransactionSize(*this); + if (nTxSize == 0) nTxSize = GetTotalSize(); for (std::vector::const_iterator it(vin.begin()); it != vin.end(); ++it) { unsigned int offset = @@ -142,8 +142,4 @@ for (unsigned int i = 0; i < vout.size(); i++) str += " " + vout[i].ToString() + "\n"; return str; -} - -int64_t GetTransactionSize(const CTransaction &tx) { - return ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); -} +} \ No newline at end of file diff --git a/src/qt/walletmodeltransaction.cpp b/src/qt/walletmodeltransaction.cpp --- a/src/qt/walletmodeltransaction.cpp +++ b/src/qt/walletmodeltransaction.cpp @@ -27,7 +27,9 @@ } unsigned int WalletModelTransaction::getTransactionSize() { - return (!walletTransaction ? 0 : ::GetTransactionSize(*walletTransaction)); + return (!walletTransaction + ? 0 + : CTransaction(*walletTransaction).GetTotalSize()); } Amount WalletModelTransaction::getTransactionFee() { 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 @@ -383,7 +383,7 @@ tx2.vout[0].nValue = 2 * COIN; pool.addUnchecked(tx2.GetId(), entry.Fee(Amount(20000LL)).Priority(9.0).FromTx(tx2)); - uint64_t tx2Size = GetTransactionSize(tx2); + uint64_t tx2Size = CTransaction(tx2).GetTotalSize(); /* lowest fee */ CMutableTransaction tx3 = CMutableTransaction(); @@ -433,7 +433,7 @@ tx6.vout.resize(1); tx6.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; 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)); BOOST_CHECK_EQUAL(pool.size(), 6UL); @@ -453,7 +453,7 @@ tx7.vout.resize(1); tx7.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; 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 */ Amount fee((20000 / tx2Size) * (tx7Size + tx6Size) - 1); @@ -530,13 +530,14 @@ BOOST_CHECK(pool.exists(tx3.GetId())); // 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(tx2.GetId())); BOOST_CHECK(!pool.exists(tx3.GetId())); - CFeeRate maxFeeRateRemoved( - Amount(25000), GetTransactionSize(tx3) + GetTransactionSize(tx2)); + CFeeRate maxFeeRateRemoved(Amount(25000), + CTransaction(tx3).GetTotalSize() + + CTransaction(tx2).GetTotalSize()); BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + Amount(1000)); 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 @@ -40,7 +40,7 @@ tx.vin[0].scriptSig = garbage; tx.vout.resize(1); tx.vout[0].nValue = Amount(0); - CFeeRate baseRate(basefee, GetTransactionSize(tx)); + CFeeRate baseRate(basefee, CTransaction(tx).GetTotalSize()); // Create a fake block std::vector block; diff --git a/src/txmempool.cpp b/src/txmempool.cpp --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -31,7 +31,7 @@ entryHeight(_entryHeight), inChainInputValue(_inChainInputValue), spendsCoinbase(_spendsCoinbase), sigOpCount(_sigOpsCount), lockPoints(lp) { - nTxSize = GetTransactionSize(*tx); + nTxSize = tx->GetTotalSize(); nModSize = tx->CalculateModifiedSize(GetTxSize()); nUsageSize = RecursiveDynamicUsage(tx); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2916,7 +2916,7 @@ return false; } - unsigned int nBytes = GetTransactionSize(txNew); + unsigned int nBytes = CTransaction(txNew).GetTotalSize(); CTransaction txNewConst(txNew); dPriority = txNewConst.ComputePriority(dPriority, nBytes); @@ -3039,7 +3039,7 @@ wtxNew.SetTx(MakeTransactionRef(std::move(txNew))); // Limit size. - if (GetTransactionSize(wtxNew) >= MAX_STANDARD_TX_SIZE) { + if (CTransaction(wtxNew).GetTotalSize() >= MAX_STANDARD_TX_SIZE) { strFailReason = _("Transaction too large"); return false; }