|
@ -62,8 +62,17 @@ std::map<Address, Account> const& genesisState(); |
|
|
|
|
|
|
|
|
ldb::Slice toSlice(h256 _h, unsigned _sub = 0); |
|
|
ldb::Slice toSlice(h256 _h, unsigned _sub = 0); |
|
|
|
|
|
|
|
|
|
|
|
using BlocksHash = std::map<h256, bytes>; |
|
|
using TransactionHashes = h256s; |
|
|
using TransactionHashes = h256s; |
|
|
|
|
|
|
|
|
|
|
|
enum { |
|
|
|
|
|
ExtraDetails = 0, |
|
|
|
|
|
ExtraBlockHash, |
|
|
|
|
|
ExtraTransactionAddress, |
|
|
|
|
|
ExtraLogBlooms, |
|
|
|
|
|
ExtraReceipts |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* @brief Implements the blockchain database. All data this gives is disk-backed. |
|
|
* @brief Implements the blockchain database. All data this gives is disk-backed. |
|
|
* @threadsafe |
|
|
* @threadsafe |
|
@ -99,28 +108,31 @@ public: |
|
|
BlockInfo info(h256 _hash) const { return BlockInfo(block(_hash)); } |
|
|
BlockInfo info(h256 _hash) const { return BlockInfo(block(_hash)); } |
|
|
BlockInfo info() const { return BlockInfo(block()); } |
|
|
BlockInfo info() const { return BlockInfo(block()); } |
|
|
|
|
|
|
|
|
|
|
|
/// Get a block (RLP format) for the given hash (or the most recent mined if none given). Thread-safe.
|
|
|
|
|
|
bytes block(h256 _hash) const; |
|
|
|
|
|
bytes block() const { return block(currentHash()); } |
|
|
|
|
|
|
|
|
/// Get the familial details concerning a block (or the most recent mined if none given). Thread-safe.
|
|
|
/// Get the familial details concerning a block (or the most recent mined if none given). Thread-safe.
|
|
|
BlockDetails details(h256 _hash) const { return queryExtras<BlockDetails, 0>(_hash, m_details, x_details, NullBlockDetails); } |
|
|
BlockDetails details(h256 _hash) const { return queryExtras<BlockDetails, ExtraDetails>(_hash, m_details, x_details, NullBlockDetails); } |
|
|
BlockDetails details() const { return details(currentHash()); } |
|
|
BlockDetails details() const { return details(currentHash()); } |
|
|
|
|
|
|
|
|
/// Get the transactions' log blooms of a block (or the most recent mined if none given). Thread-safe.
|
|
|
/// Get the transactions' log blooms of a block (or the most recent mined if none given). Thread-safe.
|
|
|
BlockLogBlooms logBlooms(h256 _hash) const { return queryExtras<BlockLogBlooms, 3>(_hash, m_logBlooms, x_logBlooms, NullBlockLogBlooms); } |
|
|
BlockLogBlooms logBlooms(h256 _hash) const { return queryExtras<BlockLogBlooms, ExtraLogBlooms>(_hash, m_logBlooms, x_logBlooms, NullBlockLogBlooms); } |
|
|
BlockLogBlooms logBlooms() const { return logBlooms(currentHash()); } |
|
|
BlockLogBlooms logBlooms() const { return logBlooms(currentHash()); } |
|
|
|
|
|
|
|
|
/// Get the transactions' receipts of a block (or the most recent mined if none given). Thread-safe.
|
|
|
/// Get the transactions' receipts of a block (or the most recent mined if none given). Thread-safe.
|
|
|
BlockReceipts receipts(h256 _hash) const { return queryExtras<BlockReceipts, 4>(_hash, m_receipts, x_receipts, NullBlockReceipts); } |
|
|
BlockReceipts receipts(h256 _hash) const { return queryExtras<BlockReceipts, ExtraReceipts>(_hash, m_receipts, x_receipts, NullBlockReceipts); } |
|
|
BlockReceipts receipts() const { return receipts(currentHash()); } |
|
|
BlockReceipts receipts() const { return receipts(currentHash()); } |
|
|
|
|
|
|
|
|
/// Get a list of transaction hashes for a given block. Thread-safe.
|
|
|
/// Get a list of transaction hashes for a given block. Thread-safe.
|
|
|
TransactionHashes transactionHashes(h256 _hash) const { auto b = block(_hash); RLP rlp(b); h256s ret; for (auto t: rlp[1]) ret.push_back(sha3(t.data())); return ret; } |
|
|
TransactionHashes transactionHashes(h256 _hash) const { auto b = block(_hash); RLP rlp(b); h256s ret; for (auto t: rlp[1]) ret.push_back(sha3(t.data())); return ret; } |
|
|
TransactionHashes transactionHashes() const { return transactionHashes(currentHash()); } |
|
|
TransactionHashes transactionHashes() const { return transactionHashes(currentHash()); } |
|
|
|
|
|
|
|
|
/// Get a block (RLP format) for the given hash (or the most recent mined if none given). Thread-safe.
|
|
|
/// Get a list of transaction hashes for a given block. Thread-safe.
|
|
|
bytes block(h256 _hash) const; |
|
|
h256 numberHash(u256 _index) const { if (!_index) return genesisHash(); return queryExtras<BlockHash, ExtraBlockHash>(h256(_index), m_blockHashes, x_blockHashes, NullBlockHash).value; } |
|
|
bytes block() const { return block(currentHash()); } |
|
|
|
|
|
|
|
|
|
|
|
/// Get a transaction from its hash. Thread-safe.
|
|
|
/// Get a transaction from its hash. Thread-safe.
|
|
|
bytes transaction(h256 _transactionHash) const { TransactionAddress ta = queryExtras<TransactionAddress, 5>(_transactionHash, m_transactionAddresses, x_transactionAddresses, NullTransactionAddress); if (!ta) return bytes(); return transaction(ta.blockHash, ta.index); } |
|
|
bytes transaction(h256 _transactionHash) const { TransactionAddress ta = queryExtras<TransactionAddress, ExtraTransactionAddress>(_transactionHash, m_transactionAddresses, x_transactionAddresses, NullTransactionAddress); if (!ta) return bytes(); return transaction(ta.blockHash, ta.index); } |
|
|
|
|
|
|
|
|
/// Get a block's transaction (RLP format) for the given block hash (or the most recent mined if none given) & index. Thread-safe.
|
|
|
/// Get a block's transaction (RLP format) for the given block hash (or the most recent mined if none given) & index. Thread-safe.
|
|
|
bytes transaction(h256 _blockHash, unsigned _i) const { bytes b = block(_blockHash); return RLP(b)[1][_i].data().toBytes(); } |
|
|
bytes transaction(h256 _blockHash, unsigned _i) const { bytes b = block(_blockHash); return RLP(b)[1][_i].data().toBytes(); } |
|
@ -136,9 +148,6 @@ public: |
|
|
/// Get the hash of the genesis block. Thread-safe.
|
|
|
/// Get the hash of the genesis block. Thread-safe.
|
|
|
h256 genesisHash() const { return m_genesisHash; } |
|
|
h256 genesisHash() const { return m_genesisHash; } |
|
|
|
|
|
|
|
|
/// Get the hash of a block of a given number. Slow; try not to use it too much.
|
|
|
|
|
|
h256 numberHash(unsigned _n) const; |
|
|
|
|
|
|
|
|
|
|
|
/// Get all blocks not allowed as uncles given a parent (i.e. featured as uncles/main in parent, parent + 1, ... parent + 5).
|
|
|
/// Get all blocks not allowed as uncles given a parent (i.e. featured as uncles/main in parent, parent + 1, ... parent + 5).
|
|
|
/// @returns set including the header-hash of every parent (including @a _parent) up to and including generation +5
|
|
|
/// @returns set including the header-hash of every parent (including @a _parent) up to and including generation +5
|
|
|
/// togther with all their quoted uncles.
|
|
|
/// togther with all their quoted uncles.
|
|
@ -160,6 +169,21 @@ public: |
|
|
*/ |
|
|
*/ |
|
|
h256s treeRoute(h256 _from, h256 _to, h256* o_common = nullptr, bool _pre = true, bool _post = true) const; |
|
|
h256s treeRoute(h256 _from, h256 _to, h256* o_common = nullptr, bool _pre = true, bool _post = true) const; |
|
|
|
|
|
|
|
|
|
|
|
struct Statistics |
|
|
|
|
|
{ |
|
|
|
|
|
unsigned memDetails; |
|
|
|
|
|
unsigned memLogBlooms; |
|
|
|
|
|
unsigned memReceipts; |
|
|
|
|
|
unsigned memTransactionAddresses; |
|
|
|
|
|
unsigned memCache; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/// @returns statistics about memory usage.
|
|
|
|
|
|
Statistics usage() const; |
|
|
|
|
|
|
|
|
|
|
|
/// Deallocate unused data.
|
|
|
|
|
|
void garbageCollect(); |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
void open(std::string _path, bool _killExisting = false); |
|
|
void open(std::string _path, bool _killExisting = false); |
|
|
void close(); |
|
|
void close(); |
|
@ -189,6 +213,8 @@ private: |
|
|
void checkConsistency(); |
|
|
void checkConsistency(); |
|
|
|
|
|
|
|
|
/// The caches of the disk DB and their locks.
|
|
|
/// The caches of the disk DB and their locks.
|
|
|
|
|
|
mutable boost::shared_mutex x_blocks; |
|
|
|
|
|
mutable BlocksHash m_blocks; |
|
|
mutable boost::shared_mutex x_details; |
|
|
mutable boost::shared_mutex x_details; |
|
|
mutable BlockDetailsHash m_details; |
|
|
mutable BlockDetailsHash m_details; |
|
|
mutable boost::shared_mutex x_logBlooms; |
|
|
mutable boost::shared_mutex x_logBlooms; |
|
@ -197,11 +223,11 @@ private: |
|
|
mutable BlockReceiptsHash m_receipts; |
|
|
mutable BlockReceiptsHash m_receipts; |
|
|
mutable boost::shared_mutex x_transactionAddresses; |
|
|
mutable boost::shared_mutex x_transactionAddresses; |
|
|
mutable TransactionAddressHash m_transactionAddresses; |
|
|
mutable TransactionAddressHash m_transactionAddresses; |
|
|
mutable boost::shared_mutex x_cache; |
|
|
mutable boost::shared_mutex x_blockHashes; |
|
|
mutable std::map<h256, bytes> m_cache; |
|
|
mutable BlockHashHash m_blockHashes; |
|
|
|
|
|
|
|
|
/// The disk DBs. Thread-safe, so no need for locks.
|
|
|
/// The disk DBs. Thread-safe, so no need for locks.
|
|
|
ldb::DB* m_db; |
|
|
ldb::DB* m_blocksDB; |
|
|
ldb::DB* m_extrasDB; |
|
|
ldb::DB* m_extrasDB; |
|
|
|
|
|
|
|
|
/// Hash of the last (valid) block on the longest chain.
|
|
|
/// Hash of the last (valid) block on the longest chain.
|
|
|