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 ¶
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 (*Commit) UnmarshalJSON ¶
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 (*NewView) UnmarshalJSON ¶
type Option ¶
type Option func(*Config)
Option can be used to set PBFT configuration options.
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.
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 (*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 { ID string `json:"id"` Timestamp time.Time `json:"timestamp"` Origin peer.ID `json:"origin"` Execute execute.Request `json:"execute"` }
func (Request) MarshalJSON ¶
func (*Request) UnmarshalJSON ¶
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
Source Files ¶
Click to show internal directories.
Click to hide internal directories.