Fabcoin Core  0.16.2
P2P Digital Currency
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
dev::eth::BlockChain Class Reference

Implements the blockchain database. More...

#include <BlockChain.h>

Collaboration diagram for dev::eth::BlockChain:
[legend]

Classes

struct  Statistics
 

Public Member Functions

 BlockChain (ChainParams const &_p, std::string 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. More...
 
 ~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 ()
 (Potentially) renders invalid existing bytesConstRef returned by lastBlock. More...
 
std::tuple< ImportRoute, bool, unsigned > sync (BlockQueue &_bq, OverlayDB const &_stateDB, unsigned _max)
 Sync the chain with any incoming blocks. More...
 
std::pair< ImportResult, ImportRouteattemptImport (bytes const &_block, OverlayDB const &_stateDB, bool _mutBeNew=true) noexcept
 Attempt to import the given block directly into the BlockChain and sync with the state DB. More...
 
ImportRoute import (bytes const &_block, OverlayDB const &_stateDB, bool _mustBeNew=true)
 Import block into disk-backed DB. More...
 
ImportRoute import (VerifiedBlockRef const &_block, OverlayDB const &_db, bool _mustBeNew=true)
 
void insert (bytes const &_block, bytesConstRef _receipts, bool _mustBeNew=true)
 Import data into disk-backed DB. More...
 
void insert (VerifiedBlockRef _block, bytesConstRef _receipts, bool _mustBeNew=true)
 
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
 Get the transactions' receipts of a block (or the most recent mined if none given). More...
 
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...
 
LastHashes lastHashes () const
 Get the last N hashes for a given block. (N is determined by the LastHashes type.) More...
 
LastHashes lastHashes (h256 const &_mostRecentHash) const
 
BlocksBlooms blocksBlooms (unsigned _level, unsigned _index) const
 Get the block blooms for a number of blocks. More...
 
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< bytestransactions (h256 const &_blockHash) const
 Get all transactions from a block. More...
 
std::vector< bytestransactions () 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
 Get all blocks not allowed as uncles given a parent (i.e. More...
 
void rebuild (std::string const &_path, ProgressCallback const &_progress=std::function< void(unsigned, unsigned)>())
 Run through database and verify all blocks by reevaluating. More...
 
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
 
SealEngineFacesealEngine () const
 
BlockHeader const & genesis () const
 

Private Types

using CacheID = std::pair< h256, unsigned >
 

Private Member Functions

void init (ChainParams const &_p)
 Initialise everything and ready for openning the database. More...
 
unsigned open (std::string const &_path, WithExisting _we)
 Open the database. More...
 
void open (std::string const &_path, WithExisting _we, ProgressCallback const &_pc)
 Open the database, rebuilding if necessary. More...
 
void close ()
 Finalise everything and close the database. More...
 
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
 
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
 
void checkConsistency ()
 
void clearCachesDuringChainReversion (unsigned _firstInvalid)
 Clears all caches from the tip of the chain up to (including) _firstInvalid. More...
 
void clearBlockBlooms (unsigned _begin, unsigned _end)
 
void noteUsed (h256 const &_h, unsigned _extra=(unsigned)-1) const
 
void noteUsed (uint64_t const &_h, unsigned _extra=(unsigned)-1) const
 
void noteCanonChanged () const
 
void updateStats () const
 

Static Private Member Functions

static h256 chunkId (unsigned _level, unsigned _index)
 

Private Attributes

SharedMutex x_blocks
 The caches of the disk DB and their locks. More...
 
BlocksHash m_blocks
 
SharedMutex x_details
 
BlockDetailsHash m_details
 
SharedMutex x_logBlooms
 
BlockLogBloomsHash m_logBlooms
 
SharedMutex x_receipts
 
BlockReceiptsHash m_receipts
 
SharedMutex x_transactionAddresses
 
TransactionAddressHash m_transactionAddresses
 
SharedMutex x_blockHashes
 
BlockHashHash m_blockHashes
 
SharedMutex x_blocksBlooms
 
BlocksBloomsHash m_blocksBlooms
 
Mutex x_cacheUsage
 
std::deque< std::unordered_set< CacheID > > m_cacheUsage
 
std::unordered_set< CacheIDm_inUse
 
std::chrono::system_clock::time_point m_lastCollection
 
Mutex x_lastLastHashes
 
LastHashes m_lastLastHashes
 
Statistics m_lastStats
 
ldb::DB * m_blocksDB
 The disk DBs. Thread-safe, so no need for locks. More...
 
ldb::DB * m_extrasDB
 
boost::shared_mutex x_lastBlockHash
 Hash of the last (valid) block on the longest chain. More...
 
h256 m_lastBlockHash
 
unsigned m_lastBlockNumber = 0
 
ldb::ReadOptions m_readOptions
 
ldb::WriteOptions m_writeOptions
 
ChainParams m_params
 
std::shared_ptr< SealEngineFacem_sealEngine
 
SharedMutex x_genesis
 
BlockHeader m_genesis
 
bytes m_genesisHeaderBytes
 
h256 m_genesisHash
 
std::function< void(Exception &)> m_onBad
 Called if we have a block that doesn't verify. More...
 
std::function< void(BlockHeader const &)> m_onBlockImport
 Called if we have imported a new block into the db. More...
 
std::string m_dbPath
 

Friends

std::ostream & operator<< (std::ostream &_out, BlockChain const &_bc)
 

Detailed Description

Implements the blockchain database.

All data this gives is disk-backed.

Definition at line 105 of file BlockChain.h.

Member Typedef Documentation

using dev::eth::BlockChain::CacheID = std::pair<h256, unsigned>
private

Definition at line 374 of file BlockChain.h.

Constructor & Destructor Documentation

BlockChain::BlockChain ( ChainParams const &  _p,
std::string 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 146 of file BlockChain.cpp.

Here is the call graph for this function:

BlockChain::~BlockChain ( )

Definition at line 153 of file BlockChain.cpp.

Here is the call graph for this function:

Member Function Documentation

h256Hash BlockChain::allKinFrom ( h256 const &  _parent,
unsigned  _generations 
) const

Get all blocks not allowed as uncles given a parent (i.e.

featured as uncles/main in parent, parent + 1, ... parent + _generations).

Returns
set including the header-hash of every parent (including _parent) up to and including generation + _generations togther with all their quoted uncles.

Definition at line 1338 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

pair< ImportResult, ImportRoute > BlockChain::attemptImport ( bytes const &  _block,
OverlayDB const &  _stateDB,
bool  _mutBeNew = true 
)
noexcept

Attempt to import the given block directly into the BlockChain and sync with the state DB.

Returns
the block hashes of any blocks that came into/went out of the canonical block chain.

Definition at line 472 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bytes BlockChain::block ( h256 const &  _hash) const

Get a block (RLP format) for the given hash (or the most recent mined if none given). Thread-safe.

Definition at line 1379 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bytes dev::eth::BlockChain::block ( ) const
inline

Definition at line 149 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

LogBloom dev::eth::BlockChain::blockBloom ( unsigned  _number) const
inline

Definition at line 205 of file BlockChain.h.

Here is the caller graph for this function:

BlocksBlooms dev::eth::BlockChain::blocksBlooms ( unsigned  _level,
unsigned  _index 
) const
inline

Get the block blooms for a number of blocks.

Thread-safe.

Returns
the object pertaining to the blocks: level 0: 0x, 0x + 1, .. (1x - 1) 1x, 1x + 1, .. (2x - 1) ... (255x .. (256x - 1)) level 1: 0x .. (1x - 1), 1x .. (2x - 1), ..., (255x .. (256x - 1)) 256x .. (257x - 1), 257x .. (258x - 1), ..., (511x .. (512x - 1)) ... level n, index i, offset o: i * (x ^ n) + o * x ^ (n - 1)

Definition at line 203 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

BlocksBlooms dev::eth::BlockChain::blocksBlooms ( h256 const &  _chunkId) const
inline

Definition at line 204 of file BlockChain.h.

ChainParams const& dev::eth::BlockChain::chainParams ( ) const
inline

Definition at line 307 of file BlockChain.h.

Here is the caller graph for this function:

void BlockChain::checkConsistency ( )
private

Definition at line 1231 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

static h256 dev::eth::BlockChain::chunkId ( unsigned  _level,
unsigned  _index 
)
inlinestaticprivate

Definition at line 314 of file BlockChain.h.

Here is the caller graph for this function:

void BlockChain::clearBlockBlooms ( unsigned  _begin,
unsigned  _end 
)
private

Definition at line 980 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void BlockChain::clearCachesDuringChainReversion ( unsigned  _firstInvalid)
private

Clears all caches from the tip of the chain up to (including) _firstInvalid.

These include the blooms, the block hashes and the transaction lookup tables.

Definition at line 1254 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void BlockChain::close ( )
private

Finalise everything and close the database.

Definition at line 277 of file BlockChain.cpp.

Here is the caller graph for this function:

h256 dev::eth::BlockChain::currentHash ( ) const
inline

Get a given block (RLP format). Thread-safe.

Definition at line 229 of file BlockChain.h.

Here is the caller graph for this function:

BlockDetails dev::eth::BlockChain::details ( h256 const &  _hash) const
inline

Get the familial details concerning a block (or the most recent mined if none given). Thread-safe.

Definition at line 156 of file BlockChain.h.

Here is the caller graph for this function:

BlockDetails dev::eth::BlockChain::details ( ) const
inline

Definition at line 157 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

string BlockChain::dumpDatabase ( ) const

Gives a dump of the blockchain database. For debug/test use only.

Definition at line 384 of file BlockChain.cpp.

Here is the call graph for this function:

void BlockChain::garbageCollect ( bool  _force = false)

Deallocate unused data.

Definition at line 1182 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

BlockHeader const & BlockChain::genesis ( ) const

Definition at line 158 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Block BlockChain::genesisBlock ( OverlayDB const &  _db) const

Get a pre-made genesis State object.

Definition at line 1439 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

h256 dev::eth::BlockChain::genesisHash ( ) const
inline

Get the hash of the genesis block. Thread-safe.

Definition at line 232 of file BlockChain.h.

Here is the caller graph for this function:

bytes BlockChain::headerData ( h256 const &  _hash) const

Get a block (RLP format) for the given hash (or the most recent mined if none given). Thread-safe.

Definition at line 1409 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bytes dev::eth::BlockChain::headerData ( ) const
inline

Definition at line 153 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

ImportRoute BlockChain::import ( bytes const &  _block,
OverlayDB const &  _stateDB,
bool  _mustBeNew = true 
)

Import block into disk-backed DB.

Returns
the block hashes of any blocks that came into/went out of the canonical block chain.

Definition at line 498 of file BlockChain.cpp.

Here is the call graph for this function:

ImportRoute BlockChain::import ( VerifiedBlockRef const &  _block,
OverlayDB const &  _db,
bool  _mustBeNew = true 
)

Definition at line 650 of file BlockChain.cpp.

Here is the call graph for this function:

BlockHeader dev::eth::BlockChain::info ( h256 const &  _hash) const
inline

Get the partial-header of a block (or the most recent mined if none given). Thread-safe.

Definition at line 144 of file BlockChain.h.

Here is the caller graph for this function:

BlockHeader dev::eth::BlockChain::info ( ) const
inline

Definition at line 145 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void BlockChain::init ( ChainParams const &  _p)
private

Initialise everything and ready for openning the database.

Definition at line 172 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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 522 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void BlockChain::insert ( VerifiedBlockRef  _block,
bytesConstRef  _receipts,
bool  _mustBeNew = true 
)

Definition at line 546 of file BlockChain.cpp.

Here is the call graph for this function:

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 1354 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool dev::eth::BlockChain::isKnownTransaction ( h256 const &  _transactionHash) const
inline

Returns true if transaction is known. Thread-safe.

Definition at line 210 of file BlockChain.h.

LastHashes dev::eth::BlockChain::lastHashes ( ) const
inline

Get the last N hashes for a given block. (N is determined by the LastHashes type.)

Definition at line 186 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

LastHashes BlockChain::lastHashes ( h256 const &  _mostRecentHash) const

Definition at line 395 of file BlockChain.cpp.

Here is the call graph for this function:

BlockLogBlooms dev::eth::BlockChain::logBlooms ( h256 const &  _hash) const
inline

Get the transactions' log blooms of a block (or the most recent mined if none given). Thread-safe.

Definition at line 160 of file BlockChain.h.

BlockLogBlooms dev::eth::BlockChain::logBlooms ( ) const
inline

Definition at line 161 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void dev::eth::BlockChain::noteCanonChanged ( ) const
inlineprivate

Definition at line 382 of file BlockChain.h.

Here is the caller graph for this function:

void BlockChain::noteUsed ( h256 const &  _h,
unsigned  _extra = (unsigned)-1 
) const
private

Definition at line 1144 of file BlockChain.cpp.

Here is the caller graph for this function:

void dev::eth::BlockChain::noteUsed ( uint64_t const &  _h,
unsigned  _extra = (unsigned)-1 
) const
inlineprivate

Definition at line 379 of file BlockChain.h.

unsigned dev::eth::BlockChain::number ( h256 const &  _hash) const
inline

Get a number for the given hash (or the most recent mined if none given). Thread-safe.

Definition at line 225 of file BlockChain.h.

Here is the caller graph for this function:

unsigned dev::eth::BlockChain::number ( ) const
inline

Definition at line 226 of file BlockChain.h.

Here is the caller graph for this function:

h256 dev::eth::BlockChain::numberHash ( unsigned  _i) const
inline

Get the hash for a given block's number.

Definition at line 183 of file BlockChain.h.

Here is the caller graph for this function:

unsigned BlockChain::open ( std::string const &  _path,
WithExisting  _we 
)
private

Open the database.

Definition at line 185 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void BlockChain::open ( std::string const &  _path,
WithExisting  _we,
ProgressCallback const &  _pc 
)
private

Open the database, rebuilding if necessary.

Definition at line 264 of file BlockChain.cpp.

Here is the call graph for this function:

void dev::eth::BlockChain::process ( )

(Potentially) renders invalid existing bytesConstRef returned by lastBlock.

To be called from main loop every 100ms or so.

template<class T , class K , unsigned N>
T dev::eth::BlockChain::queryExtras ( K const &  _h,
std::unordered_map< K, T > &  _m,
boost::shared_mutex &  _x,
T const &  _n,
ldb::DB *  _extrasDB = nullptr 
) const
inlineprivate

Definition at line 325 of file BlockChain.h.

Here is the call graph for this function:

template<class T , unsigned N>
T dev::eth::BlockChain::queryExtras ( h256 const &  _h,
std::unordered_map< h256, T > &  _m,
boost::shared_mutex &  _x,
T const &  _n,
ldb::DB *  _extrasDB = nullptr 
) const
inlineprivate

Definition at line 346 of file BlockChain.h.

void BlockChain::rebuild ( std::string 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 297 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

BlockReceipts dev::eth::BlockChain::receipts ( h256 const &  _hash) const
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 165 of file BlockChain.h.

Here is the caller graph for this function:

BlockReceipts dev::eth::BlockChain::receipts ( ) const
inline

Definition at line 166 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void dev::eth::BlockChain::reopen ( WithExisting  _we = WithExisting::Trust,
ProgressCallback const &  _pc = ProgressCallback() 
)
inline

Reopen everything.

Definition at line 114 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void BlockChain::reopen ( ChainParams const &  _p,
WithExisting  _we = WithExisting::Trust,
ProgressCallback const &  _pc = ProgressCallback() 
)

Definition at line 270 of file BlockChain.cpp.

Here is the call graph for this function:

void BlockChain::rescue ( OverlayDB const &  _db)

Rescue the database.

Definition at line 1022 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void BlockChain::rewind ( unsigned  _newHead)

Alter the head of the chain to some prior block along it.

Definition at line 1072 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

SealEngineFace* dev::eth::BlockChain::sealEngine ( ) const
inline

Definition at line 309 of file BlockChain.h.

Here is the caller graph for this function:

void dev::eth::BlockChain::setOnBad ( std::function< void(Exception &)>  _t)
inline

Change the function that is called with a bad block.

Definition at line 293 of file BlockChain.h.

Here is the caller graph for this function:

void dev::eth::BlockChain::setOnBlockImport ( std::function< void(BlockHeader const &)>  _t)
inline

Change the function that is called when a new block is imported.

Definition at line 296 of file BlockChain.h.

Here is the caller graph for this function:

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.

Returns
fresh blocks, dead blocks and true iff there are additional blocks to be processed waiting.

Definition at line 408 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bytes dev::eth::BlockChain::transaction ( h256 const &  _transactionHash) const
inline

Get a transaction from its hash. Thread-safe.

Definition at line 213 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

bytes dev::eth::BlockChain::transaction ( h256 const &  _blockHash,
unsigned  _i 
) const
inline

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 217 of file BlockChain.h.

Here is the call graph for this function:

bytes dev::eth::BlockChain::transaction ( unsigned  _i) const
inline

Definition at line 218 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

TransactionHashes dev::eth::BlockChain::transactionHashes ( h256 const &  _hash) const
inline

Get a list of transaction hashes for a given block. Thread-safe.

Definition at line 175 of file BlockChain.h.

Here is the call graph for this function:

TransactionHashes dev::eth::BlockChain::transactionHashes ( ) const
inline

Definition at line 176 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

std::pair<h256, unsigned> dev::eth::BlockChain::transactionLocation ( h256 const &  _transactionHash) const
inline

Definition at line 214 of file BlockChain.h.

TransactionReceipt dev::eth::BlockChain::transactionReceipt ( h256 const &  _blockHash,
unsigned  _i 
) const
inline

Get the transaction by block hash and index;.

Definition at line 169 of file BlockChain.h.

TransactionReceipt dev::eth::BlockChain::transactionReceipt ( h256 const &  _transactionHash) const
inline

Get the transaction receipt by transaction hash. Thread-safe.

Definition at line 172 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector<bytes> dev::eth::BlockChain::transactions ( h256 const &  _blockHash) const
inline

Get all transactions from a block.

Definition at line 221 of file BlockChain.h.

Here is the caller graph for this function:

std::vector<bytes> dev::eth::BlockChain::transactions ( ) const
inline

Definition at line 222 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

tuple< h256s, h256, unsigned > BlockChain::treeRoute ( h256 const &  _from,
h256 const &  _to,
bool  _common = true,
bool  _pre = true,
bool  _post = true 
) const
Returns
a tuple of:
  • an vector of hashes of all blocks between _from and _to, all blocks are ordered first by a number of blocks that are parent-to-child, then two sibling blocks, then a number of blocks that are child-to-parent;
  • the block hash of the latest common ancestor of both blocks;
  • the index where the latest common ancestor of both blocks would either be found or inserted, depending on whether it is included.
Parameters
_commonif true, include the common ancestor in the returned vector.
_preif true, include all block hashes running from _from until the common ancestor in the returned vector.
_postif 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:

treeRoute(3a, 2b, false) == make_tuple({ 3a, 2a, 1a, 1b, 2b }, g, 3);
treeRoute(2a, 1a, false) == make_tuple({ 2a, 1a }, 1a, 1)
treeRoute(1a, 2a, false) == make_tuple({ 1a, 2a }, 1a, 0)
treeRoute(1b, 2a, false) == make_tuple({ 1b, 1a, 2a }, g, 1)
treeRoute(3a, 2b, true) == make_tuple({ 3a, 2a, 1a, g, 1b, 2b }, g, 3);
treeRoute(2a, 1a, true) == make_tuple({ 2a, 1a }, 1a, 1)
treeRoute(1a, 2a, true) == make_tuple({ 1a, 2a }, 1a, 0)
treeRoute(1b, 2a, true) == make_tuple({ 1b, g, 1a, 2a }, g, 1)

Definition at line 1093 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

UncleHashes dev::eth::BlockChain::uncleHashes ( h256 const &  _hash) const
inline

Get a list of uncle hashes for a given block. Thread-safe.

Definition at line 179 of file BlockChain.h.

Here is the call graph for this function:

UncleHashes dev::eth::BlockChain::uncleHashes ( ) const
inline

Definition at line 180 of file BlockChain.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void BlockChain::updateStats ( ) const
private

Definition at line 1163 of file BlockChain.cpp.

Here is the caller graph for this function:

Statistics dev::eth::BlockChain::usage ( bool  _freshen = false) const
inline
Returns
statistics about memory usage.

Definition at line 287 of file BlockChain.h.

Here is the caller graph for this function:

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 1461 of file BlockChain.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

vector< unsigned > BlockChain::withBlockBloom ( LogBloom const &  _b,
unsigned  _earliest,
unsigned  _latest 
) const

Definition at line 1284 of file BlockChain.cpp.

Here is the caller graph for this function:

vector< unsigned > BlockChain::withBlockBloom ( LogBloom const &  _b,
unsigned  _earliest,
unsigned  _latest,
unsigned  _topLevel,
unsigned  _index 
) const

Definition at line 1298 of file BlockChain.cpp.

Here is the call graph for this function:

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  _out,
BlockChain const &  _bc 
)
friend

Member Data Documentation

BlockHashHash dev::eth::BlockChain::m_blockHashes
mutableprivate

Definition at line 370 of file BlockChain.h.

BlocksHash dev::eth::BlockChain::m_blocks
mutableprivate

Definition at line 360 of file BlockChain.h.

BlocksBloomsHash dev::eth::BlockChain::m_blocksBlooms
mutableprivate

Definition at line 372 of file BlockChain.h.

ldb::DB* dev::eth::BlockChain::m_blocksDB
private

The disk DBs. Thread-safe, so no need for locks.

Definition at line 390 of file BlockChain.h.

std::deque<std::unordered_set<CacheID> > dev::eth::BlockChain::m_cacheUsage
mutableprivate

Definition at line 376 of file BlockChain.h.

std::string dev::eth::BlockChain::m_dbPath
private

Definition at line 411 of file BlockChain.h.

BlockDetailsHash dev::eth::BlockChain::m_details
mutableprivate

Definition at line 362 of file BlockChain.h.

ldb::DB* dev::eth::BlockChain::m_extrasDB
private

Definition at line 391 of file BlockChain.h.

BlockHeader dev::eth::BlockChain::m_genesis
mutableprivate

Definition at line 404 of file BlockChain.h.

h256 dev::eth::BlockChain::m_genesisHash
mutableprivate

Definition at line 406 of file BlockChain.h.

bytes dev::eth::BlockChain::m_genesisHeaderBytes
mutableprivate

Definition at line 405 of file BlockChain.h.

std::unordered_set<CacheID> dev::eth::BlockChain::m_inUse
mutableprivate

Definition at line 377 of file BlockChain.h.

h256 dev::eth::BlockChain::m_lastBlockHash
private

Definition at line 395 of file BlockChain.h.

unsigned dev::eth::BlockChain::m_lastBlockNumber = 0
private

Definition at line 396 of file BlockChain.h.

std::chrono::system_clock::time_point dev::eth::BlockChain::m_lastCollection
private

Definition at line 380 of file BlockChain.h.

LastHashes dev::eth::BlockChain::m_lastLastHashes
mutableprivate

Definition at line 384 of file BlockChain.h.

Statistics dev::eth::BlockChain::m_lastStats
mutableprivate

Definition at line 387 of file BlockChain.h.

BlockLogBloomsHash dev::eth::BlockChain::m_logBlooms
mutableprivate

Definition at line 364 of file BlockChain.h.

std::function<void(Exception&)> dev::eth::BlockChain::m_onBad
private

Called if we have a block that doesn't verify.

Definition at line 408 of file BlockChain.h.

std::function<void(BlockHeader const&)> dev::eth::BlockChain::m_onBlockImport
private

Called if we have imported a new block into the db.

Definition at line 409 of file BlockChain.h.

ChainParams dev::eth::BlockChain::m_params
private

Definition at line 401 of file BlockChain.h.

ldb::ReadOptions dev::eth::BlockChain::m_readOptions
private

Definition at line 398 of file BlockChain.h.

BlockReceiptsHash dev::eth::BlockChain::m_receipts
mutableprivate

Definition at line 366 of file BlockChain.h.

std::shared_ptr<SealEngineFace> dev::eth::BlockChain::m_sealEngine
private

Definition at line 402 of file BlockChain.h.

TransactionAddressHash dev::eth::BlockChain::m_transactionAddresses
mutableprivate

Definition at line 368 of file BlockChain.h.

ldb::WriteOptions dev::eth::BlockChain::m_writeOptions
private

Definition at line 399 of file BlockChain.h.

SharedMutex dev::eth::BlockChain::x_blockHashes
mutableprivate

Definition at line 369 of file BlockChain.h.

SharedMutex dev::eth::BlockChain::x_blocks
mutableprivate

The caches of the disk DB and their locks.

Definition at line 359 of file BlockChain.h.

SharedMutex dev::eth::BlockChain::x_blocksBlooms
mutableprivate

Definition at line 371 of file BlockChain.h.

Mutex dev::eth::BlockChain::x_cacheUsage
mutableprivate

Definition at line 375 of file BlockChain.h.

SharedMutex dev::eth::BlockChain::x_details
mutableprivate

Definition at line 361 of file BlockChain.h.

SharedMutex dev::eth::BlockChain::x_genesis
mutableprivate

Definition at line 403 of file BlockChain.h.

boost::shared_mutex dev::eth::BlockChain::x_lastBlockHash
mutableprivate

Hash of the last (valid) block on the longest chain.

Definition at line 394 of file BlockChain.h.

Mutex dev::eth::BlockChain::x_lastLastHashes
mutableprivate

Definition at line 383 of file BlockChain.h.

SharedMutex dev::eth::BlockChain::x_logBlooms
mutableprivate

Definition at line 363 of file BlockChain.h.

SharedMutex dev::eth::BlockChain::x_receipts
mutableprivate

Definition at line 365 of file BlockChain.h.

SharedMutex dev::eth::BlockChain::x_transactionAddresses
mutableprivate

Definition at line 367 of file BlockChain.h.


The documentation for this class was generated from the following files: