cli: restart notary service on USR1

This commit is contained in:
Roman Khimov 2022-07-26 22:03:58 +03:00
parent 2adcf406d3
commit 9341bb6628
4 changed files with 28 additions and 7 deletions

View file

@ -427,15 +427,15 @@ func mkConsensus(config network.ServerConfig, chain *core.Blockchain, serv *netw
return srv, nil return srv, nil
} }
func mkP2PNotary(config network.ServerConfig, chain *core.Blockchain, serv *network.Server, log *zap.Logger) (*notary.Notary, error) { func mkP2PNotary(config config.P2PNotary, chain *core.Blockchain, serv *network.Server, log *zap.Logger) (*notary.Notary, error) {
if !config.P2PNotaryCfg.Enabled { if !config.Enabled {
return nil, nil return nil, nil
} }
if !chain.P2PSigExtensionsEnabled() { if !chain.P2PSigExtensionsEnabled() {
return nil, errors.New("P2PSigExtensions are disabled, but Notary service is enabled") return nil, errors.New("P2PSigExtensions are disabled, but Notary service is enabled")
} }
cfg := notary.Config{ cfg := notary.Config{
MainCfg: config.P2PNotaryCfg, MainCfg: config,
Chain: chain, Chain: chain,
Log: log, Log: log,
} }
@ -501,7 +501,7 @@ func startServer(ctx *cli.Context) error {
if err != nil { if err != nil {
return cli.NewExitError(err, 1) return cli.NewExitError(err, 1)
} }
_, err = mkP2PNotary(serverConfig, chain, serv, log) p2pNotary, err := mkP2PNotary(cfg.ApplicationConfiguration.P2PNotary, chain, serv, log)
if err != nil { if err != nil {
return cli.NewExitError(err, 1) return cli.NewExitError(err, 1)
} }
@ -576,6 +576,18 @@ Main:
oracleSrv.Start() oracleSrv.Start()
} }
} }
if p2pNotary != nil {
chain.SetNotary(nil)
p2pNotary.Shutdown()
}
p2pNotary, err = mkP2PNotary(cfgnew.ApplicationConfiguration.P2PNotary, chain, serv, log)
if err != nil {
log.Error("failed to create notary service", zap.Error(err))
break // Keep going.
}
if p2pNotary != nil && serv.IsInSync() {
p2pNotary.Start()
}
} }
cfg = cfgnew cfg = cfgnew
case <-grace.Done(): case <-grace.Done():

View file

@ -330,7 +330,15 @@ func (bc *Blockchain) SetOracle(mod native.OracleService) {
// SetNotary sets notary module. It doesn't protected by mutex and // SetNotary sets notary module. It doesn't protected by mutex and
// must be called before `bc.Run()` to avoid data race. // must be called before `bc.Run()` to avoid data race.
func (bc *Blockchain) SetNotary(mod native.NotaryService) { func (bc *Blockchain) SetNotary(mod native.NotaryService) {
bc.contracts.Designate.NotaryService.Store(mod) if mod != nil {
keys, _, err := bc.contracts.Designate.GetDesignatedByRole(bc.dao, noderoles.P2PNotary, bc.BlockHeight())
if err != nil {
bc.log.Error("failed to get notary key list")
return
}
mod.UpdateNotaryNodes(keys)
}
bc.contracts.Designate.NotaryService.Store(&mod)
} }
func (bc *Blockchain) init() error { func (bc *Blockchain) init() error {

View file

@ -242,8 +242,8 @@ func (s *Designate) notifyRoleChanged(v *roleData, r noderoles.Role) {
(*orc).UpdateOracleNodes(v.nodes.Copy()) (*orc).UpdateOracleNodes(v.nodes.Copy())
} }
case noderoles.P2PNotary: case noderoles.P2PNotary:
if ntr, _ := s.NotaryService.Load().(NotaryService); ntr != nil { if ntr, _ := s.NotaryService.Load().(*NotaryService); ntr != nil && *ntr != nil {
ntr.UpdateNotaryNodes(v.nodes.Copy()) (*ntr).UpdateNotaryNodes(v.nodes.Copy())
} }
case noderoles.StateValidator: case noderoles.StateValidator:
if s.StateRootService != nil { if s.StateRootService != nil {

View file

@ -219,6 +219,7 @@ func (n *Notary) Shutdown() {
if !n.started.CAS(true, false) { if !n.started.CAS(true, false) {
return return
} }
n.Config.Log.Info("stopping notary service")
close(n.stopCh) close(n.stopCh)
<-n.done <-n.done
} }