chains

package
v2.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2025 License: BSD-3-Clause Imports: 61 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChainLabel = "chain"
)

Variables

View Source
var (
	// Commonly shared VM DB prefix
	VMDBPrefix = []byte("vm")

	// Bootstrapping prefixes for LinearizableVMs
	VertexDBPrefix              = []byte("vertex")
	VertexBootstrappingDBPrefix = []byte("vertex_bs")
	TxBootstrappingDBPrefix     = []byte("tx_bs")
	BlockBootstrappingDBPrefix  = []byte("interval_block_bs")

	// Bootstrapping prefixes for ChainVMs
	ChainBootstrappingDBPrefix = []byte("interval_bs")
)
View Source
var ErrNoPrimaryNetworkConfig = errors.New("no subnet config for primary network found")

Functions

func NewLinearizeOnInitializeVM

func NewLinearizeOnInitializeVM(vm interface{}) *linearizeOnInitializeVM

Types

type ChainConfig

type ChainConfig struct {
	Config  []byte
	Upgrade []byte
}

ChainConfig is configuration settings for the current execution. [Config] is the user-provided config blob for the block. [Upgrade] is a chain-specific blob for coordinating upgrades.

type ChainParameters

type ChainParameters struct {
	// The ID of the chain being created.
	ID ids.ID
	// ID of the subnet that validates this block.
	SubnetID ids.ID
	// The genesis data of this chain's ledger.
	GenesisData []byte
	// The ID of the vm this chain is running.
	VMID ids.ID
	// The IDs of the feature extensions this chain is running.
	FxIDs []ids.ID
	// Invariant: Only used when [ID] is the P-chain ID.
	CustomBeacons validators.Manager
}

ChainParameters defines the chain being created

type ChainValidationConfig

type ChainValidationConfig struct {
	// Core chains that validators can opt into
	ValidateAChain bool // AI Chain (opt-in)
	ValidateBChain bool // Bridge Chain (Genesis NFT-gated)
	ValidateCChain bool // EVM Chain
	ValidateMChain bool // MPC Chain (Genesis NFT-gated)
	ValidatePChain bool // Platform Chain (usually required)
	ValidateQChain bool // Quantum Chain (usually required)
	ValidateXChain bool // Exchange Chain
	ValidateZChain bool // ZK Chain (opt-in)

	// Genesis NFT requirements for B/M chains
	GenesisNFTContract string   // Address of Genesis NFT contract
	GenesisNFTTokenIDs []uint64 // Required Genesis NFT token IDs

	// Optional specific NFT requirements per chain
	ChainSpecificNFTs map[ids.ID]NFTRequirement

	// Staking requirements per chain
	MinStakePerChain map[ids.ID]uint64
}

ChainValidationConfig specifies which chains a validator participates in

func DefaultValidationConfig

func DefaultValidationConfig() *ChainValidationConfig

DefaultValidationConfig returns the default validation configuration

type ChainValidatorSet

type ChainValidatorSet struct {
	ChainID        ids.ID
	Validators     []ids.NodeID
	IsGenesisGated bool
	MinValidators  int
}

ChainValidatorSet represents the validator set for a specific chain

type GenesisNFTInfo

type GenesisNFTInfo struct {
	ContractAddress string
	TotalSupply     uint64
	RequiredTokens  []uint64 // Specific token IDs required for validation

	// Different tiers of Genesis NFTs
	TierMapping map[string][]uint64
}

GenesisNFTInfo contains information about the Genesis NFT collection

func GetGenesisNFTInfo

func GetGenesisNFTInfo() *GenesisNFTInfo

GetGenesisNFTInfo returns information about the Genesis NFT collection

type GenesisNFTVerifier

type GenesisNFTVerifier struct {
	// contains filtered or unexported fields
}

GenesisNFTVerifier verifies Genesis NFT ownership for chain validation

func NewGenesisNFTVerifier

func NewGenesisNFTVerifier(cChainEndpoint string, genesisNFTAddress string) (*GenesisNFTVerifier, error)

NewGenesisNFTVerifier creates a new Genesis NFT verifier

func (*GenesisNFTVerifier) VerifyNFTOwnership

func (v *GenesisNFTVerifier) VerifyNFTOwnership(validatorID ids.NodeID, contractAddress string, requiredTokenIDs []uint64) (bool, error)

