evm

package
v0.8.12 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: GPL-3.0, LGPL-3.0 Imports: 106 Imported by: 2

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 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 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.

Documentation

Index

Constants

View Source
const (

	// TxGossipHandlerID is the handler ID for transaction gossip
	TxGossipHandlerID = uint64(0x1)
)

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 Lux EVM (set by build script via ldflags)
	Version string = "v0.8.12"
)

Functions

func NewBlockAdapter added in v0.8.8

func NewBlockAdapter(consensusBlock consensusblock.Block) nodeblock.Block

NewBlockAdapter creates a new block adapter

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) ImportChain added in v0.8.11

func (p *Admin) ImportChain(_ *http.Request, args *ImportChainArgs, reply *ImportChainReply) error

ImportChain imports a blockchain from a local file

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 Block

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

Block implements the chain.Block interface

func (*Block) Accept

func (b *Block) Accept(context.Context) error

Accept implements the chain.Block interface

func (*Block) Bytes

func (b *Block) Bytes() []byte

Bytes implements the chain.Block interface

func (*Block) Height

func (b *Block) Height() uint64

Height implements the chain.Block interface

func (*Block) ID

func (b *Block) ID() ids.ID

ID implements the chain.Block interface

func (*Block) Parent

func (b *Block) Parent() ids.ID

Parent implements the chain.Block interface

func (*Block) ParentID added in v0.8.8

func (b *Block) ParentID() ids.ID

ParentID implements the chain.Block interface (same as Parent)

func (*Block) Reject

func (b *Block) Reject(context.Context) error

Reject implements the chain.Block interface

func (*Block) SetStatus added in v0.8.8

func (b *Block) SetStatus(status choices.Status)

SetStatus implements the chain.Block interface This is required for chain.Block but not used in our implementation

func (*Block) ShouldVerifyWithContext

func (b *Block) ShouldVerifyWithContext(context.Context) (bool, error)

ShouldVerifyWithContext implements the block.WithVerifyContext interface

func (*Block) Status added in v0.8.2

func (b *Block) Status() uint8

Status implements the chain.Block interface

func (*Block) String

func (b *Block) String() string

func (*Block) Timestamp

func (b *Block) Timestamp() time.Time

Timestamp implements the chain.Block interface

func (*Block) Verify

func (b *Block) Verify(context.Context) error

Verify implements the chain.Block interface

func (*Block) VerifyWithContext

func (b *Block) VerifyWithContext(ctx context.Context, proposerVMBlockCtx *block.Context) error

VerifyWithContext implements the block.WithVerifyContext interface

type BlockAdapter added in v0.8.8

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

BlockAdapter adapts consensus Block to node Block interface

func (*BlockAdapter) Accept added in v0.8.8

func (b *BlockAdapter) Accept(ctx context.Context) error

Accept accepts the block

func (*BlockAdapter) Bytes added in v0.8.8

func (b *BlockAdapter) Bytes() []byte

Bytes returns the block bytes

func (*BlockAdapter) Height added in v0.8.8

func (b *BlockAdapter) Height() uint64

Height returns the block height

func (*BlockAdapter) ID added in v0.8.8

func (b *BlockAdapter) ID() ids.ID

ID returns the block ID

func (*BlockAdapter) Parent added in v0.8.8

func (b *BlockAdapter) Parent() ids.ID

Parent returns the parent block ID (alias for ParentID)

func (*BlockAdapter) ParentID added in v0.8.8

func (b *BlockAdapter) ParentID() ids.ID

ParentID returns the parent block ID

func (*BlockAdapter) Reject added in v0.8.8

func (b *BlockAdapter) Reject(ctx context.Context) error

Reject rejects the block

func (*BlockAdapter) ShouldVerifyWithContext added in v0.8.8

func (b *BlockAdapter) ShouldVerifyWithContext(ctx context.Context) (bool, error)

ShouldVerifyWithContext implements the block.WithVerifyContext interface by delegating to the underlying block if it supports the interface

func (*BlockAdapter) Status added in v0.8.8

func (b *BlockAdapter) Status() uint8

Status returns the block status

func (*BlockAdapter) Timestamp added in v0.8.8

func (b *BlockAdapter) Timestamp() time.Time

Timestamp returns the block timestamp

func (*BlockAdapter) Unwrap added in v0.8.8

func (b *BlockAdapter) Unwrap() consensusblock.Block

Unwrap returns the underlying consensus block. This is useful for tests that need access to the internal *Block type.

func (*BlockAdapter) Verify added in v0.8.8

func (b *BlockAdapter) Verify(ctx context.Context) error

Verify verifies the block

func (*BlockAdapter) VerifyWithContext added in v0.8.8

func (b *BlockAdapter) VerifyWithContext(ctx context.Context, blockCtx *nodeblock.Context) error

VerifyWithContext implements the block.WithVerifyContext interface by delegating to the underlying block if it supports the interface

type BlockValidator

type BlockValidator interface {
	SyntacticVerify(b *Block, rules params.Rules) error
}

func NewBlockValidator

func NewBlockValidator() BlockValidator

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

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.8.1

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

type Factory

type Factory struct{}

func (*Factory) New

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

type GossipEthTx added in v0.8.1

type GossipEthTx struct {
	Tx *types.Transaction
}

func (*GossipEthTx) GossipID added in v0.8.1

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

type GossipEthTxMarshaller added in v0.8.1

type GossipEthTxMarshaller struct{}

func (GossipEthTxMarshaller) MarshalGossip added in v0.8.1

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

func (GossipEthTxMarshaller) UnmarshalGossip added in v0.8.1

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

type GossipEthTxPool added in v0.8.1

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

func NewGossipEthTxPool added in v0.8.1

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

func (*GossipEthTxPool) Add added in v0.8.1

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.8.1

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

func (*GossipEthTxPool) Has added in v0.8.1

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.8.4

func (g *GossipEthTxPool) IsSubscribed() bool

IsSubscribed returns whether or not the gossip subscription is active.

func (*GossipEthTxPool) Iterate added in v0.8.1

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

func (*GossipEthTxPool) Subscribe added in v0.8.1

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

type ImportChainArgs added in v0.8.11

type ImportChainArgs struct {
	File string `json:"file"`
}

ImportChainArgs represents the arguments for ImportChain

type ImportChainReply added in v0.8.11

type ImportChainReply struct {
	Success        bool   `json:"success"`
	BlocksImported int    `json:"blocksImported,omitempty"`
	HeightBefore   uint64 `json:"heightBefore,omitempty"`
	HeightAfter    uint64 `json:"heightAfter,omitempty"`
	Message        string `json:"message,omitempty"`
}

ImportChainReply represents the response from ImportChain

type StateSyncClient

type StateSyncClient interface {
	// methods that implement the client side of [block.StateSyncableVM]
	StateSyncEnabled(context.Context) (bool, error)
	GetOngoingSyncStateSummary(context.Context) (block.StateSummary, error)
	ParseStateSummary(ctx context.Context, summaryBytes []byte) (block.StateSummary, error)

	// additional methods required by the evm package
	ClearOngoingSummary() error
	Shutdown() error
	Error() error
}

func NewStateSyncClient

func NewStateSyncClient(config *stateSyncClientConfig) StateSyncClient

type StateSyncServer

type StateSyncServer interface {
	GetLastStateSummary(context.Context) (block.StateSummary, error)
	GetStateSummary(context.Context, uint64) (block.StateSummary, error)
}

func NewStateSyncServer

func NewStateSyncServer(config *stateSyncServerConfig) StateSyncServer

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 Syncer

type Syncer interface {
	Start(ctx context.Context) error
	Wait(ctx context.Context) error
}

Syncer represents a step in state sync, along with Start/Done methods to control and monitor progress. Error returns an error if any was encountered.

type TestSender added in v0.8.8

type TestSender struct {
	T *testing.T

	CantSendGossip         bool
	CantSendGossipSpecific bool
	CantSendRequest        bool
	CantSendResponse       bool
	CantSendError          bool

	SendGossipF             func(context.Context, p2p.SendConfig, []byte) error
	SendGossipSpecificF     func(context.Context, set.Set[ids.NodeID], []byte) error
	SendRequestF            func(context.Context, set.Set[ids.NodeID], uint32, []byte) error
	SendResponseF           func(context.Context, ids.NodeID, uint32, []byte) error
	SendErrorF              func(context.Context, ids.NodeID, uint32, int32, string) error
	SendCrossChainRequestF  func(context.Context, ids.ID, uint32, []byte) error
	SendCrossChainResponseF func(context.Context, ids.ID, uint32, []byte) error
	SendCrossChainErrorF    func(context.Context, ids.ID, uint32, int32, string) error

	// Channel for capturing sent gossip messages
	SentGossip chan []byte
}

TestSender is a test implementation of the p2p.Sender interface

func (*TestSender) SendCrossChainError added in v0.8.11

func (s *TestSender) SendCrossChainError(ctx context.Context, chainID ids.ID, requestID uint32, errorCode int32, errorMessage string) error

SendCrossChainError sends a cross-chain error

func (*TestSender) SendCrossChainRequest added in v0.8.11

func (s *TestSender) SendCrossChainRequest(ctx context.Context, chainID ids.ID, requestID uint32, requestBytes []byte) error

SendCrossChainRequest sends a cross-chain request

func (*TestSender) SendCrossChainResponse added in v0.8.11

func (s *TestSender) SendCrossChainResponse(ctx context.Context, chainID ids.ID, requestID uint32, responseBytes []byte) error

SendCrossChainResponse sends a cross-chain response

func (*TestSender) SendError added in v0.8.11

