state

package
v1.2.0-rc Latest Latest
Warning

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

Go to latest
Published: May 7, 2020 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const SilentStateActiveBlocks = 0

SilentStateActiveBlocks is a number of blocks for which a state that do not exchange any network messages as a part of its execution should be active.

Such state is active only for a time needed to perform required computations and not any longer.

View Source
const SilentStateDelayBlocks = 0

SilentStateDelayBlocks is a delay in blocks for a state that do not exchange any network messages as a part of its execution.

There is no delay before such state enters initialization.

Variables

This section is empty.

Functions

This section is empty.

Types

type Machine

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

Machine is a state machine that executes over states implemented from State interface.

func NewMachine

func NewMachine(
	channel net.BroadcastChannel,
	blockCounter chain.BlockCounter,
	initialState State,
) *Machine

NewMachine returns a new state machine. It requires a broadcast channel and an initialization function for the channel to be able to perform interactions.

func (*Machine) Execute

func (m *Machine) Execute(startBlockHeight uint64) (State, uint64, error)

Execute state machine starting with initial state up to finalization. It requires the broadcast channel to be pre-initialized.

type State

type State interface {
	// DelayBlocks returns the number of blocks for which the current state
	// initialization is delayed. We delay the initialization to give all other
	// cooperating state machines (e.g. those running on other clients)
	// a chance to enter the new state.
	//
	// State machine moves to the new state immediately after the active blocks
	// time of the previous state has been reached but waits with the
	// initialization of the new state before delay blocks timeout is reached.
	DelayBlocks() uint64

	// ActiveBlocks returns the number of blocks during which the current state
	// is active. Blocks are counted after the initiation process of the
	// current state has completed.
	ActiveBlocks() uint64

	// Initiate performs all the required calculations and sends out all the
	// messages associated with the current state. The context passed to this
	// function is scoped to the lifetime of the current state.
	Initiate(ctx context.Context) error

	// Receive is called each time a new message arrived. Receive is expected to
	// be called for all broadcast channel messages, including the member's own
	// messages.
	Receive(msg net.Message) error

	// NextState performs a state transition to the next state of the protocol.
	// If the current state is the last one, nextState returns `nil`.
	Next() State

	// MemberIndex returns the index of member associated with the current state.
	MemberIndex() group.MemberIndex
}

State is and interface against which relay states should be implemented.

Jump to

Keyboard shortcuts

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