diff --git a/src/Application.cpp b/src/Application.cpp index 4a44115d94..92c009069b 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -37,6 +37,7 @@ Application::Application() : mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL) { RAND_bytes(mNonce256.begin(), mNonce256.size()); + RAND_bytes(reinterpret_cast(&mNonceST), sizeof(mNonceST)); } extern const char *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[], *NetNodeDBInit[]; diff --git a/src/Application.h b/src/Application.h index 96e58bdeef..bf763f3998 100644 --- a/src/Application.h +++ b/src/Application.h @@ -48,6 +48,7 @@ class Application RPCDoor* mRPCDoor; uint256 mNonce256; + std::size_t mNonceST; std::map mPeerMap; boost::recursive_mutex mPeerMapLock; @@ -69,13 +70,14 @@ public: LedgerAcquireMaster& getMasterLedgerAcquire() { return mMasterLedgerAcquire; } TransactionMaster& getMasterTransaction() { return mMasterTransaction; } - DatabaseCon* getTxnDB() { return mTxnDB; } - DatabaseCon* getLedgerDB() { return mLedgerDB; } - DatabaseCon* getWalletDB() { return mWalletDB; } - DatabaseCon* getHashNodeDB() { return mHashNodeDB; } - DatabaseCon* getNetNodeDB() { return mNetNodeDB; } + DatabaseCon* getTxnDB() { return mTxnDB; } + DatabaseCon* getLedgerDB() { return mLedgerDB; } + DatabaseCon* getWalletDB() { return mWalletDB; } + DatabaseCon* getHashNodeDB() { return mHashNodeDB; } + DatabaseCon* getNetNodeDB() { return mNetNodeDB; } - uint256 getNonce256() { return mNonce256; } + uint256 getNonce256() { return mNonce256; } + std::size_t getNonceST() { return mNonceST; } void run(); void stop(); diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index 709a732b1c..c84eec80e0 100644 --- a/src/SHAMap.cpp +++ b/src/SHAMap.cpp @@ -17,15 +17,15 @@ std::size_t hash_value(const SHAMapNode& mn) { - return mn.getDepth() - ^ *reinterpret_cast(mn.getNodeID().begin()) - ^ *reinterpret_cast(theApp->getNonce256().begin()); + std::size_t seed = theApp->getNonceST(); + boost::hash_combine(seed, mn.getDepth()); + return mn.getNodeID().hash_combine(seed); } std::size_t hash_value(const uint256& u) { - return *reinterpret_cast(u.begin()) - ^ *reinterpret_cast(theApp->getNonce256().begin()); + std::size_t seed = theApp->getNonceST(); + return u.hash_combine(seed); } SHAMap::SHAMap(uint32 seq) : mSeq(seq), mState(Modifying) diff --git a/src/uint256.h b/src/uint256.h index 78b9b169c4..356433e619 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -13,6 +13,8 @@ #include #include +#include + #include "types.h" #include "utils.h" @@ -136,6 +138,13 @@ public: return ret; } + std::size_t hash_combine(std::size_t& seed) const + { + for (int i = 0; i < WIDTH; ++i) + boost::hash_combine(seed, pn[i]); + return seed; + } + friend inline int compare(const base_uint& a, const base_uint& b) { const unsigned char* pA = a.begin();