evm

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: GPL-3.0, LGPL-3.0 Imports: 104 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 Coreth specific APIs. Additionally, the Ethereum backend APIs are also returned at the /rpc extension.

Block Handling

The VM implements buildBlock, parseBlock, and getBlock and uses the chain package from AvalancheGo to construct a metered state, which uses these functions to implement an efficient caching layer and maintain the required invariants for blocks that get returned to the consensus engine.

To do this, the VM uses a modified version of the Ethereum RLP block type here and uses the core package's BlockChain type here to handle 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 wraps the stateless block type here and implements these functions to allow the consensus engine to verify blocks as valid, perform consensus, and mark them as accepted or rejected. See the documentation in AvalancheGo for the more detailed VM invariants that are maintained here.

Atomic Transactions

Atomic transactions utilize Shared Memory (documented here) to send assets to the P-Chain and X-Chain.

Operations on shared memory cannot be reverted, so atomic transactions must separate their verification and processing into two stages: verifying the transaction as valid to be performed within its block and actually performing the operation. For example, once an export transaction is accepted, there is no way for the C-Chain to take that asset back and it can be imported immediately by the recipient chain.

The C-Chain uses the account model for its own state, but atomic transactions must be compatible with the P-Chain and X-Chain, such that C-Chain atomic transactions must transform between the account model and the UTXO model.

Documentation

Index

Constants

View Source
const (
	GenesisTestAddr = "0x751a0b96e1042bee789452ecb20253fba40dbe85"
	GenesisTestKey  = "0xabd71b35d559563fea757f0f5edbde286fb8c043105b15abb7cd57189306d7d1"
)

test constants

Variables

View Source
var (
	// GitCommit is set by the build script
	GitCommit string
	// Version is the version of Coreth
	Version string = "v0.15.1"
)
View Source
var (
	// ID this VM should be referenced by
	ID = ids.ID{'e', 'v', 'm'}
)

Functions

This section is empty.

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, reply *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(r *http.Request, _ *struct{}, _ *api.EmptyReply) error

StopCPUProfiler stops the cpu profile

type AvaxAPI

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

AvaxAPI offers Avalanche network related API methods

func (*AvaxAPI) GetAtomicTx

func (service *AvaxAPI) GetAtomicTx(r *http.Request, args *api.GetTxArgs, reply *FormattedTx) error

GetAtomicTx returns the specified transaction

func (*AvaxAPI) GetAtomicTxStatus

func (service *AvaxAPI) GetAtomicTxStatus(r *http.Request, args *api.JSONTxID, reply *client.GetAtomicTxStatusReply) error

GetAtomicTxStatus returns the status of the specified transaction

func (*AvaxAPI) GetUTXOs

func (service *AvaxAPI) GetUTXOs(r *http.Request, args *api.GetUTXOsArgs, reply *api.GetUTXOsReply) error

GetUTXOs gets all utxos for passed in addresses

func (*AvaxAPI) IssueTx

func (service *AvaxAPI) IssueTx(r *http.Request, args *api.FormattedTx, response *api.JSONTxID) error

func (*AvaxAPI) Version

func (service *AvaxAPI) Version(r *http.Request, _ *struct{}, reply *VersionReply) error

ClientVersion returns the version of the VM running

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 FormattedTx

type FormattedTx struct {
	api.FormattedTx
	BlockHeight *json.Uint64 `json:"blockHeight,omitempty"`
}

type GetAcceptedFrontReply

type GetAcceptedFrontReply struct {
	Hash   common.Hash `json:"hash"`
	Number *big.Int    `json:"number"`
}

GetAcceptedFrontReply defines the reply that will be sent from the GetAcceptedFront API call

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 (g GossipEthTxMarshaller) MarshalGossip(tx *GossipEthTx) ([]byte, error)

func (GossipEthTxMarshaller) UnmarshalGossip

func (g 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) GetFilter

func (g *GossipEthTxPool) GetFilter() ([]byte, []byte)

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 SnowmanAPI

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

SnowmanAPI introduces snowman specific functionality to the evm

func (*SnowmanAPI) GetAcceptedFront

func (api *SnowmanAPI) GetAcceptedFront(ctx context.Context) (*GetAcceptedFrontReply, error)

GetAcceptedFront returns the last accepted block's hash and height

func (*SnowmanAPI) IssueBlock

