cosipbft

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: 29 Imported by: 5

Documentation

Overview

Package cosipbft implements an ordering service using collective signatures for the consensus.

The consensus follows the PBFT algorithm using collective signatures to perform the prepare and commit phases. The leader is orchestrating the protocol and the followers wait for incoming messages to update their own state machines and reply with signatures when the leader candidate is valid. If the leader fails to send a candidate, or finalize it, the followers will timeout after some time and move to a view change state.

The view change procedure is always waiting on the leader+1 confirmation before moving to leader+2, leader+3, etc. It means that if not enough nodes are online to create a block, the round will fail until enough wakes up and confirm leader+1. If leader+1 fails to create a block within the round timeout, a new view change starts for leader+2 and so on until a block is created.

Before each PBFT round, a synchronization is run from the leader to allow nodes that have fallen behind (or are new) to catch missing blocks. Only a PBFT threshold of nodes needs to confirm a hard synchronization (having all the blocks) for the round to proceed, but others will keep catching up.

Related Papers:

Enhancing Bitcoin Security and Performance with Strong Consistency via Collective Signing (2016) https://www.usenix.org/system/files/conference/usenixsecurity16/sec16_paper_kokoris-kogias.pdf

Documentation Last Review: 12.10.2020

Index

Constants

View Source
const (
	// DefaultRoundTimeout is the maximum round time the service waits
	// for an event to happen.
	DefaultRoundTimeout = 10 * time.Second

	// DefaultFailedRoundTimeout is the maximum round time the service waits
	// for an event to happen, after a round has failed, thus letting time
	// for a view change to establish a new leader.
	// DefaultFailedRoundTimeout is generally bigger than DefaultRoundTimeout
	DefaultFailedRoundTimeout = 20 * time.Second

	// DefaultTransactionTimeout is the maximum allowed age of transactions
	// before a view change is executed.
	DefaultTransactionTimeout = 30 * time.Second

	// RoundWait is the constant value of the exponential backoff use between
	// round failures.
	RoundWait = 5 * time.Millisecond

	// RoundMaxWait is the maximum amount for the backoff.
	RoundMaxWait = 5 * time.Minute
)

Variables

This section is empty.

Functions

func NewServiceStart

func NewServiceStart(s *Service)

NewServiceStart runs the necessary go-routines to start the service

func RegisterRosterContract

func RegisterRosterContract(exec *native.Service, rFac authority.Factory, srvc access.Service)

RegisterRosterContract registers the native smart contract to update the roster to the given service.

Types

type Proof

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

Proof is a combination of elements that will prove the inclusion or the absence of a key/value pair in the given block.

- implements ordering.Proof

func (Proof) GetKey

func (p Proof) GetKey() []byte

GetKey implements ordering.Proof. It returns the key associated to the proof.

func (Proof) GetValue

func (p Proof) GetValue() []byte

GetValue implements ordering.Proof. It returns the value associated to the proof if the key exists, otherwise it returns nil.

func (Proof) Verify

func (p Proof) Verify(genesis types.Genesis, fac crypto.VerifierFactory) error

Verify takes the genesis block and the verifier factory to verify the chain up to the latest block. It verifies the whole chain.

type Service

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

Service is an ordering service using collective signatures combined with PBFT to create a chain of blocks.

- implements ordering.Service

func NewService

func NewService(param ServiceParam, opts ...ServiceOption) (*Service, error)

NewService starts a new ordering service.

func NewServiceStruct

func NewServiceStruct(param ServiceParam, opts ...ServiceOption) (*Service, error)

NewServiceStruct returns the service struct without actually starting the service. This is useful for testing purposes.

func (*Service) Close

func (s *Service) Close() error

Close implements ordering.Service. It gracefully closes the service. It will announce the closing request and wait for the current to end before returning.

func (*Service) GetProof

func (s *Service) GetProof(key []byte) (ordering.Proof, error)

GetProof implements ordering.Service. It returns the proof of absence or inclusion for the latest block. The proof integrity is not verified as this is assumed the node is acting correctly so the data is anyway consistent. The proof must be verified by the caller when leaving the trusted environment, for instance when the proof is sent over the network.

func (*Service) GetRoster

func (s *Service) GetRoster() (authority.Authority, error)

GetRoster returns the current roster of the service.

func (*Service) GetStore

func (s *Service) GetStore() store.Readable

GetStore implements ordering.Service. It returns the current tree as a read-only storage.

func (Service) Invoke

func (h Service) Invoke(from mino.Address, msg serde.Message) ([]byte, error)

Invoke implements cosi.Reactor. It processes the messages from the collective signature module. The messages are either from the the prepare or the commit phase.

func (Service) Process

func (h Service) Process(req mino.Request) (serde.Message, error)

Process implements mino.Handler. It processes the messages from the RPC.

func (*Service) SetTimeouts

func (s *Service) SetTimeouts(round, roundAfterFailure, transaction time.Duration)

SetTimeouts sets the timeouts for the service.

func (*Service) Setup

Setup creates a genesis block and sends it to the collective authority.

func (*Service) Watch

func (s *Service) Watch(ctx context.Context) <-chan ordering.Event

Watch implements ordering.Service. It returns a channel that will be populated with new incoming blocks and some information about them. The channel must be listened at all time and the context must be closed when done.

type ServiceOption

type ServiceOption func(*serviceTemplate)

ServiceOption is the type of option to set some fields of the service.

func WithBlockStore

func WithBlockStore(store blockstore.BlockStore) ServiceOption

WithBlockStore is an option to set the block store.

func WithGenesisStore

func WithGenesisStore(store blockstore.GenesisStore) ServiceOption

WithGenesisStore is an option to set the genesis store.

func WithHashFactory

func WithHashFactory(fac crypto.HashFactory) ServiceOption

WithHashFactory is an option to set the hash factory used by the service.

type ServiceParam

type ServiceParam struct {
	Mino       mino.Mino
	Cosi       cosi.CollectiveSigning
	Validation validation.Service
	Access     access.Service
	Pool       pool.Pool
	Tree       hashtree.Tree
	DB         kv.DB
}

ServiceParam is the different components to provide to the service. All the fields are mandatory and it will panic if any is nil.

Directories

Path Synopsis
Package authority defines the collective authority for cosipbft.
Package authority defines the collective authority for cosipbft.
Package blockstore defines the different storage the ordering service is using.
Package blockstore defines the different storage the ordering service is using.
Package blocksync defines a block synchronizer for the ordering service.
Package blocksync defines a block synchronizer for the ordering service.
types
Package types implements the network messages for a synchronization.
Package types implements the network messages for a synchronization.
contracts
viewchange
Package viewchange implements a native smart contract to update the roster of a chain.
Package viewchange implements a native smart contract to update the roster of a chain.
Package controller implements a minimal controller for cosipbft.
Package controller implements a minimal controller for cosipbft.
Package pbft defines a state machine to perform PBFT using collective signatures.
Package pbft defines a state machine to perform PBFT using collective signatures.
Package types implements the network messages for cosipbft.
Package types implements the network messages for cosipbft.

Jump to

Keyboard shortcuts

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