From a92c9596dced9a94b891fbf932c614d9dbb14481 Mon Sep 17 00:00:00 2001 From: muXxer Date: Thu, 28 Mar 2024 14:05:40 +0100 Subject: [PATCH] Move ConstructedEvent triggers --- .../consensus/slotgadget/totalweightslotgadget/gadget.go | 8 ++++---- .../sybilprotection/sybilprotectionv1/sybilprotection.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/protocol/engine/consensus/slotgadget/totalweightslotgadget/gadget.go b/pkg/protocol/engine/consensus/slotgadget/totalweightslotgadget/gadget.go index 63df6ec56..84dd24ec8 100644 --- a/pkg/protocol/engine/consensus/slotgadget/totalweightslotgadget/gadget.go +++ b/pkg/protocol/engine/consensus/slotgadget/totalweightslotgadget/gadget.go @@ -42,14 +42,16 @@ func NewProvider(opts ...options.Option[Gadget]) module.Provider[*engine.Engine, e.ConstructedEvent().OnTrigger(func() { g.seatManager = e.SybilProtection.SeatManager() - e.Events.BlockGadget.BlockConfirmed.Hook(g.trackVotes) - g.storeLastFinalizedSlotFunc = func(slot iotago.SlotIndex) { if err := e.Storage.Settings().SetLatestFinalizedSlot(slot); err != nil { g.errorHandler(ierrors.Wrap(err, "failed to set latest finalized slot")) } } + g.ConstructedEvent().Trigger() + + e.Events.BlockGadget.BlockConfirmed.Hook(g.trackVotes) + e.InitializedEvent().OnTrigger(func() { // Can't use setter here as it has a side effect. g.mutex.Lock() @@ -79,8 +81,6 @@ func New(subModule module.Module, engine *engine.Engine, opts ...options.Option[ g.ShutdownEvent().OnTrigger(func() { g.StoppedEvent().Trigger() }) - - g.ConstructedEvent().Trigger() }) } diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go index f9e1111d8..00acef023 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go @@ -63,6 +63,8 @@ func NewProvider(opts ...options.Option[SybilProtection]) module.Provider[*engin } } + s.ConstructedEvent().Trigger() + // When the engine is triggered initialized, snapshot has been read or database has been initialized properly, // so the committee should be available in the performance manager. e.InitializedEvent().OnTrigger(func() { @@ -99,8 +101,6 @@ func New(subModule module.Module, engine *engine.Engine, opts ...options.Option[ s.ShutdownEvent().OnTrigger(func() { s.StoppedEvent().Trigger() }) - - s.ConstructedEvent().Trigger() }) }