func (api *SnowmanAPI) IssueBlock(ctx context.Context) error

IssueBlock to the chain

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

	IsPlugin bool

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

VM implements the snowman.ChainVM interface

func (*VM) AtomicMempool

func (vm *VM) AtomicMempool() *txpool.Mempool

func (*VM) ChainConfig

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

func (*VM) Config

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

func (*VM) CreateHTTP2Handler

func (vm *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) Ethereum

func (vm *VM) Ethereum() *eth.Ethereum

func (*VM) FormatAddress

func (vm *VM) FormatAddress(chainID ids.ID, addr ids.ShortID) (string, error)

FormatAddress takes in a chainID and a raw address and produces the formatted address

func (*VM) FormatLocalAddress

func (vm *VM) FormatLocalAddress(addr ids.ShortID) (string, error)

FormatLocalAddress takes in a raw address and produces the formatted address

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) GetAtomicUTXOs

func (vm *VM) GetAtomicUTXOs(
	chainID ids.ID,
	addrs set.Set[ids.ShortID],
	startAddr ids.ShortID,
	startUTXOID ids.ID,
	limit int,
) ([]*avax.UTXO, ids.ShortID, ids.ID, error)

GetAtomicUTXOs returns the utxos that at least one of the provided addresses is referenced in.

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) GetExtendedBlock

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

func (*VM) HealthCheck

func (vm *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,
	_ []byte,
	configBytes []byte,
	toEngine chan<- commonEng.Message,
	_ []*commonEng.Fx,
	appSender commonEng.AppSender,
) error

Initialize implements the snowman.ChainVM interface

func (*VM) IsBootstrapped

func (vm *VM) IsBootstrapped() bool

IsBootstrapped returns true if the VM has finished bootstrapping

func (*VM) LastAcceptedExtendedBlock

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

func (*VM) NewBlockBuilder

func (vm *VM) NewBlockBuilder(notifyBuildBlockChan chan<- commonEng.Message) *blockBuilder

func (*VM) ParseAddress

func (vm *VM) ParseAddress(addrStr string) (ids.ID, ids.ShortID, error)

ParseAddress takes in an address and produces the ID of the chain it's for the ID of the address

func (*VM) ParseEthBlock

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

func (*VM) ParseLocalAddress

func (vm *VM) ParseLocalAddress(addrStr string) (ids.ShortID, error)

ParseLocalAddress takes in an address for this chain and produces the ID

func (*VM) ParseServiceAddress

func (vm *VM) ParseServiceAddress(addrStr string) (ids.ShortID, error)

ParseServiceAddress get address ID from address string, being it either localized (using address manager, doing also components validations), or not localized. If both attempts fail, reports error from localized address parsing

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) Version

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

func (*VM) VersionDB

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

type VersionReply

type VersionReply struct {
	Version string `json:"version"`
}

Directories

Path Synopsis
vm
upgrade
acp176
ACP176 implements the fee logic specified here: https://github.com/avalanche-foundation/ACPs/blob/main/ACPs/176-dynamic-evm-gas-limit-and-price-discovery-updates/README.md
ACP176 implements the fee logic specified here: https://github.com/avalanche-foundation/ACPs/blob/main/ACPs/176-dynamic-evm-gas-limit-and-price-discovery-updates/README.md
ap0
AP0 defines constants used during the initial network launch.
AP0 defines constants used during the initial network launch.
ap1
AP1 defines constants used after the Apricot Phase 1 upgrade.
AP1 defines constants used after the Apricot Phase 1 upgrade.
ap3
AP3 defines the dynamic fee window used after the Apricot Phase 3 upgrade.
AP3 defines the dynamic fee window used after the Apricot Phase 3 upgrade.
ap4
AP4 implements the block gas cost logic activated by the Apricot Phase 4 upgrade.
AP4 implements the block gas cost logic activated by the Apricot Phase 4 upgrade.
ap5
AP5 defines constants used after the Apricot Phase 5 upgrade.
AP5 defines constants used after the Apricot Phase 5 upgrade.
cortina
Cortina defines constants used after the Cortina upgrade.
Cortina defines constants used after the Cortina upgrade.
etna
Etna defines constants used after the Etna upgrade.
Etna defines constants used after the Etna upgrade.

Jump to

Keyboard shortcuts

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