diff --git a/plugins/dashboard/drng_livefeed.go b/plugins/dashboard/drng_livefeed.go index 3877ed0e2d1a0e2d3cb286812fa8d3ecfc171440..8b814972617e5e9cfe9e4f1c215ef055f474d0d2 100644 --- a/plugins/dashboard/drng_livefeed.go +++ b/plugins/dashboard/drng_livefeed.go @@ -32,26 +32,25 @@ func configureDrngLiveFeed() { } func runDrngLiveFeed() { - newMsgRateLimiter := time.NewTicker(time.Second / 10) - notifyNewRandomness := events.NewClosure(func(message state.Randomness) { - select { - case <-newMsgRateLimiter.C: - drngLiveFeedWorkerPool.TrySubmit(message) - default: - } - }) - daemon.BackgroundWorker("Dashboard[DRNGUpdater]", func(shutdownSignal <-chan struct{}) { - if !drng.Enabled() { - return - } + newMsgRateLimiter := time.NewTicker(time.Second / 10) + defer newMsgRateLimiter.Stop() + + notifyNewRandomness := events.NewClosure(func(message state.Randomness) { + select { + case <-newMsgRateLimiter.C: + drngLiveFeedWorkerPool.TrySubmit(message) + default: + } + }) drng.Instance().Events.Randomness.Attach(notifyNewRandomness) + drngLiveFeedWorkerPool.Start() + defer drngLiveFeedWorkerPool.Stop() + <-shutdownSignal log.Info("Stopping Dashboard[DRNGUpdater] ...") drng.Instance().Events.Randomness.Detach(notifyNewRandomness) - newMsgRateLimiter.Stop() - drngLiveFeedWorkerPool.Stop() log.Info("Stopping Dashboard[DRNGUpdater] ... done") }, shutdown.PriorityDashboard) } diff --git a/plugins/dashboard/plugin.go b/plugins/dashboard/plugin.go index 774bfc5f169a3e17fa67df41ab7da467af2c0602..2fab6b08b8298685d3a009c4d430e7f36184aedb 100644 --- a/plugins/dashboard/plugin.go +++ b/plugins/dashboard/plugin.go @@ -14,6 +14,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/autopeering/local" "github.com/iotaledger/goshimmer/plugins/banner" "github.com/iotaledger/goshimmer/plugins/config" + "github.com/iotaledger/goshimmer/plugins/drng" "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/goshimmer/plugins/messagelayer" "github.com/iotaledger/goshimmer/plugins/metrics" @@ -77,7 +78,11 @@ func run(plugin *node.Plugin) { }, shutdown.PriorityDashboard) runLiveFeed() - runDrngLiveFeed() + + // run dRNG live feed if dRNG plugin is enabled + if !node.IsSkipped(drng.Plugin) { + runDrngLiveFeed() + } // allow any origin for websocket connections upgrader.CheckOrigin = func(r *http.Request) bool { diff --git a/plugins/drng/drng.go b/plugins/drng/drng.go index 6c879d607665be27bb2ab927e5f995998e5ffefe..ec1c7e371b4824588e66b0e19f83c256c6c4d449 100644 --- a/plugins/drng/drng.go +++ b/plugins/drng/drng.go @@ -10,6 +10,7 @@ import ( cbPayload "github.com/iotaledger/goshimmer/packages/binary/drng/subtypes/collectiveBeacon/payload" "github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/hive.go/crypto/ed25519" + "github.com/iotaledger/hive.go/logger" "github.com/mr-tron/base58/base58" ) @@ -19,6 +20,7 @@ var ( ) func configureDRNG() *drng.DRNG { + log = logger.NewLogger(PluginName) // parse identities of the committee members committeeMembers, err := parseCommitteeMembers() if err != nil { diff --git a/plugins/drng/plugin.go b/plugins/drng/plugin.go index 34afb9fe702103a33c7dfc410cb601d868bfdb67..294f564d4884d5654cec07b05caa91bead13072b 100644 --- a/plugins/drng/plugin.go +++ b/plugins/drng/plugin.go @@ -26,15 +26,14 @@ var ( log *logger.Logger ) -func configure(*node.Plugin) { - log = logger.NewLogger(PluginName) - instance = Instance() +func configure(_ *node.Plugin) { configureEvents() } func run(*node.Plugin) {} func configureEvents() { + instance := Instance() messagelayer.Tangle.Events.MessageSolid.Attach(events.NewClosure(func(cachedMessage *message.CachedMessage, cachedMessageMetadata *tangle.CachedMessageMetadata) { cachedMessageMetadata.Release() @@ -61,8 +60,3 @@ func configureEvents() { }) })) } - -// Enabled returns the enabled status of the plugin -func Enabled() bool { - return Plugin.Status != node.Disabled -}