state

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package state contains the interface TransitionBuffer and its implementation

Note: TransitionBuffer is not thread safe

`Dequeue` will return the most relevant `Proposed` transition for the given `Height`.

Index

Constants

View Source
const NumTicksToTriggerTimeOut = 2

NumTicksToTriggerTimeOut specifies the maximum number of Ticks to wait before triggering a TimedOut transition.

Variables

This section is empty.

Functions

func NewTimer

func NewTimer(numTicksToExpiry int) timer

NewTimer returns a timer object that is initialized with the number of ticks required for expiry of the timer.

Types

type Action

type Action interface {

	// IsAction is a marker function. It is implemented by types to ensure that
	// we cannot accidentally use the wrong types is some functions. We use type
	// switching is used to enumerate the possible concrete types.
	IsAction()
}

An Action is emitted by the state Machine to signal to other packages that some Action needs to be broadcast to other state Machines that are participating in the consensus algorithm.

type Commit

type Commit struct {
	block.Commit
}

func (Commit) IsAction

func (Commit) IsAction()

IsAction is a marker function that implements the Action interface for the Commit type.

func (*Commit) Read

func (commit *Commit) Read(r io.Reader) error

func (Commit) Write

func (commit Commit) Write(w io.Writer) error

type Machine

type Machine interface {

	// State returns the current state of the Machine. Generally, the Machine
	// will be waiting for a Propose, waiting for a Polka, or waiting for a
	// Commit.
	State() State

	// Height returns the current height on which the Machine is trying to reach
	// consensus on a new Block.
	Height() block.Height

	// Round returns the current round in which the Machine is trying tp reach
	// consensus on a new Block.
	Round() block.Round

	// LastBlock returns the last Block to which the Machine has committed. If
	// no such Block exists, the genesis block is returned.
	LastBlock() block.SignedBlock

	// StartRound is called once when the StateMachine starts operating and
	// everytime a round is completed. Actions returned by StartRound are
	// expected to be dispatched to all other Replicas in the system. If the
	// action returned by StartRound is not nil, it must be sent back to the
	// same StateMachine for it to progress.
	StartRound(round block.Round, commit *block.Commit) Action

	// Commit the Machine to a Block that has already been committed to by the
	// BFT replicated state machine.
	Commit(commit block.Commit)

	// Transition the Machine from one state to another. The state might not
	// actually change, depending on the Transition and the current state of the
	// Machine.
	Transition(transition Transition) Action
}

A Machine is a deterministic state machine that is used to implement all states and transitions required to participate in a BFT replicated state machine using the Tendermint consensus algorithm. For more information, see https://arxiv.org/pdf/1807.04938.pdf.

func NewMachine

func NewMachine(state State, polkaBuilder block.PolkaBuilder, commitBuilder block.CommitBuilder, signer sig.Signer, shard shard.Shard, txPool tx.Pool, lastCommit *block.Commit) Machine

type PreCommitted

type PreCommitted struct {
	block.SignedPreCommit
}

A PreCommitted polka has been signed and broadcast by another `Replica`.

func (PreCommitted) IsTransition

func (PreCommitted) IsTransition()

IsTransition implements the `Transition` interface for the `PreCommitted` event.

func (PreCommitted) Round

func (precommitted PreCommitted) Round() block.Round

Round implements the `Transition` interface for the `PreCommitted` event.

func (PreCommitted) Signer

func (precommitted PreCommitted) Signer() sig.Signatory

Signer implements the `Transition` interface for the `PreCommitted` event.

type PreVoted

type PreVoted struct {
	block.SignedPreVote
}

A PreVoted block has been signed and broadcast by another `Replica`.

func (PreVoted) IsTransition

func (PreVoted) IsTransition()

IsTransition implements the `Transition` interface for the `PreVoted` event.

func (PreVoted) Round

func (prevoted PreVoted) Round() block.Round

Round implements the `Transition` interface for the `PreVoted` event.

func (PreVoted) Signer

func (prevoted PreVoted) Signer() sig.Signatory

Signer implements the `Transition` interface for the `PreVoted` event.

type Propose

type Propose struct {
	block.SignedPropose

	LastCommit Commit
}

Propose a Block for consensus in the current round. A previously found Commit can be included to help locked state Machines to unlock.

func (Propose) IsAction

func (Propose) IsAction()

IsAction is a marker function that implements the Action interface for the Propose type.

func (*Propose) Read

func (propose *Propose) Read(r io.Reader) error

func (Propose) Write

func (propose Propose) Write(w io.Writer) error

type Proposed

type Proposed struct {
	block.SignedPropose
}

A Proposed block has been received by another Replica.

func (Proposed) IsTransition

func (Proposed) IsTransition()

IsTransition implements the `Transition` interface for the `Proposed` event.

func (Proposed) Round

func (proposed Proposed) Round() block.Round

Round implements the `Transition` interface for the `Proposed` event.

func (Proposed) Signer

func (proposed Proposed) Signer() sig.Signatory

Signer implements the `Transition` interface for the `Proposed` event.

type SignedPreCommit

type SignedPreCommit struct {
	block.SignedPreCommit
}

func (SignedPreCommit) IsAction

func (SignedPreCommit) IsAction()

IsAction is a marker function that implements the Action interface for the SignedPreCommit type.

func (*SignedPreCommit) Read

func (signedPreCommit *SignedPreCommit) Read(r io.Reader) error

func (SignedPreCommit) Write

func (signedPreCommit SignedPreCommit) Write(w io.Writer) error

type SignedPreVote

type SignedPreVote struct {
	block.SignedPreVote
}

func (SignedPreVote) IsAction

func (SignedPreVote) IsAction()

IsAction is a marker function that implements the Action interface for the SignedPreVote type.

func (*SignedPreVote) Read

func (preVote *SignedPreVote) Read(r io.Reader) error

func (SignedPreVote) Write

func (preVote SignedPreVote) Write(w io.Writer) error

type State

type State interface {
	IsState()
}

type Ticked

type Ticked struct {
	time.Time
}

An external event has triggered a Tick.

func (Ticked) IsTransition

func (Ticked) IsTransition()

IsTransition implements the `Transition` interface for the `Ticked` event.

func (Ticked) Round

func (Ticked) Round() block.Round

Round implements the `Transition` interface for the `Ticked` event.

func (Ticked) Signer

func (Ticked) Signer() sig.Signatory

Signer implements the `Transition` interface for the `Ticked` event.

type Transition

type Transition interface {
	IsTransition()
	Round() block.Round
	Signer() sig.Signatory
}

A Transition is an event that transitions a `Machine` from one State to another. It is generated externally to the `Machine`.

type TransitionBuffer

type TransitionBuffer interface {
	Enqueue(transition Transition)
	Dequeue(height block.Height) (Transition, bool)
	// Drop everything below the given Height. You should call this
	// the moment you know everything below the current height is
	// meaningless.
	Drop(height block.Height)
}

A TransitionBuffer is used to temporarily buffer `Proposed` that are not ready to be processed because they are from higher rounds. All `Transitions` are buffered against their respective `Height` and will be dequeued one by one.

func NewTransitionBuffer

func NewTransitionBuffer(cap int) TransitionBuffer

NewTransitionBuffer creates an empty TransitionBuffer with a maximum queue capacity.

type WaitingForCommit

type WaitingForCommit struct {
}

func (WaitingForCommit) IsState

func (WaitingForCommit) IsState()

type WaitingForPolka

type WaitingForPolka struct {
}

func (WaitingForPolka) IsState

func (WaitingForPolka) IsState()

type WaitingForPropose

type WaitingForPropose struct {
}

func (WaitingForPropose) IsState

func (WaitingForPropose) IsState()

Jump to

Keyboard shortcuts

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