voter

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateVote

func CreateVote(privKey crypto.PrivKey, block xchain.Block) (*types.Vote, error)

CreateVote creates an vote for the given block.

func GenEmptyStateFile

func GenEmptyStateFile(path string) error

GenEmptyStateFile generates an empty attester state file at the given path. This must be called before LoadVoter.

Types

type Voter

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

Voter implements the types.Voter interface. It is responsible for creating and persisting votes. The goal is to ensure "all blocks are votes for".

Note Start must be called only once on startup. GetAvailable, SetProposed, and SetCommitted are thread safe, but must be called after Start.

func LoadVoter

func LoadVoter(privKey crypto.PrivKey, path string, provider xchain.Provider, deps types.VoterDeps,
	chains map[uint64]string,
) (*Voter, error)

LoadVoter returns a new attester with state loaded from disk.

func (*Voter) GetAvailable

func (a *Voter) GetAvailable() []*types.Vote

GetAvailable returns a copy of all the available votes.

func (*Voter) LocalAddress

func (a *Voter) LocalAddress() common.Address

func (*Voter) SetCommitted

func (a *Voter) SetCommitted(headers []*types.BlockHeader) error

SetCommitted sets the votes as committed. Persisting the result to disk.

func (*Voter) SetProposed

func (a *Voter) SetProposed(headers []*types.BlockHeader) error

SetProposed sets the votes as proposed.

func (*Voter) Start

func (a *Voter) Start(ctx context.Context)

Start starts runners that attest to each source chain. It does not block, it returns immediately.

func (*Voter) TrimBehind

func (a *Voter) TrimBehind(thresholds map[uint64]uint64) int

TrimBehind trims all votes that are behind the vote window thresholds (map[chainID]height) and returns the number that was deleted.

func (*Voter) Vote

func (a *Voter) Vote(block xchain.Block, allowSkip bool) error

Vote creates a vote for the given block and adds it to the internal state.

func (*Voter) WaitDone

func (a *Voter) WaitDone()

WaitDone waits for all runners to exit. Note the original Start context must be canceled to exit.

Jump to

Keyboard shortcuts

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