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

Active model of a block within the block chain. More...

#include <Block.h>

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

Public Types

enum  NullType { Null }
 

Public Member Functions

 Block (u256 const &_accountStartNonce)
 Default constructor; creates with a blank database prepopulated with the genesis block. More...
 
 Block (BlockChain const &_bc, OverlayDB const &_db, BaseState _bs=BaseState::PreExisting, Address const &_author=Address())
 Basic state object from database. More...
 
 Block (BlockChain const &_bc, OverlayDB const &_db, h256 const &_root, Address const &_author=Address())
 Basic state object from database. More...
 
 Block (NullType)
 
 Block (BlockChain const &_bc)
 Construct from a given blockchain. Empty, but associated with _bc 's chain params. More...
 
 Block (Block const &_s)
 Copy state object. More...
 
Blockoperator= (Block const &_s)
 Copy state object. More...
 
Address author () const
 Get the author address for any transactions we do and rewards we get. More...
 
void setAuthor (Address const &_id)
 Set the author address for any transactions we do and rewards we get. More...
 
void noteChain (BlockChain const &_bc)
 Note the fact that this block is being used with a particular chain. More...
 
u256 balance (Address const &_address) const
 Get an account's balance. More...
 
u256 transactionsFrom (Address const &_address) const
 Get the number of transactions a particular address has sent (used for the transaction nonce). More...
 
bool addressInUse (Address const &_address) const
 Check if the address is in use. More...
 
bool addressHasCode (Address const &_address) const
 Check if the address contains executable code. More...
 
h256 storageRoot (Address const &_contract) const
 Get the root of the storage of an account. More...
 
u256 storage (Address const &_contract, u256 const &_memory) const
 Get the value of a storage position of an account. More...
 
std::map< h256, std::pair< u256, u256 > > storage (Address const &_contract) const
 Get the storage of an account. More...
 
bytes const & code (Address const &_contract) const
 Get the code of an account. More...
 
h256 codeHash (Address const &_contract) const
 Get the code hash of an account. More...
 
State const & state () const
 Get the backing state object. More...
 
OverlayDB const & db () const
 Open a DB - useful for passing into the constructor & keeping for other states that are necessary. More...
 
h256 rootHash () const
 The hash of the root of our state tree. More...
 
std::unordered_map< Address, u256addresses () const
 
StatemutableState ()
 Get a mutable State object which is backing this block. More...
 
u256 gasLimitRemaining () const
 Get the remaining gas limit in this block. More...
 
Transactions const & pending () const
 Get the list of pending transactions. More...
 
h256Hash const & pendingHashes () const
 Get the list of hashes of pending transactions. More...
 
TransactionReceipt const & receipt (unsigned _i) const
 Get the transaction receipt for the transaction of the given index. More...
 
LogEntries const & log (unsigned _i) const
 Get the list of pending transactions. More...
 
LogBloom logBloom () const
 Get the bloom filter of all logs that happened in the block. More...
 
LogBloom const & logBloom (unsigned _i) const
 Get the bloom filter of a particular transaction that happened in the block. More...
 
State fromPending (unsigned _i) const
 Get the State immediately after the given number of pending transactions have been applied. More...
 
PopulationStatistics populateFromChain (BlockChain const &_bc, h256 const &_hash, ImportRequirements::value _ir=ImportRequirements::None)
 Construct state object from arbitrary point in blockchain. More...
 
ExecutionResult execute (LastHashes const &_lh, Transaction const &_t, Permanence _p=Permanence::Committed, OnOpFunc const &_onOp=OnOpFunc())
 Execute a given transaction. More...
 
std::pair< TransactionReceipts, bool > sync (BlockChain const &_bc, TransactionQueue &_tq, GasPricer const &_gp, unsigned _msTimeout=100)
 Sync our transactions, killing those from the queue that we have and assimilating those that we don't. More...
 
bool sync (BlockChain const &_bc)
 Sync our state with the block chain. More...
 
bool sync (BlockChain const &_bc, h256 const &_blockHash, BlockHeader const &_bi=BlockHeader())
 Sync with the block chain, but rather than synching to the latest block, instead sync to the given block. More...
 
u256 enactOn (VerifiedBlockRef const &_block, BlockChain const &_bc)
 Execute all transactions within a given block. More...
 
void cleanup (bool _fullCommit)
 Returns back to a pristine state after having done a playback. More...
 
