pbft

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

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

type AuthorityReader func(tree hashtree.Tree) (authority.Authority, error)

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
)

func (State) String

func (s State) String() string

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 NewView

func NewView(param ViewParam, sig crypto.Signature) View

NewView creates a new view.

func NewViewAndSign

func NewViewAndSign(param ViewParam, signer crypto.Signer) (View, error)

NewViewAndSign creates a new view and uses the signer to make the signature that will be verified by other participants.

func (View) GetFrom

func (v View) GetFrom() mino.Address

GetFrom returns the address the view is coming from.

func (View) GetID

func (v View) GetID() types.Digest

GetID returns the block digest the view is targeting.

func (View) GetLeader

func (v View) GetLeader() uint16

GetLeader returns the index of the leader proposed by the view.

func (View) GetSignature

func (v View) GetSignature() crypto.Signature

GetSignature returns the signature of the view.

func (View) Verify

func (v View) Verify(pubkey crypto.PublicKey) error

Verify takes the public key to verify the signature of the view.

type ViewParam

type ViewParam struct {
	From   mino.Address
	ID     types.Digest
	Leader uint16
}

ViewParam contains the parameters to create a view.

Jump to

Keyboard shortcuts

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