context

package
v1.22.41 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: BSD-3-Clause Imports: 4 Imported by: 22

Documentation

Overview

Package context provides consensus context for VMs

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 (1=mainnet, 2=testnet)

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 added in v1.22.2

func GetWarpSigner(ctx context.Context) interface{}

GetWarpSigner gets the warp signer from context

func IsPrimaryNetwork added in v1.22.39

func IsPrimaryNetwork(ctx context.Context) bool

IsPrimaryNetwork checks if the network is the primary network (NetworkID == 1)

func WithContext

func WithContext(ctx context.Context, cc *Context) context.Context

WithContext adds consensus context to a context

func WithIDs

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

WithIDs adds IDs to the context

func WithValidatorState

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

WithValidatorState adds validator state to the context

Types

type AtomicPutRequest added in v1.22.26

type AtomicPutRequest struct {
	Key    []byte   // The key to store
	Value  []byte   // The value to store
	Traits [][]byte // Traits for indexing
}

AtomicPutRequest represents a put operation in shared memory

type AtomicRequests added in v1.22.26

type AtomicRequests struct {
	RemoveRequests [][]byte            // Keys to remove
	PutRequests    []*AtomicPutRequest // Key-value pairs to put
}

AtomicRequests contains atomic operations for a chain

type BCLookup added in v1.22.23

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 BlockchainIDLookup

type BlockchainIDLookup = BCLookup

BlockchainIDLookup is an alias for BCLookup for backward compatibility

type Context

type Context struct {
	// NetworkID is the numeric network identifier (1=mainnet, 2=testnet)
	// EVM chain IDs are derived: mainnet=96369, testnet=96368
	NetworkID uint32 `json:"networkID"`
	// ChainID identifies the specific chain within the network
	ChainID      ids.ID     `json:"chainID"`
	NodeID       ids.NodeID `json:"nodeID"`
	PublicKey    []byte     `json:"publicKey"`
	XChainID     ids.ID     `json:"xChainID"`
	CChainID     ids.ID     `json:"cChainID"`
	XAssetID     ids.ID     `json:"xAssetID"` // Primary asset ID (X-chain native)
	ChainDataDir string     `json:"chainDataDir"`

	// Timing
	StartTime time.Time `json:"startTime"`

	ValidatorState  interface{} // validators.State or ValidatorState interface
	Keystore        Keystore
	Metrics         interface{} // metrics.MultiGatherer or Metrics interface
	Log             interface{} // logging.Logger
	SharedMemory    interface{} // atomic.SharedMemory
	BCLookup        BCLookup    // Blockchain alias lookup
	WarpSigner      interface{} // warp.Signer
	NetworkUpgrades interface{} // upgrade.Config

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

Context provides consensus context for VMs

func FromContext

func FromContext(ctx context.Context) *Context

FromContext extracts consensus context from a context

type GetValidatorOutput

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

GetValidatorOutput contains validator information

type IDs

type IDs struct {
	NetworkID    uint32 // 1=mainnet, 2=testnet
	ChainID      ids.ID
	NodeID       ids.NodeID
	PublicKey    []byte
	XAssetID     ids.ID // Primary asset ID (X-chain native)
	ChainDataDir string `json:"chainDataDir"`
}

IDs holds the IDs for consensus context

type Keystore

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

Keystore provides key management

type Logger added in v1.19.12

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 added in v1.19.12

type NetworkUpgrades interface {
	// IsApricotPhase3Activated returns true if the Apricot Phase 3 upgrade is activated
	IsApricotPhase3Activated(timestamp time.Time) bool
	// IsApricotPhase5Activated returns true if the Apricot Phase 5 upgrade is activated
	IsApricotPhase5Activated(timestamp time.Time) bool
	// IsBanffActivated returns true if the Banff upgrade is activated
	IsBanffActivated(timestamp time.Time) bool
	// IsCortinaActivated returns true if the Cortina upgrade is activated
	IsCortinaActivated(timestamp time.Time) bool
	// IsDurangoActivated returns true if the Durango upgrade is activated
	IsDurangoActivated(timestamp time.Time) bool
	// IsEtnaActivated returns true if the Etna upgrade is activated
	IsEtnaActivated(timestamp time.Time) bool
}

NetworkUpgrades contains network upgrade activation times

type SharedMemory added in v1.19.12

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 applies atomic requests to shared memory
	Apply(requests map[ids.ID]*AtomicRequests, batch interface{}) error
}

SharedMemory provides cross-chain shared memory

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 This is kept as a minimal interface for compatibility with node package

func GetValidatorState

func GetValidatorState(ctx context.Context) ValidatorState

GetValidatorState gets the validator state from context

type WarpSigner added in v1.19.12

type WarpSigner interface {
	// Sign signs the given message and returns the signature
	Sign(msg interface{}) ([]byte, error)
	// PublicKey returns the BLS public key bytes
	PublicKey() []byte
	// NodeID returns the node ID associated with this signer
	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