leader

package
v0.22.9-patch-1-epoch-... Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2021 License: AGPL-3.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const EstimatedSixMonthOfViews = 15000000 // 1 sec block time * 60 secs * 60 mins * 24 hours * 30 days * 6 months

Variables

This section is empty.

Functions

func IsInvalidViewError

func IsInvalidViewError(err error) bool

IsInvalidViwError returns whether or not the input error is an invalid view error.

func WeightedRandomSelection

func WeightedRandomSelection(seed []byte, count int, weights []uint64) ([]uint16, error)

WeightedRandomSelection - given a seed and a given count, pre-generate the indexs of leader. The chance to be selected as leader is proportional to its weight. If an identity has 0 stake (weight is 0), it won't be selected as leader. This algorithm is essentially Fitness proportionate selection: See https://en.wikipedia.org/wiki/Fitness_proportionate_selection

Types

type InvalidViewError

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

InvalidViewError is returned when a requested view is outside the pre-computed range.

func (InvalidViewError) Error

func (err InvalidViewError) Error() string

type LeaderSelection

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

LeaderSelection caches the pre-generated leader selections for a certain number of views starting from the epoch start view.

func ComputeLeaderSelectionFromSeed

func ComputeLeaderSelectionFromSeed(firstView uint64, seed []byte, count int, identities flow.IdentityList) (*LeaderSelection, error)

ComputeLeaderSelectionFromSeed pre-generates a certain number of leader selections, and returns a leader selection instance for querying the leader indexes for certain views. firstView - the start view of the epoch, the generated leader selections start from this view. seed - the random seed for leader selection count - the number of leader selections to be pre-generated and cached. identities - the identities that contain the stake info, which is used as weight for the chance of

the identity to be selected as leader.

func NewSelectionForBootstrap

func NewSelectionForBootstrap() *LeaderSelection

NewBootstrapLeaderSelection creates a leader selection for bootstrapping process to create genesis QC. The returned leader selection does not have any pre-generated leader selections since the bootstrapping process don't need it.

func SelectionForCluster

func SelectionForCluster(cluster protocol.Cluster, epoch protocol.Epoch) (*LeaderSelection, error)

SelectionForCluster pre-computes and returns leaders for the given cluster committee in the given epoch.

func SelectionForConsensus

func SelectionForConsensus(epoch protocol.Epoch) (*LeaderSelection, error)

SelectionForConsensus pre-computes and returns leaders for the consensus committee in the given epoch. The consensus committee spans multiple epochs and the leader selection returned here is only valid for the input epoch, so it is necessary to call this for each upcoming epoch.

func (LeaderSelection) FinalView

func (l LeaderSelection) FinalView() uint64

func (LeaderSelection) FirstView

func (l LeaderSelection) FirstView() uint64

func (LeaderSelection) LeaderForView

func (l LeaderSelection) LeaderForView(view uint64) (flow.Identifier, error)

LeaderForView returns the node ID of the leader for a given view. Returns InvalidViewError if the view is outside the pre-computed range.

Jump to

Keyboard shortcuts

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