func (s *TestSender) SendError(ctx context.Context, nodeID ids.NodeID, requestID uint32, errorCode int32, errorMessage string) error

SendError implements p2p.Sender

func (*TestSender) SendGossip added in v0.8.11

func (s *TestSender) SendGossip(ctx context.Context, config p2p.SendConfig, msg []byte) error

SendGossip implements p2p.Sender

func (*TestSender) SendGossipSpecific added in v0.8.11

func (s *TestSender) SendGossipSpecific(ctx context.Context, nodeIDs set.Set[ids.NodeID], msg []byte) error

SendGossipSpecific sends gossip to specific nodes

func (*TestSender) SendRequest added in v0.8.11

func (s *TestSender) SendRequest(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, request []byte) error

SendRequest implements p2p.Sender

func (*TestSender) SendResponse added in v0.8.11

func (s *TestSender) SendResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error

SendResponse implements p2p.Sender

type VM

type VM struct {

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

	Network *network.Network

	// State sync server and client
	StateSyncServer
	StateSyncClient
	// contains filtered or unexported fields
}

func (*VM) AppRequestFailed added in v0.8.1

func (vm *VM) AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32, appErr *commonEng.AppError) error

AppRequestFailed implements the VM interface

func (*VM) BuildBlock added in v0.8.2

func (vm *VM) BuildBlock(ctx context.Context) (nodeConsensusBlock.Block, error)

BuildBlock implements the ChainVM interface Uses State.BuildBlock to ensure proper block tracking (for LastAccepted, etc.)

func (*VM) BuildBlockWithContext added in v0.8.2

func (vm *VM) BuildBlockWithContext(ctx context.Context, proposerVMBlockCtx *nodeblock.Context) (nodeConsensusBlock.Block, error)

BuildBlockWithContext implements the BuildBlockWithContextChainVM interface

func (*VM) Connected added in v0.8.1

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

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) CrossChainAppRequestFailed added in v0.8.8

func (vm *VM) CrossChainAppRequestFailed(ctx context.Context, chainID ids.ID, requestID uint32, appErr *commonEng.AppError) error

CrossChainAppRequestFailed implements the VM interface

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) (nodeConsensusBlock.Block, error)

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

func (*VM) GetBlock added in v0.8.2

func (vm *VM) GetBlock(ctx context.Context, id ids.ID) (nodeConsensusBlock.Block, error)

getBlock attempts to retrieve block [id] from the VM to be wrapped by ChainState. GetBlock implements the ChainVM interface

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) GetLastStateSummary added in v0.8.8

func (vm *VM) GetLastStateSummary(ctx context.Context) (nodeblock.StateSummary, error)

GetLastStateSummary implements the StateSyncableVM interface

func (*VM) GetOngoingSyncStateSummary added in v0.8.8

func (vm *VM) GetOngoingSyncStateSummary(ctx context.Context) (nodeblock.StateSummary, error)

GetOngoingSyncStateSummary implements the StateSyncableVM interface

func (*VM) GetStateSummary added in v0.8.8

func (vm *VM) GetStateSummary(ctx context.Context, height uint64) (nodeblock.StateSummary, error)

GetStateSummary implements the StateSyncableVM interface

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(
	ctx context.Context,
	chainCtx interface{},
	dbManager interface{},
	genesisBytes []byte,
	upgradeBytes []byte,
	configBytes []byte,
	msgChan interface{},
	fxs []interface{},
	sender interface{},
) error

Initialize implements the chain.ChainVM interface with generic interface{} parameters

func (*VM) NewBlockBuilder

func (vm *VM) NewBlockBuilder() *blockBuilder

func (*VM) NewHTTPHandler added in v0.7.10

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

NewHTTPHandler implements the block.ChainVM interface

func (*VM) ParseBlock added in v0.8.2

func (vm *VM) ParseBlock(ctx context.Context, b []byte) (nodeConsensusBlock.Block, error)

ParseBlock implements nodeblock.ChainVM interface

func (*VM) ParseEthBlock

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

func (*VM) ParseStateSummary added in v0.8.8

func (vm *VM) ParseStateSummary(ctx context.Context, summaryBytes []byte) (nodeblock.StateSummary, error)

ParseStateSummary implements the StateSyncableVM interface

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 uint32) error

func (*VM) Shutdown

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

Shutdown implements the chain.ChainVM interface

func (*VM) StateSyncEnabled added in v0.8.8

func (vm *VM) StateSyncEnabled(ctx context.Context) (bool, error)

StateSyncEnabled implements the StateSyncableVM interface

func (*VM) Version

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

func (*VM) WaitForEvent added in v0.7.10

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

type ValidatorsAPI

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

func (*ValidatorsAPI) GetCurrentValidators

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.
state/interfaces
Package interfaces is a generated GoMock package.
Package interfaces is a generated GoMock package.

Jump to

Keyboard shortcuts

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