runtime

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package runtime provides chain wiring and runtime dependencies for VMs. This module is the bottom of the dependency graph - no imports from node, evm, netrunner, or cli are allowed.

Use stdlib context.Context for cancellation/deadlines. Use *Runtime for chain wiring (IDs, logging, validators, etc.)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetChainID

func GetChainID(ctx context.Context) ids.ID

GetChainID gets the chain ID from context

func GetNetworkID

func GetNetworkID(ctx context.Context) uint32

GetNetworkID gets the numeric network ID from context

func GetNodeID

func GetNodeID(ctx context.Context) ids.NodeID

GetNodeID gets the node ID from context

func GetTimestamp

func GetTimestamp() int64

GetTimestamp returns the current timestamp

func GetWarpSigner

func GetWarpSigner(ctx context.Context) interface{}

GetWarpSigner gets the warp signer from context

func IsPrimaryNetwork

func IsPrimaryNetwork(ctx context.Context) bool

IsPrimaryNetwork checks if the network is the primary network

func WithIDs

func WithIDs(ctx context.Context, id IDs) context.Context

WithIDs adds IDs to the context via Runtime

func WithRuntime

func WithRuntime(ctx context.Context, rt *Runtime) context.Context

WithRuntime adds Runtime to a context.Context

func WithValidatorState

func WithValidatorState(ctx context.Context, vs interface{}) context.Context

WithValidatorState adds validator state to the context

Types

type AtomicPutRequest

type AtomicPutRequest struct {
	Key    []byte
	Value  []byte
	Traits [][]byte
}

AtomicPutRequest represents a put operation in shared memory

type AtomicRequests

type AtomicRequests struct {
	RemoveRequests [][]byte
	PutRequests    []*AtomicPutRequest
}

AtomicRequests contains atomic operations for a chain

type BCLookup

type BCLookup interface {
	Lookup(alias string) (ids.ID, error)
	PrimaryAlias(id ids.ID) (string, error)
	Aliases(id ids.ID) ([]string, error)
}

BCLookup provides blockchain alias lookup

type GetValidatorOutput

type GetValidatorOutput struct {
	NodeID    ids.NodeID
	PublicKey []byte
	Weight    uint64
}

GetValidatorOutput contains validator information

type IDs

type IDs struct {
	NetworkID    uint32
	ChainID      ids.ID
	NodeID       ids.NodeID
	PublicKey    []byte
	XAssetID     ids.ID
	ChainDataDir string `json:"chainDataDir"`
}

IDs holds the IDs for runtime context

type Keystore

type Keystore interface {
	GetDatabase(username, password string) (interface{}, error)
	NewAccount(username, password string) error
}

Keystore provides key management

type Logger

type Logger interface {
	Debug(msg string, fields ...interface{})
	Info(msg string, fields ...interface{})
	Warn(msg string, fields ...interface{})
	Error(msg string, fields ...interface{})
	Fatal(msg string, fields ...interface{})
}

Logger provides logging functionality

type Metrics

type Metrics interface {
	Register(namespace string, registerer interface{}) error
}

Metrics provides metrics tracking

type NetworkUpgrades

type NetworkUpgrades interface {
	IsApricotPhase3Activated(timestamp time.Time) bool
	IsApricotPhase5Activated(timestamp time.Time) bool
	IsBanffActivated(timestamp time.Time) bool
	IsCortinaActivated(timestamp time.Time) bool
	IsDurangoActivated(timestamp time.Time) bool
	IsEtnaActivated(timestamp time.Time) bool
}

NetworkUpgrades contains network upgrade activation times

type Runtime

