From a9301cfa0730d1d08c9e982f990dfc8aa0b3a27a Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Mon, 27 Apr 2026 14:14:07 +0200 Subject: [PATCH] refactor: disable default std::hash for CTransactionRef The default std::hash for shared_ptr compares by pointer. CTransactionRefHash or a custom hasher should be used instead. Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> --- src/primitives/transaction.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 34bb9571c15..3a7735e149b 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -403,4 +403,16 @@ struct CMutableTransaction typedef std::shared_ptr CTransactionRef; template static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared(std::forward(txIn)); } +namespace std { +/** Disable default std::hash for CTransactionRef to prevent accidentally + * comparing by pointer. Use CTransactionRefHash or provide a custom + * hasher. */ +template <> +struct hash { + hash() = delete; + // Belt-and-suspenders, already implied by the above. + size_t operator()(const CTransactionRef&) const = delete; +}; +} // namespace std + #endif // BITCOIN_PRIMITIVES_TRANSACTION_H