evm

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2026 License: GPL-3.0, LGPL-3.0 Imports: 99 Imported by: 0

README

EVM Package

The EVM package implements the AvalancheGo VM interface.

VM

The VM creates the Ethereum backend and provides basic block building, parsing, and retrieval logic to the consensus engine.

APIs

The VM creates APIs for the node through the function CreateHandlers(). CreateHandlers returns the Service struct to serve subnet-evm specific APIs. Additionally, the Ethereum backend APIs are also returned at the /rpc extension.

Block Handling

The VM implements buildBlock, parseBlock, and getBlock which are used by the chain package from AvalancheGo to construct a metered state. The metered state wraps blocks returned by these functions with an efficient caching layer and maintains the required invariants for blocks that get returned to the consensus engine.

The VM uses the block type from libevm/core/types and extends it with Avalanche-specific fields (such as ExtDataHash, BlockGasCost, and Version) using libevm's extensibility mechanism (defined in customtypes), then wraps it with wrappedBlock to implement the AvalancheGo Block interface. The core package's BlockChain type in blockchain.go handles the insertion and storage of blocks into the chain.

Block

The Block type implements the AvalancheGo ChainVM Block interface. The key functions for this interface are Verify(), Accept(), Reject(), and Status().

The Block type (implemented as wrappedBlock) wraps the block type from libevm/core/types and implements these functions to allow the consensus engine to verify blocks as valid, perform consensus, and mark them as accepted or rejected. Blocks contain standard Ethereum transactions that enable cross-chain asset transfers. Blocks may also include optional block extensions for extensible VM functionality. See the documentation in AvalancheGo for the more detailed VM invariants that are maintained here.

Documentation

Index

Constants

View Source
const (
	// Minimum amount of time to wait to retry building a block after a failed attempt.
	// It is assumed that the first block building attempt is already after the minimum delay time.
	RetryDelay = 100 * time.Millisecond
)

Variables

View Source
var (
	// ID this VM should be referenced by
	IDStr = "subnetevm"
	ID    = ids.ID{'s', 'u', 'b', 'n', 'e', 't', 'e', 'v', 'm'}
)
View Source
var (
	// GitCommit is set by the build script
	GitCommit string
	// Version is the version of Subnet EVM
	Version string = "v0.8.0"
)

Functions

func RegisterAllLibEVMExtras

func RegisterAllLibEVMExtras()

RegisterAllLibEVMExtras is a convenience wrapper for calling core.RegisterExtras, customtypes.Register, and params.RegisterExtras. Together these are necessary and sufficient for configuring libevm for C-Chain behaviour.

It MUST NOT be called more than once and therefore is only allowed to be used in tests and `package main`, to avoid polluting other packages that transitively depend on this one but don't need registration.

func WithTempRegisteredLibEVMExtras

func WithTempRegisteredLibEVMExtras(fn func() error) error

WithTempRegisteredLibEVMExtras runs `fn` with temporary registration otherwise equivalent to a call to RegisterAllLibEVMExtras, but limited to the life of `fn`.

Types

type Admin

type Admin struct {
	// contains filtered or unexported fields
}

Admin is the API service for admin API calls

func NewAdminService

func NewAdminService(vm *VM, performanceDir string) *Admin

func (*Admin) GetVMConfig

func (p *Admin) GetVMConfig(_ *http.Request, _ *struct{}, reply *client.ConfigReply) error

func (*Admin) LockProfile

func (p *Admin) LockProfile(*http.Request, *struct{}, *api.EmptyReply) error

LockProfile runs a mutex profile writing to the specified file

func (*Admin) MemoryProfile

func (p *Admin) MemoryProfile(*http.Request, *struct{}, *api.EmptyReply) error

MemoryProfile runs a memory profile writing to the specified file

func (*Admin) SetLogLevel

func (p *Admin) SetLogLevel(_ *http.Request, args *client.SetLogLevelArgs, _ *api.EmptyReply) error

func (*Admin) StartCPUProfiler

func (p *Admin) StartCPUProfiler(*http.Request, *struct{}, *api.EmptyReply) error

StartCPUProfiler starts a cpu profile writing to the specified file

func (*Admin) StopCPUProfiler

func (p *Admin) StopCPUProfiler(*http.Request, *struct{}, *api.EmptyReply) error

StopCPUProfiler stops the cpu profile

type DatabaseConfig

