validators

package
v1.11.6-stella Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Overview

Package validators is a generated GoMock package.

Package validators is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrZeroWeight        = errors.New("weight must be non-zero")
	ErrMissingValidators = errors.New("missing validators")
)

Functions

This section is empty.

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 represents a handler that is called when a connection is marked as connected or disconnected

type GetValidatorOutput

type GetValidatorOutput struct {
	NodeID    ids.NodeID
	PublicKey *bls.PublicKey
	Weight    uint64
}

GetValidatorOutput is a struct that contains the publicly relevant values of a validator of the Avalanche Network for the output of GetValidator.

type Manager

type Manager interface {
	fmt.Stringer

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

	// AddWeight to an existing staker to the subnet.
	// Returns an error if:
	// - [weight] is 0
	// - [nodeID] is not already in the validator set
	// If an error is returned, the set will be unmodified.
	// AddWeight can result in a total weight that overflows uint64.
	// In this case no error will be returned for this call.
	// However, the next TotalWeight call will return an error.
	AddWeight(subnetID ids.ID, nodeID ids.NodeID, weight uint64) error

	// GetWeight retrieves the validator weight from the subnet.
	GetWeight(subnetID ids.ID, nodeID ids.NodeID) uint64

	// GetValidator returns the validator tied to the specified ID in subnet.
	// If the validator doesn't exist, returns false.
	GetValidator(subnetID ids.ID, nodeID ids.NodeID) (*Validator, bool)

	// GetValidatoIDs returns the validator IDs in the subnet.
	GetValidatorIDs(subnetID ids.ID) []ids.NodeID

	// SubsetWeight returns the sum of the weights of the validators in the subnet.
	// Returns err if subset weight overflows uint64.
	SubsetWeight(subnetID ids.ID, validatorIDs set.Set[ids.NodeID]) (uint64, error)

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

	// Count returns the number of validators currently in the subnet.
	Count(subnetID ids.ID) int

	// TotalWeight returns the cumulative weight of all validators in the subnet.
	// Returns err if total weight overflows uint64.
	TotalWeight(subnetID ids.ID) (uint64, error)

	// Sample returns a collection of validatorIDs in the subnet, potentially with duplicates.
	// If sampling the requested size isn't possible, an error will be returned.
	Sample(subnetID ids.ID, size int) ([]ids.NodeID, error)

	// Map of the validators in this subnet
	GetMap(subnetID ids.ID) map[ids.NodeID]*GetValidatorOutput

	// When a validator is added, removed, or its weight changes, the listener
	// will be notified of the event.
	RegisterCallbackListener(listener ManagerCallbackListener)

	// When a validator is added, removed, or its weight changes on [subnetID],
	// the listener will be notified of the event.
	RegisterSetCallbackListener(subnetID ids.ID, listener SetCallbackListener)
}

Manager holds the validator set of each subnet

func NewManager

func NewManager() Manager

NewManager returns a new, empty manager

type ManagerCallbackListener

type ManagerCallbackListener interface {
	OnValidatorAdded(subnetID ids.ID, nodeID ids.NodeID, pk *bls.PublicKey, txID ids.ID, weight uint64)
	OnValidatorRemoved(subnetID ids.ID, nodeID ids.NodeID, weight uint64)
	OnValidatorWeightChanged(subnetID ids.ID, nodeID ids.NodeID, oldWeight, newWeight uint64)
}

type MockState

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

MockState is a mock of State interface.

func NewMockState

func NewMockState(ctrl *gomock.Controller) *MockState

NewMockState creates a new mock instance.

func (*MockState) EXPECT

func (m *MockState) EXPECT() *MockStateMockRecorder

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

func (*MockState) GetCurrentHeight

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

GetCurrentHeight mocks base method.

func (*MockState) GetMinimumHeight

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

GetMinimumHeight mocks base method.

func (*MockState) GetSubnetID

func (m *MockState) GetSubnetID(arg0 context.Context, arg1 ids.ID) (ids.ID, error)

GetSubnetID mocks base method.

func (*MockState) GetValidatorSet

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

GetValidatorSet mocks base method.

type MockStateMockRecorder

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

MockStateMockRecorder is the mock recorder for MockState.

func (*MockStateMockRecorder) GetCurrentHeight

func (mr *MockStateMockRecorder) GetCurrentHeight(arg0 any) *gomock.Call

GetCurrentHeight indicates an expected call of GetCurrentHeight.

func (*MockStateMockRecorder) GetMinimumHeight

func (mr *MockStateMockRecorder) GetMinimumHeight(arg0 any) *gomock.Call

GetMinimumHeight indicates an expected call of GetMinimumHeight.

func (*MockStateMockRecorder) GetSubnetID

func (mr *MockStateMockRecorder) GetSubnetID(arg0, arg1 any) *gomock.Call

GetSubnetID indicates an expected call of GetSubnetID.

func (*MockStateMockRecorder) GetValidatorSet

func (mr *MockStateMockRecorder) GetValidatorSet(arg0, arg1, arg2 any) *gomock.Call

GetValidatorSet indicates an expected call of GetValidatorSet.

type MockSubnetConnector

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

MockSubnetConnector is a mock of SubnetConnector interface.

func NewMockSubnetConnector

func NewMockSubnetConnector(ctrl *gomock.Controller) *MockSubnetConnector

NewMockSubnetConnector creates a new mock instance.

func (*MockSubnetConnector) ConnectedSubnet

func (m *MockSubnetConnector) ConnectedSubnet(arg0 context.Context, arg1 ids.NodeID, arg2 ids.ID) error

ConnectedSubnet mocks base method.

func (*MockSubnetConnector) EXPECT

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

type MockSubnetConnectorMockRecorder

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

MockSubnetConnectorMockRecorder is the mock recorder for MockSubnetConnector.

func (*MockSubnetConnectorMockRecorder) ConnectedSubnet

func (mr *MockSubnetConnectorMockRecorder) ConnectedSubnet(arg0, arg1, arg2 any) *gomock.Call

ConnectedSubnet indicates an expected call of ConnectedSubnet.

type SetCallbackListener

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

func NewLogger

func NewLogger(
	log logging.Logger,
	subnetID ids.ID,
	nodeIDs ...ids.NodeID,
) SetCallbackListener

NewLogger returns a callback listener that will log validator set changes for the specified validators

type State

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)

	// GetSubnetID returns the subnetID of the provided chain.
	GetSubnetID(ctx context.Context, chainID ids.ID) (ids.ID, error)

	// GetValidatorSet returns the validators of 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]*GetValidatorOutput, error)
}

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

func NewLockedState

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

func NewNoValidatorsState

func NewNoValidatorsState(state State) State

func Trace

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

type SubnetConnector

type SubnetConnector interface {
	ConnectedSubnet(ctx context.Context, nodeID ids.NodeID, subnetID ids.ID) error
}

SubnetConnector represents a handler that is called when a connection is marked as connected to a subnet

var UnhandledSubnetConnector SubnetConnector = &unhandledSubnetConnector{}

type TestState

type TestState struct {
	T testing.TB

	CantGetMinimumHeight,
	CantGetCurrentHeight,
	CantGetSubnetID,
	CantGetValidatorSet bool

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

func (*TestState) GetCurrentHeight

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

func (*TestState) GetMinimumHeight

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

func (*TestState) GetSubnetID

func (vm *TestState) GetSubnetID(ctx context.Context, chainID ids.ID) (ids.ID, error)

func (*TestState) GetValidatorSet

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

type Validator

type Validator struct {
	NodeID    ids.NodeID
	PublicKey *bls.PublicKey
	TxID      ids.ID
	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