Skip to content

Commit

Permalink
Feat: cleaned up engine
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoog committed Mar 12, 2024
1 parent 59204cf commit 80771cc
Showing 1 changed file with 32 additions and 34 deletions.
66 changes: 32 additions & 34 deletions pkg/protocol/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,58 +570,56 @@ func (e *Engine) initLatestCommitment() {
}

func (e *Engine) initReactiveModule(parentLogger log.Logger) (reactiveModule module.Module) {
logger := parentLogger.NewChildLogger("Engine", true)
reactiveModule = module.New(logger)
reactiveModule = module.New(parentLogger.NewChildLogger("Engine", true))

e.RootCommitment.LogUpdates(logger, log.LevelTrace, "RootCommitment")
e.LatestCommitment.LogUpdates(logger, log.LevelTrace, "LatestCommitment")
e.RootCommitment.LogUpdates(reactiveModule, log.LevelTrace, "RootCommitment")
e.LatestCommitment.LogUpdates(reactiveModule, log.LevelTrace, "LatestCommitment")

reactiveModule.ShutdownEvent().OnTrigger(func() {
subModules := []module.Module{
e.Scheduler,
e.TipSelection,
e.TipManager,
e.Attestations,
e.SyncManager,
e.Notarization,
e.Clock,
e.SlotGadget,
e.BlockGadget,
e.UpgradeOrchestrator,
e.SybilProtection,
e.Booker,
e.Ledger,
e.PostSolidFilter,
e.BlockDAG,
e.PreSolidFilter,
e.BlockRetainer,
e.TxRetainer,
}

reactiveModule.LogDebug("shutting down")

logger.UnsubscribeFromParentLogger()

// Shutdown should be performed in the reverse dataflow order.
e.BlockRequester.Shutdown()

module.TriggerAll(module.Module.ShutdownEvent, subModules...)
e.shutdownSubModules()

e.Workers.Shutdown()
e.Storage.Shutdown()

wg := module.WaitAll(module.Module.StoppedEvent, subModules...)
wg.Debug(module.Module.LogName)
wg.Wait()
e.StoppedEvent().Trigger()

reactiveModule.LogDebug("stopped")

e.StoppedEvent().Trigger()
})

return reactiveModule
}

func (e *Engine) shutdownSubModules() {
// shutdown should be performed in the reverse dataflow order.
shutdownOrder := []module.Module{
e.Scheduler,
e.TipSelection,
e.TipManager,
e.Attestations,
e.SyncManager,
e.Notarization,
e.Clock,
e.SlotGadget,
e.BlockGadget,
e.UpgradeOrchestrator,
e.SybilProtection,
e.Booker,
e.Ledger,
e.PostSolidFilter,
e.BlockDAG,
e.PreSolidFilter,
e.BlockRetainer,
e.TxRetainer,
}

module.TriggerAll(module.Module.ShutdownEvent, shutdownOrder...)
module.WaitAll(module.Module.StoppedEvent, shutdownOrder...).Wait()
}

// endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////

// region Options //////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 80771cc

Please sign in to comment.