ceremonyclient/consensus/consensus_events.go
Cassandra Heart c797d482f9
v2.1.0.5 (#457)
* wip: conversion of hotstuff from flow into Q-oriented model

* bulk of tests

* remaining non-integration tests

* add integration test, adjust log interface, small tweaks

* further adjustments, restore full pacemaker shape

* add component lifecycle management+supervisor

* further refinements

* resolve timeout hanging

* mostly finalized state for consensus

* bulk of engine swap out

* lifecycle-ify most types

* wiring nearly complete, missing needed hooks for proposals

* plugged in, vetting message validation paths

* global consensus, plugged in and verified

* app shard now wired in too

* do not decode empty keys.yml (#456)

* remove obsolete engine.maxFrames config parameter (#454)

* default to Info log level unless debug is enabled (#453)

* respect config's  "logging" section params, remove obsolete single-file logging (#452)

* Trivial code cleanup aiming to reduce Go compiler warnings (#451)

* simplify range traversal

* simplify channel read for single select case

* delete rand.Seed() deprecated in Go 1.20 and no-op as of Go 1.24

* simplify range traversal

* simplify channel read for single select case

* remove redundant type from array

* simplify range traversal

* simplify channel read for single select case

* RC slate

* finalize 2.1.0.5

* Update comments in StrictMonotonicCounter

Fix comment formatting and clarify description.

---------

Co-authored-by: Black Swan <3999712+blacks1ne@users.noreply.github.com>
2025-11-11 05:00:17 -06:00

85 lines
3.7 KiB
Go

package consensus
import (
"context"
"time"
"source.quilibrium.com/quilibrium/monorepo/consensus/models"
"source.quilibrium.com/quilibrium/monorepo/lifecycle"
)
// PartialTimeoutCertificateCreated represents a notification emitted by the
// TimeoutProcessor component, whenever it has collected TimeoutStates from a
// superminority of consensus participants for a specific rank. Along with the
// rank, it reports the newest QuorumCertificate and TimeoutCertificate (for
// previous rank) discovered during timeout collection. Per convention, the
// newest QuorumCertificate is never nil, while the TimeoutCertificate for the
// previous rank might be nil.
type PartialTimeoutCertificateCreated struct {
Rank uint64
NewestQuorumCertificate models.QuorumCertificate
PriorRankTimeoutCertificate models.TimeoutCertificate
}
// EventHandler runs a state machine to process proposals, QuorumCertificate and
// local timeouts. Not concurrency safe.
type EventHandler[StateT models.Unique, VoteT models.Unique] interface {
// OnReceiveQuorumCertificate processes a valid quorumCertificate constructed
// by internal vote aggregator or discovered in TimeoutState. All inputs
// should be validated before feeding into this function. Assuming trusted
// data. No errors are expected during normal operation.
OnReceiveQuorumCertificate(quorumCertificate models.QuorumCertificate) error
// OnReceiveTimeoutCertificate processes a valid timeoutCertificate
// constructed by internal timeout aggregator, discovered in TimeoutState 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.
OnReceiveTimeoutCertificate(
timeoutCertificate models.TimeoutCertificate,
) error
// OnReceiveProposal processes a state 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.
OnReceiveProposal(proposal *models.SignedProposal[StateT, VoteT]) error
// OnLocalTimeout handles a local timeout event by creating a
// models.TimeoutState and broadcasting it. No errors are expected during
// normal operation.
OnLocalTimeout() error
// OnPartialTimeoutCertificateCreated handles notification produces by the
// internal timeout aggregator. If the notification is for the current rank,
// a corresponding models.TimeoutState is broadcast to the consensus
// committee. No errors are expected during normal operation.
OnPartialTimeoutCertificateCreated(
partialTimeoutCertificate *PartialTimeoutCertificateCreated,
) error
// TimeoutChannel returns a channel that sends a signal on timeout.
TimeoutChannel() <-chan time.Time
// 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.
Start(ctx context.Context) error
}
// EventLoop performs buffer and processing of incoming proposals and QCs.
type EventLoop[StateT models.Unique, VoteT models.Unique] interface {
lifecycle.Component
TimeoutCollectorConsumer[VoteT]
VoteCollectorConsumer[VoteT]
SubmitProposal(proposal *models.SignedProposal[StateT, VoteT])
}
// FollowerLoop only follows certified states, does not actively process the
// collection of proposals and QC/TCs.
type FollowerLoop[StateT models.Unique, VoteT models.Unique] interface {
AddCertifiedState(certifiedState *models.CertifiedState[StateT])
}