Documentation ¶
Index ¶
- Constants
- func MarshalOrPanic(msg proto.Message) []byte
- func ValidateInFlight(inFlightProposal *protos.Proposal, lastSequence uint64) error
- func ValidateLastDecision(vd *protos.ViewData, quorum int, N uint64, verifier api.Verifier) (err error, lastSequence uint64)
- type ApplicationMock
- type AssemblerMock
- type BatchBuilder
- type Batcher
- type Comm
- type CommMock
- type Controller
- func (c *Controller) AbortView()
- func (c *Controller) Decide(proposal types.Proposal, signatures []types.Signature, ...)
- func (c *Controller) HandleRequest(sender uint64, req []byte)
- func (c *Controller) OnAutoRemoveTimeout(requestInfo types.RequestInfo)
- func (c *Controller) OnHeartbeatTimeout(view uint64, leaderID uint64)
- func (c *Controller) OnLeaderFwdRequestTimeout(request []byte, info types.RequestInfo)
- func (c *Controller) OnRequestTimeout(request []byte, info types.RequestInfo)
- func (c *Controller) ProcessMessages(sender uint64, m *protos.Message)
- func (c *Controller) Start(startViewNumber uint64, startProposalSequence uint64)
- func (c *Controller) Stop()
- func (c *Controller) SubmitRequest(request []byte) error
- func (c *Controller) Sync()
- func (c *Controller) ViewChanged(newViewNumber uint64, newProposalSequence uint64)
- type Decider
- type FailureDetector
- type HeartbeatMonitor
- type HeartbeatTimeoutHandler
- type InFlightData
- type LeaderMonitor
- type PersistedState
- type Phase
- type Pool
- func (rp *Pool) Close()
- func (rp *Pool) NextRequests(n int) [][]byte
- func (rp *Pool) Prune(predicate func([]byte) error)
- func (rp *Pool) RemoveRequest(requestInfo types.RequestInfo) error
- func (rp *Pool) RestartTimers()
- func (rp *Pool) Size() int
- func (rp *Pool) StopTimers()
- func (rp *Pool) Submit(request []byte) error
- type PoolOptions
- type ProposalMaker
- type Proposer
- type ProposerBuilder
- type RequestPool
- type RequestTimeoutHandler
- type RequestsTimer
- type Role
- type Scheduler
- type SignerMock
- type State
- type StateRecorder
- type Stopper
- type Synchronizer
- type SynchronizerMock
- type Task
- type TaskQueue
- type VerifierMock
- type View
- type ViewChanger
- type ViewController
Constants ¶
const ( DefaultHeartbeatTimeout = 60 * time.Second HeartbeatFrequency = 10 // How much heart beats per timeout Leader Role = false Follower Role = true )
const ( COMMITTED = iota PROPOSED PREPARED ABORT )
const (
DefaultRequestTimeout = 10 * time.Second
)
Variables ¶
This section is empty.
Functions ¶
func MarshalOrPanic ¶
func ValidateInFlight ¶
Types ¶
type ApplicationMock ¶
type ApplicationMock interface { api.Application }
type AssemblerMock ¶
type BatchBuilder ¶
type BatchBuilder struct {
// contains filtered or unexported fields
}
func NewBatchBuilder ¶
func NewBatchBuilder(pool RequestPool, batchSize int, batchTimeout time.Duration) *BatchBuilder
func (*BatchBuilder) BatchRemainder ¶
func (b *BatchBuilder) BatchRemainder(remainder [][]byte)
BatchRemainder sets the remainder of requests to be included in the next batch
func (*BatchBuilder) Close ¶
func (b *BatchBuilder) Close()
Close closes the close channel to stop NextBatch
func (*BatchBuilder) NextBatch ¶
func (b *BatchBuilder) NextBatch() [][]byte
NextBatch returns the next batch of requests to be proposed
func (*BatchBuilder) PopRemainder ¶
func (b *BatchBuilder) PopRemainder() [][]byte
PopRemainder returns the remainder and resets it
func (*BatchBuilder) Reset ¶
func (b *BatchBuilder) Reset()
Reset resets the remainder and reopens the close channel to allow calling NextBatch
type Controller ¶
type Controller struct { // configuration ID uint64 N uint64 RequestPool RequestPool Batcher Batcher LeaderMonitor LeaderMonitor Verifier api.Verifier Logger api.Logger Assembler api.Assembler Application api.Application FailureDetector FailureDetector Synchronizer api.Synchronizer Comm Comm Signer api.Signer RequestInspector api.RequestInspector WAL api.WriteAheadLog ProposerBuilder ProposerBuilder Checkpoint *types.Checkpoint ViewChanger *ViewChanger // contains filtered or unexported fields }
func (*Controller) AbortView ¶
func (c *Controller) AbortView()
AbortView makes the controller abort the current view
func (*Controller) Decide ¶
func (c *Controller) Decide(proposal types.Proposal, signatures []types.Signature, requests []types.RequestInfo)
Decide delivers the decision to the application
func (*Controller) HandleRequest ¶
func (c *Controller) HandleRequest(sender uint64, req []byte)
func (*Controller) OnAutoRemoveTimeout ¶
func (c *Controller) OnAutoRemoveTimeout(requestInfo types.RequestInfo)
OnAutoRemoveTimeout is called when the auto-remove timeout expires. Called by the request-pool timeout goroutine.
func (*Controller) OnHeartbeatTimeout ¶
func (c *Controller) OnHeartbeatTimeout(view uint64, leaderID uint64)
OnHeartbeatTimeout is called when the heartbeat timeout expires. Called by the HeartbeatMonitor timer goroutine.
func (*Controller) OnLeaderFwdRequestTimeout ¶
func (c *Controller) OnLeaderFwdRequestTimeout(request []byte, info types.RequestInfo)
OnLeaderFwdRequestTimeout is called when the leader-forward timeout expires, and complains about the leader. Called by the request-pool timeout goroutine. Upon return, the auto-remove timeout is started.
func (*Controller) OnRequestTimeout ¶
func (c *Controller) OnRequestTimeout(request []byte, info types.RequestInfo)
OnRequestTimeout is called when request-timeout expires and forwards the request to leader. Called by the request-pool timeout goroutine. Upon return, the leader-forward timeout is started.
func (*Controller) ProcessMessages ¶
func (c *Controller) ProcessMessages(sender uint64, m *protos.Message)
ProcessMessages dispatches the incoming message to the required component
func (*Controller) Start ¶
func (c *Controller) Start(startViewNumber uint64, startProposalSequence uint64)
Start the controller
func (*Controller) SubmitRequest ¶
func (c *Controller) SubmitRequest(request []byte) error
SubmitRequest Submits a request to go through consensus.
func (*Controller) Sync ¶
func (c *Controller) Sync()
func (*Controller) ViewChanged ¶
func (c *Controller) ViewChanged(newViewNumber uint64, newProposalSequence uint64)
ViewChanged makes the controller abort the current view and start a new one with the given numbers
type FailureDetector ¶
type FailureDetector interface {
Complain(stopView bool)
}
type HeartbeatMonitor ¶
type HeartbeatMonitor struct {
// contains filtered or unexported fields
}
func NewHeartbeatMonitor ¶
func NewHeartbeatMonitor( scheduler <-chan time.Time, logger api.Logger, heartbeatTimeout time.Duration, comm Comm, handler HeartbeatTimeoutHandler, ) *HeartbeatMonitor
func (*HeartbeatMonitor) ChangeRole ¶
func (hm *HeartbeatMonitor) ChangeRole(follower Role, view uint64, leaderID uint64)
ChangeRole will change the role of this HeartbeatMonitor
func (*HeartbeatMonitor) Close ¶
func (hm *HeartbeatMonitor) Close()
Close stops following or sending heartbeats.
func (*HeartbeatMonitor) ProcessMsg ¶
func (hm *HeartbeatMonitor) ProcessMsg(sender uint64, msg *smartbftprotos.Message)
ProcessMsg handles an incoming heartbeat. If the sender and msg.View equal what we expect, and the timeout had not expired yet, the timeout is extended.
type HeartbeatTimeoutHandler ¶
HeartbeatTimeoutHandler defines who to call when a heartbeat timeout expires.
type InFlightData ¶
type InFlightData struct {
// contains filtered or unexported fields
}
InFlightData records proposals that are in-flight, as well as their corresponding prepares.
func (*InFlightData) InFlightProposal ¶
func (ifp *InFlightData) InFlightProposal() *types.Proposal
InFlightData returns an in-flight proposal or nil if there is no such.
func (*InFlightData) IsInFlightPrepared ¶
func (ifp *InFlightData) IsInFlightPrepared() bool
func (*InFlightData) StorePrepares ¶
func (ifp *InFlightData) StorePrepares(view, seq uint64)
func (*InFlightData) StoreProposal ¶
func (ifp *InFlightData) StoreProposal(prop types.Proposal)
Store stores an in-flight proposal.
type LeaderMonitor ¶
type PersistedState ¶
type PersistedState struct { InFlightProposal *InFlightData Entries [][]byte Logger api.Logger WAL api.WriteAheadLog }
func (*PersistedState) Restore ¶
func (ps *PersistedState) Restore(v *View) error
func (*PersistedState) Save ¶
func (ps *PersistedState) Save(msgToSave *smartbftprotos.SavedMessage) error
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool implements requests pool, maintains pool of given size provided during construction. In case there are more incoming request than given size it will block during submit until there will be place to submit new ones.
func NewPool ¶
func NewPool(log api.Logger, inspector api.RequestInspector, th RequestTimeoutHandler, options PoolOptions) *Pool
NewPool constructs new requests pool
func (*Pool) Close ¶
func (rp *Pool) Close()
Close removes all the requests, stops all the timeout timers.
func (*Pool) NextRequests ¶
NextRequests returns the next requests to be batched. It returns at most n request, in a newly allocated slice.
func (*Pool) RemoveRequest ¶
func (rp *Pool) RemoveRequest(requestInfo types.RequestInfo) error
RemoveRequest removes the given request from the pool
func (*Pool) RestartTimers ¶
func (rp *Pool) RestartTimers()
RestartTimers restarts all the timeout timers attached to the pending requests, as RequestTimeout, and re-allows submission of new requests.
func (*Pool) StopTimers ¶
func (rp *Pool) StopTimers()
StopTimers stops all the timeout timers attached to the pending requests, and marks the pool as "stopped". This which prevents submission of new requests, and renewal of timeouts by timer go-routines that where running at the time of the call to StopTimers().
type PoolOptions ¶
type ProposalMaker ¶
type ProposalMaker struct { N uint64 SelfID uint64 Decider Decider FailureDetector FailureDetector Sync Synchronizer Logger api.Logger Comm Comm Verifier api.Verifier Signer api.Signer State State // contains filtered or unexported fields }
func (*ProposalMaker) NewProposer ¶
func (pm *ProposalMaker) NewProposer(leader, proposalSequence, viewNum uint64, quorumSize int) Proposer
type ProposerBuilder ¶
type RequestPool ¶
type RequestTimeoutHandler ¶
type RequestTimeoutHandler interface { // OnRequestTimeout is called when a request timeout expires. OnRequestTimeout(request []byte, requestInfo types.RequestInfo) // OnLeaderFwdRequestTimeout is called when a leader forwarding timeout expires. OnLeaderFwdRequestTimeout(request []byte, requestInfo types.RequestInfo) // OnAutoRemoveTimeout is called when a auto-remove timeout expires. OnAutoRemoveTimeout(requestInfo types.RequestInfo) }
RequestTimeoutHandler defines the methods called by request timeout timers created by time.AfterFunc. This interface is implemented by the bft.Controller.
type RequestsTimer ¶
type RequestsTimer interface { StopTimers() RestartTimers() RemoveRequest(request types.RequestInfo) error }
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
func NewScheduler ¶
type SignerMock ¶
type State ¶
type State interface { // Save saves a message. Save(message *protos.SavedMessage) error // Restore restores the given view to its latest state // before a crash, if applicable. Restore(*View) error }
type StateRecorder ¶
type StateRecorder struct {
SavedMessages []*smartbftprotos.SavedMessage
}
func (*StateRecorder) Restore ¶
func (*StateRecorder) Restore(_ *View) error
func (*StateRecorder) Save ¶
func (sr *StateRecorder) Save(message *smartbftprotos.SavedMessage) error
type Synchronizer ¶
type Synchronizer interface {
Sync()
}
type SynchronizerMock ¶
type SynchronizerMock interface { api.Synchronizer }
type TaskQueue ¶
type TaskQueue struct {
// contains filtered or unexported fields
}
func NewTaskQueue ¶
func NewTaskQueue() *TaskQueue
type VerifierMock ¶
type View ¶
type View struct { // Configuration SelfID uint64 N uint64 LeaderID uint64 Quorum int Number uint64 Decider Decider FailureDetector FailureDetector Sync Synchronizer Logger api.Logger Comm Comm Verifier api.Verifier Signer api.Signer ProposalSequence uint64 State State Phase Phase // contains filtered or unexported fields }
func (*View) GetMetadata ¶
type ViewChanger ¶
type ViewChanger struct { // Configuration SelfID uint64 N uint64 Logger api.Logger Comm Comm Signer api.Signer Verifier api.Verifier Application api.Application Synchronizer Synchronizer Checkpoint *types.Checkpoint InFlight *InFlightData Controller ViewController RequestsTimer RequestsTimer Ticker <-chan time.Time ResendTimeout time.Duration TimeoutViewChange time.Duration // contains filtered or unexported fields }
func (*ViewChanger) HandleMessage ¶
func (v *ViewChanger) HandleMessage(sender uint64, m *protos.Message)
HandleMessage passes a message to the view changer
func (*ViewChanger) InformNewView ¶
func (v *ViewChanger) InformNewView(view uint64)
InformNewView tells the view changer to advance to a new view number
func (*ViewChanger) Start ¶
func (v *ViewChanger) Start(startViewNumber uint64)
Start the view changer
func (*ViewChanger) StartViewChange ¶
func (v *ViewChanger) StartViewChange(stopView bool)
StartViewChange initiates a view change