diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index afa1d4d403..db1d0ba420 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1181,6 +1181,8 @@ func RegisterEthService(stack *node.Node, cfg *eth.Config) { if err == nil { err = stack.RegisterCallback(reflect.TypeOf(ð.Ethereum{}), func(service node.Service) error { if e, ok := service.(*eth.Ethereum); ok { + // The node lock will be held during the whole node setup procedure, so no extra + // lock operation is needed. rpcClient, err := stack.AttachLocked() if err != nil { return err diff --git a/les/server.go b/les/server.go index 56bd04f61c..617212166c 100644 --- a/les/server.go +++ b/les/server.go @@ -151,18 +151,22 @@ func (s *LesServer) SetBloomBitsIndexer(bloomIndexer *core.ChainIndexer) { // SetClient sets the rpc client and starts watching checkpoint contract if it is not yet watched. func (s *LesServer) SetClient(client *ethclient.Client) { - if addr, ok := registrar.RegistrarAddr[s.genesis]; ok { - if !atomic.CompareAndSwapInt32(&s.watching, 0, 1) { - return - } - registrar, err := registrar.NewRegistrar(addr, client) - if err != nil { - atomic.StoreInt32(&s.watching, 0) - return - } - s.registrar = registrar - go s.checkpointLoop(s.recoverCheckpoint()) + addr, ok := registrar.RegistrarAddr[s.genesis] + if !ok { + log.Info("The registrar contract is not deployed") + return } + registrar, err := registrar.NewRegistrar(addr, client) + if err != nil { + log.Info("Bind registrar contract failed", "err", err) + return + } + if !atomic.CompareAndSwapInt32(&s.watching, 0, 1) { + log.Info("Already bound and listening to registrar contract") + return + } + s.registrar = registrar + go s.checkpointLoop(s.recoverCheckpoint()) } // Stop stops the LES service