From 889a05fdd42f031a609f62bd8a5ffa9e6c5602fa Mon Sep 17 00:00:00 2001 From: Mark Friedenbach Date: Sat, 11 Mar 2017 14:20:27 -0800 Subject: [PATCH] Segwit: Rename CTransaction::GetWitnessHash() -> CTransaction::GetHashWithWitness() The upstream name of GetWitnessHash() is very confusing as it is not a hash of the witness data for the transaction, but rather a hash of the full serialization of the transaction including witness data. This goes beyond confusing to downright wrong with CT/CA where the witness hash will be a hash tree of witness data (rangeproofs, surjectionproofs, script signatures, etc.) and NOT have any transaction data. --- src/blockencodings.cpp | 2 +- src/core_write.cpp | 2 +- src/primitives/transaction.cpp | 2 +- src/primitives/transaction.h | 2 +- src/rpc/mining.cpp | 2 +- src/rpc/rawtransaction.cpp | 2 +- src/txmempool.cpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/blockencodings.cpp b/src/blockencodings.cpp index 93d3fa372b..8cfebeb7c0 100644 --- a/src/blockencodings.cpp +++ b/src/blockencodings.cpp @@ -25,7 +25,7 @@ CBlockHeaderAndShortTxIDs::CBlockHeaderAndShortTxIDs(const CBlock& block, bool f prefilledtxn[0] = {0, block.vtx[0]}; for (size_t i = 1; i < block.vtx.size(); i++) { const CTransaction& tx = block.vtx[i]; - shorttxids[i - 1] = GetShortID(fUseWTXID ? tx.GetWitnessHash() : tx.GetHash()); + shorttxids[i - 1] = GetShortID(fUseWTXID ? tx.GetHashWithWitness() : tx.GetHash()); } } diff --git a/src/core_write.cpp b/src/core_write.cpp index d559848607..fb371c2761 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -158,7 +158,7 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey, void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry) { entry.pushKV("txid", tx.GetHash().GetHex()); - entry.pushKV("hash", tx.GetWitnessHash().GetHex()); + entry.pushKV("hash", tx.GetHashWithWitness().GetHex()); entry.pushKV("version", tx.nVersion); entry.pushKV("locktime", (int64_t)tx.nLockTime); diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 80ce8a7124..057674b176 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -103,7 +103,7 @@ void CTransaction::UpdateHash() const *const_cast(&hash) = SerializeHash(*this, SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS); } -uint256 CTransaction::GetWitnessHash() const +uint256 CTransaction::GetHashWithWitness() const { return SerializeHash(*this, SER_GETHASH, 0); } diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index e572d42036..33560a51e4 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -760,7 +760,7 @@ public: } // Compute a hash that includes both transaction and witness data - uint256 GetWitnessHash() const; + uint256 GetHashWithWitness() const; // Check if explicit TX fees overflow or are negative bool HasValidFee() const; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index aa6a80e39d..0ebe6646d1 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -633,7 +633,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) entry.push_back(Pair("data", EncodeHexTx(tx))); entry.push_back(Pair("txid", txHash.GetHex())); - entry.push_back(Pair("hash", tx.GetWitnessHash().GetHex())); + entry.push_back(Pair("hash", tx.GetHashWithWitness().GetHex())); UniValue deps(UniValue::VARR); BOOST_FOREACH (const CTxIn &in, tx.vin) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 0ace935962..939661f306 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -89,7 +89,7 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fInclud void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) { entry.push_back(Pair("txid", tx.GetHash().GetHex())); - entry.push_back(Pair("hash", tx.GetWitnessHash().GetHex())); + entry.push_back(Pair("hash", tx.GetHashWithWitness().GetHex())); entry.push_back(Pair("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION))); entry.push_back(Pair("vsize", (int)::GetVirtualTransactionSize(tx))); entry.push_back(Pair("version", tx.nVersion)); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 90a28f1474..64d44979d2 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -442,7 +442,7 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, totalTxSize += entry.GetTxSize(); minerPolicyEstimator->processTransaction(entry, fCurrentEstimate); - vTxHashes.emplace_back(tx.GetWitnessHash(), newit); + vTxHashes.emplace_back(tx.GetHashWithWitness(), newit); newit->vTxHashesIdx = vTxHashes.size() - 1; typedef std::pair WithdrawPair;