Use SipHash-2-4 for CCoinsCache index

This commit is contained in:
Pieter Wuille
2016-05-06 20:47:12 +02:00
committed by lateminer
parent 3806509c82
commit c4641ab588
4 changed files with 13 additions and 75 deletions

View File

@@ -9,6 +9,7 @@
#include "compressor.h"
#include "core_memusage.h"
#include "hash.h"
#include "memusage.h"
#include "serialize.h"
#include "uint256.h"
@@ -291,21 +292,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);
}
};
@@ -322,7 +324,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