validators

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewManager

func NewManager() *manager

NewManager creates a new validator manager

Types

type Connector

type Connector interface {
	Connected(ctx context.Context, nodeID ids.NodeID, nodeVersion *version.Application) error
	Disconnected(ctx context.Context, nodeID ids.NodeID) error
}

Connector handles validator connections

type GetValidatorOutput

type GetValidatorOutput struct {
	NodeID    ids.NodeID
	PublicKey []byte
	Light     uint64
	Weight    uint64 // Alias for Light for backward compatibility
	TxID      ids.ID // Transaction ID that added this validator
}

GetValidatorOutput provides validator information

type Manager

type Manager interface {
	GetValidators(netID ids.ID) (Set, error)
	GetValidator(netID ids.ID, nodeID ids.NodeID) (*GetValidatorOutput, bool)
	GetLight(netID ids.ID, nodeID ids.NodeID) uint64
	GetWeight(netID ids.ID, nodeID ids.NodeID) uint64 // Deprecated: use GetLight
	TotalLight(netID ids.ID) (uint64, error)
	TotalWeight(netID ids.ID) (uint64, error) // Deprecated: use TotalLight

	// Mutable operations
	AddStaker(netID ids.ID, nodeID ids.NodeID, publicKey []byte, txID ids.ID, light uint64) error
	AddWeight(netID ids.ID, nodeID ids.NodeID, light uint64) error
	RemoveWeight(netID ids.ID, nodeID ids.NodeID, light uint64) error
	NumNets() int

	// Additional utility methods
	Count(netID ids.ID) int
	NumValidators(netID ids.ID) int // Alias for Count
	Sample(netID ids.ID, size int) ([]ids.NodeID, error)
	GetValidatorIDs(netID ids.ID) []ids.NodeID
	SubsetWeight(netID ids.ID, nodeIDs set.Set[ids.NodeID]) (uint64, error)
	GetMap(netID ids.ID) map[ids.NodeID]*GetValidatorOutput
	RegisterCallbackListener(listener ManagerCallbackListener)
	RegisterSetCallbackListener(netID ids.ID, listener SetCallbackListener)
}

Manager manages validator sets

type ManagerCallbackListener

type ManagerCallbackListener interface {
	OnValidatorAdded(netID ids.ID, nodeID ids.NodeID, light uint64)
	OnValidatorRemoved(netID ids.ID, nodeID ids.NodeID, light uint64)
	OnValidatorLightChanged(netID ids.ID, nodeID ids.NodeID, oldLight, newLight uint64)
}

ManagerCallbackListener listens to manager changes

type Set

type Set interface {
	Has(ids.NodeID) bool
	Len() int
	List() []Validator
	Light() uint64
	Sample(size int) ([]ids.NodeID, error)
}

Set represents a set of validators

type SetCallbackListener

type SetCallbackListener interface {
	OnValidatorAdded(nodeID ids.NodeID, light uint64)
	OnValidatorRemoved(nodeID ids.NodeID, light uint64)
	OnValidatorLightChanged(nodeID ids.NodeID, oldLight, newLight uint64)
}

SetCallbackListener listens to validator set changes

type State

type State interface {
	GetValidatorSet(ctx context.Context, height uint64, netID ids.ID) (map[ids.NodeID]*GetValidatorOutput, error)
	GetCurrentValidators(ctx context.Context, height uint64, netID ids.ID) (map[ids.NodeID]*GetValidatorOutput, error)
	GetCurrentHeight(ctx context.Context) (uint64, error)
}

State provides validator state management

type Validator

type Validator interface {
	ID() ids.NodeID
	Light() uint64
}

Validator represents a validator

type ValidatorImpl

type ValidatorImpl struct {
	NodeID   ids.NodeID
	LightVal uint64
}

ValidatorImpl is a concrete implementation of Validator

func (*ValidatorImpl) ID

func (v *ValidatorImpl) ID() ids.NodeID

ID returns the node ID

func (*ValidatorImpl) Light

func (v *ValidatorImpl) Light() uint64

Light returns the validator light

Directories

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

Jump to

Keyboard shortcuts

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