Skip to content

Commit

Permalink
feat(simapp/v2): wire grpcgateway server (partial backport #22701) (#…
Browse files Browse the repository at this point in the history
…22713)

Co-authored-by: mmsqe <mavis@crypto.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
  • Loading branch information
3 people authored Dec 2, 2024
1 parent b357013 commit 21bad34
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 16 deletions.
6 changes: 3 additions & 3 deletions server/v2/cometbft/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ replace (
// pseudo version lower than the latest tag
cosmossdk.io/api => cosmossdk.io/api v0.7.3-0.20240924065902-eb7653cfecdf // main
// pseudo version lower than the latest tag
cosmossdk.io/store => cosmossdk.io/store v1.0.0-rc.0.0.20241108140525-43e28b43ad7a // main
cosmossdk.io/store => cosmossdk.io/store v1.0.0-rc.0.0.20241202115147-f350775d0ed2 // main
cosmossdk.io/x/bank => ../../../x/bank
cosmossdk.io/x/consensus => ../../../x/consensus
cosmossdk.io/x/staking => ../../../x/staking
Expand All @@ -20,10 +20,10 @@ require (
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5
cosmossdk.io/log v1.5.0
cosmossdk.io/schema v0.3.1-0.20241128094659-bd76b47e1d8b //main
cosmossdk.io/server/v2 v2.0.0-20241129190247-24d456db40a8 // main
cosmossdk.io/server/v2 v2.0.0-20241202115147-f350775d0ed2 // main
cosmossdk.io/server/v2/appmanager v0.0.0-20241119134933-d697a3de0f95 // main
cosmossdk.io/server/v2/stf v0.0.0-20241119134933-d697a3de0f95 // main
cosmossdk.io/store/v2 v2.0.0-20241129190247-24d456db40a8 // main
cosmossdk.io/store/v2 v2.0.0-20241202115147-f350775d0ed2 // main
cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000
github.com/cometbft/cometbft v1.0.0-rc2.0.20241127125717-4ce33b646ac9
github.com/cometbft/cometbft/api v1.0.0-rc2
Expand Down
12 changes: 6 additions & 6 deletions server/v2/cometbft/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ=
cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk=
cosmossdk.io/schema v0.3.1-0.20241128094659-bd76b47e1d8b h1:svpFdulZRrYz+RTHu2u9CeKkMKrIHx5354vjiHerovo=
cosmossdk.io/schema v0.3.1-0.20241128094659-bd76b47e1d8b/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
cosmossdk.io/server/v2 v2.0.0-20241129190247-24d456db40a8 h1:FkHyUGwkMdohzNls+7qmg7nPjOLidMDOP6X0N21kD5g=
cosmossdk.io/server/v2 v2.0.0-20241129190247-24d456db40a8/go.mod h1:NT1O+DPv2bWxqX8QTtvBbjXpeXFw5doT2hoRRNr8ob4=
cosmossdk.io/server/v2 v2.0.0-20241202115147-f350775d0ed2 h1:PBV8S+nGjXNEW/sGUgYYwsyI315I4LtXQTrKk5g8G2A=
cosmossdk.io/server/v2 v2.0.0-20241202115147-f350775d0ed2/go.mod h1:NT1O+DPv2bWxqX8QTtvBbjXpeXFw5doT2hoRRNr8ob4=
cosmossdk.io/server/v2/appmanager v0.0.0-20241119134933-d697a3de0f95 h1:GOznErJieaI0OS0LDUsu5Vy3qPnCyjdvkncejP0Zv5s=
cosmossdk.io/server/v2/appmanager v0.0.0-20241119134933-d697a3de0f95/go.mod h1:elhlrldWtm+9U4PxE0G3wjz83yQwVVGVAOncXJPY1Xc=
cosmossdk.io/server/v2/stf v0.0.0-20241119134933-d697a3de0f95 h1:cK7wvmlA18AvLcaInseKTBmt5EXtLwafe7oH1rx7veU=
cosmossdk.io/server/v2/stf v0.0.0-20241119134933-d697a3de0f95/go.mod h1:4e9SzLyeGptQ3tSR6nKCNwCu7Ye4uUS2WIJih29dG2c=
cosmossdk.io/store v1.0.0-rc.0.0.20241108140525-43e28b43ad7a h1:5ENKFUhhJPkpx6dGDmc0/LXinjE3oIQDEES9gVVA4xM=
cosmossdk.io/store v1.0.0-rc.0.0.20241108140525-43e28b43ad7a/go.mod h1:pjNPBX9giCOI18kf3mgNtn4J3SFaZbV1mAmM58iHdgg=
cosmossdk.io/store/v2 v2.0.0-20241129190247-24d456db40a8 h1:LvlYyjMBF6+CV3lOCnkZqNk0+LkVehDnTPHh+JLO7Mg=
cosmossdk.io/store/v2 v2.0.0-20241129190247-24d456db40a8/go.mod h1:1DbksNgjyQ1XxlCYqkU82WqBGWcxmgciO5dBf6dRhKM=
cosmossdk.io/store v1.0.0-rc.0.0.20241202115147-f350775d0ed2 h1:UCe04NMBR+1M5JRpZJvM+I0EZzD3zXrk9YOm2RZdKDg=
cosmossdk.io/store v1.0.0-rc.0.0.20241202115147-f350775d0ed2/go.mod h1:oZBBY4BrkYnghr6MFL0MP5mGqpkPedHcWkXwXddd6tU=
cosmossdk.io/store/v2 v2.0.0-20241202115147-f350775d0ed2 h1:SmP9frnyUuBXW6rqNfPXDGaLfgN9INaHzBMZZW8ZraU=
cosmossdk.io/store/v2 v2.0.0-20241202115147-f350775d0ed2/go.mod h1:1DbksNgjyQ1XxlCYqkU82WqBGWcxmgciO5dBf6dRhKM=
cosmossdk.io/x/tx v1.0.0-alpha.2 h1:UW80FMm7B0fiAMsrfe5+HabSJ3XBg+tQa6/GK9prqWk=
cosmossdk.io/x/tx v1.0.0-alpha.2/go.mod h1:r4yTKSJ7ZCCR95YbBfY3nfvbgNw6m9F6f25efWYYQWo=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
Expand Down
4 changes: 2 additions & 2 deletions simapp/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ require (
cosmossdk.io/log v1.5.0
cosmossdk.io/math v1.4.0
cosmossdk.io/runtime/v2 v2.0.0-20241119134933-d697a3de0f95 // main
cosmossdk.io/server/v2 v2.0.0-20241129190247-24d456db40a8 // main
cosmossdk.io/server/v2 v2.0.0-20241202115147-f350775d0ed2 // main
cosmossdk.io/server/v2/cometbft v0.0.0-00010101000000-000000000000
cosmossdk.io/store/v2 v2.0.0-20241129190247-24d456db40a8 // main
cosmossdk.io/store/v2 v2.0.0-20241202115147-f350775d0ed2 // main
cosmossdk.io/tools/confix v0.0.0-00010101000000-000000000000
cosmossdk.io/x/accounts v0.0.0-20240913065641-0064ccbce64e
cosmossdk.io/x/authz v0.0.0-00010101000000-000000000000
Expand Down
8 changes: 4 additions & 4 deletions simapp/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,16 @@ cosmossdk.io/runtime/v2 v2.0.0-20241119134933-d697a3de0f95 h1:hYI7pvrmdkgFZJ4HVQ
cosmossdk.io/runtime/v2 v2.0.0-20241119134933-d697a3de0f95/go.mod h1:J4Wv2eOwAz8t14Ak8XBMWDoFbwqwyllMaJF91O7n/wI=
cosmossdk.io/schema v0.3.1-0.20241128094659-bd76b47e1d8b h1:svpFdulZRrYz+RTHu2u9CeKkMKrIHx5354vjiHerovo=
cosmossdk.io/schema v0.3.1-0.20241128094659-bd76b47e1d8b/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
cosmossdk.io/server/v2 v2.0.0-20241129190247-24d456db40a8 h1:FkHyUGwkMdohzNls+7qmg7nPjOLidMDOP6X0N21kD5g=
cosmossdk.io/server/v2 v2.0.0-20241129190247-24d456db40a8/go.mod h1:NT1O+DPv2bWxqX8QTtvBbjXpeXFw5doT2hoRRNr8ob4=
cosmossdk.io/server/v2 v2.0.0-20241202115147-f350775d0ed2 h1:PBV8S+nGjXNEW/sGUgYYwsyI315I4LtXQTrKk5g8G2A=
cosmossdk.io/server/v2 v2.0.0-20241202115147-f350775d0ed2/go.mod h1:NT1O+DPv2bWxqX8QTtvBbjXpeXFw5doT2hoRRNr8ob4=
cosmossdk.io/server/v2/appmanager v0.0.0-20241119134933-d697a3de0f95 h1:GOznErJieaI0OS0LDUsu5Vy3qPnCyjdvkncejP0Zv5s=
cosmossdk.io/server/v2/appmanager v0.0.0-20241119134933-d697a3de0f95/go.mod h1:elhlrldWtm+9U4PxE0G3wjz83yQwVVGVAOncXJPY1Xc=
cosmossdk.io/server/v2/stf v0.0.0-20241119134933-d697a3de0f95 h1:cK7wvmlA18AvLcaInseKTBmt5EXtLwafe7oH1rx7veU=
cosmossdk.io/server/v2/stf v0.0.0-20241119134933-d697a3de0f95/go.mod h1:4e9SzLyeGptQ3tSR6nKCNwCu7Ye4uUS2WIJih29dG2c=
cosmossdk.io/store v1.0.0-rc.0.0.20241119134933-d697a3de0f95 h1:5hIgRL6VsicdJ7FVK6AG7cSy1C8tiVbCp6W3Y+QQ5ko=
cosmossdk.io/store v1.0.0-rc.0.0.20241119134933-d697a3de0f95/go.mod h1:ceNwMZIU8ZIDoeUdA9+sGxz3GVt0orEGoVpkBfa/UtU=
cosmossdk.io/store/v2 v2.0.0-20241129190247-24d456db40a8 h1:LvlYyjMBF6+CV3lOCnkZqNk0+LkVehDnTPHh+JLO7Mg=
cosmossdk.io/store/v2 v2.0.0-20241129190247-24d456db40a8/go.mod h1:1DbksNgjyQ1XxlCYqkU82WqBGWcxmgciO5dBf6dRhKM=
cosmossdk.io/store/v2 v2.0.0-20241202115147-f350775d0ed2 h1:SmP9frnyUuBXW6rqNfPXDGaLfgN9INaHzBMZZW8ZraU=
cosmossdk.io/store/v2 v2.0.0-20241202115147-f350775d0ed2/go.mod h1:1DbksNgjyQ1XxlCYqkU82WqBGWcxmgciO5dBf6dRhKM=
cosmossdk.io/x/tx v1.0.0-alpha.2 h1:UW80FMm7B0fiAMsrfe5+HabSJ3XBg+tQa6/GK9prqWk=
cosmossdk.io/x/tx v1.0.0-alpha.2/go.mod h1:r4yTKSJ7ZCCR95YbBfY3nfvbgNw6m9F6f25efWYYQWo=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
Expand Down
20 changes: 20 additions & 0 deletions simapp/v2/simdv2/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
runtimev2 "cosmossdk.io/runtime/v2"
serverv2 "cosmossdk.io/server/v2"
grpcserver "cosmossdk.io/server/v2/api/grpc"
"cosmossdk.io/server/v2/api/grpcgateway"
"cosmossdk.io/server/v2/api/rest"
"cosmossdk.io/server/v2/api/telemetry"
"cosmossdk.io/server/v2/cometbft"
Expand All @@ -26,6 +27,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/rpc"
sdktelemetry "github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/genutil"
Expand Down Expand Up @@ -85,6 +87,7 @@ func InitRootCmd[T transaction.Tx](
&serverstore.Server[T]{},
&telemetry.Server[T]{},
&rest.Server[T]{},
&grpcgateway.Server[T]{},
)
}

Expand Down Expand Up @@ -142,6 +145,22 @@ func InitRootCmd[T transaction.Tx](
return nil, err
}

grpcgatewayServer, err := grpcgateway.New[T](
logger,
deps.GlobalConfig,
simApp.InterfaceRegistry(),
)
if err != nil {
return nil, err
}

for _, mod := range deps.ModuleManager.Modules() {
if gmod, ok := mod.(module.HasGRPCGateway); ok {
// TODO(@julienrbrt) https://github.com/cosmos/cosmos-sdk/pull/22701#pullrequestreview-2470651390
gmod.RegisterGRPCGatewayRoutes(deps.ClientContext, grpcgatewayServer.GRPCGatewayRouter)
}
}

// wire server commands
return serverv2.AddCommands[T](
rootCmd,
Expand All @@ -154,6 +173,7 @@ func InitRootCmd[T transaction.Tx](
storeComponent,
telemetryServer,
restServer,
grpcgatewayServer,
)
}

Expand Down
11 changes: 10 additions & 1 deletion simapp/v2/simdv2/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
runtimev2 "cosmossdk.io/runtime/v2"
serverv2 "cosmossdk.io/server/v2"
"cosmossdk.io/server/v2/api/grpc"
"cosmossdk.io/server/v2/api/grpcgateway"
"cosmossdk.io/server/v2/api/rest"
"cosmossdk.io/server/v2/cometbft"
"cosmossdk.io/server/v2/store"
Expand Down Expand Up @@ -193,7 +194,9 @@ func initTestnetFiles[T transaction.Tx](
for i := 0; i < args.numValidators; i++ {
var portOffset int
grpcConfig := grpc.DefaultConfig()
grpcgatewayConfig := grpcgateway.DefaultConfig()
restConfig := rest.DefaultConfig()

if args.singleMachine {
portOffset = i
p2pPortStart = 16656 // use different start point to not conflict with rpc port
Expand All @@ -208,6 +211,11 @@ func initTestnetFiles[T transaction.Tx](
MaxSendMsgSize: grpc.DefaultConfig().MaxSendMsgSize,
}

grpcgatewayConfig = &grpcgateway.Config{
Enable: true,
Address: fmt.Sprintf("127.0.0.1:%d", apiPort+portOffset),
}

restConfig = &rest.Config{
Enable: true,
Address: fmt.Sprintf("127.0.0.1:%d", restPort+portOffset),
Expand Down Expand Up @@ -345,8 +353,9 @@ func initTestnetFiles[T transaction.Tx](
cometServer := cometbft.NewWithConfigOptions[T](cometbft.OverwriteDefaultConfigTomlConfig(nodeConfig))
storeServer := &store.Server[T]{}
grpcServer := grpc.NewWithConfigOptions[T](grpc.OverwriteDefaultConfig(grpcConfig))
grpcgatewayServer := grpcgateway.NewWithConfigOptions[T](grpcgateway.OverwriteDefaultConfig(grpcgatewayConfig))
restServer := rest.NewWithConfigOptions[T](rest.OverwriteDefaultConfig(restConfig))
server := serverv2.NewServer[T](serverCfg, cometServer, storeServer, grpcServer, restServer)
server := serverv2.NewServer[T](serverCfg, cometServer, storeServer, grpcServer, grpcgatewayServer, restServer)
err = server.WriteConfig(filepath.Join(nodeDir, "config"))
if err != nil {
return err
Expand Down

0 comments on commit 21bad34

Please sign in to comment.