Skip to content

Commit 6e6255d

Browse files
refactor(simdv2): allow non-comet server components (#22351)
1 parent 0630099 commit 6e6255d

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

simapp/v2/simdv2/cmd/commands.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"cosmossdk.io/server/v2/api/grpc"
1818
"cosmossdk.io/server/v2/api/rest"
1919
"cosmossdk.io/server/v2/api/telemetry"
20-
"cosmossdk.io/server/v2/cometbft"
2120
serverstore "cosmossdk.io/server/v2/store"
2221
"cosmossdk.io/simapp/v2"
2322
confixcmd "cosmossdk.io/tools/confix/cmd"
@@ -43,8 +42,8 @@ func newApp[T transaction.Tx](logger log.Logger, viper *viper.Viper) serverv2.Ap
4342

4443
func initRootCmd[T transaction.Tx](
4544
rootCmd *cobra.Command,
46-
txConfig client.TxConfig,
4745
moduleManager *runtimev2.MM[T],
46+
consensusComponent serverv2.ServerComponent[T],
4847
) {
4948
cfg := sdk.GetConfig()
5049
cfg.Seal()
@@ -70,11 +69,7 @@ func initRootCmd[T transaction.Tx](
7069
rootCmd,
7170
newApp,
7271
initServerConfig(),
73-
cometbft.New(
74-
&genericTxDecoder[T]{txConfig},
75-
initCometOptions[T](),
76-
initCometConfig(),
77-
),
72+
consensusComponent,
7873
grpc.New[T](),
7974
serverstore.New[T](),
8075
telemetry.New[T](),

simapp/v2/simdv2/cmd/root_di.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"cosmossdk.io/depinject"
1414
"cosmossdk.io/log"
1515
"cosmossdk.io/runtime/v2"
16+
serverv2 "cosmossdk.io/server/v2"
17+
"cosmossdk.io/server/v2/cometbft"
1618
"cosmossdk.io/simapp/v2"
1719
basedepinject "cosmossdk.io/x/accounts/defaults/base/depinject"
1820
lockupdepinject "cosmossdk.io/x/accounts/defaults/lockup/depinject"
@@ -28,8 +30,25 @@ import (
2830
"github.com/cosmos/cosmos-sdk/x/auth/types"
2931
)
3032

31-
// NewRootCmd creates a new root command for simd. It is called once in the main function.
32-
func NewRootCmd[T transaction.Tx]() *cobra.Command {
33+
// NewCometBFTRootCmd creates a new root command for simd,
34+
// using the CometBFT server component for consensus.
35+
// It is called once in the main function.
36+
func NewCometBFTRootCmd[T transaction.Tx]() *cobra.Command {
37+
return NewRootCmdWithConsensusComponent(func(cc client.Context) serverv2.ServerComponent[T] {
38+
return cometbft.New[T](
39+
&genericTxDecoder[T]{cc.TxConfig},
40+
initCometOptions[T](),
41+
initCometConfig(),
42+
)
43+
})
44+
}
45+
46+
// NewRootCmdWithConsensusComponent returns a new root command,
47+
// using the provided callback to instantiate the server component for the consensus layer.
48+
// Callers who want to use CometBFT should call [NewCometBFTRootCmd] directly.
49+
func NewRootCmdWithConsensusComponent[T transaction.Tx](
50+
makeConsensusComponent func(cc client.Context) serverv2.ServerComponent[T],
51+
) *cobra.Command {
3352
var (
3453
autoCliOpts autocli.AppOptions
3554
moduleManager *runtime.MM[T]
@@ -82,12 +101,12 @@ func NewRootCmd[T transaction.Tx]() *cobra.Command {
82101
},
83102
}
84103

85-
initRootCmd(rootCmd, clientCtx.TxConfig, moduleManager)
104+
consensusComponent := makeConsensusComponent(clientCtx)
105+
initRootCmd(rootCmd, moduleManager, consensusComponent)
86106

87107
nodeCmds := nodeservice.NewNodeCommands()
88108
autoCliOpts.ModuleOptions = make(map[string]*autocliv1.ModuleOptions)
89109
autoCliOpts.ModuleOptions[nodeCmds.Name()] = nodeCmds.AutoCLIOptions()
90-
91110
if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
92111
panic(err)
93112
}

simapp/v2/simdv2/cmd/root_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
func TestInitCmd(t *testing.T) {
19-
rootCmd := cmd.NewRootCmd[transaction.Tx]()
19+
rootCmd := cmd.NewCometBFTRootCmd[transaction.Tx]()
2020
rootCmd.SetArgs([]string{
2121
"init", // Test the init cmd
2222
"simapp-test", // Moniker
@@ -29,7 +29,7 @@ func TestInitCmd(t *testing.T) {
2929
func TestHomeFlagRegistration(t *testing.T) {
3030
homeDir := "/tmp/foo"
3131

32-
rootCmd := cmd.NewRootCmd[transaction.Tx]()
32+
rootCmd := cmd.NewCometBFTRootCmd[transaction.Tx]()
3333
rootCmd.SetArgs([]string{
3434
"query",
3535
fmt.Sprintf("--%s", flags.FlagHome),

simapp/v2/simdv2/cmd/testnet_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
func TestInitTestFilesCmd(t *testing.T) {
19-
rootCmd := cmd.NewRootCmd[transaction.Tx]()
19+
rootCmd := cmd.NewCometBFTRootCmd[transaction.Tx]()
2020
rootCmd.SetArgs([]string{
2121
"testnet", // Test the testnet init-files command
2222
"init-files",

simapp/v2/simdv2/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func main() {
15-
rootCmd := cmd.NewRootCmd[transaction.Tx]()
15+
rootCmd := cmd.NewCometBFTRootCmd[transaction.Tx]()
1616
if err := serverv2.Execute(rootCmd, clientv2helpers.EnvPrefix, simapp.DefaultNodeHome); err != nil {
1717
fmt.Fprintln(rootCmd.OutOrStderr(), err)
1818
os.Exit(1)

0 commit comments

Comments
 (0)