chore(simapp/v2): consensus server isn't command dep (#23480)
This commit is contained in:
parent
9fdcd6de98
commit
18a82523bf
@ -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,
|
||||
|
||||
@ -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"`
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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"
|
||||
@ -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
|
||||
@ -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,
|
||||
@ -209,7 +210,7 @@ var (
|
||||
authtxconfig.DepinjectModuleName,
|
||||
validate.ModuleName,
|
||||
genutiltypes.ModuleName,
|
||||
runtime.ModuleName,
|
||||
runtimev2types.ModuleName,
|
||||
vestingtypes.ModuleName,
|
||||
},
|
||||
}),
|
||||
|
||||
@ -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](
|
||||
@ -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]{},
|
||||
@ -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)
|
||||
@ -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,
|
||||
),
|
||||
@ -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](
|
||||
@ -170,7 +162,7 @@ func InitRootCmd[T transaction.Tx](
|
||||
simApp,
|
||||
deps.GlobalConfig,
|
||||
initServerConfig(),
|
||||
deps.ConsensusServer,
|
||||
consensusServer,
|
||||
grpcServer,
|
||||
storeComponent,
|
||||
telemetryServer,
|
||||
@ -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))
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user