From 435eacecb587571887ef547d78f82d67f026db28 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Tue, 18 Aug 2020 10:44:56 +0200 Subject: [PATCH] Handle wallet initialization StartWallet was called before service initialization. After the recent changes this call was moved after initialization, but the geth system automatically start services. This meant that `IsStarted()` returned true, although the reactor was not started, and only after calling `StopWallet()` and `StartWallet()` again the system would reach the right state. This commit changes the behavior so that we only check whether the reactor has been started when calling `IsStarted()` and we allow multiple calls to `Start()` on the signal service, which won't return an error (it's a noop if callled multiple times). --- VERSION | 2 +- services/wallet/service.go | 5 ++++- services/wallet/transmitter.go | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 731d500dc..22a3057d2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.56.8 +0.56.9 diff --git a/services/wallet/service.go b/services/wallet/service.go index 2ae71d65f..2c8e33104 100644 --- a/services/wallet/service.go +++ b/services/wallet/service.go @@ -32,6 +32,7 @@ type Service struct { reactor *Reactor signals *SignalsTransmitter client *ethclient.Client + started bool group *Group accountsFeed *event.Feed @@ -55,6 +56,7 @@ func (s *Service) StartReactor(client *ethclient.Client, accounts []common.Addre s.group.Add(func(ctx context.Context) error { return WatchAccountsChanges(ctx, s.accountsFeed, accounts, reactor) }) + s.started = true return nil } @@ -68,6 +70,7 @@ func (s *Service) StopReactor() error { s.group.Stop() s.group.Wait() } + s.started = false return nil } @@ -153,5 +156,5 @@ func mapToList(m map[common.Address]struct{}) []common.Address { } func (s *Service) IsStarted() bool { - return s.group != nil + return s.started } diff --git a/services/wallet/transmitter.go b/services/wallet/transmitter.go index 14d99b9b5..d31d34069 100644 --- a/services/wallet/transmitter.go +++ b/services/wallet/transmitter.go @@ -24,7 +24,8 @@ type SignalsTransmitter struct { // Start runs loop in background. func (tmr *SignalsTransmitter) Start() error { if tmr.quit != nil { - return errAlreadyRunning + // already running, nothing to do + return nil } tmr.quit = make(chan struct{}) events := make(chan Event, 10)