Ethereum  PoC-8
The C++ Implementation of Ethereum
dev::eth::Block Class Reference

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. More...

#include <Block.h>

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())
 
 Block (BlockChain const &_bc, OverlayDB const &_db, h256 const &_root, Address const &_author=Address())
 
 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)
 
void noteChain (BlockChain const &_bc)
 
u256 balance (Address const &_address) const
 
u256 transactionsFrom (Address const &_address) const
 
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
 
std::map< h256, std::pair< u256, u256 > > storage (Address const &_contract) const
 
bytes const & code (Address const &_contract) const
 
h256 codeHash (Address const &_contract) const
 
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 ()
 
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...
 
h256 stateRootBeforeTx (unsigned _i) const
 
PopulationStatistics populateFromChain (BlockChain const &_bc, h256 const &_hash, ImportRequirements::value _ir=ImportRequirements::None)
 Construct state object from arbitrary point in blockchain. More...
 
ExecutionResult execute (LastBlockHashesFace const &_lh, Transaction const &_t, Permanence _p=Permanence::Committed, OnOpFunc const &_onOp=OnOpFunc())
 
std::pair< TransactionReceipts, bool > sync (BlockChain const &_bc, TransactionQueue &_tq, GasPricer const &_gp, unsigned _msTimeout=100)
 
bool sync (BlockChain const &_bc)
 
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)
 
void cleanup ()
 Returns back to a pristine state after having done a playback. More...
 
void resetCurrent (int64_t _timestamp=utcTime())
 
void commitToSeal (BlockChain const &_bc, bytes const &_extraData={})
 
bool sealBlock (bytes const &_header)
 
bool sealBlock (bytesConstRef _header)
 
bool isSealed () const
 
bytes const & blockData () const
 
BlockHeader const & info () const
 Get the header information on the present block. More...
 

Friends

class ExtVM
 
class dev::test::ImportTest
 
class dev::test::StateLoader
 
class Executive
 
class BlockChain
 

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 68 of file Block.h.

Member Enumeration Documentation

◆ NullType

Enumerator
Null 

Definition at line 96 of file Block.h.

Constructor & Destructor Documentation

◆ Block() [1/6]

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

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

Definition at line 80 of file Block.h.

◆ Block() [2/6]

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 60 of file Block.cpp.

◆ Block() [3/6]

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 71 of file Block.cpp.

◆ Block() [4/6]

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

Definition at line 97 of file Block.h.

◆ Block() [5/6]

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

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

Definition at line 100 of file Block.h.

◆ Block() [6/6]

Block::Block ( Block const &  _s)

Copy state object.

Definition at line 83 of file Block.cpp.

Member Function Documentation

◆ addresses()

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 168 of file Block.h.

◆ addressHasCode()

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

Check if the address contains executable code.

Definition at line 133 of file Block.h.

◆ addressInUse()

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

Check if the address is in use.

Definition at line 130 of file Block.h.

◆ author()

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

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

Definition at line 109 of file Block.h.

◆ balance()

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 123 of file Block.h.

◆ blockData()

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 270 of file Block.h.

◆ cleanup()

void Block::cleanup ( )

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

Definition at line 879 of file Block.cpp.

◆ code()

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 149 of file Block.h.

◆ codeHash()

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 153 of file Block.h.

◆ commitToSeal()

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 728 of file Block.cpp.

◆ db()

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 161 of file Block.h.

◆ enactOn()

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

Execute all transactions within a given block.

Returns
the additional total difficulty.

Definition at line 414 of file Block.cpp.

◆ execute()

ExecutionResult Block::execute ( LastBlockHashesFace 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 657 of file Block.cpp.

◆ gasLimitRemaining()

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

Get the remaining gas limit in this block.

Definition at line 180 of file Block.h.

◆ info()

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

Get the header information on the present block.

Definition at line 273 of file Block.h.

◆ isSealed()

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

Definition at line 266 of file Block.h.

◆ log()

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

Get the list of pending transactions.

Definition at line 192 of file Block.h.

◆ logBloom() [1/2]

LogBloom Block::logBloom ( ) const

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

Definition at line 871 of file Block.cpp.

◆ logBloom() [2/2]

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 198 of file Block.h.

◆ mutableState()

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 175 of file Block.h.

◆ noteChain()

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 146 of file Block.cpp.

◆ operator=()

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

Copy state object.

Definition at line 98 of file Block.cpp.

◆ pending()

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

Get the list of pending transactions.

Definition at line 183 of file Block.h.

◆ pendingHashes()

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

Get the list of hashes of pending transactions.

Definition at line 186 of file Block.h.

◆ populateFromChain()

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 156 of file Block.cpp.

◆ receipt()

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

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

Definition at line 189 of file Block.h.

◆ resetCurrent()

void Block::resetCurrent ( int64_t  _timestamp = utcTime())

Sets m_currentBlock to a clean state, (i.e. no change from m_previousBlock) and optionally modifies the timestamp.

Definition at line 118 of file Block.cpp.

◆ rootHash()

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

The hash of the root of our state tree.

Definition at line 164 of file Block.h.

◆ sealBlock() [1/2]

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 262 of file Block.h.

◆ sealBlock() [2/2]

bool Block::sealBlock ( bytesConstRef  _header)

Definition at line 832 of file Block.cpp.

◆ setAuthor()

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 113 of file Block.h.

◆ state()

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

Get the backing state object.

Definition at line 158 of file Block.h.

◆ stateRootBeforeTx()

h256 Block::stateRootBeforeTx ( unsigned  _i) const

Get the State root hash immediately after all previous transactions before transaction _i 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. Returns zero hash if intermediate state root is not available in the receipt (the case after EIP98)

Definition at line 858 of file Block.cpp.

◆ storage() [1/2]

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 145 of file Block.h.

◆ storage() [2/2]

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 140 of file Block.h.

◆ storageRoot()

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

Get the root of the storage of an account.

Definition at line 136 of file Block.h.

◆ sync() [1/3]

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 199 of file Block.cpp.

◆ sync() [2/3]

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 204 of file Block.cpp.

◆ sync() [3/3]

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 307 of file Block.cpp.

◆ transactionsFrom()

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 127 of file Block.h.

Friends And Related Function Documentation

◆ BlockChain

friend class BlockChain
friend

Definition at line 74 of file Block.h.

◆ dev::test::ImportTest

friend class dev::test::ImportTest
friend

Definition at line 71 of file Block.h.

◆ dev::test::StateLoader

friend class dev::test::StateLoader
friend

Definition at line 72 of file Block.h.

◆ Executive

friend class Executive
friend

Definition at line 73 of file Block.h.

◆ ExtVM

friend class ExtVM
friend

Definition at line 70 of file Block.h.


The documentation for this class was generated from the following files:
dev::eth::Block::commitToSeal
void commitToSeal(BlockChain const &_bc, bytes const &_extraData={})
Definition: Block.cpp:728
dev::eth::Block::isSealed
bool isSealed() const
Definition: Block.h:266
dev::eth::Block::sealBlock
bool sealBlock(bytes const &_header)
Definition: Block.h:262