VerifyNFTOwnership checks if a validator owns the required NFTs

type Manager

type Manager interface {
	ids.Aliaser

	// Queues a chain to be created in the future after chain creator is unblocked.
	// This is only called from the P-chain thread to create other chains
	// Queued chains are created only after P-chain is bootstrapped.
	// This assumes only chains in tracked subnets are queued.
	QueueChainCreation(ChainParameters)

	// Add a registrant [r]. Every time a chain is
	// created, [r].RegisterChain([new chain]) is called.
	AddRegistrant(Registrant)

	// Given an alias, return the ID of the chain associated with that alias
	Lookup(string) (ids.ID, error)

	// Given an alias, return the ID of the VM associated with that alias
	LookupVM(string) (ids.ID, error)

	// Returns true iff the chain with the given ID exists and is finished bootstrapping
	IsBootstrapped(ids.ID) bool

	// Starts the chain creator with the initial platform chain parameters, must
	// be called once.
	StartChainCreator(platformChain ChainParameters) error

	Shutdown()
}

Manager manages the chains running on this node. It can:

  • Create a chain
  • Add a registrant. When a chain is created, each registrant calls RegisterChain with the new chain as the argument.
  • Manage the aliases of chains
var TestManager Manager = testManager{}

TestManager implements Manager but does nothing. Always returns nil error. To be used only in tests

func New

func New(config *ManagerConfig) (Manager, error)

New returns a new Manager

type ManagerConfig

type ManagerConfig struct {
	SybilProtectionEnabled bool
	StakingTLSSigner       crypto.Signer
	StakingTLSCert         *staking.Certificate
	StakingBLSKey          bls.Signer
	TracingEnabled         bool
	// Must not be used unless [TracingEnabled] is true as this may be nil.
	Tracer                    trace.Tracer
	Log                       log.Logger
	LogFactory                log.Factory
	VMManager                 vms.Manager // Manage mappings from vm ID --> vm
	BlockAcceptorGroup        quasar.AcceptorGroup
	TxAcceptorGroup           quasar.AcceptorGroup
	VertexAcceptorGroup       quasar.AcceptorGroup
	DB                        db.Database
	MsgCreator                message.OutboundMsgBuilder // message creator, shared with network
	Router                    router.Router              // Routes incoming messages to the appropriate chain
	Net                       network.Network            // Sends consensus messages to other validators
	Validators                validators.Manager         // Validators validating on this chain
	NodeID                    ids.NodeID                 // The ID of this node
	NetworkID                 uint32                     // ID of the network this node is connected to
	PartialSyncPrimaryNetwork bool
	Server                    server.Server // Handles HTTP API calls
	AtomicMemory              *atomic.Memory
	LUXAssetID                ids.ID
	XChainID                  ids.ID          // ID of the X-Chain,
	CChainID                  ids.ID          // ID of the C-Chain,
	CriticalChains            set.Set[ids.ID] // Chains that can't exit gracefully
	TimeoutManager            timeout.Manager // Manages request timeouts when sending messages to other validators
	Health                    health.Registerer
	SubnetConfigs             map[ids.ID]subnets.Config // ID -> SubnetConfig
	ChainConfigs              map[string]ChainConfig    // alias -> ChainConfig
	// ShutdownNodeFunc allows the chain manager to issue a request to shutdown the node
	ShutdownNodeFunc func(exitCode int)
	MeterVMEnabled   bool // Should each VM be wrapped with a MeterVM
	ImportMode       bool // If true, disable pruning for one-time blockchain data import

	Metrics        metrics.MultiGatherer
	MeterDBMetrics metrics.MultiGatherer

	FrontierPollFrequency   time.Duration
	ConsensusAppConcurrency int

	// Max Time to spend fetching a container and its
	// ancestors when responding to a GetAncestors
	BootstrapMaxTimeGetAncestors time.Duration
	// Max number of containers in an ancestors message sent by this node.
	BootstrapAncestorsMaxContainersSent int
	// This node will only consider the first [AncestorsMaxContainersReceived]
	// containers in an ancestors message it receives.
	BootstrapAncestorsMaxContainersReceived int

	Upgrades upgrade.Config

	// Tracks CPU/disk usage caused by each peer.
	ResourceTracker timetracker.ResourceTracker

	StateSyncBeacons []ids.NodeID

	ChainDataDir string

	Subnets *Subnets
}

