refactor(simdv2): allow non-comet server components (#22351)
This commit is contained in:
parent
0630099f4c
commit
6e6255df1f
@ -17,7 +17,6 @@ import (
|
||||
"cosmossdk.io/server/v2/api/grpc"
|
||||
"cosmossdk.io/server/v2/api/rest"
|
||||
"cosmossdk.io/server/v2/api/telemetry"
|
||||
"cosmossdk.io/server/v2/cometbft"
|
||||
serverstore "cosmossdk.io/server/v2/store"
|
||||
"cosmossdk.io/simapp/v2"
|
||||
confixcmd "cosmossdk.io/tools/confix/cmd"
|
||||
@ -43,8 +42,8 @@ func newApp[T transaction.Tx](logger log.Logger, viper *viper.Viper) serverv2.Ap
|
||||
|
||||
func initRootCmd[T transaction.Tx](
|
||||
rootCmd *cobra.Command,
|
||||
txConfig client.TxConfig,
|
||||
moduleManager *runtimev2.MM[T],
|
||||
consensusComponent serverv2.ServerComponent[T],
|
||||
) {
|
||||
cfg := sdk.GetConfig()
|
||||
cfg.Seal()
|
||||
@ -70,11 +69,7 @@ func initRootCmd[T transaction.Tx](
|
||||
rootCmd,
|
||||
newApp,
|
||||
initServerConfig(),
|
||||
cometbft.New(
|
||||
&genericTxDecoder[T]{txConfig},
|
||||
initCometOptions[T](),
|
||||
initCometConfig(),
|
||||
),
|
||||
consensusComponent,
|
||||
grpc.New[T](),
|
||||
serverstore.New[T](),
|
||||
telemetry.New[T](),
|
||||
|
||||
@ -13,6 +13,8 @@ import (
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/runtime/v2"
|
||||
serverv2 "cosmossdk.io/server/v2"
|
||||
"cosmossdk.io/server/v2/cometbft"
|
||||
"cosmossdk.io/simapp/v2"
|
||||
basedepinject "cosmossdk.io/x/accounts/defaults/base/depinject"
|
||||
lockupdepinject "cosmossdk.io/x/accounts/defaults/lockup/depinject"
|
||||
@ -28,8 +30,25 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
// NewRootCmd creates a new root command for simd. It is called once in the main function.
|
||||
func NewRootCmd[T transaction.Tx]() *cobra.Command {
|
||||
// NewCometBFTRootCmd creates a new root command for simd,
|
||||
// using the CometBFT server component for consensus.
|
||||
// It is called once in the main function.
|
||||
func NewCometBFTRootCmd[T transaction.Tx]() *cobra.Command {
|
||||
return NewRootCmdWithConsensusComponent(func(cc client.Context) serverv2.ServerComponent[T] {
|
||||
return cometbft.New[T](
|
||||
&genericTxDecoder[T]{cc.TxConfig},
|
||||
initCometOptions[T](),
|
||||
initCometConfig(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// NewRootCmdWithConsensusComponent returns a new root command,
|
||||
// using the provided callback to instantiate the server component for the consensus layer.
|
||||
// Callers who want to use CometBFT should call [NewCometBFTRootCmd] directly.
|
||||
func NewRootCmdWithConsensusComponent[T transaction.Tx](
|
||||
makeConsensusComponent func(cc client.Context) serverv2.ServerComponent[T],
|
||||
) *cobra.Command {
|
||||
var (
|
||||
autoCliOpts autocli.AppOptions
|
||||
moduleManager *runtime.MM[T]
|
||||
@ -82,12 +101,12 @@ func NewRootCmd[T transaction.Tx]() *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
initRootCmd(rootCmd, clientCtx.TxConfig, moduleManager)
|
||||
consensusComponent := makeConsensusComponent(clientCtx)
|
||||
initRootCmd(rootCmd, moduleManager, consensusComponent)
|
||||
|
||||
nodeCmds := nodeservice.NewNodeCommands()
|
||||
autoCliOpts.ModuleOptions = make(map[string]*autocliv1.ModuleOptions)
|
||||
autoCliOpts.ModuleOptions[nodeCmds.Name()] = nodeCmds.AutoCLIOptions()
|
||||
|
||||
if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func TestInitCmd(t *testing.T) {
|
||||
rootCmd := cmd.NewRootCmd[transaction.Tx]()
|
||||
rootCmd := cmd.NewCometBFTRootCmd[transaction.Tx]()
|
||||
rootCmd.SetArgs([]string{
|
||||
"init", // Test the init cmd
|
||||
"simapp-test", // Moniker
|
||||
@ -29,7 +29,7 @@ func TestInitCmd(t *testing.T) {
|
||||
func TestHomeFlagRegistration(t *testing.T) {
|
||||
homeDir := "/tmp/foo"
|
||||
|
||||
rootCmd := cmd.NewRootCmd[transaction.Tx]()
|
||||
rootCmd := cmd.NewCometBFTRootCmd[transaction.Tx]()
|
||||
rootCmd.SetArgs([]string{
|
||||
"query",
|
||||
fmt.Sprintf("--%s", flags.FlagHome),
|
||||
|
||||
@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func TestInitTestFilesCmd(t *testing.T) {
|
||||
rootCmd := cmd.NewRootCmd[transaction.Tx]()
|
||||
rootCmd := cmd.NewCometBFTRootCmd[transaction.Tx]()
|
||||
rootCmd.SetArgs([]string{
|
||||
"testnet", // Test the testnet init-files command
|
||||
"init-files",
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
rootCmd := cmd.NewRootCmd[transaction.Tx]()
|
||||
rootCmd := cmd.NewCometBFTRootCmd[transaction.Tx]()
|
||||
if err := serverv2.Execute(rootCmd, clientv2helpers.EnvPrefix, simapp.DefaultNodeHome); err != nil {
|
||||
fmt.Fprintln(rootCmd.OutOrStderr(), err)
|
||||
os.Exit(1)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user