VM

VM

class eth.vm.base.VM(header: eth.abc.BlockHeaderAPI, chaindb: eth.abc.ChainDatabaseAPI, chain_context: eth.abc.ChainContextAPI, consensus_context: eth.abc.ConsensusContextAPI)
consensus_class

alias of eth.consensus.pow.PowConsensus

apply_all_transactions(transactions: Sequence[eth.abc.SignedTransactionAPI], base_header: eth.abc.BlockHeaderAPI) → Tuple[eth.abc.BlockHeaderAPI, Tuple[eth.abc.ReceiptAPI, ...], Tuple[eth.abc.ComputationAPI, ...]]

Determine the results of applying all transactions to the base header. This does not update the current block or header of the VM.

Parameters:
  • transactions – an iterable of all transactions to apply
  • base_header – the starting header to apply transactions to
Returns:

the final header, the receipts of each transaction, and the computations

apply_transaction(header: eth.abc.BlockHeaderAPI, transaction: eth.abc.SignedTransactionAPI) → Tuple[eth.abc.ReceiptAPI, eth.abc.ComputationAPI]

Apply the transaction to the current block. This is a wrapper around apply_transaction() with some extra orchestration logic.

Parameters:
  • header – header of the block before application
  • transaction – to apply
classmethod build_state(db: eth.abc.AtomicDatabaseAPI, header: eth.abc.BlockHeaderAPI, chain_context: eth.abc.ChainContextAPI, previous_hashes: Iterable[NewType.<locals>.new_type] = ()) → eth.abc.StateAPI

You probably want VM().state instead of this.

Occasionally, you want to build custom state against a particular header and DB, even if you don’t have the VM initialized. This is a convenience method to do that.

classmethod create_execution_context(header: eth.abc.BlockHeaderAPI, prev_hashes: Iterable[NewType.<locals>.new_type], chain_context: eth.abc.ChainContextAPI) → eth.abc.ExecutionContextAPI

Create and return the ExecutionContextAPI` for the given header, iterable of block hashes that precede the block and the chain_context.

classmethod create_genesis_header(**genesis_params) → eth.abc.BlockHeaderAPI

Create a genesis header using this VM’s rules.

This is equivalent to calling create_header_from_parent() with parent_header set to None.

create_transaction(*args, **kwargs) → eth.abc.SignedTransactionAPI

Proxy for instantiating a signed transaction for this VM.

classmethod create_unsigned_transaction(*, nonce: int, gas_price: int, gas: int, to: NewType.<locals>.new_type, value: int, data: bytes) → eth.abc.UnsignedTransactionAPI

Proxy for instantiating an unsigned transaction for this VM.

execute_bytecode(origin: NewType.<locals>.new_type, gas_price: int, gas: int, to: NewType.<locals>.new_type, sender: NewType.<locals>.new_type, value: int, data: bytes, code: bytes, code_address: NewType.<locals>.new_type = None) → eth.abc.ComputationAPI

Execute raw bytecode in the context of the current state of the virtual machine. Note that this skips over some of the logic that would normally happen during a call. Watch out for:

  • value (ether) is not transferred
  • state is not rolled back in case of an error
  • The target account is not necessarily created
  • others…

For other potential surprises, check the implementation differences between ComputationAPI.apply_computation() and ComputationAPI.apply_message(). (depending on the VM fork)

finalize_block(block: eth.abc.BlockAPI) → eth.abc.BlockAndMetaWitness

Perform any finalization steps like awarding the block mining reward, and persisting the final state root.

classmethod generate_block_from_parent_header_and_coinbase(parent_header: eth.abc.BlockHeaderAPI, coinbase: NewType.<locals>.new_type) → eth.abc.BlockAPI

Generate block from parent header and coinbase.

get_block() → eth.abc.BlockAPI

Return the current block.

classmethod get_block_class() → Type[eth.abc.BlockAPI]

Return the Block class that this VM uses for blocks.

get_header() → eth.abc.BlockHeaderAPI

Return the current header.

classmethod get_receipt_builder() → Type[eth.abc.ReceiptBuilderAPI]

Return the class that this VM uses to encode and decode receipts.

classmethod get_state_class() → Type[eth.abc.StateAPI]

Return the class that this VM uses for states.

classmethod get_transaction_builder() → Type[eth.abc.TransactionBuilderAPI]

Return the class that this VM uses to build and encode transactions.

import_block(block: eth.abc.BlockAPI) → eth.abc.BlockAndMetaWitness

Import the given block to the chain.

in_costless_state() → Iterator[eth.abc.StateAPI]

Return a ContextManager with the current state wrapped in a temporary block. In this state, the ability to pay gas costs is ignored.

mine_block(block: eth.abc.BlockAPI, *args, **kwargs) → eth.abc.BlockAndMetaWitness

Mine the given block. Proxies to self.pack_block method.

pack_block(block: eth.abc.BlockAPI, *args, **kwargs) → eth.abc.BlockAPI

Pack block for mining.

Parameters:
  • coinbase (bytes) – 20-byte public address to receive block reward
  • uncles_hash (bytes) – 32 bytes
  • state_root (bytes) – 32 bytes
  • transaction_root (bytes) – 32 bytes
  • receipt_root (bytes) – 32 bytes
  • bloom (int) –
  • gas_used (int) –
  • extra_data (bytes) – 32 bytes
  • mix_hash (bytes) – 32 bytes
  • nonce (bytes) – 8 bytes
set_block_transactions(base_block: eth.abc.BlockAPI, new_header: eth.abc.BlockHeaderAPI, transactions: Sequence[eth.abc.SignedTransactionAPI], receipts: Sequence[eth.abc.ReceiptAPI]) → eth.abc.BlockAPI

Create a new block with the given transactions.

validate_block(block: eth.abc.BlockAPI) → None

Validate the the given block.

classmethod validate_header(header: eth.abc.BlockHeaderAPI, parent_header: eth.abc.BlockHeaderAPI) → None
Raises:eth.exceptions.ValidationError – if the header is not valid
classmethod validate_receipt(receipt: eth.abc.ReceiptAPI) → None

Validate the given receipt.

validate_seal(header: eth.abc.BlockHeaderAPI) → None

Validate the seal on the given header.

validate_seal_extension(header: eth.abc.BlockHeaderAPI, parents: Iterable[eth.abc.BlockHeaderAPI]) → None

Validate the seal on the given header when all parents must be present. Parent headers that are not yet in the database must be passed as parents.

classmethod validate_uncle(block: eth.abc.BlockAPI, uncle: eth.abc.BlockHeaderAPI, uncle_parent: eth.abc.BlockHeaderAPI) → None

Validate the given uncle in the context of the given block.

previous_hashes

Convenience API for accessing the previous 255 block hashes.

state

Return the current state.