Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): start grpc server and register services when starting in standalone mode (v0.47) #18109

49 changes: 47 additions & 2 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/mempool"

rpchttp "github.com/cometbft/cometbft/rpc/client/http"
)

const (
Expand Down Expand Up @@ -142,7 +144,7 @@
if !withTM {
serverCtx.Logger.Info("starting ABCI without Tendermint")
return wrapCPUProfile(serverCtx, func() error {
return startStandAlone(serverCtx, appCreator)
return startStandAlone(serverCtx, clientCtx, appCreator)
})
}

Expand Down Expand Up @@ -206,7 +208,7 @@
return cmd
}

func startStandAlone(ctx *Context, appCreator types.AppCreator) error {
func startStandAlone(ctx *Context, clientCtx client.Context, appCreator types.AppCreator) error {
addr := ctx.Viper.GetString(flagAddress)
transport := ctx.Viper.GetString(flagTransport)
home := ctx.Viper.GetString(flags.FlagHome)
Expand All @@ -229,11 +231,54 @@
return err
}

// Add the tx service to the gRPC router. We only need to register this
// service if gRPC is enabled
if config.GRPC.Enable {
p-offtermatt marked this conversation as resolved.
Show resolved Hide resolved
// create tendermint client
// assumes the rpc listen address is where tendermint has its rpc server
rpcclient, err := rpchttp.New(ctx.Config.RPC.ListenAddress, "/websocket")
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
// re-assign for making the client available below
// do not use := to avoid shadowing clientCtx
clientCtx = clientCtx.WithClient(rpcclient)
// use the clientCtx provided to start command
app.RegisterTxService(clientCtx)
app.RegisterTendermintService(clientCtx)
app.RegisterNodeService(clientCtx)
}

_, err = startTelemetry(config)
if err != nil {
return err
}

var (
grpcSrv *grpc.Server
grpcWebSrv *http.Server
)

if config.GRPC.Enable {
grpcSrv, err = servergrpc.StartGRPCServer(clientCtx, app, config.GRPC)
if err != nil {
return err
}
defer grpcSrv.Stop()
if config.GRPCWeb.Enable {
grpcWebSrv, err = servergrpc.StartGRPCWeb(grpcSrv, config)
if err != nil {
ctx.Logger.Error("failed to start grpc-web http server: ", err)
return err
}
defer func() {
if err := grpcWebSrv.Close(); err != nil {
ctx.Logger.Error("failed to close grpc-web http server: ", err)
}
}()
}
}

svr, err := server.NewServer(addr, transport, app)
if err != nil {
return fmt.Errorf("error creating listener: %v", err)
Expand All @@ -244,7 +289,7 @@
err = svr.Start()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)

Check failure on line 292 in server/start.go

View workflow job for this annotation

GitHub Actions / golangci-lint

exitAfterDefer: os.Exit will exit, and `defer func(){...}(...)` will not run (gocritic)

Check failure on line 292 in server/start.go

View workflow job for this annotation

GitHub Actions / Analyze

exitAfterDefer: os.Exit will exit, and `defer func(){...}(...)` will not run (gocritic)
}

defer func() {
Expand Down
Loading