Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
Julien Robert
parent
8641cd2a7c
commit
7b35e36329
+24
-15
@@ -115,8 +115,12 @@ type StartCmdOptions struct {
|
||||
// PostSetup can be used to setup extra services under the same cancellable context,
|
||||
// it's not called in stand-alone mode, only for in-process mode.
|
||||
PostSetup func(svrCtx *Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error
|
||||
// PostSetupStandalone can be used to setup extra services under the same cancellable context,
|
||||
PostSetupStandalone func(svrCtx *Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error
|
||||
// AddFlags add custom flags to start cmd
|
||||
AddFlags func(cmd *cobra.Command)
|
||||
// StartCommandHanlder can be used to customize the start command handler
|
||||
StartCommandHandler func(svrCtx *Context, clientCtx client.Context, appCreator types.AppCreator, inProcessConsensus bool, opts StartCmdOptions) error
|
||||
}
|
||||
|
||||
// StartCmd runs the service passed in, either stand-alone or in-process with
|
||||
@@ -132,6 +136,10 @@ func StartCmdWithOptions(appCreator types.AppCreator, defaultNodeHome string, op
|
||||
opts.DBOpener = openDB
|
||||
}
|
||||
|
||||
if opts.StartCommandHandler == nil {
|
||||
opts.StartCommandHandler = start
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "start",
|
||||
Short: "Run the full node",
|
||||
@@ -187,7 +195,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled.
|
||||
}
|
||||
|
||||
err = wrapCPUProfile(serverCtx, func() error {
|
||||
return start(serverCtx, clientCtx, appCreator, withCMT, opts)
|
||||
return opts.StartCommandHandler(serverCtx, clientCtx, appCreator, withCMT, opts)
|
||||
})
|
||||
|
||||
serverCtx.Logger.Debug("received quit signal")
|
||||
@@ -271,14 +279,17 @@ func startStandAlone(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clie
|
||||
return err
|
||||
}
|
||||
|
||||
cmtCfg := svrCtx.Config
|
||||
home := cmtCfg.RootDir
|
||||
|
||||
err = startAPIServer(ctx, g, cmtCfg, svrCfg, clientCtx, svrCtx, app, home, grpcSrv, metrics)
|
||||
err = startAPIServer(ctx, g, svrCfg, clientCtx, svrCtx, app, svrCtx.Config.RootDir, grpcSrv, metrics)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if opts.PostSetupStandalone != nil {
|
||||
if err := opts.PostSetupStandalone(svrCtx, clientCtx, ctx, g); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
g.Go(func() error {
|
||||
if err := svr.Start(); err != nil {
|
||||
svrCtx.Logger.Error("failed to start out-of-process ABCI server", "err", err)
|
||||
@@ -299,8 +310,6 @@ func startInProcess(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clien
|
||||
metrics *telemetry.Metrics, opts StartCmdOptions,
|
||||
) error {
|
||||
cmtCfg := svrCtx.Config
|
||||
home := cmtCfg.RootDir
|
||||
|
||||
gRPCOnly := svrCtx.Viper.GetBool(flagGRPCOnly)
|
||||
|
||||
g, ctx := getCtx(svrCtx, true)
|
||||
@@ -336,7 +345,7 @@ func startInProcess(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clien
|
||||
return err
|
||||
}
|
||||
|
||||
err = startAPIServer(ctx, g, cmtCfg, svrCfg, clientCtx, svrCtx, app, home, grpcSrv, metrics)
|
||||
err = startAPIServer(ctx, g, svrCfg, clientCtx, svrCtx, app, cmtCfg.RootDir, grpcSrv, metrics)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -499,7 +508,6 @@ func startGrpcServer(
|
||||
func startAPIServer(
|
||||
ctx context.Context,
|
||||
g *errgroup.Group,
|
||||
cmtCfg *cmtcfg.Config,
|
||||
svrCfg serverconfig.Config,
|
||||
clientCtx client.Context,
|
||||
svrCtx *Context,
|
||||
@@ -606,7 +614,7 @@ func startApp(svrCtx *Context, appCreator types.AppCreator, opts StartCmdOptions
|
||||
}
|
||||
|
||||
if isTestnet, ok := svrCtx.Viper.Get(KeyIsTestnet).(bool); ok && isTestnet {
|
||||
app, err = testnetify(svrCtx, home, appCreator, db, traceWriter)
|
||||
app, err = testnetify(svrCtx, appCreator, db, traceWriter)
|
||||
if err != nil {
|
||||
return app, traceCleanupFn, err
|
||||
}
|
||||
@@ -632,6 +640,10 @@ func InPlaceTestnetCreator(testnetAppCreator types.AppCreator) *cobra.Command {
|
||||
opts.DBOpener = openDB
|
||||
}
|
||||
|
||||
if opts.StartCommandHandler == nil {
|
||||
opts.StartCommandHandler = start
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "in-place-testnet [newChainID] [newOperatorAddress]",
|
||||
Short: "Create and start a testnet from current local state",
|
||||
@@ -696,7 +708,7 @@ you want to test the upgrade handler itself.
|
||||
serverCtx.Viper.Set(KeyNewOpAddr, newOperatorAddress)
|
||||
|
||||
err = wrapCPUProfile(serverCtx, func() error {
|
||||
return start(serverCtx, clientCtx, testnetAppCreator, withCMT, opts)
|
||||
return opts.StartCommandHandler(serverCtx, clientCtx, testnetAppCreator, withCMT, opts)
|
||||
})
|
||||
|
||||
serverCtx.Logger.Debug("received quit signal")
|
||||
@@ -719,7 +731,7 @@ you want to test the upgrade handler itself.
|
||||
|
||||
// testnetify modifies both state and blockStore, allowing the provided operator address and local validator key to control the network
|
||||
// that the state in the data folder represents. The chainID of the local genesis file is modified to match the provided chainID.
|
||||
func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, db dbm.DB, traceWriter io.WriteCloser) (types.Application, error) {
|
||||
func testnetify(ctx *Context, testnetAppCreator types.AppCreator, db dbm.DB, traceWriter io.WriteCloser) (types.Application, error) {
|
||||
config := ctx.Config
|
||||
|
||||
newChainID, ok := ctx.Viper.Get(KeyNewChainID).(string)
|
||||
@@ -765,9 +777,6 @@ func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, d
|
||||
return nil, err
|
||||
}
|
||||
validatorAddress := userPubKey.Address()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
|
||||
DiscardABCIResponses: config.Storage.DiscardABCIResponses,
|
||||
|
||||
@@ -341,6 +341,35 @@ func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator type
|
||||
)
|
||||
}
|
||||
|
||||
// AddCommandsWithStartCmdOptions adds server commands with the provided StartCmdOptions.
|
||||
func AddCommandsWithStartCmdOptions(rootCmd *cobra.Command, defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter, opts StartCmdOptions) {
|
||||
cometCmd := &cobra.Command{
|
||||
Use: "comet",
|
||||
Aliases: []string{"cometbft", "tendermint"},
|
||||
Short: "CometBFT subcommands",
|
||||
}
|
||||
|
||||
cometCmd.AddCommand(
|
||||
ShowNodeIDCmd(),
|
||||
ShowValidatorCmd(),
|
||||
ShowAddressCmd(),
|
||||
VersionCmd(),
|
||||
cmtcmd.ResetAllCmd,
|
||||
cmtcmd.ResetStateCmd,
|
||||
BootstrapStateCmd(appCreator),
|
||||
)
|
||||
|
||||
startCmd := StartCmdWithOptions(appCreator, defaultNodeHome, opts)
|
||||
|
||||
rootCmd.AddCommand(
|
||||
startCmd,
|
||||
cometCmd,
|
||||
ExportCmd(appExport, defaultNodeHome),
|
||||
version.NewVersionCommand(),
|
||||
NewRollbackCmd(appCreator, defaultNodeHome),
|
||||
)
|
||||
}
|
||||
|
||||
// AddTestnetCreatorCommand allows chains to create a testnet from the state existing in their node's data directory.
|
||||
func AddTestnetCreatorCommand(rootCmd *cobra.Command, appCreator types.AppCreator, addStartFlags types.ModuleInitFlags) {
|
||||
testnetCreateCmd := InPlaceTestnetCreator(appCreator)
|
||||
|
||||
Reference in New Issue
Block a user