@@ -20,6 +20,7 @@ import (
2020 "github.com/onflow/flow-go/consensus"
2121 "github.com/onflow/flow-go/consensus/hotstuff"
2222 "github.com/onflow/flow-go/consensus/hotstuff/committees"
23+ "github.com/onflow/flow-go/consensus/hotstuff/notifications"
2324 "github.com/onflow/flow-go/consensus/hotstuff/notifications/pubsub"
2425 "github.com/onflow/flow-go/consensus/hotstuff/pacemaker/timeout"
2526 hotsignature "github.com/onflow/flow-go/consensus/hotstuff/signature"
@@ -37,7 +38,6 @@ import (
3738 "github.com/onflow/flow-go/model/flow"
3839 "github.com/onflow/flow-go/model/flow/filter"
3940 "github.com/onflow/flow-go/module"
40- "github.com/onflow/flow-go/module/buffer"
4141 builder "github.com/onflow/flow-go/module/builder/collection"
4242 "github.com/onflow/flow-go/module/chainsync"
4343 "github.com/onflow/flow-go/module/epochs"
@@ -50,7 +50,6 @@ import (
5050 badgerState "github.com/onflow/flow-go/state/protocol/badger"
5151 "github.com/onflow/flow-go/state/protocol/blocktimer"
5252 "github.com/onflow/flow-go/state/protocol/events/gadgets"
53- storagekv "github.com/onflow/flow-go/storage/badger"
5453)
5554
5655func main () {
@@ -80,15 +79,14 @@ func main() {
8079 clusterComplianceConfig modulecompliance.Config
8180
8281 pools * epochpool.TransactionPools // epoch-scoped transaction pools
83- followerBuffer * buffer.PendingBlocks // pending block cache for follower
8482 finalizationDistributor * pubsub.FinalizationDistributor
8583 finalizedHeader * consync.FinalizedHeaderCache
8684
8785 push * pusher.Engine
8886 ing * ingest.Engine
8987 mainChainSyncCore * chainsync.Core
9088 followerCore * hotstuff.FollowerLoop // follower hotstuff logic
91- followerEng * followereng.Engine
89+ followerEng * followereng.ComplianceEngine
9290 colMetrics module.CollectionMetrics
9391 err error
9492
@@ -173,6 +171,11 @@ func main() {
173171
174172 nodeBuilder .
175173 PreInit (cmd .DynamicStartPreInit ).
174+ Module ("finalization distributor" , func (node * cmd.NodeConfig ) error {
175+ finalizationDistributor = pubsub .NewFinalizationDistributor ()
176+ finalizationDistributor .AddConsumer (notifications .NewSlashingViolationsConsumer (node .Logger ))
177+ return nil
178+ }).
176179 Module ("mutable follower state" , func (node * cmd.NodeConfig ) error {
177180 // For now, we only support state implementations from package badger.
178181 // If we ever support different implementations, the following can be replaced by a type-aware factory
@@ -199,10 +202,6 @@ func main() {
199202 err := node .Metrics .Mempool .Register (metrics .ResourceTransaction , pools .CombinedSize )
200203 return err
201204 }).
202- Module ("pending block cache" , func (node * cmd.NodeConfig ) error {
203- followerBuffer = buffer .NewPendingBlocks ()
204- return nil
205- }).
206205 Module ("metrics" , func (node * cmd.NodeConfig ) error {
207206 colMetrics = metrics .NewCollectionCollector (node .Tracer )
208207 return nil
@@ -251,6 +250,14 @@ func main() {
251250
252251 return validator , err
253252 }).
253+ Component ("finalized snapshot" , func (node * cmd.NodeConfig ) (module.ReadyDoneAware , error ) {
254+ finalizedHeader , err = consync .NewFinalizedHeaderCache (node .Logger , node .State , finalizationDistributor )
255+ if err != nil {
256+ return nil , fmt .Errorf ("could not create finalized snapshot cache: %w" , err )
257+ }
258+
259+ return finalizedHeader , nil
260+ }).
254261 Component ("consensus committee" , func (node * cmd.NodeConfig ) (module.ReadyDoneAware , error ) {
255262 // initialize consensus committee's membership state
256263 // This committee state is for the HotStuff follower, which follows the MAIN CONSENSUS Committee
@@ -270,7 +277,6 @@ func main() {
270277 packer := hotsignature .NewConsensusSigDataPacker (mainConsensusCommittee )
271278 // initialize the verifier for the protocol consensus
272279 verifier := verification .NewCombinedVerifier (mainConsensusCommittee , packer )
273- finalizationDistributor = pubsub .NewFinalizationDistributor ()
274280 // creates a consensus follower with noop consumer as the notifier
275281 followerCore , err = consensus .NewFollower (
276282 node .Logger ,
@@ -290,45 +296,47 @@ func main() {
290296 return followerCore , nil
291297 }).
292298 Component ("follower engine" , func (node * cmd.NodeConfig ) (module.ReadyDoneAware , error ) {
293- // initialize cleaner for DB
294- cleaner := storagekv .NewCleaner (node .Logger , node .DB , node .Metrics .CleanCollector , flow .DefaultValueLogGCFrequency )
295-
296299 packer := hotsignature .NewConsensusSigDataPacker (mainConsensusCommittee )
297300 // initialize the verifier for the protocol consensus
298301 verifier := verification .NewCombinedVerifier (mainConsensusCommittee , packer )
299302
300303 validator := validator .New (mainConsensusCommittee , verifier )
301304
302- followerEng , err = followereng .New (
305+ var heroCacheCollector module.HeroCacheMetrics = metrics .NewNoopCollector ()
306+ if node .HeroCacheMetricsEnable {
307+ heroCacheCollector = metrics .FollowerCacheMetrics (node .MetricsRegisterer )
308+ }
309+
310+ core , err := followereng .NewComplianceCore (
303311 node .Logger ,
304- node .Network ,
305- node .Me ,
306- node .Metrics .Engine ,
307312 node .Metrics .Mempool ,
308- cleaner ,
309- node .Storage .Headers ,
310- node .Storage .Payloads ,
313+ heroCacheCollector ,
314+ finalizationDistributor ,
311315 followerState ,
312- followerBuffer ,
313316 followerCore ,
314317 validator ,
315318 mainChainSyncCore ,
316319 node .Tracer ,
317- followereng . WithComplianceOptions ( modulecompliance .WithSkipNewProposalsThreshold (node .ComplianceConfig .SkipNewProposalsThreshold ) ),
320+ modulecompliance .WithSkipNewProposalsThreshold (node .ComplianceConfig .SkipNewProposalsThreshold ),
318321 )
319322 if err != nil {
320- return nil , fmt .Errorf ("could not create follower engine : %w" , err )
323+ return nil , fmt .Errorf ("could not create follower core : %w" , err )
321324 }
322325
323- return followerEng , nil
324- }).
325- Component ("finalized snapshot" , func (node * cmd.NodeConfig ) (module.ReadyDoneAware , error ) {
326- finalizedHeader , err = consync .NewFinalizedHeaderCache (node .Logger , node .State , finalizationDistributor )
326+ followerEng , err = followereng .NewComplianceLayer (
327+ node .Logger ,
328+ node .Network ,
329+ node .Me ,
330+ node .Metrics .Engine ,
331+ node .Storage .Headers ,
332+ finalizedHeader .Get (),
333+ core ,
334+ )
327335 if err != nil {
328- return nil , fmt .Errorf ("could not create finalized snapshot cache : %w" , err )
336+ return nil , fmt .Errorf ("could not create follower engine : %w" , err )
329337 }
330338
331- return finalizedHeader , nil
339+ return followerEng , nil
332340 }).
333341 Component ("main chain sync engine" , func (node * cmd.NodeConfig ) (module.ReadyDoneAware , error ) {
334342
0 commit comments