|
|
@ -72,6 +72,7 @@ struct BlockChainDebug: public LogChannel { static const char* name(); static co |
|
|
|
std::unordered_map<Address, Account> const& genesisState(); |
|
|
|
|
|
|
|
ldb::Slice toSlice(h256 const& _h, unsigned _sub = 0); |
|
|
|
ldb::Slice toSlice(uint64_t _n, unsigned _sub = 0); |
|
|
|
|
|
|
|
using BlocksHash = std::unordered_map<h256, bytes>; |
|
|
|
using TransactionHashes = h256s; |
|
|
@ -168,7 +169,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(_i), m_blockHashes, x_blockHashes, NullBlockHash).value; } |
|
|
|
h256 numberHash(unsigned _i) const { if (!_i) return genesisHash(); return queryExtras<BlockHash, uint64_t, ExtraBlockHash>(_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()); } |
|
|
@ -293,7 +294,7 @@ protected: |
|
|
|
unsigned open(std::string const& _path, WithExisting _we = WithExisting::Trust); |
|
|
|
void close(); |
|
|
|
|
|
|
|
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 |
|
|
|
template<class T, class K, unsigned N> T queryExtras(K const& _h, std::unordered_map<K, T>& _m, boost::shared_mutex& _x, T const& _n, ldb::DB* _extrasDB = nullptr) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
ReadGuard l(_x); |
|
|
@ -305,10 +306,7 @@ protected: |
|
|
|
std::string s; |
|
|
|
(_extrasDB ? _extrasDB : m_extrasDB)->Get(m_readOptions, toSlice(_h, N), &s); |
|
|
|
if (s.empty()) |
|
|
|
{ |
|
|
|
// cout << "Not found in DB: " << _h << endl;
|
|
|
|
return _n; |
|
|
|
} |
|
|
|
|
|
|
|
noteUsed(_h, N); |
|
|
|
|
|
|
@ -317,6 +315,11 @@ protected: |
|
|
|
return ret.first->second; |
|
|
|
} |
|
|
|
|
|
|
|
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 |
|
|
|
{ |
|
|
|
return queryExtras<T, h256, N>(_h, _m, _x, _n, _extrasDB); |
|
|
|
} |
|
|
|
|
|
|
|
void checkConsistency(); |
|
|
|
|
|
|
|
/// The caches of the disk DB and their locks.
|
|
|
@ -340,6 +343,7 @@ protected: |
|
|
|
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; |
|
|
|
void noteUsed(uint64_t const& _h, unsigned _extra = (unsigned)-1) const { (void)_h; (void)_extra; } // don't note non-hash types
|
|
|
|
std::chrono::system_clock::time_point m_lastCollection; |
|
|
|
|
|
|
|
void noteCanonChanged() const { Guard l(x_lastLastHashes); m_lastLastHashes.clear(); } |
|
|
|