|
|
@ -28,6 +28,8 @@ |
|
|
|
|
|
|
|
#include <deque> |
|
|
|
#include <chrono> |
|
|
|
#include <unordered_map> |
|
|
|
#include <unordered_set> |
|
|
|
#include <libdevcore/Log.h> |
|
|
|
#include <libdevcore/Exceptions.h> |
|
|
|
#include <libdevcore/Guards.h> |
|
|
@ -40,6 +42,11 @@ |
|
|
|
#include "BlockQueue.h" |
|
|
|
namespace ldb = leveldb; |
|
|
|
|
|
|
|
template <> struct std::hash<std::pair<dev::h256, unsigned>> |
|
|
|
{ |
|
|
|
size_t operator()(const pair<dev::h256, unsigned> &x ) const { return std::hash<dev::h256>()(x.first) ^ std::hash<unsigned>()(x.second); } |
|
|
|
}; |
|
|
|
|
|
|
|
namespace dev |
|
|
|
{ |
|
|
|
|
|
|
@ -66,7 +73,7 @@ std::map<Address, Account> const& genesisState(); |
|
|
|
|
|
|
|
ldb::Slice toSlice(h256 const& _h, unsigned _sub = 0); |
|
|
|
|
|
|
|
using BlocksHash = std::map<h256, bytes>; |
|
|
|
using BlocksHash = std::unordered_map<h256, bytes>; |
|
|
|
using TransactionHashes = h256s; |
|
|
|
using UncleHashes = h256s; |
|
|
|
using ImportRoute = std::pair<h256s, h256s>; |
|
|
@ -144,7 +151,7 @@ public: |
|
|
|
UncleHashes uncleHashes() const { return uncleHashes(currentHash()); } |
|
|
|
|
|
|
|
/// Get the hash for a given block's number.
|
|
|
|
h256 numberHash(unsigned _i) const { if (!_i) return genesisHash(); return queryExtras<BlockHash, ExtraBlockHash>(h256(u256(_i)), m_blockHashes, x_blockHashes, NullBlockHash).value; } |
|
|
|
h256 numberHash(unsigned _i) const { if (!_i) return genesisHash(); return queryExtras<BlockHash, ExtraBlockHash>(h256(_i), m_blockHashes, x_blockHashes, NullBlockHash).value; } |
|
|
|
|
|
|
|
/// Get the last N hashes for a given block. (N is determined by the LastHashes type.)
|
|
|
|
LastHashes lastHashes() const { return lastHashes(number()); } |
|
|
@ -251,7 +258,7 @@ private: |
|
|
|
void open(std::string const& _path, WithExisting _we = WithExisting::Trust); |
|
|
|
void close(); |
|
|
|
|
|
|
|
template<class T, unsigned N> T queryExtras(h256 const& _h, std::map<h256, T>& _m, boost::shared_mutex& _x, T const& _n, ldb::DB* _extrasDB = nullptr) const |
|
|
|
template<class T, unsigned N> T queryExtras(h256 const& _h, std::unordered_map<h256, T>& _m, boost::shared_mutex& _x, T const& _n, ldb::DB* _extrasDB = nullptr) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
ReadGuard l(_x); |
|
|
@ -295,11 +302,12 @@ private: |
|
|
|
|
|
|
|
using CacheID = std::pair<h256, unsigned>; |
|
|
|
mutable Mutex x_cacheUsage; |
|
|
|
mutable std::deque<std::set<CacheID>> m_cacheUsage; |
|
|
|
mutable std::set<CacheID> m_inUse; |
|
|
|
mutable std::deque<std::unordered_set<CacheID>> m_cacheUsage; |
|
|
|
mutable std::unordered_set<CacheID> m_inUse; |
|
|
|
void noteUsed(h256 const& _h, unsigned _extra = (unsigned)-1) const; |
|
|
|
std::chrono::system_clock::time_point m_lastCollection; |
|
|
|
|
|
|
|
void noteCanonChanged() const { Guard l(x_lastLastHashes); m_lastLastHashes.clear(); } |
|
|
|
mutable Mutex x_lastLastHashes; |
|
|
|
mutable LastHashes m_lastLastHashes; |
|
|
|
mutable unsigned m_lastLastHashesNumber = (unsigned)-1; |
|
|
|