ceremonyclient/node/consensus/global/factory.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

182 lines
6.0 KiB
Go

package global
import (
"github.com/pkg/errors"
"go.uber.org/zap"
"source.quilibrium.com/quilibrium/monorepo/config"
"source.quilibrium.com/quilibrium/monorepo/consensus"
"source.quilibrium.com/quilibrium/monorepo/node/consensus/events"
consensustime "source.quilibrium.com/quilibrium/monorepo/node/consensus/time"
"source.quilibrium.com/quilibrium/monorepo/node/execution/intrinsics/global/compat"
"source.quilibrium.com/quilibrium/monorepo/protobufs"
"source.quilibrium.com/quilibrium/monorepo/types/channel"
"source.quilibrium.com/quilibrium/monorepo/types/compiler"
tconsensus "source.quilibrium.com/quilibrium/monorepo/types/consensus"
"source.quilibrium.com/quilibrium/monorepo/types/crypto"
"source.quilibrium.com/quilibrium/monorepo/types/hypergraph"
"source.quilibrium.com/quilibrium/monorepo/types/keys"
tp2p "source.quilibrium.com/quilibrium/monorepo/types/p2p"
"source.quilibrium.com/quilibrium/monorepo/types/store"
)
// ConsensusEngineFactory provides a factory method for creating properly wired
// GlobalConsensusEngine instances with time reels and event distributors
type ConsensusEngineFactory struct {
logger *zap.Logger
config *config.Config
pubsub tp2p.PubSub
hypergraph hypergraph.Hypergraph
keyManager keys.KeyManager
keyStore store.KeyStore
frameProver crypto.FrameProver
inclusionProver crypto.InclusionProver
signerRegistry tconsensus.SignerRegistry
proverRegistry tconsensus.ProverRegistry
dynamicFeeManager tconsensus.DynamicFeeManager
appFrameValidator tconsensus.AppFrameValidator
frameValidator tconsensus.GlobalFrameValidator
difficultyAdjuster tconsensus.DifficultyAdjuster
rewardIssuance tconsensus.RewardIssuance
clockStore store.ClockStore
inboxStore store.InboxStore
hypergraphStore store.HypergraphStore
shardsStore store.ShardsStore
workerStore store.WorkerStore
consensusStore consensus.ConsensusStore[*protobufs.ProposalVote]
encryptedChannel channel.EncryptedChannel
bulletproofProver crypto.BulletproofProver
verEnc crypto.VerifiableEncryptor
decafConstructor crypto.DecafConstructor
compiler compiler.CircuitCompiler
blsConstructor crypto.BlsConstructor
peerInfoManager tp2p.PeerInfoManager
}
// NewConsensusEngineFactory creates a new factory for consensus engines
func NewConsensusEngineFactory(
logger *zap.Logger,
config *config.Config,
pubsub tp2p.PubSub,
hypergraph hypergraph.Hypergraph,
keyManager keys.KeyManager,
keyStore store.KeyStore,
frameProver crypto.FrameProver,
inclusionProver crypto.InclusionProver,
signerRegistry tconsensus.SignerRegistry,
proverRegistry tconsensus.ProverRegistry,
dynamicFeeManager tconsensus.DynamicFeeManager,
appFrameValidator tconsensus.AppFrameValidator,
frameValidator tconsensus.GlobalFrameValidator,
difficultyAdjuster tconsensus.DifficultyAdjuster,
rewardIssuance tconsensus.RewardIssuance,
clockStore store.ClockStore,
inboxStore store.InboxStore,
hypergraphStore store.HypergraphStore,
shardsStore store.ShardsStore,
workerStore store.WorkerStore,
consensusStore consensus.ConsensusStore[*protobufs.ProposalVote],
encryptedChannel channel.EncryptedChannel,
bulletproofProver crypto.BulletproofProver,
verEnc crypto.VerifiableEncryptor,
decafConstructor crypto.DecafConstructor,
compiler compiler.CircuitCompiler,
blsConstructor crypto.BlsConstructor,
peerInfoManager tp2p.PeerInfoManager,
) *ConsensusEngineFactory {
// Initialize peer seniority data
compat.RebuildPeerSeniority(uint(config.P2P.Network))
return &ConsensusEngineFactory{
logger: logger,
config: config,
pubsub: pubsub,
hypergraph: hypergraph,
keyManager: keyManager,
keyStore: keyStore,
frameProver: frameProver,
inclusionProver: inclusionProver,
signerRegistry: signerRegistry,
proverRegistry: proverRegistry,
dynamicFeeManager: dynamicFeeManager,
appFrameValidator: appFrameValidator,
frameValidator: frameValidator,
difficultyAdjuster: difficultyAdjuster,
rewardIssuance: rewardIssuance,
clockStore: clockStore,
inboxStore: inboxStore,
hypergraphStore: hypergraphStore,
shardsStore: shardsStore,
workerStore: workerStore,
consensusStore: consensusStore,
encryptedChannel: encryptedChannel,
bulletproofProver: bulletproofProver,
verEnc: verEnc,
decafConstructor: decafConstructor,
compiler: compiler,
blsConstructor: blsConstructor,
peerInfoManager: peerInfoManager,
}
}
// CreateGlobalConsensusEngine creates a new GlobalConsensusEngine
func (f *ConsensusEngineFactory) CreateGlobalConsensusEngine(
frameTimeMillis int64,
) (*GlobalConsensusEngine, *consensustime.GlobalTimeReel, error) {
// Create the global time reel
globalTimeReel, err := consensustime.NewGlobalTimeReel(
f.logger,
f.proverRegistry,
f.clockStore,
f.config.P2P.Network,
f.config.Engine.ArchiveMode,
)
if err != nil {
return nil, nil, errors.Wrap(err, "create global time reel")
}
// Create the event distributor with channel from the global time reel
eventDistributor := events.NewGlobalEventDistributor(
globalTimeReel.GetEventCh(),
)
// Create the consensus engine with the wired event distributor and time reel
engine, err := NewGlobalConsensusEngine(
f.logger,
f.config,
frameTimeMillis,
f.pubsub,
f.hypergraph,
f.keyManager,
f.keyStore,
f.frameProver,
f.inclusionProver,
f.signerRegistry,
f.proverRegistry,
f.dynamicFeeManager,
f.appFrameValidator,
f.frameValidator,
f.difficultyAdjuster,
f.rewardIssuance,
eventDistributor,
globalTimeReel,
f.clockStore,
f.inboxStore,
f.hypergraphStore,
f.shardsStore,
f.consensusStore,
f.workerStore,
f.encryptedChannel,
f.bulletproofProver,
f.verEnc,
f.decafConstructor,
f.compiler,
f.blsConstructor,
f.peerInfoManager,
)
if err != nil {
return nil, nil, errors.Wrap(err, "create global consensus engine")
}
return engine, globalTimeReel, nil
}