validators

package
v1.9.4-rc.3 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: BSD-3-Clause Imports: 19 Imported by: 121

Documentation

Overview

Package validators is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add added in v1.9.4

func Add(m Manager, subnetID ids.ID, nodeID ids.NodeID, pk *bls.PublicKey, weight uint64) error

Add is a helper that fetches the validator set of [subnetID] from [m] and adds [nodeID] to the validator set. Returns an error if: - [subnetID] does not have a registered validator set in [m] - adding [nodeID] to the validator set returns an error

func AddWeight added in v1.9.4

func AddWeight(m Manager, subnetID ids.ID, nodeID ids.NodeID, weight uint64) error

AddWeight is a helper that fetches the validator set of [subnetID] from [m] and adds [weight] to [nodeID] in the validator set. Returns an error if: - [subnetID] does not have a registered validator set in [m] - adding [weight] to [nodeID] in the validator set returns an error

func Contains added in v1.9.4

func Contains(m Manager, subnetID ids.ID, nodeID ids.NodeID) bool

AddWeight is a helper that fetches the validator set of [subnetID] from [m] and returns if the validator set contains [nodeID]. If [m] does not contain a validator set for [subnetID], false is returned.

func RemoveWeight added in v1.9.4

func RemoveWeight(m Manager, subnetID ids.ID, nodeID ids.NodeID, weight uint64) error

RemoveWeight is a helper that fetches the validator set of [subnetID] from [m] and removes [weight] from [nodeID] in the validator set. Returns an error if: - [subnetID] does not have a registered validator set in [m] - removing [weight] from [nodeID] in the validator set returns an error

Types

type Connector added in v0.8.0

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

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

type Manager

type Manager interface {
	fmt.Stringer

	// Add a subnet's validator set to the manager.
	//
	// If the subnet had previously registered a validator set, false will be
	// returned and the manager will not be modified.
	Add(subnetID ids.ID, set Set) bool

	// Get returns the validator set for the given subnet
	// Returns false if the subnet doesn't exist
	Get(ids.ID) (Set, bool)
}

Manager holds the validator set of each subnet

func NewManager

func NewManager() Manager

NewManager returns a new, empty manager

type MockState added in v1.9.2

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

MockState is a mock of State interface.

func NewMockState added in v1.9.2

func NewMockState(ctrl *gomock.Controller) *MockState

NewMockState creates a new mock instance.

func (*MockState) EXPECT added in v1.9.2

func (m *MockState) EXPECT() *MockStateMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockState) GetCurrentHeight added in v1.9.2

func (m *MockState) GetCurrentHeight(arg0 context.Context) (uint64, error)

GetCurrentHeight mocks base method.

func (*MockState) GetMinimumHeight added in v1.9.2

func (m *MockState) GetMinimumHeight(arg0 context.Context) (uint64, error)

GetMinimumHeight mocks base method.

func (*MockState) GetValidatorSet added in v1.9.2

func (m *MockState) GetValidatorSet(arg0 context.Context, arg1 uint64, arg2 ids.ID) (map[ids.NodeID]uint64, error)

GetValidatorSet mocks base method.

type MockStateMockRecorder added in v1.9.2

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

MockStateMockRecorder is the mock recorder for MockState.

func (*MockStateMockRecorder) GetCurrentHeight added in v1.9.2

func (mr *MockStateMockRecorder) GetCurrentHeight(arg0 interface{}) *gomock.Call

GetCurrentHeight indicates an expected call of GetCurrentHeight.

func (*MockStateMockRecorder) GetMinimumHeight added in v1.9.2

func (mr *MockStateMockRecorder) GetMinimumHeight(arg0 interface{}) *gomock.Call

GetMinimumHeight indicates an expected call of GetMinimumHeight.

func (*MockStateMockRecorder) GetValidatorSet added in v1.9.2

func (mr *MockStateMockRecorder) GetValidatorSet(arg0, arg1, arg2 interface{}) *gomock.Call

GetValidatorSet indicates an expected call of GetValidatorSet.

type Set

type Set interface {
	formatting.PrefixedStringer

	// Add a new staker to the set.
	// Returns an error if:
	// - [weight] is 0
	// - [nodeID] is already in the validator set
	// - the total weight of the validator set would overflow uint64
	// If an error is returned, the set will be unmodified.
	Add(nodeID ids.NodeID, pk *bls.PublicKey, weight uint64) error

	// AddWeight to an existing staker.
	// Returns an error if:
	// - [weight] is 0
	// - [nodeID] is not already in the validator set
	// - the total weight of the validator set would overflow uint64
	// If an error is returned, the set will be unmodified.
	AddWeight(nodeID ids.NodeID, weight uint64) error

	// GetWeight retrieves the validator weight from the set.
	GetWeight(ids.NodeID) uint64

	// Get returns the validator tied to the specified ID.
	Get(ids.NodeID) (*Validator, bool)

	// SubsetWeight returns the sum of the weights of the validators.
	SubsetWeight(ids.NodeIDSet) uint64

	// RemoveWeight from a staker. If the staker's weight becomes 0, the staker
	// will be removed from the validator set.
	// Returns an error if:
	// - [weight] is 0
	// - [nodeID] is not already in the validator set
	// - the weight of the validator would become negative
	// If an error is returned, the set will be unmodified.
	RemoveWeight(nodeID ids.NodeID, weight uint64) error

	// Contains returns true if there is a validator with the specified ID
	// currently in the set.
	Contains(ids.NodeID) 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 validatorIDs, potentially with duplicates.
	// If sampling the requested size isn't possible, an error will be returned.
	Sample(size int) ([]ids.NodeID, error)

	// When a validator's weight changes, or a validator is added/removed,
	// this listener is called.
	RegisterCallbackListener(SetCallbackListener)
}

Set of validators that can be sampled

func NewBestSet added in v0.8.0

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

type SetCallbackListener interface {
	OnValidatorAdded(validatorID ids.NodeID, pk *bls.PublicKey, weight uint64)
	OnValidatorRemoved(validatorID ids.NodeID, weight uint64)
	OnValidatorWeightChanged(validatorID ids.NodeID, oldWeight, newWeight uint64)
}

type State added in v1.6.0

type State interface {
	// GetMinimumHeight returns the minimum height of the block still in the
	// proposal window.
	GetMinimumHeight(context.Context) (uint64, error)
	// GetCurrentHeight returns the current height of the P-chain.
	GetCurrentHeight(context.Context) (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(ctx context.Context, height uint64, subnetID ids.ID) (map[ids.NodeID]uint64, error)
}

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

func NewLockedState added in v1.6.0

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

func NewNoValidatorsState added in v1.7.14

func NewNoValidatorsState(state State) State

func Trace added in v1.9.3

func Trace(s State, name string, tracer trace.Tracer) State

type TestState added in v1.6.0

type TestState struct {
	T *testing.T

	CantGetMinimumHeight,
	CantGetCurrentHeight,
	CantGetValidatorSet bool

	GetMinimumHeightF func(context.Context) (uint64, error)
	GetCurrentHeightF func(context.Context) (uint64, error)
	GetValidatorSetF  func(ctx context.Context, height uint64, subnetID ids.ID) (map[ids.NodeID]uint64, error)
}

func (*TestState) GetCurrentHeight added in v1.6.0

func (vm *TestState) GetCurrentHeight(ctx context.Context) (uint64, error)

func (*TestState) GetMinimumHeight added in v1.7.10

func (vm *TestState) GetMinimumHeight(ctx context.Context) (uint64, error)

func (*TestState) GetValidatorSet added in v1.6.0

func (vm *TestState) GetValidatorSet(ctx context.Context, height uint64, subnetID ids.ID) (map[ids.NodeID]uint64, error)

type Validator

type Validator struct {
	NodeID    ids.NodeID
	PublicKey *bls.PublicKey
	Weight    uint64
	// contains filtered or unexported fields
}

Validator is a struct that contains the base values representing a validator of the Avalanche Network.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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