void resetCurrent (u256 const &_timestamp=u256(utcTime()))
 Sets m_currentBlock to a clean state, (i.e. More...
 
void commitToSeal (BlockChain const &_bc, bytes const &_extraData={})
 Prepares the current state for mining. More...
 
bool sealBlock (bytes const &_header)
 Pass in a properly sealed header matching this block. More...
 
bool sealBlock (bytesConstRef _header)
 
bool isSealed () const
 
bytes const & blockData () const
 Get the complete current block, including valid nonce. More...
 
BlockHeader const & info () const
 Get the header information on the present block. More...
 

Private Member Functions

SealEngineFacesealEngine () const
 
void uncommitToSeal ()
 Undo the changes to the state for committing to mine. More...
 
void ensureCached (Address const &_a, bool _requireCode, bool _forceCreate) const
 Retrieve all information about a given address into the cache. More...
 
void ensureCached (std::unordered_map< Address, Account > &_cache, Address const &_a, bool _requireCode, bool _forceCreate) const
 Retrieve all information about a given address into a cache. More...
 
u256 enact (VerifiedBlockRef const &_block, BlockChain const &_bc)
 Execute the given block, assuming it corresponds to m_currentBlock. More...
 
void applyRewards (std::vector< BlockHeader > const &_uncleBlockHeaders, u256 const &_blockReward)
 Finalise the block, applying the earned rewards. More...
 
u256 gasUsed () const
 
void performIrregularModifications ()
 Performs irregular modifications right after initialization, e.g. to implement a hard fork. More...
 
std::string vmTrace (bytesConstRef _block, BlockChain const &_bc, ImportRequirements::value _ir)
 Provide a standard VM trace for debugging purposes. More...
 

Private Attributes

State m_state
 Our state tree, as an OverlayDB DB. More...
 
Transactions m_transactions
 The current list of transactions that we've included in the state. More...
 
TransactionReceipts m_receipts
 The corresponding list of transaction receipts. More...
 
h256Hash m_transactionSet
 The set of transaction hashes that we've included in the state. More...
 
State m_precommit
 State at the point immediately prior to rewards. More...
 
BlockHeader m_previousBlock
 The previous block's information. More...
 
BlockHeader m_currentBlock
 The current block's information. More...
 
bytes m_currentBytes
 The current block's bytes. More...
 
bool m_committedToSeal = false
 Have we committed to mine on the present m_currentBlock? More...
 
bytes m_currentTxs
 The RLP-encoded block of transactions. More...
 
bytes m_currentUncles
 The RLP-encoded block of uncles. More...
 
Address m_author
 Our address (i.e. the address to which fees go). More...
 
SealEngineFacem_sealEngine = nullptr
 The chain's seal engine. More...
 

Friends

class ExtVM
 
class dev::test::ImportTest
 
class dev::test::StateLoader
 
class Executive
 
class BlockChain
 
std::ostream & operator<< (std::ostream &_out, Block const &_s)
 

Detailed Description

Active model of a block within the block chain.

Keeps track of all transactions, receipts and state for a particular block. Can apply all needed transforms of the state for rewards and contains logic for sealing the block.

Definition at line 73 of file Block.h.

Member Enumeration Documentation

enum dev::eth::Block::NullType
Enumerator
Null 

Definition at line 101 of file Block.h.

Constructor & Destructor Documentation

dev::eth::Block::Block ( u256 const &  _accountStartNonce)
inline

Default constructor; creates with a blank database prepopulated with the genesis block.

Definition at line 85 of file Block.h.

Block::Block ( BlockChain const &  _bc,
OverlayDB const &  _db,
BaseState  _bs = BaseState::PreExisting,
Address const &  _author = Address() 
)

Basic state object from database.

Use the default when you already have a database and you just want to make a Block object which uses it. If you have no preexisting database then set BaseState to something other than BaseState::PreExisting in order to prepopulate the Trie. You can also set the author address.

Definition at line 55 of file Block.cpp.

Here is the call graph for this function:

Block::Block ( BlockChain const &  _bc,
OverlayDB const &  _db,
h256 const &  _root,
Address const &  _author = Address() 
)

Basic state object from database.

Use the default when you already have a database and you just want to make a Block object which uses it. Will throw InvalidRoot if the root passed is not in the database. You can also set the author address.

Definition at line 66 of file Block.cpp.

Here is the call graph for this function:

dev::eth::Block::Block ( NullType  )
inline

Definition at line 102 of file Block.h.

dev::eth::Block::Block ( BlockChain const &  _bc)
inlineexplicit

Construct from a given blockchain. Empty, but associated with _bc 's chain params.

Definition at line 105 of file Block.h.

Block::Block ( Block const &  _s)

Copy state object.

Definition at line 78 of file Block.cpp.

Member Function Documentation

std::unordered_map<Address, u256> dev::eth::Block::addresses ( ) const
inline
Returns
the set containing all addresses currently in use in Ethereum.
Exceptions
InterfaceNotSupportedif compiled without ETH_FATDB.

Definition at line 173 of file Block.h.

bool dev::eth::Block::addressHasCode ( Address const &  _address) const
inline

Check if the address contains executable code.

Definition at line 138 of file Block.h.

bool dev::eth::Block::addressInUse ( Address const &  _address) const
inline

Check if the address is in use.

Definition at line 135 of file Block.h.

void Block::applyRewards ( std::vector< BlockHeader > const &  _uncleBlockHeaders,
u256 const &  _blockReward 
)
private

Finalise the block, applying the earned rewards.

Definition at line 671 of file Block.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Address dev::eth::Block::author ( ) const
inline

Get the author address for any transactions we do and rewards we get.

Definition at line 114 of file Block.h.

Here is the caller graph for this function:

u256 dev::eth::Block::balance ( Address const &  _address) const
inline

Get an account's balance.

Returns
0 if the address has never been used.

Definition at line 128 of file Block.h.

bytes const& dev::eth::Block::blockData ( ) const
inline

Get the complete current block, including valid nonce.

Only valid when isSealed() is true.

Definition at line 276 of file Block.h.

Here is the caller graph for this function:

void Block::cleanup ( bool  _fullCommit)

Returns back to a pristine state after having done a playback.

  • _fullCommit if true flush everything out to disk. If false, this effectively only validates the block since all state changes are ultimately reversed.

Definition at line 851 of file Block.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bytes const& dev::eth::Block::code ( Address const &  _contract) const
inline

Get the code of an account.

Returns
bytes() if no account exists at that address.

Definition at line 154 of file Block.h.

h256 dev::eth::Block::codeHash ( Address const &  _contract) const
inline

Get the code hash of an account.

Returns
EmptySHA3 if no account exists at that address or if there is no code associated with the address.

Definition at line 158 of file Block.h.

void Block::commitToSeal ( BlockChain const &  _bc,
bytes const &  _extraData = {} 
)

Prepares the current state for mining.

Commits all transactions into the trie, compiles uncles and transactions list, applies all rewards and populates the current block header with the appropriate hashes. The only thing left to do after this is to actually mine().

This may be called multiple times and without issue.

Definition at line 695 of file Block.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

OverlayDB const& dev::eth::Block::db ( ) const
inline

Open a DB - useful for passing into the constructor & keeping for other states that are necessary.

Definition at line 166 of file Block.h.

Here is the call graph for this function:

Here is the caller graph for this function:

u256 Block::enact ( VerifiedBlockRef const &  _block,
BlockChain const &  _bc 
)
private

Execute the given block, assuming it corresponds to m_currentBlock.

Throws on failure.

Definition at line 450 of file Block.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

u256 Block::enactOn ( VerifiedBlockRef const &  _block,
BlockChain const &  _bc 
)

Execute all transactions within a given block.

Returns
the additional total difficulty.

Definition at line 401 of file Block.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void dev::eth::Block::ensureCached ( Address const &  _a,
bool  _requireCode,
bool  _forceCreate 
) const
private

Retrieve all information about a given address into the cache.

If _requireMemory is true, grab the full memory should it be a contract item. If _forceCreate is true, then insert a default item into the cache, in the case it doesn't exist in the DB.

void dev::eth::Block::ensureCached ( std::unordered_map< Address, Account > &  _cache,
Address const &  _a,
bool  _requireCode,
bool  _forceCreate 
) const
private

Retrieve all information about a given address into a cache.

ExecutionResult Block::execute ( LastHashes const &  _lh,
Transaction const &  _t,
Permanence  _p = Permanence::Committed,
OnOpFunc const &  _onOp = OnOpFunc() 
)

Execute a given transaction.

This will append _t to the transaction list and change the state accordingly.

Definition at line 649 of file Block.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

State Block::fromPending ( unsigned  _i) const

Get the State immediately after the given number of pending transactions have been applied.

If (_i == 0) returns the initial state of the block. If (_i == pending().size()) returns the final state of the block, prior to rewards.

Definition at line 832 of file Block.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

u256 dev::eth::Block::gasLimitRemaining ( ) const
inline

Get the remaining gas limit in this block.

Definition at line 185 of file Block.h.

u256 dev::eth::Block::gasUsed ( ) const
inlineprivate
Returns
gas used by transactions thus far executed.

Definition at line 304 of file Block.h.

Here is the caller graph for this function:

BlockHeader const& dev::eth::Block::info ( ) const
inline

Get the header information on the present block.

Definition at line 279 of file Block.h.

Here is the caller graph for this function:

bool dev::eth::Block::isSealed ( ) const
inline
Returns
true if sealed - in this case you can no longer append transactions.

Definition at line 272 of file Block.h.

Here is the caller graph for this function:

LogEntries const& dev::eth::Block::log ( unsigned  _i) const
inline

Get the list of pending transactions.

Definition at line 197 of file Block.h.

LogBloom Block::logBloom ( ) const

Get the bloom filter of all logs that happened in the block.

Definition at line 843 of file Block.cpp.

Here is the caller graph for this function:

LogBloom const& dev::eth::Block::logBloom ( unsigned  _i) const
inline

Get the bloom filter of a particular transaction that happened in the block.

Definition at line 203 of file Block.h.

Here is the call graph for this function:

State& dev::eth::Block::mutableState ( )
inline

Get a mutable State object which is backing this block.

Warning
Only use this is you know what you're doing. If you use it while constructing a normal sealable block, don't expect things to work right.

Definition at line 180 of file Block.h.

Here is the caller graph for this function:

void Block::noteChain ( BlockChain const &  _bc)

Note the fact that this block is being used with a particular chain.

Call this before using any non-const methods.

Definition at line 140 of file Block.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Block & Block::operator= ( Block const &  _s)

Copy state object.

Definition at line 93 of file Block.cpp.

Transactions const& dev::eth::Block::pending ( ) const
inline

Get the list of pending transactions.

Definition at line 188 of file Block.h.

Here is the caller graph for this function:

h256Hash const& dev::eth::Block::pendingHashes ( ) const
inline

Get the list of hashes of pending transactions.

Definition at line 191 of file Block.h.

void Block::performIrregularModifications ( )
private

Performs irregular modifications right after initialization, e.g. to implement a hard fork.

Definition at line 682 of file Block.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

PopulationStatistics Block::populateFromChain ( BlockChain const &  _bc,
h256 const &  _hash,
ImportRequirements::value  _ir = ImportRequirements::None 
)

Construct state object from arbitrary point in blockchain.

Definition at line 150 of file Block.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

TransactionReceipt const& dev::eth::Block::receipt ( unsigned  _i) const
inline

Get the transaction receipt for the transaction of the given index.

Definition at line 194 of file Block.h.

Here is the caller graph for this function:

void Block::resetCurrent ( u256 const &  _timestamp = u256(utcTime()))

Sets m_currentBlock to a clean state, (i.e.

no change from m_previousBlock) and optionally modifies the timestamp.

Definition at line 113 of file Block.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

h256 dev::eth::Block::rootHash ( ) const
inline

The hash of the root of our state tree.

Definition at line 169 of file Block.h.

Here is the caller graph for this function:

bool dev::eth::Block::sealBlock ( bytes const &  _header)
inline

Pass in a properly sealed header matching this block.

Returns
true iff we were previously committed to sealing, the header is valid and it corresponds to this block. TODO: verify it prior to calling this. Commit to DB and build the final block if the previous call to mine()'s result is completion. Typically looks like:
while (!isSealed)
{
// lock
commitToSeal(_blockChain); // will call uncommitToSeal if a repeat.
sealBlock(sealedHeader);
// unlock

Definition at line 268 of file Block.h.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Block::sealBlock ( bytesConstRef  _header)

Definition at line 804 of file Block.cpp.

Here is the call graph for this function:

SealEngineFace * Block::sealEngine ( ) const
private

Definition at line 133 of file Block.cpp.

Here is the caller graph for this function:

void dev::eth::Block::setAuthor ( Address const &  _id)
inline

Set the author address for any transactions we do and rewards we get.

This causes a complete reset of current block.

Definition at line 118 of file Block.h.

Here is the caller graph for this function:

State const& dev::eth::Block::state ( ) const
inline

Get the backing state object.

Definition at line 163 of file Block.h.

Here is the caller graph for this function:

u256 dev::eth::Block::storage ( Address const &  _contract,
u256 const &  _memory 
) const
inline

Get the value of a storage position of an account.

Returns
0 if no account exists at that address.

Definition at line 145 of file Block.h.

std::map<h256, std::pair<u256, u256> > dev::eth::Block::storage ( Address const &  _contract) const
inline

Get the storage of an account.

Note
This is expensive. Don't use it unless you need to.
Returns
map of hashed keys to key-value pairs or empty map if no account exists at that address.

Definition at line 150 of file Block.h.

h256 dev::eth::Block::storageRoot ( Address const &  _contract) const
inline

Get the root of the storage of an account.

Definition at line 141 of file Block.h.

pair< TransactionReceipts, bool > Block::sync ( BlockChain const &  _bc,
TransactionQueue _tq,
GasPricer const &  _gp,
unsigned  _msTimeout = 100 
)

Sync our transactions, killing those from the queue that we have and assimilating those that we don't.

Returns
a list of receipts one for each transaction placed from the queue into the state and bool, true iff there are more transactions to be processed.

Definition at line 301 of file Block.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Block::sync ( BlockChain const &  _bc)

Sync our state with the block chain.

This basically involves wiping ourselves if we've been superceded and rebuilding from the transaction queue.

Definition at line 193 of file Block.cpp.

Here is the call graph for this function:

bool Block::sync ( BlockChain const &  _bc,
h256 const &  _blockHash,
BlockHeader const &  _bi = BlockHeader() 
)

Sync with the block chain, but rather than synching to the latest block, instead sync to the given block.

Definition at line 198 of file Block.cpp.

Here is the call graph for this function:

u256 dev::eth::Block::transactionsFrom ( Address const &  _address) const
inline

Get the number of transactions a particular address has sent (used for the transaction nonce).

Returns
0 if the address has never been used.

Definition at line 132 of file Block.h.

Here is the caller graph for this function:

void Block::uncommitToSeal ( )
private

Undo the changes to the state for committing to mine.

Definition at line 795 of file Block.cpp.

Here is the caller graph for this function:

string Block::vmTrace ( bytesConstRef  _block,
BlockChain const &  _bc,
ImportRequirements::value  _ir 
)
private

Provide a standard VM trace for debugging purposes.

Definition at line 886 of file Block.cpp.

Here is the call graph for this function:

Friends And Related Function Documentation

friend class BlockChain
friend

Definition at line 79 of file Block.h.

friend class dev::test::ImportTest
friend

Definition at line 76 of file Block.h.

friend class dev::test::StateLoader
friend

Definition at line 77 of file Block.h.

friend class Executive
friend

Definition at line 78 of file Block.h.

friend class ExtVM
friend

Definition at line 75 of file Block.h.

std::ostream& operator<< ( std::ostream &  _out,
Block const &  _s 
)
friend

Member Data Documentation

Address dev::eth::Block::m_author
private

Our address (i.e. the address to which fees go).

Definition at line 326 of file Block.h.

bool dev::eth::Block::m_committedToSeal = false
private

Have we committed to mine on the present m_currentBlock?

Definition at line 321 of file Block.h.

BlockHeader dev::eth::Block::m_currentBlock
private

The current block's information.

Definition at line 319 of file Block.h.

bytes dev::eth::Block::m_currentBytes
private

The current block's bytes.

Definition at line 320 of file Block.h.

bytes dev::eth::Block::m_currentTxs
private

The RLP-encoded block of transactions.

Definition at line 323 of file Block.h.

bytes dev::eth::Block::m_currentUncles
private

The RLP-encoded block of uncles.

Definition at line 324 of file Block.h.

State dev::eth::Block::m_precommit
private

State at the point immediately prior to rewards.

Definition at line 316 of file Block.h.

BlockHeader dev::eth::Block::m_previousBlock
private

The previous block's information.

Definition at line 318 of file Block.h.

TransactionReceipts dev::eth::Block::m_receipts
private

The corresponding list of transaction receipts.

Definition at line 314 of file Block.h.

SealEngineFace* dev::eth::Block::m_sealEngine = nullptr
private

The chain's seal engine.

Definition at line 328 of file Block.h.

State dev::eth::Block::m_state
private

Our state tree, as an OverlayDB DB.

Definition at line 312 of file Block.h.

Transactions dev::eth::Block::m_transactions
private

The current list of transactions that we've included in the state.

Definition at line 313 of file Block.h.

h256Hash dev::eth::Block::m_transactionSet
private

The set of transaction hashes that we've included in the state.

Definition at line 315 of file Block.h.


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