runtime

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: BSD-3-Clause Imports: 8 Imported by: 85

Documentation

Overview

Package runtime provides chain wiring and runtime dependencies for VMs. This package is part of the consensus module and provides the Runtime struct that VMs use for chain configuration, logging, validators, etc.

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 extracts chain ID from context (backwards compatibility)

func GetNetworkID

func GetNetworkID(ctx context.Context) uint32

GetNetworkID extracts network ID from context (backwards compatibility)

func GetTimestamp

func GetTimestamp() int64

GetTimestamp returns the current timestamp

func WithContext

func WithContext(ctx context.Context, chainCtx interface{}) context.Context

WithContext returns a new context.Context with the runtime embedded. This allows extracting chain info from a stdlib context using FromContext.

func WithValidatorState

func WithValidatorState(ctx context.Context, state ValidatorState) context.Context

WithValidatorState adds a validator state to the context (backwards compatibility)

Types

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 Context

type Context = Runtime

Context is an alias for *Runtime for backwards compatibility with old consensus context patterns

type GetValidatorOutput

type GetValidatorOutput = validators.GetValidatorOutput

GetValidatorOutput is re-exported from validator package for convenience

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{})
	IsZero() bool
}

Logger provides logging functionality

type Metrics

type Metrics interface {
	metric.Gatherer
	Register(name string, gatherer metric.Gatherer) error
}

Metrics provides metrics tracking. Matches api/metrics.MultiGatherer interface.

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"`

	// PChainHeight is the optional proposer P-Chain height for block-specific operations.
	PChainHeight uint64 `json:"pChainHeight"`

	// ValidatorState provides validator information (uses consensus/validators.State)
	ValidatorState validators.State

	// Keystore provides key management
	Keystore Keystore

	// Metrics provides metrics tracking
	Metrics Metrics

	// Log provides logging
	Log Logger

	// SharedMemory provides cross-chain atomic operations
	SharedMemory SharedMemory

	// BCLookup provides blockchain alias lookup
	BCLookup BCLookup

	// WarpSigner provides BLS signing for Warp messages
	WarpSigner WarpSigner

	// Sender is the canonical warp sender
	Sender warp.Sender

	// 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 the Runtime from a stdlib context.Context. Returns nil if no runtime is embedded.

func (*Runtime) AsBCLookup

func (r *Runtime) AsBCLookup() BCLookup

AsBCLookup returns the BCLookup interface for blockchain alias lookup. This method is used by VMs (particularly coreth) to resolve chain aliases.

func (*Runtime) GetAssetID

func (r *Runtime) GetAssetID() ids.ID

func (*Runtime) GetBCLookup

func (r *Runtime) GetBCLookup() BCLookup

func (*Runtime) GetCChainID

func (r *Runtime) GetCChainID() ids.ID

func (*Runtime) GetChainDataDir

func (r *Runtime) GetChainDataDir() string

func (*Runtime) GetChainID

func (r *Runtime) GetChainID() ids.ID

func (*Runtime) GetLog

func (r *Runtime) GetLog() Logger

func (*Runtime) GetMetrics

func (r *Runtime) GetMetrics() Metrics

func (*Runtime) GetNetworkID

func (r *Runtime) GetNetworkID() uint32

func (*Runtime) GetNodeID

func (r *Runtime) GetNodeID() ids.NodeID

func (*Runtime) GetPublicKey

func (r *Runtime) GetPublicKey() []byte

func (*Runtime) GetSender

func (r *Runtime) GetSender() warp.Sender

func (*Runtime) GetSharedMemory

func (r *Runtime) GetSharedMemory() SharedMemory

func (*Runtime) GetValidatorState

func (r *Runtime) GetValidatorState() ValidatorState

func (*Runtime) GetWarpSigner

func (r *Runtime) GetWarpSigner() WarpSigner

func (*Runtime) GetXChainID

func (r *Runtime) GetXChainID() ids.ID

type SharedMemory

type SharedMemory = atomic.SharedMemory

SharedMemory is the canonical interface for cross-chain atomic operations. Uses atomic.Requests and atomic.Element as the ONE canonical types.

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() Logger
	GetSharedMemory() SharedMemory
	GetMetrics() Metrics
	GetValidatorState() ValidatorState
	GetBCLookup() BCLookup
	GetWarpSigner() WarpSigner
	GetSender() warp.Sender
}

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 = validators.State

ValidatorState is an alias to validators.State for convenience

func GetValidatorState

func GetValidatorState(ctx context.Context) ValidatorState

GetValidatorState extracts validator state from context (backwards compatibility)

func GetValidatorStateFromKey

func GetValidatorStateFromKey(ctx context.Context) ValidatorState

GetValidatorStateFromKey extracts validator state from context using key (backwards compatibility)

type WarpSigner

type WarpSigner = warp.Signer

WarpSigner provides BLS signing for Warp messages. Matches warp.Signer interface exactly.

Jump to

Keyboard shortcuts

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