From bc791bd801affb52db615b943b076978a954a3d1 Mon Sep 17 00:00:00 2001 From: capossele <angelocapossele@gmail.com> Date: Fri, 24 Apr 2020 08:54:13 +0100 Subject: [PATCH] :ok_hand: Updating code due to code review changes. --- plugins/dashboard/drng_livefeed.go | 27 +++++++++++++-------------- plugins/dashboard/plugin.go | 7 ++++++- plugins/drng/drng.go | 2 ++ plugins/drng/plugin.go | 10 ++-------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/plugins/dashboard/drng_livefeed.go b/plugins/dashboard/drng_livefeed.go index 3877ed0e..8b814972 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 774bfc5f..2fab6b08 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 6c879d60..ec1c7e37 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 34afb9fe..294f564d 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 -} -- GitLab