VM
VM
- class eth.vm.base.VM(header: BlockHeaderAPI, chaindb: ChainDatabaseAPI, chain_context: ChainContextAPI, consensus_context: ConsensusContextAPI)
- consensus_class
alias of
PowConsensus
- apply_all_transactions(transactions: Sequence[SignedTransactionAPI], base_header: BlockHeaderAPI) Tuple[BlockHeaderAPI, Tuple[ReceiptAPI, ...], Tuple[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_all_withdrawals(withdrawals: Sequence[WithdrawalAPI]) None
Updates the state by applying all withdrawals. This does not update the current block or header of the VM.
- Parameters:
withdrawals – an iterable of all withdrawals to apply
- apply_transaction(header: BlockHeaderAPI, transaction: SignedTransactionAPI) Tuple[ReceiptAPI, 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 block_preprocessing(state: StateAPI, header: BlockHeaderAPI) None
Process any state changes before processing a block. Pre-processing does not become relevant until the Cancun network upgrade.
- classmethod build_state(db: AtomicDatabaseAPI, header: BlockHeaderAPI, chain_context: ChainContextAPI, previous_hashes: Iterable[Hash32] = ()) 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: BlockHeaderAPI, prev_hashes: Iterable[Hash32], chain_context: ChainContextAPI) ExecutionContextAPI
Create and return the
ExecutionContextAPI`
for the givenheader
, iterable of block hashes that precede the block and thechain_context
.
- classmethod create_genesis_header(**genesis_params: Any) BlockHeaderAPI
Create a genesis header using this VM’s rules.
This is equivalent to calling
create_header_from_parent()
withparent_header
set to None.
- create_transaction(*args: Any, **kwargs: Any) SignedTransactionAPI
Proxy for instantiating a signed transaction for this VM.
- classmethod create_unsigned_transaction(*, nonce: int, gas_price: int, gas: int, to: Address, value: int, data: bytes) UnsignedTransactionAPI
Proxy for instantiating an unsigned transaction for this VM.
- execute_bytecode(origin: Address, gas_price: int, gas: int, to: Address, sender: Address, value: int, data: bytes, code: bytes, code_address: Address | None = None) 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()
andComputationAPI.apply_message()
. (depending on the VM fork)
- finalize_block(block: BlockAPI) 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: BlockHeaderAPI, coinbase: Address) BlockAPI
Generate block from parent header and coinbase.
- get_header() BlockHeaderAPI
Return the current header.
- classmethod get_receipt_builder() Type[ReceiptBuilderAPI]
Return the class that this VM uses to encode and decode receipts.
- classmethod get_transaction_builder() Type[TransactionBuilderAPI]
Return the class that this VM uses to build and encode transactions.
- in_costless_state() Iterator[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: BlockAPI, *args: Any, **kwargs: Any) BlockAndMetaWitness
Mine the given block. Proxies to self.pack_block method.
- pack_block(block: BlockAPI, *args: Any, **kwargs: Any) 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_and_withdrawals(base_block: BlockAPI, new_header: BlockHeaderAPI, transactions: Sequence[SignedTransactionAPI], receipts: Sequence[ReceiptAPI], withdrawals: Sequence[WithdrawalAPI] | None = None) BlockAPI
Create a new block with the given
transactions
and/orwithdrawals
.
- classmethod validate_gas(header: BlockHeaderAPI, parent_header: BlockHeaderAPI) None
- classmethod validate_header(header: BlockHeaderAPI, parent_header: BlockHeaderAPI) None
- Raises:
eth.exceptions.ValidationError – if the header is not valid
- classmethod validate_receipt(receipt: ReceiptAPI) None
Validate the given
receipt
.
- validate_seal(header: BlockHeaderAPI) None
Validate the seal on the given header.
- validate_seal_extension(header: BlockHeaderAPI, parents: Iterable[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: BlockAPI, uncle: BlockHeaderAPI, uncle_parent: BlockHeaderAPI) None
Validate the given uncle in the context of the given block.
- chaindb: ChainDatabaseAPI = None
- cls_logger = <Logger eth.vm.base.VM (WARNING)>