mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-21 18:37:26 +08:00
* 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>
105 lines
2.7 KiB
Go
105 lines
2.7 KiB
Go
package pubsub
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"source.quilibrium.com/quilibrium/monorepo/consensus"
|
|
"source.quilibrium.com/quilibrium/monorepo/consensus/models"
|
|
)
|
|
|
|
// CommunicatorDistributor ingests outbound consensus messages from HotStuff's
|
|
// core logic and distributes them to consumers. This logic only runs inside
|
|
// active consensus participants proposing states, voting, collecting +
|
|
// aggregating votes to QCs, and participating in the pacemaker (sending
|
|
// timeouts, collecting + aggregating timeouts to TCs).
|
|
// Concurrency safe.
|
|
type CommunicatorDistributor[StateT models.Unique, VoteT models.Unique] struct {
|
|
consumers []consensus.CommunicatorConsumer[StateT, VoteT]
|
|
lock sync.RWMutex
|
|
}
|
|
|
|
var _ consensus.CommunicatorConsumer[*nilUnique, *nilUnique] = (*CommunicatorDistributor[*nilUnique, *nilUnique])(nil)
|
|
|
|
func NewCommunicatorDistributor[
|
|
StateT models.Unique,
|
|
VoteT models.Unique,
|
|
]() *CommunicatorDistributor[StateT, VoteT] {
|
|
return &CommunicatorDistributor[StateT, VoteT]{}
|
|
}
|
|
|
|
func (d *CommunicatorDistributor[StateT, VoteT]) AddCommunicatorConsumer(
|
|
consumer consensus.CommunicatorConsumer[StateT, VoteT],
|
|
) {
|
|
d.lock.Lock()
|
|
defer d.lock.Unlock()
|
|
d.consumers = append(d.consumers, consumer)
|
|
}
|
|
|
|
func (d *CommunicatorDistributor[StateT, VoteT]) OnOwnVote(
|
|
vote *VoteT,
|
|
recipientID models.Identity,
|
|
) {
|
|
d.lock.RLock()
|
|
defer d.lock.RUnlock()
|
|
for _, s := range d.consumers {
|
|
s.OnOwnVote(vote, recipientID)
|
|
}
|
|
}
|
|
|
|
func (d *CommunicatorDistributor[StateT, VoteT]) OnOwnTimeout(
|
|
timeout *models.TimeoutState[VoteT],
|
|
) {
|
|
d.lock.RLock()
|
|
defer d.lock.RUnlock()
|
|
for _, s := range d.consumers {
|
|
s.OnOwnTimeout(timeout)
|
|
}
|
|
}
|
|
|
|
func (d *CommunicatorDistributor[StateT, VoteT]) OnOwnProposal(
|
|
proposal *models.SignedProposal[StateT, VoteT],
|
|
targetPublicationTime time.Time,
|
|
) {
|
|
d.lock.RLock()
|
|
defer d.lock.RUnlock()
|
|
for _, s := range d.consumers {
|
|
s.OnOwnProposal(proposal, targetPublicationTime)
|
|
}
|
|
}
|
|
|
|
// Type used to satisfy generic arguments in compiler time type assertion check
|
|
type nilUnique struct{}
|
|
|
|
// GetSignature implements models.Unique.
|
|
func (n *nilUnique) GetSignature() []byte {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
// GetTimestamp implements models.Unique.
|
|
func (n *nilUnique) GetTimestamp() uint64 {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
// Source implements models.Unique.
|
|
func (n *nilUnique) Source() models.Identity {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
// Clone implements models.Unique.
|
|
func (n *nilUnique) Clone() models.Unique {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
// GetRank implements models.Unique.
|
|
func (n *nilUnique) GetRank() uint64 {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
// Identity implements models.Unique.
|
|
func (n *nilUnique) Identity() models.Identity {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
var _ models.Unique = (*nilUnique)(nil)
|