type DatabaseConfig struct {
	// If true, all writes are to memory and are discarded at shutdown.
	ReadOnly bool `json:"readOnly"`

	// Path to database
	Path string `json:"path"`

	// Name of the database type to use
	Name string `json:"name"`

	// Config bytes (JSON) for the database
	// See relevant (pebbledb, leveldb) config options
	Config []byte `json:"-"`
}

type EthPushGossiper

type EthPushGossiper struct {
	// contains filtered or unexported fields
}

EthPushGossiper is used by the ETH backend to push transactions issued over the RPC and added to the mempool to peers.

func (*EthPushGossiper) Add

func (e *EthPushGossiper) Add(tx *types.Transaction)

type Factory

type Factory struct{}

func (*Factory) New

func (*Factory) New(logging.Logger) (interface{}, error)

type GossipEthTx

type GossipEthTx struct {
	Tx *types.Transaction
}

func (*GossipEthTx) GossipID

func (tx *GossipEthTx) GossipID() ids.ID

type GossipEthTxMarshaller

type GossipEthTxMarshaller struct{}

func (GossipEthTxMarshaller) MarshalGossip

func (GossipEthTxMarshaller) MarshalGossip(tx *GossipEthTx) ([]byte, error)

func (GossipEthTxMarshaller) UnmarshalGossip

func (GossipEthTxMarshaller) UnmarshalGossip(bytes []byte) (*GossipEthTx, error)

type GossipEthTxPool

type GossipEthTxPool struct {
	// contains filtered or unexported fields
}

func NewGossipEthTxPool

func NewGossipEthTxPool(mempool *txpool.TxPool, registerer prometheus.Registerer) (*GossipEthTxPool, error)

func (*GossipEthTxPool) Add

func (g *GossipEthTxPool) Add(tx *GossipEthTx) error

Add enqueues the transaction to the mempool. Subscribe should be called to receive an event if tx is actually added to the mempool or not.

func (*GossipEthTxPool) BloomFilter

func (g *GossipEthTxPool) BloomFilter() (*bloom.Filter, ids.ID)

func (*GossipEthTxPool) Has

func (g *GossipEthTxPool) Has(txID ids.ID) bool

Has should just return whether or not the [txID] is still in the mempool, not whether it is in the mempool AND pending.

func (*GossipEthTxPool) IsSubscribed

func (g *GossipEthTxPool) IsSubscribed() bool

IsSubscribed returns whether or not the gossip subscription is active.

func (*GossipEthTxPool) Iterate

func (g *GossipEthTxPool) Iterate(f func(tx *GossipEthTx) bool)

func (*GossipEthTxPool) Subscribe

func (g *GossipEthTxPool) Subscribe(ctx context.Context)

type LeafRequestTypeConfig

type LeafRequestTypeConfig struct {
	NodeType     message.NodeType
	NodeKeyLen   int
	TrieDB       *triedb.Database
	UseSnapshots bool
	MetricName   string
}

type Status

type Status uint32

Status ...

const (
	Unknown Status = iota
	Dropped
	Processing
	Accepted
)

List of possible status values Unknown Zero value, means the status is not known Dropped means the transaction was in the mempool, but was dropped because it failed verification Processing means the transaction is in the mempool Accepted means the transaction was accepted

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (Status) String

func (s Status) String() string

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(b []byte) error

UnmarshalJSON ...

func (Status) Valid

func (s Status) Valid() error

Valid returns nil if the status is a valid status.

type VM

type VM struct {

	// *chain.State helps to implement the VM interface by wrapping blocks
	// with an efficient caching layer.
	*chain.State

	network.Network

	// State sync server and client
	vmsync.Server
	vmsync.Client
	// contains filtered or unexported fields
}

VM implements the snowman.ChainVM interface

func (*VM) Blockchain

func (vm *VM) Blockchain() *core.BlockChain

func (*VM) ChainConfig

func (vm *VM) ChainConfig() *params.ChainConfig

ChainConfig returns the chain config for the VM Even though this is available through Blockchain().Config(), ChainConfig() here will be available before the blockchain is initialized.

func (*VM) Config

func (vm *VM) Config() config.Config

func (*VM) Connected

func (vm *VM) Connected(ctx context.Context, nodeID ids.NodeID, version *version.Application) error

func (*VM) CreateHTTP2Handler

func (*VM) CreateHTTP2Handler(context.Context) (http.Handler, error)

func (*VM) CreateHandlers

func (vm *VM) CreateHandlers(context.Context) (map[string]http.Handler, error)

