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).
This commit is contained in:
parent
2e231e690e
commit
435eacecb5
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue