Documentation ¶
Overview ¶
Package pbft defines a state machine to perform PBFT using collective signatures.
The package also implements a default state machine that allows only one block candidate per leader so that after a successful prepare phase, it expects the block to be committed and finalized. The only other state allowed is the view change if the round has expired.
The view change can be fixed only by providing enough valid views from unique participants to comply to the 2f threshold, or if a catch up that provides a proof of acceptance of the block.
Documentation Last Review: 13.10.2020
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthorityReader ¶
AuthorityReader is a function to help the state machine to read the current authority for a given tree.
type State ¶
type State byte
State is the type of the different possible states for the PBFT state machine.
const ( // NoneState is the very first state of the machine where nothing is set. NoneState State = iota // InitialState is the entry state which means the beginning of the PBFT // protocol. InitialState // PrepareState is the state to indicate that a proposal has been received // and the machine is waiting for confirmations. PrepareState // CommitState is the state to indicate that the participants have accepted // the proposal and the machine is waiting for the second confirmation. CommitState // ViewChangeState is the state to indicate that the protocol is failing and // the machine is waiting for view change requests. ViewChangeState )
type StateMachine ¶
type StateMachine interface { // GetState returns the current state. GetState() State // GetLeader returns the address of the round leader. GetLeader() (mino.Address, error) // GetViews returns the list of views for which the round has been accepted, // after a successful view change. Otherwise it is empty. GetViews() map[mino.Address]View // GetCommit returns the candidate digest and the associated block if the // state machine is committed to a candidate, otherwise the behaviour is // undefined. GetCommit() (types.Digest, types.Block) // Prepare processes the candidate block and moves the state machine if it // is valid and from the correct leader. Prepare(from mino.Address, block types.Block) (types.Digest, error) // Commit moves the state machine to the next state if the signature is // valid for the candidate. Commit(types.Digest, crypto.Signature) error // Finalize finalizes a round if the signature is a valid commit signature. Finalize(types.Digest, crypto.Signature) error // Accept processes the view during a view change state, and moves to a new // round if enough have been received. Accept(View) error // AcceptAll processes the list of views so that it may proceed to a future // round if the list contains enough valid views. AcceptAll([]View) error // Expire announces that the round has expired and moves the state machine // to a view change state. Expire(addr mino.Address) (View, error) // CatchUp forces a valid block to be processed by the state machine without // doing the intermediate phases. CatchUp(types.BlockLink) error // Watch returns a channel that is populated with the changes of states from // the state machine. Watch(context.Context) <-chan State }
StateMachine is the interface to implement to support a PBFT protocol.
func NewStateMachine ¶
func NewStateMachine(param StateMachineParam) StateMachine
NewStateMachine returns a new state machine.
type StateMachineParam ¶
type StateMachineParam struct { Logger zerolog.Logger Validation validation.Service VerifierFactory crypto.VerifierFactory Signer crypto.Signer Blocks blockstore.BlockStore Genesis blockstore.GenesisStore Tree blockstore.TreeCache AuthorityReader AuthorityReader DB kv.DB }
StateMachineParam is a structure to pass the different components of the PBFT state machine.
type View ¶
type View struct {
// contains filtered or unexported fields
}
View is the view change request sent to other participants.
func NewViewAndSign ¶
NewViewAndSign creates a new view and uses the signer to make the signature that will be verified by other participants.
func (View) GetSignature ¶
GetSignature returns the signature of the view.