Documentation ¶
Index ¶
Constants ¶
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 ¶
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") )
var DefaultConfig = Config{ NetworkTimeout: NetworkTimeout, RequestTimeout: RequestTimeout, MetadataProvider: metadata.NewNoopProvider(), }
var (
NullRequest = Request{}
)
var Summaries = []prometheus.SummaryDefinition{
{
Name: pbftExecutionsTimeMetric,
Help: "Time needed to reach pBFT consensus.",
},
}
Functions ¶
func MinClusterResults ¶
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
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 (Commit) Type ¶ added in v0.7.0
func (c Commit) Type() MessageType
func (*Commit) UnmarshalJSON ¶
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 (NewView) Type ¶ added in v0.7.0
func (v NewView) Type() MessageType
func (*NewView) UnmarshalJSON ¶
type Option ¶
type Option func(*Config)
Option can be used to set PBFT configuration options.
func WithMetadataProvider ¶ added in v0.6.4
WithMetadataProvider sets the metadata provider for the node.
func WithNetworkTimeout ¶
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 ¶
WithRequestTimeout sets the inactivity period before we trigger a view change.
func WithTraceInfo ¶ added in v0.7.0
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 (Prepare) Type ¶ added in v0.7.0
func (p Prepare) Type() MessageType
func (*Prepare) UnmarshalJSON ¶
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.
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 (Request) Type ¶ added in v0.7.0
func (r Request) Type() MessageType
func (*Request) UnmarshalJSON ¶
type TraceableMessage ¶ added in v0.7.0
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