forked from TrueCloudLab/neoneo-go
rpc: add StartWhenSynchronized option, fix #2433
This commit is contained in:
parent
2593bb0535
commit
887fe0634d
5 changed files with 28 additions and 3 deletions
|
@ -506,9 +506,12 @@ func startServer(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
rpcServer := server.New(chain, cfg.ApplicationConfiguration.RPC, serv, oracleSrv, log, errChan)
|
rpcServer := server.New(chain, cfg.ApplicationConfiguration.RPC, serv, oracleSrv, log, errChan)
|
||||||
|
serv.AddService(&rpcServer)
|
||||||
|
|
||||||
go serv.Start(errChan)
|
go serv.Start(errChan)
|
||||||
|
if !cfg.ApplicationConfiguration.RPC.StartWhenSynchronized {
|
||||||
rpcServer.Start()
|
rpcServer.Start()
|
||||||
|
}
|
||||||
|
|
||||||
sighupCh := make(chan os.Signal, 1)
|
sighupCh := make(chan os.Signal, 1)
|
||||||
signal.Notify(sighupCh, syscall.SIGHUP)
|
signal.Notify(sighupCh, syscall.SIGHUP)
|
||||||
|
@ -530,12 +533,14 @@ Main:
|
||||||
log.Info("SIGHUP received, restarting rpc-server")
|
log.Info("SIGHUP received, restarting rpc-server")
|
||||||
rpcServer.Shutdown()
|
rpcServer.Shutdown()
|
||||||
rpcServer = server.New(chain, cfg.ApplicationConfiguration.RPC, serv, oracleSrv, log, errChan)
|
rpcServer = server.New(chain, cfg.ApplicationConfiguration.RPC, serv, oracleSrv, log, errChan)
|
||||||
|
serv.AddService(&rpcServer) // Replaces old one by service name.
|
||||||
|
if !cfg.ApplicationConfiguration.RPC.StartWhenSynchronized || serv.IsInSync() {
|
||||||
rpcServer.Start()
|
rpcServer.Start()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case <-grace.Done():
|
case <-grace.Done():
|
||||||
signal.Stop(sighupCh)
|
signal.Stop(sighupCh)
|
||||||
serv.Shutdown()
|
serv.Shutdown()
|
||||||
rpcServer.Shutdown()
|
|
||||||
break Main
|
break Main
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
docs/cli.md
11
docs/cli.md
|
@ -55,6 +55,17 @@ Or specify a different network with appropriate flag like this:
|
||||||
By default, the node will run in foreground using current standard output for
|
By default, the node will run in foreground using current standard output for
|
||||||
logging.
|
logging.
|
||||||
|
|
||||||
|
|
||||||
|
### Node synchronization
|
||||||
|
|
||||||
|
Most of the services (state validation, oracle, consensus and RPC if
|
||||||
|
configured with `StartWhenSynchronized` option) are only started after the
|
||||||
|
node is completely synchronizaed because running them before that is either
|
||||||
|
pointless or even dangerous. The node considers itself to be fully
|
||||||
|
synchronized with the network if it has more than `MinPeers` neighbours and if
|
||||||
|
at least 2/3 of them are known to have a height less than or equal to the
|
||||||
|
current height of the node.
|
||||||
|
|
||||||
### Restarting node services
|
### Restarting node services
|
||||||
|
|
||||||
To restart some node services without full node restart, send the SIGHUP
|
To restart some node services without full node restart, send the SIGHUP
|
||||||
|
|
|
@ -136,6 +136,7 @@ RPC:
|
||||||
MaxFindResultItems: 100
|
MaxFindResultItems: 100
|
||||||
MaxNEP11Tokens: 100
|
MaxNEP11Tokens: 100
|
||||||
Port: 10332
|
Port: 10332
|
||||||
|
StartWhenSynchronized: false
|
||||||
TLSConfig:
|
TLSConfig:
|
||||||
Address: ""
|
Address: ""
|
||||||
CertFile: serv.crt
|
CertFile: serv.crt
|
||||||
|
@ -158,6 +159,10 @@ where:
|
||||||
- `MaxNEP11Tokens` - limit for the number of tokens returned from
|
- `MaxNEP11Tokens` - limit for the number of tokens returned from
|
||||||
`getnep11balances` call.
|
`getnep11balances` call.
|
||||||
- `Port` is an RPC server port it should be bound to.
|
- `Port` is an RPC server port it should be bound to.
|
||||||
|
- `StartWhenSynchronized` controls when RPC server will be started, by default
|
||||||
|
(`false` setting) it's started immediately and RPC is availabe during node
|
||||||
|
synchronization. Setting it to `true` will make the node start RPC service only
|
||||||
|
after full synchronization.
|
||||||
- `TLS` section configures TLS protocol.
|
- `TLS` section configures TLS protocol.
|
||||||
|
|
||||||
### State Root Configuration
|
### State Root Configuration
|
||||||
|
|
|
@ -17,6 +17,7 @@ type (
|
||||||
MaxFindResultItems int `yaml:"MaxFindResultItems"`
|
MaxFindResultItems int `yaml:"MaxFindResultItems"`
|
||||||
MaxNEP11Tokens int `yaml:"MaxNEP11Tokens"`
|
MaxNEP11Tokens int `yaml:"MaxNEP11Tokens"`
|
||||||
Port uint16 `yaml:"Port"`
|
Port uint16 `yaml:"Port"`
|
||||||
|
StartWhenSynchronized bool `yaml:"StartWhenSynchronized"`
|
||||||
TLSConfig TLSConfig `yaml:"TLSConfig"`
|
TLSConfig TLSConfig `yaml:"TLSConfig"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -260,6 +260,9 @@ func (s *Server) Start() {
|
||||||
func (s *Server) Shutdown() {
|
func (s *Server) Shutdown() {
|
||||||
var httpsErr error
|
var httpsErr error
|
||||||
|
|
||||||
|
if !s.started.Load() {
|
||||||
|
return
|
||||||
|
}
|
||||||
// Signal to websocket writer routines and handleSubEvents.
|
// Signal to websocket writer routines and handleSubEvents.
|
||||||
close(s.shutdown)
|
close(s.shutdown)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue