Documentation
¶
Index ¶
- Variables
- type Connector
- type GetCurrentValidatorOutput
- type GetValidatorOutput
- type Logger
- type Manager
- type Set
- type SetCallbackListener
- type State
- type TestState
- func (ts *TestState) ApplyValidatorPublicKeyDiffs(ctx context.Context, validators map[ids.NodeID]*GetValidatorOutput, ...) error
- func (ts *TestState) ApplyValidatorWeightDiffs(ctx context.Context, validators map[ids.NodeID]*GetValidatorOutput, ...) error
- func (ts *TestState) GetCurrentHeight(ctx context.Context) (uint64, error)
- func (ts *TestState) GetCurrentValidatorSet(ctx context.Context, subnetID ids.ID) (map[ids.ID]*GetCurrentValidatorOutput, uint64, error)
- func (ts *TestState) GetMinimumHeight(ctx context.Context) (uint64, error)
- func (ts *TestState) GetSubnetID(ctx context.Context, chainID ids.ID) (ids.ID, error)
- func (ts *TestState) GetValidatorSet(ctx context.Context, height uint64, subnetID ids.ID) (map[ids.NodeID]*GetValidatorOutput, error)
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( ErrValidatorNotFound = errors.New("validator not found") ErrInvalidWeight = errors.New("invalid weight") )
var ( // PrimaryNetworkID is the ID of the primary network PrimaryNetworkID = constants.PrimaryNetworkID )
For compatibility with node expectations
Functions ¶
This section is empty.
Types ¶
type Connector ¶
type Connector interface {
// Connected is called when a validator connects
Connected(ctx context.Context, nodeID ids.NodeID, nodeVersion *version.Application) error
// Disconnected is called when a validator disconnects
Disconnected(ctx context.Context, nodeID ids.NodeID) error
}
Connector handles validator connection events
type GetCurrentValidatorOutput ¶ added in v0.15.6
type GetCurrentValidatorOutput struct {
ValidationID ids.ID
NodeID ids.NodeID
PublicKey interface{} // Can be []byte or *bls.PublicKey
Weight uint64
StartTime uint64
EndTime uint64
Delegated uint64
IsL1Validator bool
MinNonce uint64
IsActive bool
}
GetCurrentValidatorOutput is the output for getting current validators
type GetValidatorOutput ¶
GetValidatorOutput is a struct that contains the publicly relevant values of a validator of the Lux primary network or a Lux subnet.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger logs validator set changes
func (*Logger) OnValidatorAdded ¶
OnValidatorAdded implements SetCallbackListener
func (*Logger) OnValidatorRemoved ¶
OnValidatorRemoved implements SetCallbackListener
type Manager ¶
type Manager interface {
fmt.Stringer
// Add a subnet's validator set to the manager.
Add(subnetID ids.ID, validators Set) error
// Remove a subnet's validator set from the manager.
Remove(subnetID ids.ID) error
// Contains returns true if the manager is tracking the validator set for the given subnet.
Contains(subnetID ids.ID) bool
// Get returns the validator set for the given subnet.
Get(subnetID ids.ID) (Set, bool)
// GetByWeight returns a new validator set for the given subnet that contains all
// validators with at least the given weight.
GetByWeight(subnetID ids.ID, minWeight uint64) (Set, bool)
// GetWeight returns the weight of a specific validator for the given subnet.
GetWeight(subnetID ids.ID, nodeID ids.NodeID) uint64
// TotalWeight returns the total weight of all validators for the given subnet.
TotalWeight(subnetID ids.ID) (uint64, error)
// RecalculateStakes recalculates the stakes of all validators in the validator set.
RecalculateStakes(subnetID ids.ID) error
// Count returns the number of subnets that have validator sets.
Count() int
// GetValidator returns information about a validator
GetValidator(subnetID ids.ID, nodeID ids.NodeID) (*Validator, error)
// NumSubnets returns the number of subnets that have validator sets.
NumSubnets() int
// AddStaker adds a staker to the validator set for the given subnet.
AddStaker(subnetID ids.ID, nodeID ids.NodeID, pk *bls.PublicKey, txID ids.ID, weight uint64) error
// AddWeight adds weight to a validator in the set for the given subnet.
AddWeight(subnetID ids.ID, nodeID ids.NodeID, weight uint64) error
// RemoveWeight removes weight from a validator in the set for the given subnet.
RemoveWeight(subnetID ids.ID, nodeID ids.NodeID, weight uint64) error
// GetMap returns a map of all validators for the given subnet.
GetMap(subnetID ids.ID) map[ids.NodeID]*Validator
// GetValidatorIDs returns all validator node IDs for the given subnet
GetValidatorIDs(subnetID ids.ID) []ids.NodeID
// RegisterSetCallbackListener registers a callback listener for validator set changes
RegisterSetCallbackListener(subnetID ids.ID, listener SetCallbackListener)
}
Manager manages validator sets for different subnets.
type Set ¶
type Set interface {
// Add adds a validator to the set.
Add(nodeID ids.NodeID, pk []byte, weight uint64) error
// AddWeight adds weight to a validator in the set.
AddWeight(nodeID ids.NodeID, weight uint64) error
// RemoveWeight removes weight from a validator in the set.
RemoveWeight(nodeID ids.NodeID, weight uint64) error
// Remove removes a validator from the set.
Remove(nodeID ids.NodeID) error
// Contains returns true if the set contains the given nodeID.
Contains(nodeID ids.NodeID) bool
// Get returns the validator with the given nodeID.
Get(nodeID ids.NodeID) (*Validator, bool)
// Len returns the number of validators in the set.
Len() int
// List returns the validators in this set
List() []*Validator
// Weight returns the total weight of the validator set.
Weight() uint64
// Sample returns a random validator from the set, weighted by stake.
Sample(seed uint64) (ids.NodeID, error)
// String returns a string representation of the set.
String() string
// GetMap returns a map of all validators in the set.
GetMap() map[ids.NodeID]*Validator
}
Set is a set of validators with each validator having a weight.
type SetCallbackListener ¶ added in v0.15.6
type SetCallbackListener interface {
// OnValidatorAdded is called when a validator is added to the set
OnValidatorAdded(nodeID ids.NodeID, pk *bls.PublicKey, txID ids.ID, weight uint64)
// OnValidatorRemoved is called when a validator is removed from the set
OnValidatorRemoved(nodeID ids.NodeID, weight uint64)
// OnValidatorWeightChanged is called when a validator's weight changes
OnValidatorWeightChanged(nodeID ids.NodeID, oldWeight, newWeight uint64)
}
SetCallbackListener is called when the validator set changes
type State ¶
type State interface {
// GetMinimumHeight returns the minimum height of the P-chain.
GetMinimumHeight(ctx context.Context) (uint64, error)
// GetCurrentHeight returns the current height of the P-chain.
GetCurrentHeight(ctx context.Context) (uint64, error)
// GetSubnetID returns the subnet ID for the given chain ID.
GetSubnetID(ctx context.Context, chainID ids.ID) (ids.ID, error)
// GetValidatorSet returns the validators of the given subnet at the
// given P-chain height.
// Returns [database.ErrNotFound] if the validator set doesn't exist.
GetValidatorSet(
ctx context.Context,
height uint64,
subnetID ids.ID,
) (map[ids.NodeID]*GetValidatorOutput, error)
// ApplyValidatorWeightDiffs iterates from [startHeight] towards the genesis
// block until it has applied all of the diffs up to and including
// [endHeight]. Applying the diffs modifies [validators].
ApplyValidatorWeightDiffs(
ctx context.Context,
validators map[ids.NodeID]*GetValidatorOutput,
startHeight uint64,
endHeight uint64,
subnetID ids.ID,
) error
// ApplyValidatorPublicKeyDiffs iterates from [startHeight] towards the
// genesis block until it has applied all of the diffs up to and including
// [endHeight]. Applying the diffs modifies [validators].
ApplyValidatorPublicKeyDiffs(
ctx context.Context,
validators map[ids.NodeID]*GetValidatorOutput,
startHeight uint64,
endHeight uint64,
subnetID ids.ID,
) error
// GetCurrentValidatorSet returns the current validators
GetCurrentValidatorSet(ctx context.Context, subnetID ids.ID) (map[ids.ID]*GetCurrentValidatorOutput, uint64, error)
}
State allows getting a weighted validator set on a given subnet for a given P-chain height.
type TestState ¶
type TestState struct {
GetCurrentHeightF func(ctx context.Context) (uint64, error)
GetValidatorSetF func(ctx context.Context, height uint64, subnetID ids.ID) (map[ids.NodeID]*GetValidatorOutput, error)
}
TestState is a test validator state
func (*TestState) ApplyValidatorPublicKeyDiffs ¶
func (*TestState) ApplyValidatorWeightDiffs ¶
func (*TestState) GetCurrentHeight ¶
func (*TestState) GetCurrentValidatorSet ¶
func (*TestState) GetMinimumHeight ¶
func (*TestState) GetSubnetID ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package validatorsmock is a generated GoMock package.
|
Package validatorsmock is a generated GoMock package. |