CreateHandlers makes new http handlers that can handle API calls

func (*VM) Disconnected

func (vm *VM) Disconnected(ctx context.Context, nodeID ids.NodeID) error

func (*VM) GetAcceptedBlock

func (vm *VM) GetAcceptedBlock(ctx context.Context, blkID ids.ID) (snowman.Block, error)

GetAcceptedBlock attempts to retrieve block [blkID] from the VM. This method only returns accepted blocks.

func (*VM) GetBlockIDAtHeight

func (vm *VM) GetBlockIDAtHeight(_ context.Context, height uint64) (ids.ID, error)

GetBlockIDAtHeight returns the canonical block at [height]. Note: the engine assumes that if a block is not found at [height], then [database.ErrNotFound] will be returned. This indicates that the VM has state synced and does not have all historical blocks available.

func (*VM) GetCurrentNonce

func (vm *VM) GetCurrentNonce(address common.Address) (uint64, error)

GetCurrentNonce returns the nonce associated with the address at the preferred block

func (*VM) GetExtendedBlock

func (vm *VM) GetExtendedBlock(ctx context.Context, blkID ids.ID) (extension.ExtendedBlock, error)

func (*VM) HealthCheck

func (*VM) HealthCheck(context.Context) (interface{}, error)

Health returns nil if this chain is healthy. Also returns details, which should be one of: string, []byte, map[string]string

func (*VM) Initialize

func (vm *VM) Initialize(
	_ context.Context,
	chainCtx *snow.Context,
	db database.Database,
	genesisBytes []byte,
	upgradeBytes []byte,
	configBytes []byte,
	fxs []*commonEng.Fx,
	appSender commonEng.AppSender,
) error

Initialize implements the snowman.ChainVM interface

func (*VM) LastAcceptedExtendedBlock

func (vm *VM) LastAcceptedExtendedBlock() extension.ExtendedBlock

func (*VM) MetricRegistry

func (vm *VM) MetricRegistry() *prometheus.Registry

func (*VM) NewBlockBuilder

func (vm *VM) NewBlockBuilder() *blockBuilder

func (*VM) NewHTTPHandler

func (vm *VM) NewHTTPHandler(ctx context.Context) (http.Handler, error)

NewHTTPHandler implements the block.ChainVM interface

func (*VM) ParseEthBlock

func (vm *VM) ParseEthBlock(b []byte) (*types.Block, error)

func (*VM) PutLastAcceptedID

func (vm *VM) PutLastAcceptedID(id ids.ID) error

func (*VM) ReadLastAccepted

func (vm *VM) ReadLastAccepted() (common.Hash, uint64, error)

readLastAccepted reads the last accepted hash from [acceptedBlockDB] and returns the last accepted block hash and height by reading directly from [vm.chaindb] instead of relying on chain. Note: assumes [vm.chaindb] and [vm.genesisHash] have been initialized.

func (*VM) SetExtensionConfig

func (vm *VM) SetExtensionConfig(config *extension.Config) error

func (*VM) SetPreference

func (vm *VM) SetPreference(ctx context.Context, blkID ids.ID) error

SetPreference sets what the current tail of the chain is

func (*VM) SetState

func (vm *VM) SetState(_ context.Context, state snow.State) error

func (*VM) Shutdown

func (vm *VM) Shutdown(context.Context) error

Shutdown implements the snowman.ChainVM interface

func (*VM) SyncerClient

func (vm *VM) SyncerClient() vmsync.Client

func (*VM) Validators

func (vm *VM) Validators() *p2p.Validators

func (*VM) Version

func (*VM) Version(context.Context) (string, error)

func (*VM) VersionDB

func (vm *VM) VersionDB() *versiondb.Database

func (*VM) WaitForEvent

func (vm *VM) WaitForEvent(ctx context.Context) (commonEng.Message, error)

type ValidatorsAPI

type ValidatorsAPI struct {
	// contains filtered or unexported fields
}

func (*ValidatorsAPI) GetCurrentValidators

func (api *ValidatorsAPI) GetCurrentValidators(httpReq *http.Request, req *client.GetCurrentValidatorsRequest, reply *client.GetCurrentValidatorsResponse) error

Directories

Path Synopsis
blockgascost implements the block gas cost logic
blockgascost implements the block gas cost logic
upgrade
subnetevm
subnetevm defines the dynamic fee window used after subnetevm upgrade.
subnetevm defines the dynamic fee window used after subnetevm upgrade.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL