validators

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: BSD-3-Clause Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connector

type Connector interface {
	Connected(id ids.ShortID, nodeVersion version.Application) error
	Disconnected(id ids.ShortID) error
}

Connector represents a handler that is called when a connection is marked as connected or disconnected

type Manager

type Manager interface {
	fmt.Stringer

	// GetValidators returns the validator set for the given subnet
	// Returns false if the subnet doesn't exist
	GetValidators() (Set, bool)

	// MaskValidator hides the named validator from future samplings
	MaskValidator(vdrID ids.ShortID) error

	// RevealValidator ensures the named validator is not hidden from future
	// samplings
	RevealValidator(vdrID ids.ShortID) error

	// Contains returns true if there is a validator with the specified ID
	// currently in the set.
	Contains(vdrID ids.ShortID) bool

	// Mutate will mutate the validator set by copying it and adding the given
	// validators.
	Mutate(withs ...With) Manager
}

Manager holds the validator set of each subnet

func NewManager

func NewManager(networkID uint32, withs ...With) Manager

NewManager returns a new, empty manager

type Set

type Set interface {
	fmt.Stringer
	PrefixedString(string) string

	// Set removes all the current validators and adds all the provided
	// validators to the set.
	Set([]Validator) error

	// AddWeight to a staker.
	AddWeight(ids.ShortID, uint64) error

	// GetWeight retrieves the validator weight from the set.
	GetWeight(ids.ShortID) (uint64, bool)

	// SubsetWeight returns the sum of the weights of the validators.
	SubsetWeight(ids.ShortSet) (uint64, error)

	// RemoveWeight from a staker.
	RemoveWeight(ids.ShortID, uint64) error

	// Contains returns true if there is a validator with the specified ID
	// currently in the set.
	Contains(ids.ShortID) bool

	// Len returns the number of validators currently in the set.
	Len() int

	// List all the validators in this group
	List() []Validator

	// Weight returns the cumulative weight of all validators in the set.
	Weight() uint64

	// Sample returns a collection of validators, potentially with duplicates.
	// If sampling the requested size isn't possible, an error will be returned.
	Sample(size int) ([]Validator, error)

	// MaskValidator hides the named validator from future samplings
	MaskValidator(ids.ShortID) error

	// RevealValidator ensures the named validator is not hidden from future
	// samplings
	RevealValidator(ids.ShortID) error
}

Set of validators that can be sampled

func NewBestSet

func NewBestSet(expectedSampleSize int) Set

NewBestSet returns a new, empty set of validators.

func NewSet

func NewSet() Set

NewSet returns a new, empty set of validators.

type State added in v0.2.3

type State interface {
	// GetCurrentHeight returns the current height of the P-chain.
	GetCurrentHeight() (uint64, error)

	// GetValidatorSet returns the weights of the nodeIDs for the provided
	// subnet at the requested P-chain height.
	// The returned map should not be modified.
	GetValidatorSet(height uint64, subnetID ids.ID) (map[ids.ShortID]uint64, error)
}

State allows the lookup of validator sets on specified subnets at the requested P-chain height.

func NewLockedState added in v0.2.3

func NewLockedState(lock sync.Locker, s State) State

func NewNoState added in v0.2.3

func NewNoState() State

type TestState added in v0.2.3

type TestState struct {
	T *testing.T

	CantGetCurrentHeight,
	CantGetValidatorSet bool

	GetCurrentHeightF func() (uint64, error)
	GetValidatorSetF  func(height uint64, subnetID ids.ID) (map[ids.ShortID]uint64, error)
}

func (*TestState) GetCurrentHeight added in v0.2.3

func (vm *TestState) GetCurrentHeight() (uint64, error)

func (*TestState) GetValidatorSet added in v0.2.3

func (vm *TestState) GetValidatorSet(height uint64, subnetID ids.ID) (map[ids.ShortID]uint64, error)

type Validator

type Validator interface {
	// ID returns the node ID of this validator
	ID() ids.ShortID

	// Weight that can be used for weighted sampling. If this validator is
	// validating the primary network, returns the amount of AVAX staked.
	Weight() uint64
}

Validator is the minimal description of someone that can be sampled.

func GenerateRandomValidator

func GenerateRandomValidator(weight uint64) Validator

GenerateRandomValidator creates a random validator with the provided weight

func NewValidator

func NewValidator(
	nodeID ids.ShortID,
	weight uint64,
) Validator

NewValidator returns a validator object that implements the Validator interface

type With added in v0.5.1

type With func(Set)

func WithValidator added in v0.5.1

func WithValidator(vdr ids.ShortID, weight uint64) With

Jump to

Keyboard shortcuts

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