type Runtime struct {
	// NetworkID is the numeric network identifier (1=mainnet, 2=testnet)
	NetworkID uint32 `json:"networkID"`

	// ChainID identifies the specific chain within the network
	ChainID ids.ID `json:"chainID"`

	// NodeID identifies this node
	NodeID ids.NodeID `json:"nodeID"`

	// PublicKey is the node's BLS public key bytes
	PublicKey []byte `json:"publicKey"`

	// XChainID is the X-Chain identifier
	XChainID ids.ID `json:"xChainID"`

	// CChainID is the C-Chain identifier
	CChainID ids.ID `json:"cChainID"`

	// XAssetID is the primary asset ID (X-chain native, typically LUX)
	XAssetID ids.ID `json:"xAssetID"`

	// ChainDataDir is the directory for chain-specific data
	ChainDataDir string `json:"chainDataDir"`

	// StartTime is when the node started
	StartTime time.Time `json:"startTime"`

	// ValidatorState provides validator information
	// Concrete type depends on context (node vs plugin)
	ValidatorState interface{}

	// Keystore provides key management
	Keystore interface{}

	// Metrics provides metrics tracking
	Metrics interface{}

	// Log provides logging
	Log interface{}

	// SharedMemory provides cross-chain atomic operations
	SharedMemory interface{}

	// BCLookup provides blockchain alias lookup
	// Use AsBCLookup() method to get typed interface
	BCLookup interface{}

	// WarpSigner provides BLS signing for Warp messages
	WarpSigner interface{}

	// NetworkUpgrades contains upgrade activation times
	NetworkUpgrades interface{}

	// Lock for thread-safe access to runtime fields
	Lock sync.RWMutex
}

Runtime provides chain wiring and runtime dependencies for VMs. This is separate from stdlib context.Context which handles cancellation/deadlines.

Use context.Context for:

  • Cancellation signals
  • Request deadlines
  • Request-scoped values (sparingly)

Use *Runtime for:

  • Chain IDs, network IDs
  • Node identity (NodeID, PublicKey)
  • Logging, metrics
  • Database handles
  • Validator state
  • Upgrade configurations

func FromContext

func FromContext(ctx context.Context) *Runtime

FromContext extracts Runtime from a context.Context

func (*Runtime) AsBCLookup

func (rt *Runtime) AsBCLookup() BCLookup

AsBCLookup returns the BCLookup interface if available, or nil. Use this to access BCLookup methods with proper type safety.

func (*Runtime) AsLogger

func (rt *Runtime) AsLogger() Logger

AsLogger returns the Log field as a Logger interface if available.

func (*Runtime) AsValidatorState

func (rt *Runtime) AsValidatorState() ValidatorState

AsValidatorState returns the ValidatorState interface if available.

type SharedMemory

type SharedMemory interface {
	Get(peerChainID ids.ID, keys [][]byte) (values [][]byte, err error)
	Indexed(
		peerChainID ids.ID,
		traits [][]byte,
		startTrait, startKey []byte,
		limit int,
	) (values [][]byte, lastTrait, lastKey []byte, err error)
	Apply(requests map[ids.ID]*AtomicRequests, batch interface{}) error
}

SharedMemory provides cross-chain shared memory

type VMContext

type VMContext interface {
	GetNetworkID() uint32
	GetChainID() ids.ID
	GetNodeID() ids.NodeID
	GetPublicKey() []byte
	GetXChainID() ids.ID
	GetCChainID() ids.ID
	GetAssetID() ids.ID
	GetChainDataDir() string
	GetLog() interface{}
	GetSharedMemory() interface{}
	GetMetrics() interface{}
	GetValidatorState() interface{}
	GetBCLookup() interface{}
	GetWarpSigner() interface{}
	GetNetworkUpgrades() interface{}
}

VMContext is an interface that VM contexts must implement This allows different context types (node, plugin, etc.) to be used interchangeably

type ValidatorState

type ValidatorState interface {
	GetChainID(ids.ID) (ids.ID, error)
	GetNetworkID(ids.ID) (ids.ID, error)
	GetValidatorSet(uint64, ids.ID) (map[ids.NodeID]uint64, error)
	GetCurrentHeight(context.Context) (uint64, error)
	GetMinimumHeight(context.Context) (uint64, error)
}

ValidatorState provides validator information

func GetValidatorState

func GetValidatorState(ctx context.Context) ValidatorState

GetValidatorState gets the validator state from context

type WarpSigner

type WarpSigner interface {
	Sign(msg interface{}) ([]byte, error)
	PublicKey() []byte
	NodeID() ids.NodeID
}

WarpSigner provides BLS signing for Warp messages

Jump to

Keyboard shortcuts

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