eventhandler

package
v0.33.37-atree-inlining Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: AGPL-3.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventHandler

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

EventHandler is the main handler for individual events that trigger state transition. It exposes API to handle one event at a time synchronously. EventHandler is *not concurrency safe*. Please use the EventLoop to ensure that only a single go-routine executes the EventHandler's algorithms. EventHandler is implemented in event-driven way, it reacts to incoming events and performs certain actions. It doesn't perform any actions on its own. There are 3 main responsibilities of EventHandler, vote, propose, timeout. There are specific scenarios that lead to each of those actions.

  • create vote: voting logic is triggered by OnReceiveProposal, after receiving proposal we have all required information to create a valid vote. Compliance engine makes sure that we receive proposals, whose parents are known. Creating a vote can be triggered ONLY by receiving proposal.
  • create timeout: creating model.TimeoutObject[TO] is triggered by OnLocalTimeout, after reaching deadline for current round. EventHandler gets notified about it and has to create a model.TimeoutObject and broadcast it to other replicas. Creating a TO can be triggered by reaching round deadline or triggered as part of Bracha broadcast when superminority of replicas have contributed to TC creation and created a partial TC.
  • create a proposal: proposing logic is more complicated. Creating a proposal is triggered by the EventHandler receiving a QC or TC that induces a view change to a view where the replica is primary. As an edge case, the EventHandler can receive a QC or TC that triggers the view change, but we can't create a proposal in case we are missing parent block the newest QC refers to. In case we already have the QC, but are still missing the respective parent, OnReceiveProposal can trigger the proposing logic as well, but only when receiving proposal for view lower than active view. To summarize, to make a valid proposal for view N we need to have a QC or TC for N-1 and know the proposal with blockID NewestQC.BlockID.

Not concurrency safe.

func NewEventHandler added in v0.23.9

func NewEventHandler(
	log zerolog.Logger,
	paceMaker hotstuff.PaceMaker,
	blockProducer hotstuff.BlockProducer,
	forks hotstuff.Forks,
	persist hotstuff.Persister,
	committee hotstuff.Replicas,
	safetyRules hotstuff.SafetyRules,
	notifier hotstuff.Consumer,
) (*EventHandler, error)

NewEventHandler creates an EventHandler instance with initial components.

func (*EventHandler) OnLocalTimeout

func (e *EventHandler) OnLocalTimeout() error

OnLocalTimeout handles a local timeout event by creating a model.TimeoutObject and broadcasting it. No errors are expected during normal operation.

func (*EventHandler) OnPartialTcCreated added in v0.29.0

func (e *EventHandler) OnPartialTcCreated(partialTC *hotstuff.PartialTcCreated) error

OnPartialTcCreated handles notification produces by the internal timeout aggregator. If the notification is for the current view, a corresponding model.TimeoutObject is broadcast to the consensus committee. No errors are expected during normal operation.

func (*EventHandler) OnReceiveProposal

func (e *EventHandler) OnReceiveProposal(proposal *model.Proposal) error

OnReceiveProposal processes a block proposal received from another HotStuff consensus participant. All inputs should be validated before feeding into this function. Assuming trusted data. No errors are expected during normal operation.

func (*EventHandler) OnReceiveQc added in v0.29.0

func (e *EventHandler) OnReceiveQc(qc *flow.QuorumCertificate) error

OnReceiveQc processes a valid qc constructed by internal vote aggregator or discovered in TimeoutObject. All inputs should be validated before feeding into this function. Assuming trusted data. No errors are expected during normal operation.

func (*EventHandler) OnReceiveTc added in v0.29.0

func (e *EventHandler) OnReceiveTc(tc *flow.TimeoutCertificate) error

OnReceiveTc processes a valid tc constructed by internal timeout aggregator, discovered in TimeoutObject or broadcast over the network. All inputs should be validated before feeding into this function. Assuming trusted data. No errors are expected during normal operation.

func (*EventHandler) Start

func (e *EventHandler) Start(ctx context.Context) error

Start starts the event handler. No errors are expected during normal operation. CAUTION: EventHandler is not concurrency safe. The Start method must be executed by the same goroutine that also calls the other business logic methods, or concurrency safety has to be implemented externally.

func (*EventHandler) TimeoutChannel

func (e *EventHandler) TimeoutChannel() <-chan time.Time

TimeoutChannel returns the channel for subscribing the waiting timeout on receiving block or votes for the current view.

Jump to

Keyboard shortcuts

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