election

package
v0.0.1-rc Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Election

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

Election is cached data of election algorithm.

func New

func New(
	validators *pos.Validators,
	frameToDecide idx.Frame,
	forklessCauseFn ForklessCauseFn,
	getFrameRoots GetFrameRootsFn,
) *Election

New election context

func (*Election) DebugStateHash

func (el *Election) DebugStateHash() hash.Hash

DebugStateHash may be used in tests to match election state

func (*Election) ProcessRoot

func (el *Election) ProcessRoot(newRoot RootAndSlot) (*Res, error)

ProcessRoot calculates Atropos votes only for the new root. If this root observes that the current election is decided, then return decided Atropos

func (*Election) Reset

func (el *Election) Reset(validators *pos.Validators, frameToDecide idx.Frame)

Reset erases the current election state, prepare for new election frame

func (*Election) String

func (el *Election) String(voters []RootAndSlot) string

@param (optional) voters is roots to print votes for. May be nil @return election summary in a human readable format

type ForklessCauseFn

type ForklessCauseFn func(a hash.Event, b hash.Event) bool

ForklessCauseFn returns true if event A is forkless caused by event B

type GetFrameRootsFn

type GetFrameRootsFn func(f idx.Frame) []RootAndSlot

GetFrameRootsFn returns all the roots in the specified frame

type Res

type Res struct {
	Frame   idx.Frame
	Atropos hash.Event
}

Res defines the final election result, i.e. decided frame

type RootAndSlot

type RootAndSlot struct {
	ID   hash.Event
	Slot Slot
}

RootAndSlot specifies concrete root of slot.

type Slot

type Slot struct {
	Frame     idx.Frame
	Validator idx.ValidatorID
}

Slot specifies a root slot {addr, frame}. Normal validators can have only one root with this pair. Due to a fork, different roots may occupy the same slot

Jump to

Keyboard shortcuts

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