mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
network: make NewServer return an error, fix #612
It can return nil in two cases, so we're better return an error and handle it.
This commit is contained in:
parent
9befd8de99
commit
ea3b76ded1
4 changed files with 12 additions and 7 deletions
|
@ -321,7 +321,10 @@ func startServer(ctx *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
server := network.NewServer(serverConfig, chain, log)
|
server, err := network.NewServer(serverConfig, chain, log)
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(fmt.Errorf("failed to create network server: %v", err), 1)
|
||||||
|
}
|
||||||
rpcServer := rpc.NewServer(chain, cfg.ApplicationConfiguration.RPC, server, log)
|
rpcServer := rpc.NewServer(chain, cfg.ApplicationConfiguration.RPC, server, log)
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,8 @@ func BenchmarkTXPerformanceTest(t *testing.B) {
|
||||||
go chain.Run()
|
go chain.Run()
|
||||||
|
|
||||||
serverConfig := network.NewServerConfig(cfg)
|
serverConfig := network.NewServerConfig(cfg)
|
||||||
server := network.NewServer(serverConfig, chain, logger)
|
server, err := network.NewServer(serverConfig, chain, logger)
|
||||||
|
require.NoError(t, err, "could not create server")
|
||||||
data := prepareData(t)
|
data := prepareData(t)
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
|
|
|
@ -86,9 +86,9 @@ func randomID() uint32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer returns a new Server, initialized with the given configuration.
|
// NewServer returns a new Server, initialized with the given configuration.
|
||||||
func NewServer(config ServerConfig, chain core.Blockchainer, log *zap.Logger) *Server {
|
func NewServer(config ServerConfig, chain core.Blockchainer, log *zap.Logger) (*Server, error) {
|
||||||
if log == nil {
|
if log == nil {
|
||||||
return nil
|
return nil, errors.New("logger is a required parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &Server{
|
s := &Server{
|
||||||
|
@ -117,7 +117,7 @@ func NewServer(config ServerConfig, chain core.Blockchainer, log *zap.Logger) *S
|
||||||
TimePerBlock: config.TimePerBlock,
|
TimePerBlock: config.TimePerBlock,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.consensus = srv
|
s.consensus = srv
|
||||||
|
@ -149,7 +149,7 @@ func NewServer(config ServerConfig, chain core.Blockchainer, log *zap.Logger) *S
|
||||||
s.transport,
|
s.transport,
|
||||||
)
|
)
|
||||||
|
|
||||||
return s
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ID returns the servers ID.
|
// ID returns the servers ID.
|
||||||
|
|
|
@ -201,7 +201,8 @@ func initServerWithInMemoryChain(t *testing.T) (*core.Blockchain, http.HandlerFu
|
||||||
}
|
}
|
||||||
|
|
||||||
serverConfig := network.NewServerConfig(cfg)
|
serverConfig := network.NewServerConfig(cfg)
|
||||||
server := network.NewServer(serverConfig, chain, logger)
|
server, err := network.NewServer(serverConfig, chain, logger)
|
||||||
|
require.NoError(t, err)
|
||||||
rpcServer := NewServer(chain, cfg.ApplicationConfiguration.RPC, server, logger)
|
rpcServer := NewServer(chain, cfg.ApplicationConfiguration.RPC, server, logger)
|
||||||
handler := http.HandlerFunc(rpcServer.requestHandler)
|
handler := http.HandlerFunc(rpcServer.requestHandler)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue