pbft

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Protocol to use for PBFT related communication.
	Protocol protocol.ID = "/b7s/consensus/pbft/1.0.0"

	// PBFT offers no resiliency towards Byzantine nodes with less than four nodes.
	MinimumReplicaCount = 4

	// How long do the send/broadcast operation have until we consider it failed.
	NetworkTimeout = 5 * time.Second

	// How long is the inactivity period before we trigger a view change.
	RequestTimeout = 10 * time.Second

	EnvVarByzantine = "B7S_PBFT_BYZANTINE"
)

Variables

View Source
var (
	ErrViewChange            = errors.New("view change in progress")
	ErrActiveView            = errors.New("replica is currently in an active view")
	ErrConflictingPreprepare = errors.New("conflicting pre-prepare")
	ErrInvalidSignature      = errors.New("invalid signature")
)
View Source
var DefaultConfig = Config{
	NetworkTimeout: NetworkTimeout,
	RequestTimeout: RequestTimeout,
}
View Source
var (
	NullRequest = Request{}
)

Functions

func MinClusterResults

func MinClusterResults(n uint) uint

MinClusterResults returns the number of identical results client should expect from the cluster before accepting the result as valid. The number is f+1.

Types

type Commit

type Commit struct {
	View           uint   `json:"view"`
	SequenceNumber uint   `json:"sequence_number"`
	Digest         string `json:"digest"`

	// Signed digest of the commit message.
	Signature string `json:"signature,omitempty"`
}

func (Commit) MarshalJSON

func (c Commit) MarshalJSON() ([]byte, error)

func (*Commit) UnmarshalJSON

func (c *Commit) UnmarshalJSON(data []byte) error

type Config

type Config struct {
	PostProcessors []PostProcessFunc // Callback functions to be invoked after execution is done.
	NetworkTimeout time.Duration
	RequestTimeout time.Duration
}

type MessageType

type MessageType uint
const (
	MessageRequest MessageType = iota + 1
	MessagePrePrepare
	MessagePrepare
	MessageCommit
	MessageViewChange
	MessageNewView
)

func (MessageType) String

func (m MessageType) String() string

type NewView

type NewView struct {
	View        uint                   `json:"view"`
	Messages    map[peer.ID]ViewChange `json:"messages"`
	PrePrepares []PrePrepare           `json:"preprepares"`

	// Signed digest of the new view message.
	Signature string `json:"signature,omitempty"`
}

func (NewView) MarshalJSON

func (v NewView) MarshalJSON() ([]byte, error)

func (*NewView) UnmarshalJSON

func (n *NewView) UnmarshalJSON(data []byte) error

type Option

type Option func(*Config)

Option can be used to set PBFT configuration options.

func WithNetworkTimeout

func WithNetworkTimeout(d time.Duration) Option

WithNetworkTimeout sets how much time we allow for message sending.

func WithPostProcessors

func WithPostProcessors(callbacks ...PostProcessFunc) Option

WithPostProcessors sets the callbacks that will be invoked after execution.

func WithRequestTimeout

func WithRequestTimeout(d time.Duration) Option

WithRequestTimeout sets the inactivity period before we trigger a view change.

type PostProcessFunc

type PostProcessFunc func(requestID string, origin peer.ID, request execute.Request, result execute.Result)

PostProcessFunc is invoked by the replica after execution is done.

type PrePrepare

type PrePrepare struct {
	View           uint    `json:"view"`
	SequenceNumber uint    `json:"sequence_number"`
	Digest         string  `json:"digest"`
	Request        Request `json:"request"`

	// Signed digest of the pre-prepare message.
	Signature string `json:"signature,omitempty"`
}

func (PrePrepare) MarshalJSON

func (p PrePrepare) MarshalJSON() ([]byte, error)

func (*PrePrepare) UnmarshalJSON

func (p *PrePrepare) UnmarshalJSON(data []byte) error

type Prepare

type Prepare struct {
	View           uint   `json:"view"`
	SequenceNumber uint   `json:"sequence_number"`
	Digest         string `json:"digest"`

	// Signed digest of the prepare message.
	Signature string `json:"signature,omitempty"`
}

func (Prepare) MarshalJSON

func (p Prepare) MarshalJSON() ([]byte, error)

func (*Prepare) UnmarshalJSON

func (p *Prepare) UnmarshalJSON(data []byte) error

type PrepareInfo

type PrepareInfo struct {
	View           uint                `json:"view"`
	SequenceNumber uint                `json:"sequence_number"`
	Digest         string              `json:"digest"`
	PrePrepare     PrePrepare          `json:"preprepare"`
	Prepares       map[peer.ID]Prepare `json:"prepares"`
}

func (PrepareInfo) MarshalJSON

func (p PrepareInfo) MarshalJSON() ([]byte, error)

func (*PrepareInfo) UnmarshalJSON

func (p *PrepareInfo) UnmarshalJSON(data []byte) error

type Replica

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

Replica is a single PBFT node. Both Primary and Backup nodes are all replicas.

func NewReplica

func NewReplica(log zerolog.Logger, host *host.Host, executor blockless.Executor, peers []peer.ID, clusterID string, options ...Option) (*Replica, error)

NewReplica creates a new PBFT replica.

func (*Replica) Consensus

func (r *Replica) Consensus() consensus.Type

func (*Replica) Execute

func (r *Replica) Execute(client peer.ID, requestID string, timestamp time.Time, req execute.Request) (codes.Code, execute.Result, error)

Execute fullfils the consensus interface by inserting the request into the pipeline.

func (*Replica) Shutdown

func (r *Replica) Shutdown() error

type Request

type Request struct {
	ID        string          `json:"id"`
	Timestamp time.Time       `json:"timestamp"`
	Origin    peer.ID         `json:"origin"`
	Execute   execute.Request `json:"execute"`
}

func (Request) MarshalJSON

func (r Request) MarshalJSON() ([]byte, error)

func (*Request) UnmarshalJSON

func (r *Request) UnmarshalJSON(data []byte) error

type ViewChange

type ViewChange struct {
	View     uint          `json:"view"`
	Prepares []PrepareInfo `json:"prepares"`

	// Signed digest of the view change message.
	Signature string `json:"signature,omitempty"`
}

func (ViewChange) MarshalJSON

func (v ViewChange) MarshalJSON() ([]byte, error)

func (*ViewChange) UnmarshalJSON

func (v *ViewChange) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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