diff --git a/src/util/hasher.h b/src/util/hasher.h --- a/src/util/hasher.h +++ b/src/util/hasher.h @@ -39,13 +39,6 @@ SaltedOutpointHasher(); /** - * This *must* return size_t. With Boost 1.46 on 32-bit systems the - * unordered_map will behave unpredictably if the custom hasher returns a - * uint64_t, resulting in failures when syncing the chain (#4634). - * Note: This information above might be outdated as the unordered map - * container type has meanwhile been switched to the C++ standard library - * implementation. - * * Having the hash noexcept allows libstdc++'s unordered_map to recalculate * the hash during rehash, so it does not have to cache the value. This * reduces node's memory by sizeof(size_t). The required recalculation has @@ -98,4 +91,15 @@ } }; +class SaltedSipHasher { +private: + /** Salt */ + const uint64_t m_k0, m_k1; + +public: + SaltedSipHasher(); + + size_t operator()(const Span &script) const; +}; + #endif // BITCOIN_UTIL_HASHER_H diff --git a/src/util/hasher.cpp b/src/util/hasher.cpp --- a/src/util/hasher.cpp +++ b/src/util/hasher.cpp @@ -14,3 +14,13 @@ SaltedOutpointHasher::SaltedOutpointHasher() : k0(GetRand(std::numeric_limits::max())), k1(GetRand(std::numeric_limits::max())) {} + +SaltedSipHasher::SaltedSipHasher() + : m_k0(GetRand(std::numeric_limits::max())), + m_k1(GetRand(std::numeric_limits::max())) {} + +size_t SaltedSipHasher::operator()(const Span &script) const { + return CSipHasher(m_k0, m_k1) + .Write(script.data(), script.size()) + .Finalize(); +} diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -156,13 +156,6 @@ } }; -class KeyIDHasher { -public: - KeyIDHasher() {} - - size_t operator()(const CKeyID &id) const { return id.GetUint64(0); } -}; - /** * A class implementing ScriptPubKeyMan manages some (or all) scriptPubKeys used * in a wallet. It contains the scripts and keys related to the scriptPubKeys it @@ -377,7 +370,7 @@ /* the HD chain data model (external chain counters) */ CHDChain m_hd_chain; - std::unordered_map m_inactive_hd_chains; + std::unordered_map m_inactive_hd_chains; /* HD derive new child key (on internal or external chain) */ void DeriveNewChildKey(WalletBatch &batch, CKeyMetadata &metadata,