mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-09 02:59:31 +08:00
refactor: rename CTransaction::GetTotalSize to signal that it's not cached
Transaction hashes are cached, it may not be intuitive that their sizes are actually recalculated every time. This is done before the other refactors to clarify why we want to avoid calling this method; Co-authored-by: maflcko <6399679+maflcko@users.noreply.github.com>
This commit is contained in:
@@ -58,7 +58,7 @@ static void DuplicateInputs(benchmark::Bench& bench)
|
||||
naughtyTx.vout[0].nValue = 0;
|
||||
naughtyTx.vout[0].scriptPubKey = SCRIPT_PUB;
|
||||
|
||||
uint64_t n_inputs = (((MAX_BLOCK_SERIALIZED_SIZE / WITNESS_SCALE_FACTOR) - (CTransaction(coinbaseTx).GetTotalSize() + CTransaction(naughtyTx).GetTotalSize())) / 41) - 100;
|
||||
uint64_t n_inputs = (((MAX_BLOCK_SERIALIZED_SIZE / WITNESS_SCALE_FACTOR) - (CTransaction(coinbaseTx).ComputeTotalSize() + CTransaction(naughtyTx).ComputeTotalSize())) / 41) - 100;
|
||||
for (uint64_t x = 0; x < (n_inputs - 1); ++x) {
|
||||
naughtyTx.vin.emplace_back(Txid::FromUint256(GetRandHash()), 0, CScript(), 0);
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<
|
||||
if (vtx_missing.size() <= tx_missing_offset)
|
||||
return READ_STATUS_INVALID;
|
||||
block.vtx[i] = vtx_missing[tx_missing_offset++];
|
||||
tx_missing_size += block.vtx[i]->GetTotalSize();
|
||||
tx_missing_size += block.vtx[i]->ComputeTotalSize();
|
||||
} else
|
||||
block.vtx[i] = std::move(txn_available[i]);
|
||||
}
|
||||
|
||||
@@ -432,7 +432,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
|
||||
entry.pushKV("txid", tx.GetHash().GetHex());
|
||||
entry.pushKV("hash", tx.GetWitnessHash().GetHex());
|
||||
entry.pushKV("version", tx.version);
|
||||
entry.pushKV("size", tx.GetTotalSize());
|
||||
entry.pushKV("size", tx.ComputeTotalSize());
|
||||
entry.pushKV("vsize", (GetTransactionWeight(tx) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR);
|
||||
entry.pushKV("weight", GetTransactionWeight(tx));
|
||||
entry.pushKV("locktime", (int64_t)tx.nLockTime);
|
||||
|
||||
@@ -2577,7 +2577,7 @@ void PeerManagerImpl::SendBlockTransactions(CNode& pfrom, Peer& peer, const CBlo
|
||||
return;
|
||||
}
|
||||
resp.txn[i] = block.vtx[req.indexes[i]];
|
||||
tx_requested_size += resp.txn[i]->GetTotalSize();
|
||||
tx_requested_size += resp.txn[i]->ComputeTotalSize();
|
||||
}
|
||||
|
||||
LogDebug(BCLog::CMPCTBLOCK, "Peer %d sent us a GETBLOCKTXN for block %s, sending a BLOCKTXN with %u txns. (%u bytes)\n", pfrom.GetId(), block.GetHash().ToString(), resp.txn.size(), tx_requested_size);
|
||||
|
||||
@@ -107,7 +107,7 @@ CAmount CTransaction::GetValueOut() const
|
||||
return nValueOut;
|
||||
}
|
||||
|
||||
unsigned int CTransaction::GetTotalSize() const
|
||||
unsigned int CTransaction::ComputeTotalSize() const
|
||||
{
|
||||
return ::GetSerializeSize(TX_WITH_WITNESS(*this));
|
||||
}
|
||||
|
||||
@@ -332,11 +332,11 @@ public:
|
||||
CAmount GetValueOut() const;
|
||||
|
||||
/**
|
||||
* Get the total transaction size in bytes, including witness data.
|
||||
* Calculate the total transaction size in bytes, including witness data.
|
||||
* "Total Size" defined in BIP141 and BIP144.
|
||||
* @return Total transaction size in bytes
|
||||
*/
|
||||
unsigned int GetTotalSize() const;
|
||||
unsigned int ComputeTotalSize() const;
|
||||
|
||||
bool IsCoinBase() const
|
||||
{
|
||||
|
||||
@@ -279,7 +279,7 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
|
||||
strHTML += "<br><b>" + tr("Comment") + ":</b><br>" + GUIUtil::HtmlEscape(wtx.value_map["comment"], true) + "<br>";
|
||||
|
||||
strHTML += "<b>" + tr("Transaction ID") + ":</b> " + rec->getTxHash() + "<br>";
|
||||
strHTML += "<b>" + tr("Transaction total size") + ":</b> " + QString::number(wtx.tx->GetTotalSize()) + " bytes<br>";
|
||||
strHTML += "<b>" + tr("Transaction total size") + ":</b> " + QString::number(wtx.tx->ComputeTotalSize()) + " bytes<br>";
|
||||
strHTML += "<b>" + tr("Transaction virtual size") + ":</b> " + QString::number(GetVirtualTransactionSize(*wtx.tx)) + " bytes<br>";
|
||||
strHTML += "<b>" + tr("Output index") + ":</b> " + QString::number(rec->getOutputIndex()) + "<br>";
|
||||
|
||||
|
||||
@@ -2053,7 +2053,7 @@ static RPCHelpMan getblockstats()
|
||||
int64_t tx_size = 0;
|
||||
if (do_calculate_size) {
|
||||
|
||||
tx_size = tx->GetTotalSize();
|
||||
tx_size = tx->ComputeTotalSize();
|
||||
if (do_mediantxsize) {
|
||||
txsize_array.push_back(tx_size);
|
||||
}
|
||||
|
||||
@@ -1031,7 +1031,7 @@ static UniValue OrphanToJSON(const node::TxOrphanage::OrphanInfo& orphan)
|
||||
UniValue o(UniValue::VOBJ);
|
||||
o.pushKV("txid", orphan.tx->GetHash().ToString());
|
||||
o.pushKV("wtxid", orphan.tx->GetWitnessHash().ToString());
|
||||
o.pushKV("bytes", orphan.tx->GetTotalSize());
|
||||
o.pushKV("bytes", orphan.tx->ComputeTotalSize());
|
||||
o.pushKV("vsize", GetVirtualTransactionSize(*orphan.tx));
|
||||
o.pushKV("weight", GetTransactionWeight(*orphan.tx));
|
||||
UniValue from(UniValue::VARR);
|
||||
|
||||
@@ -68,7 +68,7 @@ FUZZ_TARGET(transaction, .init = initialize_transaction)
|
||||
}
|
||||
|
||||
(void)tx.GetHash();
|
||||
(void)tx.GetTotalSize();
|
||||
(void)tx.ComputeTotalSize();
|
||||
try {
|
||||
(void)tx.GetValueOut();
|
||||
} catch (const std::runtime_error&) {
|
||||
@@ -92,7 +92,7 @@ FUZZ_TARGET(transaction, .init = initialize_transaction)
|
||||
(void)AreInputsStandard(tx, coins_view_cache);
|
||||
(void)IsWitnessStandard(tx, coins_view_cache);
|
||||
|
||||
if (tx.GetTotalSize() < 250'000) { // Avoid high memory usage (with msan) due to json encoding
|
||||
if (tx.ComputeTotalSize() < 250'000) { // Avoid high memory usage (with msan) due to json encoding
|
||||
{
|
||||
UniValue u{UniValue::VOBJ};
|
||||
TxToUniv(tx, /*block_hash=*/uint256::ZERO, /*entry=*/u);
|
||||
|
||||
Reference in New Issue
Block a user