cmd, les: polish a bit and add some annotation

This commit is contained in:
rjl493456442 2018-07-11 16:31:19 +08:00
parent d3d408ba81
commit f923674365
2 changed files with 17 additions and 11 deletions

View file

@ -1181,6 +1181,8 @@ func RegisterEthService(stack *node.Node, cfg *eth.Config) {
if err == nil {
err = stack.RegisterCallback(reflect.TypeOf(&eth.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

View file

@ -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) {
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 {
atomic.StoreInt32(&s.watching, 0)
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