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 ¶
- func GetChainID(ctx context.Context) ids.ID
- func GetNetworkID(ctx context.Context) uint32
- func GetNodeID(ctx context.Context) ids.NodeID
- func GetTimestamp() int64
- func GetWarpSigner(ctx context.Context) interface{}
- func IsPrimaryNetwork(ctx context.Context) bool
- func WithIDs(ctx context.Context, id IDs) context.Context
- func WithRuntime(ctx context.Context, rt *Runtime) context.Context
- func WithValidatorState(ctx context.Context, vs interface{}) context.Context
- type AtomicPutRequest
- type AtomicRequests
- type BCLookup
- type GetValidatorOutput
- type IDs
- type Keystore
- type Logger
- type Metrics
- type NetworkUpgrades
- type Runtime
- type SharedMemory
- type VMContext
- type ValidatorState
- type WarpSigner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetChainID ¶
GetChainID gets the chain ID from context
func GetNetworkID ¶
GetNetworkID gets the numeric network ID from context
func GetWarpSigner ¶
GetWarpSigner gets the warp signer from context
func IsPrimaryNetwork ¶
IsPrimaryNetwork checks if the network is the primary network
func WithRuntime ¶
WithRuntime adds Runtime to a context.Context
Types ¶
type AtomicPutRequest ¶
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 ¶
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 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 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 ¶
FromContext extracts Runtime from a context.Context
func (*Runtime) AsBCLookup ¶
AsBCLookup returns the BCLookup interface if available, or nil. Use this to access BCLookup methods with proper type safety.
func (*Runtime) AsValidatorState ¶
func (rt *Runtime) AsValidatorState() ValidatorState
AsValidatorState returns the ValidatorState interface if available.
type SharedMemory ¶
type SharedMemory interface {
peerChainID ids.ID,
traits [][]byte,
startTrait, startKey []byte,
limit int,
) (values [][]byte, lastTrait, lastKey []byte, err 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{}
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