Use SipHash-2-4 for CCoinsCache index
This is ~1.7x slower than the Lookup3-of-Xor-with-salt construct we were using before, but it is a primitive designed for exactly this.
This commit is contained in:
14
src/coins.h
14
src/coins.h
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "compressor.h"
|
||||
#include "core_memusage.h"
|
||||
#include "hash.h"
|
||||
#include "memusage.h"
|
||||
#include "serialize.h"
|
||||
#include "uint256.h"
|
||||
@@ -264,21 +265,22 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class CCoinsKeyHasher
|
||||
class SaltedTxidHasher
|
||||
{
|
||||
private:
|
||||
uint256 salt;
|
||||
/** Salt */
|
||||
uint64_t k0, k1;
|
||||
|
||||
public:
|
||||
CCoinsKeyHasher();
|
||||
SaltedTxidHasher();
|
||||
|
||||
/**
|
||||
* 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).
|
||||
*/
|
||||
size_t operator()(const uint256& key) const {
|
||||
return key.GetHash(salt);
|
||||
size_t operator()(const uint256& txid) const {
|
||||
return SipHashUint256(k0, k1, txid);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -295,7 +297,7 @@ struct CCoinsCacheEntry
|
||||
CCoinsCacheEntry() : coins(), flags(0) {}
|
||||
};
|
||||
|
||||
typedef boost::unordered_map<uint256, CCoinsCacheEntry, CCoinsKeyHasher> CCoinsMap;
|
||||
typedef boost::unordered_map<uint256, CCoinsCacheEntry, SaltedTxidHasher> CCoinsMap;
|
||||
|
||||
/** Cursor for iterating over CoinsView state */
|
||||
class CCoinsViewCursor
|
||||
|
||||
Reference in New Issue
Block a user