![]() |
Ethereum
PoC-8
The C++ Implementation of Ethereum
|
Implements the blockchain database. All data this gives is disk-backed. @threadsafe. More...
#include <BlockChain.h>
Classes | |
| struct | Statistics |
Public Member Functions | |
| BlockChain (ChainParams const &_p, boost::filesystem::path const &_path, WithExisting _we=WithExisting::Trust, ProgressCallback const &_pc=ProgressCallback()) | |
| ~BlockChain () | |
| void | reopen (WithExisting _we=WithExisting::Trust, ProgressCallback const &_pc=ProgressCallback()) |
| Reopen everything. More... | |
| void | reopen (ChainParams const &_p, WithExisting _we=WithExisting::Trust, ProgressCallback const &_pc=ProgressCallback()) |
| void | process () |
| std::tuple< ImportRoute, bool, unsigned > | sync (BlockQueue &_bq, OverlayDB const &_stateDB, unsigned _max) |
| std::pair< ImportResult, ImportRoute > | attemptImport (bytes const &_block, OverlayDB const &_stateDB, bool _mutBeNew=true) noexcept |
| ImportRoute | import (bytes const &_block, OverlayDB const &_stateDB, bool _mustBeNew=true) |
| ImportRoute | import (VerifiedBlockRef const &_block, OverlayDB const &_db, bool _mustBeNew=true) |
| void | insert (bytes const &_block, bytesConstRef _receipts, bool _mustBeNew=true) |
| void | insert (VerifiedBlockRef _block, bytesConstRef _receipts, bool _mustBeNew=true) |
| ImportRoute | insertWithoutParent (bytes const &_block, bytesConstRef _receipts, u256 const &_totalDifficulty) |
| Insert that doesn't require parent to be imported, useful when we don't have the full blockchain (like restoring from partial snapshot). More... | |
| bool | isKnown (h256 const &_hash, bool _isCurrent=true) const |
| Returns true if the given block is known (though not necessarily a part of the canon chain). More... | |
| BlockHeader | info (h256 const &_hash) const |
| Get the partial-header of a block (or the most recent mined if none given). Thread-safe. More... | |
| BlockHeader | info () const |
| bytes | block (h256 const &_hash) const |
| Get a block (RLP format) for the given hash (or the most recent mined if none given). Thread-safe. More... | |
| bytes | block () const |
| bytes | headerData (h256 const &_hash) const |
| Get a block (RLP format) for the given hash (or the most recent mined if none given). Thread-safe. More... | |
| bytes | headerData () const |
| BlockDetails | details (h256 const &_hash) const |
| Get the familial details concerning a block (or the most recent mined if none given). Thread-safe. More... | |
| BlockDetails | details () const |
| BlockLogBlooms | logBlooms (h256 const &_hash) const |
| Get the transactions' log blooms of a block (or the most recent mined if none given). Thread-safe. More... | |
| BlockLogBlooms | logBlooms () const |
| BlockReceipts | receipts (h256 const &_hash) const |
| BlockReceipts | receipts () const |
| TransactionReceipt | transactionReceipt (h256 const &_blockHash, unsigned _i) const |
| Get the transaction by block hash and index;. More... | |
| TransactionReceipt | transactionReceipt (h256 const &_transactionHash) const |
| Get the transaction receipt by transaction hash. Thread-safe. More... | |
| TransactionHashes | transactionHashes (h256 const &_hash) const |
| Get a list of transaction hashes for a given block. Thread-safe. More... | |
| TransactionHashes | transactionHashes () const |
| UncleHashes | uncleHashes (h256 const &_hash) const |
| Get a list of uncle hashes for a given block. Thread-safe. More... | |
| UncleHashes | uncleHashes () const |
| h256 | numberHash (unsigned _i) const |
| Get the hash for a given block's number. More... | |
| LastBlockHashesFace const & | lastBlockHashes () const |
| BlocksBlooms | blocksBlooms (unsigned _level, unsigned _index) const |
| BlocksBlooms | blocksBlooms (h256 const &_chunkId) const |
| LogBloom | blockBloom (unsigned _number) const |
| std::vector< unsigned > | withBlockBloom (LogBloom const &_b, unsigned _earliest, unsigned _latest) const |
| std::vector< unsigned > | withBlockBloom (LogBloom const &_b, unsigned _earliest, unsigned _latest, unsigned _topLevel, unsigned _index) const |
| bool | isKnownTransaction (h256 const &_transactionHash) const |
| Returns true if transaction is known. Thread-safe. More... | |
| bytes | transaction (h256 const &_transactionHash) const |
| Get a transaction from its hash. Thread-safe. More... | |
| std::pair< h256, unsigned > | transactionLocation (h256 const &_transactionHash) const |
| bytes | transaction (h256 const &_blockHash, unsigned _i) const |
| Get a block's transaction (RLP format) for the given block hash (or the most recent mined if none given) & index. Thread-safe. More... | |
| bytes | transaction (unsigned _i) const |
| std::vector< bytes > | transactions (h256 const &_blockHash) const |
| Get all transactions from a block. More... | |
| std::vector< bytes > | transactions () const |
| unsigned | number (h256 const &_hash) const |
| Get a number for the given hash (or the most recent mined if none given). Thread-safe. More... | |
| unsigned | number () const |
| h256 | currentHash () const |
| Get a given block (RLP format). Thread-safe. More... | |
| h256 | genesisHash () const |
| Get the hash of the genesis block. Thread-safe. More... | |
| h256Hash | allKinFrom (h256 const &_parent, unsigned _generations) const |
| void | rebuild (boost::filesystem::path const &_path, ProgressCallback const &_progress=std::function< void(unsigned, unsigned)>()) |
| void | rewind (unsigned _newHead) |
| Alter the head of the chain to some prior block along it. More... | |
| void | rescue (OverlayDB const &_db) |
| Rescue the database. More... | |
| std::tuple< h256s, h256, unsigned > | treeRoute (h256 const &_from, h256 const &_to, bool _common=true, bool _pre=true, bool _post=true) const |
| Statistics | usage (bool _freshen=false) const |
| void | garbageCollect (bool _force=false) |
| Deallocate unused data. More... | |
| void | setOnBad (std::function< void(Exception &)> _t) |
| Change the function that is called with a bad block. More... | |
| void | setOnBlockImport (std::function< void(BlockHeader const &)> _t) |
| Change the function that is called when a new block is imported. More... | |
| Block | genesisBlock (OverlayDB const &_db) const |
| Get a pre-made genesis State object. More... | |
| VerifiedBlockRef | verifyBlock (bytesConstRef _block, std::function< void(Exception &)> const &_onBad, ImportRequirements::value _ir=ImportRequirements::OutOfOrderChecks) const |
| Verify block and prepare it for enactment. More... | |
| std::string | dumpDatabase () const |
| Gives a dump of the blockchain database. For debug/test use only. More... | |
| ChainParams const & | chainParams () const |
| SealEngineFace * | sealEngine () const |
| BlockHeader const & | genesis () const |
| unsigned | chainStartBlockNumber () const |
| void | setChainStartBlockNumber (unsigned _number) |
| Change the chain start block. More... | |
Friends | |
| std::ostream & | operator<< (std::ostream &_out, BlockChain const &_bc) |
Implements the blockchain database. All data this gives is disk-backed. @threadsafe.
Definition at line 104 of file BlockChain.h.
| BlockChain::BlockChain | ( | ChainParams const & | _p, |
| boost::filesystem::path const & | _path, | ||
| WithExisting | _we = WithExisting::Trust, |
||
| ProgressCallback const & | _pc = ProgressCallback() |
||
| ) |
Doesn't open the database - if you want it open it's up to you to subclass this and open it in the constructor there.
Definition at line 172 of file BlockChain.cpp.
| BlockChain::~BlockChain | ( | ) |
Definition at line 180 of file BlockChain.cpp.
Get all blocks not allowed as uncles given a parent (i.e. featured as uncles/main in parent, parent + 1, ... parent + _generations).
Definition at line 1388 of file BlockChain.cpp.
|
noexcept |
Attempt to import the given block directly into the BlockChain and sync with the state DB.
Definition at line 507 of file BlockChain.cpp.
|
inline |
Definition at line 150 of file BlockChain.h.
Get a block (RLP format) for the given hash (or the most recent mined if none given). Thread-safe.
Definition at line 1423 of file BlockChain.cpp.
|
inline |
Definition at line 204 of file BlockChain.h.
|
inline |
Definition at line 203 of file BlockChain.h.
|
inline |
Get the block blooms for a number of blocks. Thread-safe.
Definition at line 202 of file BlockChain.h.
|
inline |
Definition at line 306 of file BlockChain.h.
| unsigned BlockChain::chainStartBlockNumber | ( | ) | const |
Definition at line 1606 of file BlockChain.cpp.
|
inline |
Get a given block (RLP format). Thread-safe.
Definition at line 228 of file BlockChain.h.
|
inline |
Definition at line 158 of file BlockChain.h.
|
inline |
Get the familial details concerning a block (or the most recent mined if none given). Thread-safe.
Definition at line 157 of file BlockChain.h.
| string BlockChain::dumpDatabase | ( | ) | const |
Gives a dump of the blockchain database. For debug/test use only.
Definition at line 424 of file BlockChain.cpp.
| void BlockChain::garbageCollect | ( | bool | _force = false | ) |
Deallocate unused data.
Definition at line 1211 of file BlockChain.cpp.
| BlockHeader const & BlockChain::genesis | ( | ) | const |
Definition at line 185 of file BlockChain.cpp.
Get a pre-made genesis State object.
Definition at line 1479 of file BlockChain.cpp.
|
inline |
Get the hash of the genesis block. Thread-safe.
Definition at line 231 of file BlockChain.h.
|
inline |
Definition at line 154 of file BlockChain.h.
Get a block (RLP format) for the given hash (or the most recent mined if none given). Thread-safe.
Definition at line 1451 of file BlockChain.cpp.
| ImportRoute BlockChain::import | ( | bytes const & | _block, |
| OverlayDB const & | _stateDB, | ||
| bool | _mustBeNew = true |
||
| ) |
Import block into disk-backed DB.
Definition at line 533 of file BlockChain.cpp.
| ImportRoute BlockChain::import | ( | VerifiedBlockRef const & | _block, |
| OverlayDB const & | _db, | ||
| bool | _mustBeNew = true |
||
| ) |
Definition at line 650 of file BlockChain.cpp.
|
inline |
Definition at line 146 of file BlockChain.h.
|
inline |
Get the partial-header of a block (or the most recent mined if none given). Thread-safe.
Definition at line 145 of file BlockChain.h.
| void BlockChain::insert | ( | bytes const & | _block, |
| bytesConstRef | _receipts, | ||
| bool | _mustBeNew = true |
||
| ) |
Import data into disk-backed DB. This will not execute the block and populate the state trie, but rather will simply add the block/header and receipts directly into the databases.
Definition at line 540 of file BlockChain.cpp.
| void BlockChain::insert | ( | VerifiedBlockRef | _block, |
| bytesConstRef | _receipts, | ||
| bool | _mustBeNew = true |
||
| ) |
Definition at line 547 of file BlockChain.cpp.
| ImportRoute BlockChain::insertWithoutParent | ( | bytes const & | _block, |
| bytesConstRef | _receipts, | ||
| u256 const & | _totalDifficulty | ||
| ) |
Insert that doesn't require parent to be imported, useful when we don't have the full blockchain (like restoring from partial snapshot).
Definition at line 733 of file BlockChain.cpp.
| bool BlockChain::isKnown | ( | h256 const & | _hash, |
| bool | _isCurrent = true |
||
| ) | const |
Returns true if the given block is known (though not necessarily a part of the canon chain).
Definition at line 1404 of file BlockChain.cpp.
|
inline |
Returns true if transaction is known. Thread-safe.
Definition at line 209 of file BlockChain.h.
|
inline |
Definition at line 186 of file BlockChain.h.
|
inline |
Definition at line 162 of file BlockChain.h.
|
inline |
Get the transactions' log blooms of a block (or the most recent mined if none given). Thread-safe.
Definition at line 161 of file BlockChain.h.
|
inline |
Definition at line 225 of file BlockChain.h.
|
inline |
Get a number for the given hash (or the most recent mined if none given). Thread-safe.
Definition at line 224 of file BlockChain.h.
|
inline |
Get the hash for a given block's number.
Definition at line 184 of file BlockChain.h.
| void dev::eth::BlockChain::process | ( | ) |
(Potentially) renders invalid existing bytesConstRef returned by lastBlock. To be called from main loop every 100ms or so.
| void BlockChain::rebuild | ( | boost::filesystem::path const & | _path, |
| ProgressCallback const & | _progress = std::function<void(unsigned, unsigned)>() |
||
| ) |
Run through database and verify all blocks by reevaluating. Will call _progress with the progress in this operation first param done, second total.
Definition at line 341 of file BlockChain.cpp.
|
inline |
Definition at line 167 of file BlockChain.h.
|
inline |
Get the transactions' receipts of a block (or the most recent mined if none given). Thread-safe. receipts are given in the same order are in the same order as the transactions
Definition at line 166 of file BlockChain.h.
| void BlockChain::reopen | ( | ChainParams const & | _p, |
| WithExisting | _we = WithExisting::Trust, |
||
| ProgressCallback const & | _pc = ProgressCallback() |
||
| ) |
Definition at line 311 of file BlockChain.cpp.
|
inline |
Reopen everything.
Definition at line 113 of file BlockChain.h.
| void BlockChain::rescue | ( | OverlayDB const & | _db | ) |
Rescue the database.
Definition at line 1041 of file BlockChain.cpp.
| void BlockChain::rewind | ( | unsigned | _newHead | ) |
Alter the head of the chain to some prior block along it.
Definition at line 1091 of file BlockChain.cpp.
|
inline |
Definition at line 308 of file BlockChain.h.
| void BlockChain::setChainStartBlockNumber | ( | unsigned | _number | ) |
Change the chain start block.
Definition at line 1587 of file BlockChain.cpp.
|
inline |
Change the function that is called with a bad block.
Definition at line 292 of file BlockChain.h.
|
inline |
Change the function that is called when a new block is imported.
Definition at line 295 of file BlockChain.h.
| tuple< ImportRoute, bool, unsigned > BlockChain::sync | ( | BlockQueue & | _bq, |
| OverlayDB const & | _stateDB, | ||
| unsigned | _max | ||
| ) |
Sync the chain with any incoming blocks. All blocks should, if processed in order.
Definition at line 443 of file BlockChain.cpp.
Get a block's transaction (RLP format) for the given block hash (or the most recent mined if none given) & index. Thread-safe.
Definition at line 216 of file BlockChain.h.
Get a transaction from its hash. Thread-safe.
Definition at line 212 of file BlockChain.h.
|
inline |
Definition at line 217 of file BlockChain.h.
|
inline |
Definition at line 177 of file BlockChain.h.
|
inline |
Get a list of transaction hashes for a given block. Thread-safe.
Definition at line 176 of file BlockChain.h.
|
inline |
Definition at line 213 of file BlockChain.h.
|
inline |
Get the transaction by block hash and index;.
Definition at line 170 of file BlockChain.h.
|
inline |
Get the transaction receipt by transaction hash. Thread-safe.
Definition at line 173 of file BlockChain.h.
|
inline |
Definition at line 221 of file BlockChain.h.
Get all transactions from a block.
Definition at line 220 of file BlockChain.h.
| tuple< h256s, h256, unsigned > BlockChain::treeRoute | ( | h256 const & | _from, |
| h256 const & | _to, | ||
| bool | _common = true, |
||
| bool | _pre = true, |
||
| bool | _post = true |
||
| ) | const |
| _common | if true, include the common ancestor in the returned vector. |
| _pre | if true, include all block hashes running from _from until the common ancestor in the returned vector. |
| _post | if true, include all block hashes running from the common ancestor until _to in the returned vector. |
e.g. if the block tree is 3a -> 2a -> 1a -> g and 2b -> 1b -> g (g is genesis, *a, *b are competing chains), then:
Definition at line 1116 of file BlockChain.cpp.
|
inline |
Definition at line 181 of file BlockChain.h.
|
inline |
Get a list of uncle hashes for a given block. Thread-safe.
Definition at line 180 of file BlockChain.h.
|
inline |
Definition at line 286 of file BlockChain.h.
| VerifiedBlockRef BlockChain::verifyBlock | ( | bytesConstRef | _block, |
| std::function< void(Exception &)> const & | _onBad, | ||
| ImportRequirements::value | _ir = ImportRequirements::OutOfOrderChecks |
||
| ) | const |
Verify block and prepare it for enactment.
Definition at line 1501 of file BlockChain.cpp.
| vector< unsigned > BlockChain::withBlockBloom | ( | LogBloom const & | _b, |
| unsigned | _earliest, | ||
| unsigned | _latest | ||
| ) | const |
Definition at line 1334 of file BlockChain.cpp.
| vector< unsigned > BlockChain::withBlockBloom | ( | LogBloom const & | _b, |
| unsigned | _earliest, | ||
| unsigned | _latest, | ||
| unsigned | _topLevel, | ||
| unsigned | _index | ||
| ) | const |
Definition at line 1348 of file BlockChain.cpp.
|
friend |