Skip to content

Commit

Permalink
Merge pull request #7 from SunriseLayer/debug-grpc
Browse files Browse the repository at this point in the history
Debug-grpc
  • Loading branch information
Senna46 committed Apr 3, 2024
2 parents 4edee39 + b14ef57 commit ddb3b15
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions test/util/testnode/rpc_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testnode

import (
"context"
"os"
"path"
"strings"
Expand All @@ -11,6 +12,7 @@ import (
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
srvgrpc "github.com/cosmos/cosmos-sdk/server/grpc"
srvtypes "github.com/cosmos/cosmos-sdk/server/types"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
Expand All @@ -31,7 +33,12 @@ func StartNode(tmNode *node.Node, cctx Context) (Context, func() error, error) {
coreClient := local.New(tmNode)

cctx.Context = cctx.WithClient(coreClient)
// Set the rpc client in the context.
cctx.RpcClient = coreClient
goCtx, cancel := context.WithCancel(context.Background())
cctx.rootCtx = goCtx
cleanup := func() error {
cancel()
err := tmNode.Stop()
if err != nil {
return err
Expand All @@ -54,6 +61,7 @@ func StartNode(tmNode *node.Node, cctx Context) (Context, func() error, error) {
// context. The returned function should be used to shutdown the server.
func StartGRPCServer(app srvtypes.Application, appCfg *srvconfig.Config, cctx Context) (Context, func() error, error) {
emptycleanup := func() error { return nil }

// Add the tx service in the gRPC router.
app.RegisterTxService(cctx.Context)

Expand All @@ -63,17 +71,20 @@ func StartGRPCServer(app srvtypes.Application, appCfg *srvconfig.Config, cctx Co
// Add the node service queries to the grpc router.
app.RegisterNodeService(cctx.Context, *appCfg)

ctx := cctx.rootCtx
errGroup, _ := errgroup.WithContext(ctx)

grpcCfg := appCfg.GRPC

// Run maxSendMsgSize := cfg.MaxSendMsgSize to gogoreflection.Register(grpcSrv)
grpcSrv, err := srvgrpc.NewGRPCServer(cctx.Context, app, appCfg.GRPC)
grpcSrv, err := srvgrpc.NewGRPCServer(cctx.Context, app, grpcCfg)
if err != nil {
return Context{}, emptycleanup, err
}

// Start the gRPC server in a goroutine. Note, the provided ctx will ensure
// that the server is gracefully shut down.
go func() error {
return srvgrpc.StartGRPCServer(cctx.rootCtx, log.NewNopLogger().With("module", "grpc-server"), appCfg.GRPC, grpcSrv)
}()
errGroup.Go(func() error {
return srvgrpc.StartGRPCServer(ctx, log.NewNopLogger().With("module", "grpc-server"), grpcCfg, grpcSrv)
})

nodeGRPCAddr := strings.Replace(appCfg.GRPC.Address, "0.0.0.0", "localhost", 1)
conn, err := grpc.Dial(nodeGRPCAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
Expand All @@ -84,7 +95,7 @@ func StartGRPCServer(app srvtypes.Application, appCfg *srvconfig.Config, cctx Co
cctx.Context = cctx.WithGRPCClient(conn)

return cctx, func() error {
grpcSrv.GracefulStop()
grpcSrv.Stop()
return nil
}, nil
}
Expand Down

0 comments on commit ddb3b15

Please sign in to comment.