Skip to content

Commit

Permalink
chore(simapp/v2): consensus server isn't command dep (#23480)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Jan 23, 2025
1 parent 9fdcd6d commit 18a8252
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 43 deletions.
2 changes: 1 addition & 1 deletion runtime/v2/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (a *AppBuilder[T]) Build(opts ...AppBuilderOption[T]) (*App[T], error) {
}
a.app.stf = stf

a.app.AppManager = appmanager.New[T](
a.app.AppManager = appmanager.New(
appmanager.Config{
ValidateTxGasLimit: a.app.config.GasConfig.ValidateTxGasLimit,
QueryGasLimit: a.app.config.GasConfig.QueryGasLimit,
Expand Down
2 changes: 1 addition & 1 deletion server/v2/appmanager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package appmanager

// Config represents the configuration options for the app manager.
type Config struct {
ValidateTxGasLimit uint64 `mapstructure:"validate-tx-gas-limit"` // TODO: check how this works on app mempool
ValidateTxGasLimit uint64 `mapstructure:"validate-tx-gas-limit"`
QueryGasLimit uint64 `mapstructure:"query-gas-limit"`
SimulationGasLimit uint64 `mapstructure:"simulation-gas-limit"`
}
9 changes: 5 additions & 4 deletions simapp/v2/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
validatemodulev1 "cosmossdk.io/api/cosmos/validate/module/v1"
vestingmodulev1 "cosmossdk.io/api/cosmos/vesting/module/v1"
"cosmossdk.io/depinject/appconfig"
runtimev2types "cosmossdk.io/runtime/v2"
"cosmossdk.io/x/accounts"
"cosmossdk.io/x/authz"
_ "cosmossdk.io/x/authz/module" // import for side-effects
Expand Down Expand Up @@ -66,7 +67,6 @@ import (
_ "cosmossdk.io/x/upgrade" // import for side-effects
upgradetypes "cosmossdk.io/x/upgrade/types"

"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import for side-effects
authtxconfig "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -108,7 +108,7 @@ var (
ModuleConfig = &appv1alpha1.Config{
Modules: []*appv1alpha1.ModuleConfig{
{
Name: runtime.ModuleName,
Name: runtimev2types.ModuleName,
Config: appconfig.WrapAny(&runtimev2.Module{
AppName: "SimAppV2",
// NOTE: upgrade module is required to be prioritized
Expand Down Expand Up @@ -197,7 +197,8 @@ var (
},
// Uncomment if you want to set a custom migration order here.
// OrderMigrations: []string{},
// TODO GasConfig was added to the config in runtimev2. Where/how was it set in v1?
// GasConfig is used to set the gas configuration for the queries and transactions.
// This config is aimed to app-wide and shouldn't be overridden by individual validators.
GasConfig: &runtimev2.GasConfig{
ValidateTxGasLimit: 10_000_000,
QueryGasLimit: 100_000,
Expand All @@ -209,7 +210,7 @@ var (
authtxconfig.DepinjectModuleName,
validate.ModuleName,
genutiltypes.ModuleName,
runtime.ModuleName,
runtimev2types.ModuleName,
vestingtypes.ModuleName,
},
}),
Expand Down
64 changes: 27 additions & 37 deletions simapp/v2/simdv2/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ type CommandDependencies[T transaction.Tx] struct {
TxConfig client.TxConfig
ModuleManager *runtimev2.MM[T]
SimApp *simapp.SimApp[T]
// could generally be more generic with serverv2.ServerComponent[T]
// however, we want to register extra grpc handlers
ConsensusServer *cometbft.CometBFTServer[T]
ClientContext client.Context
ClientContext client.Context
}

func InitRootCmd[T transaction.Tx](
Expand All @@ -76,16 +73,13 @@ func InitRootCmd[T transaction.Tx](

// build CLI skeleton for initial config parsing or a client application invocation
if deps.SimApp == nil {
if deps.ConsensusServer == nil {
deps.ConsensusServer = cometbft.NewWithConfigOptions[T](initCometConfig())
}
return serverv2.AddCommands[T](
rootCmd,
logger,
io.NopCloser(nil),
deps.GlobalConfig,
initServerConfig(),
deps.ConsensusServer,
cometbft.NewWithConfigOptions[T](initCometConfig()),
&grpcserver.Server[T]{},
&serverstore.Server[T]{},
&telemetry.Server[T]{},
Expand All @@ -108,26 +102,24 @@ func InitRootCmd[T transaction.Tx](
}

// consensus component
if deps.ConsensusServer == nil {
deps.ConsensusServer, err = cometbft.New(
logger,
simApp.Name(),
simApp.Store(),
simApp.App.AppManager,
cometbft.AppCodecs[T]{
AppCodec: simApp.AppCodec(),
TxCodec: &client.DefaultTxDecoder[T]{TxConfig: deps.TxConfig},
LegacyAmino: deps.ClientContext.LegacyAmino,
ConsensusAddressCodec: deps.ClientContext.ConsensusAddressCodec,
},
simApp.App.QueryHandlers(),
simApp.App.SchemaDecoderResolver(),
initCometOptions[T](),
deps.GlobalConfig,
)
if err != nil {
return nil, err
}
consensusServer, err := cometbft.New(
logger,
simApp.Name(),
simApp.Store(),
simApp.App.AppManager,
cometbft.AppCodecs[T]{
AppCodec: simApp.AppCodec(),
TxCodec: &client.DefaultTxDecoder[T]{TxConfig: deps.TxConfig},
LegacyAmino: deps.ClientContext.LegacyAmino,
ConsensusAddressCodec: deps.ClientContext.ConsensusAddressCodec,
},
simApp.App.QueryHandlers(),
simApp.App.SchemaDecoderResolver(),
initCometOptions[T](),
deps.GlobalConfig,
)
if err != nil {
return nil, err
}

telemetryServer, err := telemetry.New[T](deps.GlobalConfig, logger, sdktelemetry.EnableTelemetry)
Expand All @@ -142,7 +134,7 @@ func InitRootCmd[T transaction.Tx](
simApp.Query,
deps.GlobalConfig,
grpcserver.WithExtraGRPCHandlers[T](
deps.ConsensusServer.GRPCServiceRegistrar(
consensusServer.GRPCServiceRegistrar(
deps.ClientContext,
deps.GlobalConfig,
),
Expand All @@ -161,7 +153,7 @@ func InitRootCmd[T transaction.Tx](
if err != nil {
return nil, err
}
registerGRPCGatewayRoutes[T](deps, grpcgatewayServer)
registerGRPCGatewayRoutes(deps.ClientContext, grpcgatewayServer)

// wire server commands
return serverv2.AddCommands[T](
Expand All @@ -170,7 +162,7 @@ func InitRootCmd[T transaction.Tx](
simApp,
deps.GlobalConfig,
initServerConfig(),
deps.ConsensusServer,
consensusServer,
grpcServer,
storeComponent,
telemetryServer,
Expand Down Expand Up @@ -268,14 +260,12 @@ func RootCommandPersistentPreRun(clientCtx client.Context) func(*cobra.Command,
}

// registerGRPCGatewayRoutes registers the gRPC gateway routes for all modules and other components
// TODO(@julienrbrt): Eventually, this should removed and directly done within the grpcgateway.Server
// ref: https://github.com/cosmos/cosmos-sdk/pull/22701#pullrequestreview-2470651390
func registerGRPCGatewayRoutes[T transaction.Tx](
deps CommandDependencies[T],
clientContext client.Context,
server *grpcgateway.Server[T],
) {
// those are the extra services that the CometBFT server implements (server/v2/cometbft/grpc.go)
cmtservice.RegisterGRPCGatewayRoutes(deps.ClientContext, server.GRPCGatewayRouter)
_ = nodeservice.RegisterServiceHandlerClient(context.Background(), server.GRPCGatewayRouter, nodeservice.NewServiceClient(deps.ClientContext))
_ = txtypes.RegisterServiceHandlerClient(context.Background(), server.GRPCGatewayRouter, txtypes.NewServiceClient(deps.ClientContext))
cmtservice.RegisterGRPCGatewayRoutes(clientContext, server.GRPCGatewayRouter)
_ = nodeservice.RegisterServiceHandlerClient(context.Background(), server.GRPCGatewayRouter, nodeservice.NewServiceClient(clientContext))
_ = txtypes.RegisterServiceHandlerClient(context.Background(), server.GRPCGatewayRouter, txtypes.NewServiceClient(clientContext))
}

0 comments on commit 18a8252

Please sign in to comment.