evm

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: GPL-3.0, LGPL-3.0 Imports: 95 Imported by: 3

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

Documentation

Index

Constants

This section is empty.

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.7.1"
)

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

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 Block

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

Block implements the snowman.Block interface

func (*Block) Accept

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

Accept implements the snowman.Block interface

func (*Block) Bytes

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

Bytes implements the snowman.Block interface

func (*Block) Height

func (b *Block) Height() uint64

Height implements the snowman.Block interface

func (*Block) ID

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

ID implements the snowman.Block interface

func (*Block) Parent

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

Parent implements the snowman.Block interface

func (*Block) Reject

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

Reject implements the snowman.Block interface

func (*Block) ShouldVerifyWithContext added in v0.5.0

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

ShouldVerifyWithContext implements the block.WithVerifyContext interface

func (*Block) String

func (b *Block) String() string

func (*Block) Timestamp

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

Timestamp implements the snowman.Block interface

func (*Block) Verify

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

Verify implements the snowman.Block interface

func (*Block) VerifyWithContext added in v0.5.0

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

VerifyWithContext implements the block.WithVerifyContext interface

type BlockValidator

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

func NewBlockValidator added in v0.4.0

func NewBlockValidator() BlockValidator

type BuildGenesisArgs

type BuildGenesisArgs struct {
	GenesisData *core.Genesis       `json:"genesisData"`
	Encoding    formatting.Encoding `json:"encoding"`
}

BuildGenesisArgs are arguments for BuildGenesis

type BuildGenesisReply

type BuildGenesisReply struct {
	GenesisBytes string              `json:"genesisBytes"`
	Encoding     formatting.Encoding `json:"encoding"`
}

BuildGenesisReply is the reply from BuildGenesis

type DecodeGenesisArgs

type DecodeGenesisArgs struct {
	GenesisBytes string              `json:"genesisBytes"`
	Encoding     formatting.Encoding `json:"encoding"`
}

DecodeGenesisArgs are arguments for DecodeGenesis

type DecodeGenesisReply

type DecodeGenesisReply struct {
	Genesis  *core.Genesis       `json:"genesisData"`
	Encoding formatting.Encoding `json:"encoding"`
}

DecodeGenesisReply is the reply from DecodeGenesis

type EthPushGossiper added in v0.6.2

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

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

type Factory

type Factory struct{}

func (*Factory) New

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

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

type GossipEthTx struct {
	Tx *types.Transaction
}

func (*GossipEthTx) GossipID added in v0.5.11

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

type GossipEthTxMarshaller added in v0.5.11

type GossipEthTxMarshaller struct{}

func (GossipEthTxMarshaller) MarshalGossip added in v0.5.11

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

func (GossipEthTxMarshaller) UnmarshalGossip added in v0.5.11

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

type GossipEthTxPool added in v0.5.11

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

func NewGossipEthTxPool added in v0.5.11

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

func (*GossipEthTxPool) Add added in v0.5.11

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

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

func (*GossipEthTxPool) Has added in v0.6.2

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

func (g *GossipEthTxPool) IsSubscribed() bool

IsSubscribed returns whether or not the gossip subscription is active.

func (*GossipEthTxPool) Iterate added in v0.5.11

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

func (*GossipEthTxPool) Subscribe added in v0.5.11

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

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

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

func NewStateSyncClient(config *stateSyncClientConfig) StateSyncClient

type StateSyncServer added in v0.3.0

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

func NewStateSyncServer added in v0.3.0

func NewStateSyncServer(config *stateSyncServerConfig) StateSyncServer

type StaticService

type StaticService struct{}

StaticService defines the static API services exposed by the evm

func CreateStaticService

func CreateStaticService() *StaticService

func (*StaticService) BuildGenesis

func (ss *StaticService) BuildGenesis(_ *http.Request, args *BuildGenesisArgs, reply *BuildGenesisReply) error

BuildGenesis constructs a genesis file.

func (*StaticService) DecodeGenesis

func (ss *StaticService) DecodeGenesis(_ *http.Request, args *DecodeGenesisArgs, reply *DecodeGenesisReply) error

BuildGenesis constructs a genesis file.

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

type SubnetEVMLogger struct {
	gethlog.Logger
	// contains filtered or unexported fields
}

func InitLogger added in v0.2.9

func InitLogger(alias string, level string, jsonFormat bool, writer io.Writer) (SubnetEVMLogger, error)

InitLogger initializes logger with alias and sets the log level and format with the original os.StdErr interface along with the context logger.

func (*SubnetEVMLogger) SetLogLevel added in v0.2.9

func (s *SubnetEVMLogger) SetLogLevel(level string) error

SetLogLevel sets the log level of initialized log handler.

type Syncer added in v0.3.0

type Syncer interface {
	Start(ctx context.Context) error
	Done() <-chan 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 VM

type VM struct {

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

	peer.Network

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

VM implements the snowman.ChainVM interface

func (*VM) Connected

func (vm *VM) Connected(ctx context.Context, nodeID ids.NodeID, version *version.Application) 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) CreateStaticHandlers

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

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

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

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

Initialize implements the snowman.ChainVM interface

func (*VM) NewBlockBuilder

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

func (*VM) ParseEthBlock added in v0.3.0

func (vm *VM) ParseEthBlock(b []byte) (*types.Block, 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 added in v0.1.1

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) VerifyHeightIndex added in v0.1.1

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

VerifyHeightIndex always returns a nil error since the index is maintained by vm.blockChain.

func (*VM) Version

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

type ValidatorsAPI added in v0.6.12

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

func (*ValidatorsAPI) GetCurrentValidators added in v0.6.12

Directories

Path Synopsis
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