type NFTOwnership

type NFTOwnership struct {
	ValidatorID  ids.NodeID
	TokenIDs     []uint64
	LastVerified time.Time
}

NFTOwnership represents cached NFT ownership data

type NFTRequirement

type NFTRequirement struct {
	ContractAddress  string
	RequiredTokenIDs []uint64
	MinimumBalance   uint64 // Minimum number of NFTs required
}

NFTRequirement specifies NFT requirements for a specific chain

type NFTVerifier

type NFTVerifier interface {
	// VerifyNFTOwnership checks if a validator owns required NFTs
	VerifyNFTOwnership(validatorID ids.NodeID, contractAddress string, requiredTokenIDs []uint64) (bool, error)
}

NFTVerifier interface for checking NFT ownership

type Registrant

type Registrant interface {
	// Called when a chain is created
	// This function is called before the chain starts processing messages
	// [vm] should be a vertex.DAGVM or block.ChainVM
	RegisterChain(chainName string, ctx *quasar.Context, vm core.VM)
}

Registrant can register the existence of a chain

type StakingManager

type StakingManager interface {
	// GetValidatorStake returns the stake amount for a validator on a specific chain
	GetValidatorStake(validatorID ids.NodeID, chainID ids.ID) (uint64, error)
}

StakingManager interface for checking staking requirements

type Subnets

type Subnets struct {
	// contains filtered or unexported fields
}

Subnets holds the currently running subnets on this node

func NewSubnets

func NewSubnets(
	nodeID ids.NodeID,
	configs map[ids.ID]subnets.Config,
) (*Subnets, error)

NewSubnets returns an instance of Subnets

func (*Subnets) Bootstrapping

func (s *Subnets) Bootstrapping() []ids.ID

Bootstrapping returns the subnetIDs of any chains that are still bootstrapping.

func (*Subnets) GetOrCreate

func (s *Subnets) GetOrCreate(subnetID ids.ID) (subnets.Subnet, bool)

GetOrCreate returns a subnet running on this node, or creates one if it was not running before. Returns the subnet and if the subnet was created.

type ValidatorChainManager

type ValidatorChainManager struct {
	// contains filtered or unexported fields
}

ValidatorChainManager manages validator opt-in for different chains

func NewValidatorChainManager

func NewValidatorChainManager(nftVerifier NFTVerifier, stakingManager StakingManager) *ValidatorChainManager

NewValidatorChainManager creates a new validator chain manager

func (*ValidatorChainManager) CanValidateChain

func (vcm *ValidatorChainManager) CanValidateChain(validatorID ids.NodeID, chainID ids.ID) bool

CanValidateChain checks if a validator can validate a specific chain

func (*ValidatorChainManager) GetChainValidatorSet

func (vcm *ValidatorChainManager) GetChainValidatorSet(chainID ids.ID) (*ChainValidatorSet, error)

GetChainValidatorSet returns the validator set for a specific chain

func (*ValidatorChainManager) GetValidatorConfig

func (vcm *ValidatorChainManager) GetValidatorConfig(validatorID ids.NodeID) (*ChainValidationConfig, bool)

GetValidatorConfig returns the configuration for a specific validator

func (*ValidatorChainManager) GetValidatorsForChain

func (vcm *ValidatorChainManager) GetValidatorsForChain(chainID ids.ID) []ids.NodeID

GetValidatorsForChain returns all validators that can validate a specific chain

func (*ValidatorChainManager) RegisterValidator

func (vcm *ValidatorChainManager) RegisterValidator(validatorID ids.NodeID, config *ChainValidationConfig) error

RegisterValidator registers a validator with their chain preferences

func (*ValidatorChainManager) UpdateValidatorConfig

func (vcm *ValidatorChainManager) UpdateValidatorConfig(validatorID ids.NodeID, config *ChainValidationConfig) error

UpdateValidatorConfig updates a validator's chain preferences

Directories

Path Synopsis
atomicmock
Package atomicmock is a generated GoMock package.
Package atomicmock is a generated GoMock package.

Jump to

Keyboard shortcuts

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