Merge bitcoin/bitcoin#28107: util: Type-safe transaction identifiers

940a49978c Use type-safe txid types in orphanage (dergoegge)
ed70e65016 Introduce types for txids & wtxids (dergoegge)
cdb14d79e8 [net processing] Use HasWitness over comparing (w)txids (dergoegge)

Pull request description:

  We currently have two different identifiers for transactions: `txid` (refering to the hash of a transaction without witness data) and `wtxid` (referring to the hash of a transaction including witness data). Both are typed as `uint256` which could lead to type-safety bugs in which one transaction identifier type is passed where the other would be expected.

  This PR introduces explicit `Txid` and `Wtxid` types that (if used) would cause compilation errors for such type confusion bugs.

  (Only the orphanage is converted to use these types in this PR)

ACKs for top commit:
  achow101:
    ACK 940a49978c
  stickies-v:
    ACK 940a49978c
  hebasto:
    ACK 940a49978c, I have reviewed the code and it looks OK.
  instagibbs:
    re-ACK 940a49978c
  BrandonOdiwuor:
    re-ACK 940a49978c
  glozow:
    reACK 940a49978c

Tree-SHA512: 55298d1c2bb82b7a6995e96e554571c22eaf4a89fb2a4d7a236d70e0f625e8cca62ff2490e1c179c47bd93153fe6527b56870198f026f5ee7753d64d7a424c92
This commit is contained in:
Andrew Chow
2023-10-26 14:09:33 -04:00
12 changed files with 139 additions and 61 deletions

View File

@@ -618,7 +618,7 @@ private:
const CTransactionRef& m_ptx;
/** Txid. */
const uint256& m_hash;
const Txid& m_hash;
TxValidationState m_state;
/** A temporary cache containing serialized transaction data for signature verification.
* Reused across PolicyScriptChecks and ConsensusScriptChecks. */
@@ -1870,7 +1870,7 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
// transaction).
uint256 hashCacheEntry;
CSHA256 hasher = g_scriptExecutionCacheHasher;
hasher.Write(tx.GetWitnessHash().begin(), 32).Write((unsigned char*)&flags, sizeof(flags)).Finalize(hashCacheEntry.begin());
hasher.Write(UCharCast(tx.GetWitnessHash().begin()), 32).Write((unsigned char*)&flags, sizeof(flags)).Finalize(hashCacheEntry.begin());
AssertLockHeld(cs_main); //TODO: Remove this requirement by making CuckooCache not require external locks
if (g_scriptExecutionCache.contains(hashCacheEntry, !cacheFullScriptStore)) {
return true;