pbft

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: Apache-2.0 Imports: 30 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,
	MetadataProvider: metadata.NewNoopProvider(),
}
View Source
var (
	NullRequest = Request{}
)
View Source
var Summaries = []prometheus.SummaryDefinition{
	{
		Name: pbftExecutionsTimeMetric,
		Help: "Time needed to reach pBFT consensus.",
	},
}

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 BaseMessage added in v0.7.0

type BaseMessage struct {
	tracing.TraceInfo
}

func (*BaseMessage) SaveTraceContext added in v0.7.0

func (m *BaseMessage) SaveTraceContext(t tracing.TraceInfo)

type Commit

type Commit struct {
	BaseMessage
	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) Type added in v0.7.0

func (c Commit) Type() MessageType

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
	MetadataProvider metadata.Provider
	TraceInfo        tracing.TraceInfo
}

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 {
	BaseMessage
	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) Type added in v0.7.0

func (v NewView) Type() MessageType

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 WithMetadataProvider added in v0.6.4

func WithMetadataProvider(p metadata.Provider) Option

WithMetadataProvider sets the metadata provider for the node.

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.

func WithTraceInfo added in v0.7.0

func WithTraceInfo(t tracing.TraceInfo) Option

WithTraceInfo passes along telemetry trace information.

type PBFTMessage added in v0.7.0

type PBFTMessage interface {
	Type() MessageType
}

type PostProcessFunc

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

PostProcessFunc is invoked by the replica after execution is done.

type PrePrepare

type PrePrepare struct {
	BaseMessage
	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) Type added in v0.7.0

func (p PrePrepare) Type() MessageType

func (*PrePrepare) UnmarshalJSON

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

type Prepare

type Prepare struct {
	BaseMessage
	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) Type added in v0.7.0

func (p Prepare) Type() MessageType

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 {
	BaseMessage
	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) Type added in v0.7.0

func (r Request) Type() MessageType

func (*Request) UnmarshalJSON

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

type TraceableMessage added in v0.7.0

type TraceableMessage interface {
	SaveTraceContext(t tracing.TraceInfo)
}

type ViewChange

type ViewChange struct {
	BaseMessage
	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) Type added in v0.7.0

func (v ViewChange) Type() MessageType

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