Skip to content

Commit 31f5bc0

Browse files
feat(server): start grpc server and register services in standalone mode (#18110)
Co-authored-by: Marko <marko@baricevic.me>
1 parent 50f936f commit 31f5bc0

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4040

4141
### Features
4242

43+
* (server) [#18110](https://github.com/cosmos/cosmos-sdk/pull/18110) Start gRPC & API server in standalone mode
4344
* (client) [#18101](https://github.com/cosmos/cosmos-sdk/pull/18101) Add a `keyring-default-keyname` in `client.toml` for specifying a default key name, and skip the need to use the `--from` flag when signing transactions.
4445
* (tests) [#17868](https://github.com/cosmos/cosmos-sdk/pull/17868) Added helper method `SubmitTestTx` in testutil to broadcast test txns to test e2e tests.
4546
* (x/protocolpool) [#17657](https://github.com/cosmos/cosmos-sdk/pull/17657) Create a new `x/protocolpool` module that is responsible for handling community pool funds. This module is split out into a new module from x/distribution.

docs/user/run-node/01-run-node.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ The previous command allow you to run a single node. This is enough for the next
157157

158158
The naive way would be to run the same commands again in separate terminal windows. This is possible, however in the Cosmos SDK, we leverage the power of [Docker Compose](https://docs.docker.com/compose/) to run a localnet. If you need inspiration on how to set up your own localnet with Docker Compose, you can have a look at the Cosmos SDK's [`docker-compose.yml`](https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/docker-compose.yml).
159159

160+
### Standalone App/CometBFT
161+
162+
By default, the Cosmos SDK runs CometBFT in-process with the application
163+
If you want to run the application and CometBFT in separate processes,
164+
start the application with the `--with-comet=false` flag
165+
and set `rpc.laddr` in `config.toml` to the CometBFT node's RPC address.
166+
160167
## Logging
161168

162169
Logging provides a way to see what is going on with a node. By default the info level is set. This is a global level and all info logs will be outputted to the terminal. If you would like to filter specific logs to the terminal instead of all, then setting `module:log_level` is how this can work.

server/start.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/cometbft/cometbft/p2p"
1717
pvm "github.com/cometbft/cometbft/privval"
1818
"github.com/cometbft/cometbft/proxy"
19+
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
1920
"github.com/cometbft/cometbft/rpc/client/local"
2021
cmttypes "github.com/cometbft/cometbft/types"
2122
dbm "github.com/cosmos/cosmos-db"
@@ -258,12 +259,12 @@ func start(svrCtx *Context, clientCtx client.Context, appCreator types.AppCreato
258259
emitServerInfoMetrics()
259260

260261
if !withCmt {
261-
return startStandAlone(svrCtx, app, opts)
262+
return startStandAlone(svrCtx, svrCfg, clientCtx, app, metrics, opts)
262263
}
263264
return startInProcess(svrCtx, svrCfg, clientCtx, app, metrics, opts)
264265
}
265266

266-
func startStandAlone(svrCtx *Context, app types.Application, opts StartCmdOptions) error {
267+
func startStandAlone(svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app types.Application, metrics *telemetry.Metrics, opts StartCmdOptions) error {
267268
addr := svrCtx.Viper.GetString(flagAddress)
268269
transport := svrCtx.Viper.GetString(flagTransport)
269270

@@ -277,6 +278,39 @@ func startStandAlone(svrCtx *Context, app types.Application, opts StartCmdOption
277278

278279
g, ctx := getCtx(svrCtx, false)
279280

281+
// Add the tx service to the gRPC router. We only need to register this
282+
// service if API or gRPC is enabled, and avoid doing so in the general
283+
// case, because it spawns a new local CometBFT RPC client.
284+
if svrCfg.API.Enable || svrCfg.GRPC.Enable {
285+
// create tendermint client
286+
// assumes the rpc listen address is where tendermint has its rpc server
287+
rpcclient, err := rpchttp.New(svrCtx.Config.RPC.ListenAddress, "/websocket")
288+
if err != nil {
289+
return err
290+
}
291+
// re-assign for making the client available below
292+
// do not use := to avoid shadowing clientCtx
293+
clientCtx = clientCtx.WithClient(rpcclient)
294+
295+
// use the provided clientCtx to register the services
296+
app.RegisterTxService(clientCtx)
297+
app.RegisterTendermintService(clientCtx)
298+
app.RegisterNodeService(clientCtx, svrCfg)
299+
}
300+
301+
grpcSrv, clientCtx, err := startGrpcServer(ctx, g, svrCfg.GRPC, clientCtx, svrCtx, app)
302+
if err != nil {
303+
return err
304+
}
305+
306+
cmtCfg := svrCtx.Config
307+
home := cmtCfg.RootDir
308+
309+
err = startAPIServer(ctx, g, cmtCfg, svrCfg, clientCtx, svrCtx, app, home, grpcSrv, metrics)
310+
if err != nil {
311+
return err
312+
}
313+
280314
g.Go(func() error {
281315
if err := svr.Start(); err != nil {
282316
svrCtx.Logger.Error("failed to start out-of-process ABCI server", "err", err)

0 commit comments

Comments
 (0)