validators

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2020 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager interface {
	// Set a subnet's validator set
	Set(ids.ID, Set) error

	// AddWeight adds weight to a given validator on the given subnet
	AddWeight(ids.ID, ids.ShortID, uint64) error

	// RemoveWeight removes weight from a given validator on a given subnet
	RemoveWeight(ids.ID, ids.ShortID, uint64) error

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

Manager holds the validator set of each subnet

func NewManager

func NewManager() Manager

NewManager returns a new, empty manager

type Set

type Set interface {
	fmt.Stringer

	// 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

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

	// 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)
}

Set of validators that can be sampled

func NewBestSet added in v0.6.4

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 Validator

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

	// Returns this validator's weight
	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(id ids.ShortID, weight uint64) Validator

NewValidator returns a validator object that implements the Validator interface

Jump to

Keyboard shortcuts

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