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 ¶
- func GetChainID(ctx context.Context) ids.ID
- func GetNetworkID(ctx context.Context) uint32
- func GetTimestamp() int64
- func WithContext(ctx context.Context, chainCtx interface{}) context.Context
- func WithValidatorState(ctx context.Context, state ValidatorState) context.Context
- type BCLookup
- type Context
- type GetValidatorOutput
- type IDs
- type Keystore
- type Logger
- type Metrics
- type Runtime
- func (r *Runtime) AsBCLookup() BCLookup
- func (r *Runtime) GetAssetID() ids.ID
- func (r *Runtime) GetBCLookup() BCLookup
- func (r *Runtime) GetCChainID() ids.ID
- func (r *Runtime) GetChainDataDir() string
- func (r *Runtime) GetChainID() ids.ID
- func (r *Runtime) GetLog() Logger
- func (r *Runtime) GetMetrics() Metrics
- func (r *Runtime) GetNetworkID() uint32
- func (r *Runtime) GetNodeID() ids.NodeID
- func (r *Runtime) GetPublicKey() []byte
- func (r *Runtime) GetSender() warp.Sender
- func (r *Runtime) GetSharedMemory() SharedMemory
- func (r *Runtime) GetValidatorState() ValidatorState
- func (r *Runtime) GetWarpSigner() WarpSigner
- func (r *Runtime) GetXChainID() ids.ID
- type SharedMemory
- type VMContext
- type ValidatorState
- type WarpSigner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetChainID ¶
GetChainID extracts chain ID from context (backwards compatibility)
func GetNetworkID ¶
GetNetworkID extracts network ID from context (backwards compatibility)
func WithContext ¶
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
UTXOAssetID 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 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"`
// UTXOAssetID is the primary network's UTXO fee asset — burned to
// pay fees on P-chain (CreateChainTx, AddChainValidatorTx, …) and
// X-chain transfers. Sourced from the chain's genesis (the X-chain's
// native asset by upstream convention; on a sovereign L1 it's
// whatever native the chain bootstraps with — LUX on Lux primary,
// LQDTY on a Liquidity-sovereign primary). Same number on P and X
// by construction; named for the function, not the chain.
UTXOAssetID ids.ID `json:"utxoAssetID"`
// 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 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 ¶
FromContext extracts the Runtime from a stdlib context.Context. Returns nil if no runtime is embedded.
func (*Runtime) AsBCLookup ¶
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 (*Runtime) GetBCLookup ¶
func (*Runtime) GetCChainID ¶
func (*Runtime) GetChainDataDir ¶
func (*Runtime) GetChainID ¶
func (*Runtime) GetMetrics ¶
func (*Runtime) GetNetworkID ¶
func (*Runtime) GetPublicKey ¶
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 ¶
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
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 ¶
WarpSigner provides BLS signing for Warp messages. Matches warp.Signer interface exactly.