bft

package
v0.0.0-...-496c6ee Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHeartbeatTimeout      = 60 * time.Second
	HeartbeatFrequency           = 10 // How much heart beats per timeout
	Leader                  Role = false
	Follower                Role = true
)
View Source
const (
	COMMITTED = iota
	PROPOSED
	PREPARED
	ABORT
)
View Source
const (
	DefaultRequestTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

func MarshalOrPanic

func MarshalOrPanic(msg proto.Message) []byte

func ValidateInFlight

func ValidateInFlight(inFlightProposal *protos.Proposal, lastSequence uint64) error

func ValidateLastDecision

func ValidateLastDecision(vd *protos.ViewData, quorum int, N uint64, verifier api.Verifier) (err error, lastSequence uint64)

Types

type ApplicationMock

type ApplicationMock interface {
	api.Application
}

type AssemblerMock

type AssemblerMock interface {
	api.Assembler
}

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 Batcher

type Batcher interface {
	NextBatch() [][]byte
	BatchRemainder(remainder [][]byte)
	PopRemainder() [][]byte
	Close()
	Reset()
}

type Comm

type Comm interface {
	api.Comm
	BroadcastConsensus(m *protos.Message)
}

type CommMock

type CommMock interface {
	api.Comm
	BroadcastConsensus(m *smartbftprotos.Message)
}

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) Stop

func (c *Controller) Stop()

Stop 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 Decider

type Decider interface {
	Decide(proposal types.Proposal, signatures []types.Signature, requests []types.RequestInfo)
}

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

type HeartbeatTimeoutHandler interface {
	OnHeartbeatTimeout(view uint64, leaderID uint64)
}

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 LeaderMonitor interface {
	ChangeRole(role Role, view uint64, leaderID uint64)
	ProcessMsg(sender uint64, msg *protos.Message)
	Close()
}

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 Phase

type Phase uint8

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

func (rp *Pool) NextRequests(n int) [][]byte

NextRequests returns the next requests to be batched. It returns at most n request, in a newly allocated slice.

func (*Pool) Prune

func (rp *Pool) Prune(predicate func([]byte) error)

Prune removes requests for which the given predicate returns error.

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) Size

func (rp *Pool) Size() int

Size returns the number of requests currently residing the pool

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().

func (*Pool) Submit

func (rp *Pool) Submit(request []byte) error

Submit a request into the pool, returns an error when request is already in the pool

type PoolOptions

type PoolOptions struct {
	QueueSize         int64
	RequestTimeout    time.Duration
	LeaderFwdTimeout  time.Duration
	AutoRemoveTimeout time.Duration
}

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 Proposer

type Proposer interface {
	Propose(proposal types.Proposal)
	Start()
	Abort()
	GetMetadata() []byte
	HandleMessage(sender uint64, m *protos.Message)
}

type ProposerBuilder

type ProposerBuilder interface {
	NewProposer(leader, proposalSequence, viewNum uint64, quorumSize int) Proposer
}

type RequestPool

type RequestPool interface {
	Prune(predicate func([]byte) error)
	Submit(request []byte) error
	Size() int
	NextRequests(n int) [][]byte
	RemoveRequest(request types.RequestInfo) error
	StopTimers()
	RestartTimers()
	Close()
}

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 Role

type Role bool

type Scheduler

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

func NewScheduler

func NewScheduler(timeChan <-chan time.Time) *Scheduler

func (*Scheduler) Schedule

func (s *Scheduler) Schedule(timeout time.Duration, f func()) Stopper

func (*Scheduler) Start

func (s *Scheduler) Start()

func (*Scheduler) Stop

func (s *Scheduler) Stop()

type SignerMock

type SignerMock interface {
	api.Signer
}

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 Stopper

type Stopper interface {
	Stop()
}

type Synchronizer

type Synchronizer interface {
	Sync()
}

type SynchronizerMock

type SynchronizerMock interface {
	api.Synchronizer
}

type Task

type Task struct {
	Deadline time.Time
	F        func()
	// contains filtered or unexported fields
}

func (*Task) Stop

func (t *Task) Stop()

type TaskQueue

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

func NewTaskQueue

func NewTaskQueue() *TaskQueue

func (*TaskQueue) DeQueue

func (q *TaskQueue) DeQueue() *Task

func (*TaskQueue) Enqueue

func (q *TaskQueue) Enqueue(t *Task)

func (TaskQueue) Size

func (q TaskQueue) Size() int

func (*TaskQueue) Top

func (q *TaskQueue) Top() *Task

type VerifierMock

type VerifierMock interface {
	api.Verifier
}

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) Abort

func (v *View) Abort()

Abort forces the view to end

func (*View) GetMetadata

func (v *View) GetMetadata() []byte

func (*View) HandleMessage

func (v *View) HandleMessage(sender uint64, m *protos.Message)

func (*View) Propose

func (v *View) Propose(proposal types.Proposal)

Propose broadcasts a prePrepare message with the given proposal

func (*View) Start

func (v *View) Start()

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

func (*ViewChanger) Stop

func (v *ViewChanger) Stop()

Stop the view changer

type ViewController

type ViewController interface {
	ViewChanged(newViewNumber uint64, newProposalSequence uint64)
	AbortView()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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