Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMaxStepsReached = errors.New("consensus reached max number of steps without moving forward")
ErrMaxStepsReached is triggered when the consensus loop reaches the maximum amount of steps without reaching an Agreement. This means that the network is highly asynchronous or we are under attack.
Functions ¶
func CreateInitialStep ¶
func CreateInitialStep(e *consensus.Emitter, consensusTimeOut time.Duration, bg blockgenerator.BlockGenerator, verifyFn consensus.CandidateVerificationFunc, db database.DB, requestor *candidate.Requestor) consensus.Phase
CreateInitialStep creates the selection step by injecting a BlockGenerator interface to it.
func CreateStateMachine ¶
func CreateStateMachine(e *consensus.Emitter, db database.DB, consensusTimeOut time.Duration, verifyFn consensus.CandidateVerificationFunc, executeFn consensus.ExecuteTxsFunc, requestor *candidate.Requestor) (consensus.Phase, consensus.Controller, error)
CreateStateMachine creates and link the steps in the consensus. It is kept separated from consensus.New so to ease mocking the consensus up when testing.
Types ¶
type Consensus ¶
type Consensus struct { *consensus.Emitter *candidate.Requestor // contains filtered or unexported fields }
Consensus is the state machine that runs the steps of consensus. Rather than trying to coordinate the various steps, it lets them execute and indicate which should be the following status, until completion. Each round is run separately and in a synchronous, blocking fashion (except the Agreement which should be run asynchronously by design).
func New ¶
New creates a new Consensus struct. The legacy StopConsensus and RoundUpdate are now replaced with context cancellation and direct function call operated by the chain component.
func (*Consensus) CreateStateMachine ¶
func (c *Consensus) CreateStateMachine(db database.DB, consensusTimeOut time.Duration, verifyFn consensus.CandidateVerificationFunc, executeFn consensus.ExecuteTxsFunc) (consensus.Phase, consensus.Controller, error)
CreateStateMachine uses Consensus parameters as a shorthand for the static CreateStateMachine.
func (*Consensus) Spin ¶
func (c *Consensus) Spin(ctx context.Context, scr consensus.Phase, ag consensus.Controller, round consensus.RoundUpdate) consensus.Results
Spin the consensus state machine. The consensus runs for the whole round until either a new round is produced or the node needs to re-sync. The Agreement loop (acting roundwise) runs concurrently with the generation-selection-reduction loop (acting step-wise). TODO: consider stopping the phase loop with a Done phase, instead of nil.