evm

package
v1.21.46 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: GPL-3.0, LGPL-3.0 Imports: 93 Imported by: 0

README

EVM Package

The EVM package implements the Luxd 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 Luxd 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 Luxd 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 Luxd 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

This section is empty.

Variables

View Source
var (
	// GitCommit is set by the build script
	GitCommit string
	// Version is the version of Coreth (set by build script via ldflags)
	Version string = "v0.15.57"
)

Functions

func CheckImportMode added in v0.15.50

func CheckImportMode(importPath string, chainDataDir string) (bool, error)

CheckImportMode checks if we should run in import mode

func CreateImportMarker added in v0.15.50

func CreateImportMarker(chainDataDir string) error

CreateImportMarker creates a marker file to indicate import is in progress

func GetImportedChainHeight added in v0.15.50

func GetImportedChainHeight(importPath string) (uint64, common.Hash, error)

GetImportedChainHeight reads the last block height from the import database

func IsImporting added in v0.15.50

func IsImporting(chainDataDir string) bool

IsImporting checks if import is in progress

func RemoveImportMarker added in v0.15.50

func RemoveImportMarker(chainDataDir string) error

RemoveImportMarker removes the import marker file

Types

type Admin added in v0.13.7

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

Admin is the API service for admin API calls

func NewAdminService added in v0.13.7

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

func (*Admin) GetVMConfig added in v0.13.7

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

func (*Admin) LockProfile added in v0.13.7

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

LockProfile runs a mutex profile writing to the specified file

func (*Admin) MemoryProfile added in v0.13.7

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

MemoryProfile runs a memory profile writing to the specified file

func (*Admin) SetLogLevel added in v0.13.7

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

func (*Admin) StartCPUProfiler added in v0.13.7

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

StartCPUProfiler starts a cpu profile writing to the specified file

func (*Admin) StopCPUProfiler added in v0.13.7

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

StopCPUProfiler stops the cpu profile

type AutominingConfig added in v0.15.64

type AutominingConfig struct {
	// BuildBlock builds a new block and returns it wrapped for consensus.
	// The block must implement both Verify() and Accept() methods.
	BuildBlock func(ctx context.Context) (interface {
		Verify(context.Context) error
		Accept(context.Context) error
	}, error)
	// Interval is the minimum time between block builds.
	Interval time.Duration
}

AutominingConfig contains configuration for automining.

type EthPushGossiper added in v0.13.7

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 added in v0.13.7

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

type Factory

type Factory struct{}

Factory is used to create a new VM instance

func (*Factory) New

func (f *Factory) New(logger log.Logger) (interface{}, error)

New returns a new EVM instance

type GossipEthTx added in v0.13.7

type GossipEthTx struct {
	Tx *types.Transaction
}

func (*GossipEthTx) GossipID added in v0.13.7

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

type GossipEthTxMarshaller added in v0.13.7

type GossipEthTxMarshaller struct{}

func (GossipEthTxMarshaller) MarshalGossip added in v0.13.7

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

func (GossipEthTxMarshaller) UnmarshalGossip added in v0.13.7

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

type GossipEthTxPool added in v0.13.7

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

func NewGossipEthTxPool added in v0.13.7

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

func (*GossipEthTxPool) Add added in v0.13.7

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 added in v0.13.7

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

func (*GossipEthTxPool) Has added in v0.13.7

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 added in v0.13.7

func (g *GossipEthTxPool) IsSubscribed() bool

IsSubscribed returns whether or not the gossip subscription is active.

func (*GossipEthTxPool) Iterate added in v0.13.7

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

func (*GossipEthTxPool) Subscribe added in v0.13.7

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

type LeafHandlers added in v0.15.50

type LeafRequestTypeConfig added in v0.15.50

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

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 quasarman.ChainVM interface

func (*VM) Blockchain added in v0.15.50

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

func (*VM) ChainConfig added in v0.15.50

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 added in v0.15.50

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

func (*VM) Connected added in v0.15.50

func (v *VM) Connected(ctx context.Context, nodeID ids.NodeID, nodeVersion interface{}) error

Connected handles a peer connecting to the VM. This shadows the embedded Network.Connected method to satisfy the block.ChainVM interface which expects interface{} for the version parameter.

func (*VM) CreateHandlers

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

CreateHandlers makes new http handlers that can handle API calls

func (*VM) Disconnected added in v0.15.50

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

Disconnected handles a peer disconnecting from the VM.

func (*VM) GetAcceptedBlock added in v0.15.50

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

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

func (*VM) GetBlockIDAtHeight added in v0.13.7

func (v *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 added in v0.15.50

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

func (*VM) HealthCheck added in v0.13.7

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 (v *VM) Initialize(
	_ context.Context,
	chainCtx interface{},
	db interface{},
	genesisBytes []byte,
	_ []byte,
	configBytes []byte,
	toEngine interface{},
	_ []interface{},
	appSenderIface interface{},
) error

Initialize implements the quasarman.ChainVM interface

func (*VM) LastAcceptedExtendedBlock added in v0.15.50

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

func (*VM) MetricRegistry added in v0.15.50

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

func (*VM) NewBlockBuilder added in v0.13.7

func (vm *VM) NewBlockBuilder(extraMempool extension.BuilderMempool) *blockBuilder

NewBlockBuilder creates a new block builder. extraMempool is an optional mempool (can be nil) that can be used to add transactions to the block builder, in addition to the txPool.

func (*VM) NewHTTPHandler added in v0.15.50

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

func (*VM) ParseEthBlock added in v0.13.7

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

func (*VM) PutLastAcceptedID added in v0.15.50

func (v *VM) PutLastAcceptedID(ID ids.ID) error

func (*VM) ReadLastAccepted added in v0.15.50

func (v *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 [v.chaindb] instead of relying on chain. Note: assumes [v.chaindb] and [v.genesisHash] have been initialized.

func (*VM) SetExtensionConfig added in v0.15.50

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

func (*VM) SetPreference

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

SetPreference sets what the current tail of the chain is

func (*VM) SetState added in v0.13.7

func (v *VM) SetState(_ context.Context, state uint32) error

func (*VM) Shutdown

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

Shutdown implements the quasarman.ChainVM interface

func (*VM) SyncerClient added in v0.15.50

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

func (*VM) Validators added in v0.15.50

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

func (*VM) Version added in v0.13.7

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

func (*VM) VersionDB added in v0.15.50

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

func (*VM) WaitForEvent added in v0.15.50

func (v *VM) WaitForEvent(ctx context.Context) (interface{}, error)

Directories

Path Synopsis
vm
upgrade
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.
lp176
LP176 implements the fee logic specified here: https://github.com/lux-foundation/LPs/blob/main/LPs/176-dynamic-evm-gas-limit-and-price-discovery-updates/README.md
LP176 implements the fee logic specified here: https://github.com/lux-foundation/LPs/blob/main/LPs/176-dynamic-evm-gas-limit-and-price-discovery-updates/README.md

Jump to

Keyboard shortcuts

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