From 748d6885c9cb9f52d62079894927a0e97237eacb Mon Sep 17 00:00:00 2001 From: tycho garen Date: Thu, 17 Mar 2022 16:26:47 -0400 Subject: [PATCH] events: remove service aspects of event switch --- internal/consensus/state.go | 16 ---------------- libs/events/events.go | 10 ---------- libs/events/events_test.go | 11 ----------- 3 files changed, 37 deletions(-) diff --git a/internal/consensus/state.go b/internal/consensus/state.go index 92b5b84d6..52c08ebb0 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -456,10 +456,6 @@ func (cs *State) OnStart(ctx context.Context) error { } } - if err := cs.evsw.Start(ctx); err != nil { - return err - } - // Double Signing Risk Reduction if err := cs.checkDoubleSigningRisk(cs.Height); err != nil { return err @@ -514,24 +510,12 @@ func (cs *State) OnStop() { close(cs.onStopCh) - if cs.evsw.IsRunning() { - cs.evsw.Stop() - } - if cs.timeoutTicker.IsRunning() { cs.timeoutTicker.Stop() } // WAL is stopped in receiveRoutine. } -// Wait waits for the the main routine to return. -// NOTE: be sure to Stop() the event switch and drain -// any event channels or this may deadlock -func (cs *State) Wait() { - cs.evsw.Wait() - <-cs.done -} - // OpenWAL opens a file to log all consensus messages and timeouts for // deterministic accountability. func (cs *State) OpenWAL(ctx context.Context, walFile string) (WAL, error) { diff --git a/libs/events/events.go b/libs/events/events.go index 5ab5961f6..d96afd7bd 100644 --- a/libs/events/events.go +++ b/libs/events/events.go @@ -7,7 +7,6 @@ import ( "sync" "github.com/tendermint/tendermint/libs/log" - "github.com/tendermint/tendermint/libs/service" ) // ErrListenerWasRemoved is returned by AddEvent if the listener was removed. @@ -45,16 +44,11 @@ type Fireable interface { // They can be removed by calling either RemoveListenerForEvent or // RemoveListener (for all events). type EventSwitch interface { - service.Service Fireable - Stop() - AddListenerForEvent(listenerID, eventValue string, cb EventCallback) error } type eventSwitch struct { - service.BaseService - mtx sync.RWMutex eventCells map[string]*eventCell listeners map[string]*eventListener @@ -65,13 +59,9 @@ func NewEventSwitch(logger log.Logger) EventSwitch { eventCells: make(map[string]*eventCell), listeners: make(map[string]*eventListener), } - evsw.BaseService = *service.NewBaseService(logger, "EventSwitch", evsw) return evsw } -func (evsw *eventSwitch) OnStart(ctx context.Context) error { return nil } -func (evsw *eventSwitch) OnStop() {} - func (evsw *eventSwitch) AddListenerForEvent(listenerID, eventValue string, cb EventCallback) error { // Get/Create eventCell and listener. evsw.mtx.Lock() diff --git a/libs/events/events_test.go b/libs/events/events_test.go index 15f208e06..55e0103da 100644 --- a/libs/events/events_test.go +++ b/libs/events/events_test.go @@ -21,8 +21,6 @@ func TestAddListenerForEventFireOnce(t *testing.T) { logger := log.NewTestingLogger(t) evsw := NewEventSwitch(logger) - require.NoError(t, evsw.Start(ctx)) - t.Cleanup(evsw.Wait) messages := make(chan EventData) require.NoError(t, evsw.AddListenerForEvent("listener", "event", @@ -50,8 +48,6 @@ func TestAddListenerForEventFireMany(t *testing.T) { logger := log.NewTestingLogger(t) evsw := NewEventSwitch(logger) - require.NoError(t, evsw.Start(ctx)) - t.Cleanup(evsw.Wait) doneSum := make(chan uint64) doneSending := make(chan uint64) @@ -88,8 +84,6 @@ func TestAddListenerForDifferentEvents(t *testing.T) { logger := log.NewTestingLogger(t) evsw := NewEventSwitch(logger) - require.NoError(t, evsw.Start(ctx)) - t.Cleanup(evsw.Wait) doneSum := make(chan uint64) doneSending1 := make(chan uint64) @@ -151,9 +145,6 @@ func TestAddDifferentListenerForDifferentEvents(t *testing.T) { logger := log.NewTestingLogger(t) evsw := NewEventSwitch(logger) - require.NoError(t, evsw.Start(ctx)) - - t.Cleanup(evsw.Wait) doneSum1 := make(chan uint64) doneSum2 := make(chan uint64) @@ -247,8 +238,6 @@ func TestManageListenersAsync(t *testing.T) { logger := log.NewTestingLogger(t) evsw := NewEventSwitch(logger) - require.NoError(t, evsw.Start(ctx)) - t.Cleanup(evsw.Wait) doneSum1 := make(chan uint64) doneSum2 := make(chan uint64)