diff --git a/CHANGELOG-Agoric.md b/CHANGELOG-Agoric.md index 67158b64ae7..469bb83bd19 100644 --- a/CHANGELOG-Agoric.md +++ b/CHANGELOG-Agoric.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * (auth) [#407](https://github.com/agoric-labs/cosmos-sdk/pull/407) Configurable fee collector module account in DeductFeeDecorator. +* (server) [#409](https://github.com/agoric-labs/cosmos-sdk/pull/409) Flag to select ABCI client type. ### API Breaking diff --git a/server/start.go b/server/start.go index 4f88ba8f241..b60cbaa9cf5 100644 --- a/server/start.go +++ b/server/start.go @@ -12,6 +12,7 @@ import ( "github.com/spf13/cobra" "github.com/tendermint/tendermint/abci/server" + abcitypes "github.com/tendermint/tendermint/abci/types" tcmd "github.com/tendermint/tendermint/cmd/cometbft/commands" tmos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/node" @@ -59,6 +60,7 @@ const ( FlagIAVLCacheSize = "iavl-cache-size" FlagDisableIAVLFastNode = "iavl-disable-fastnode" FlagIAVLLazyLoading = "iavl-lazy-loading" + FlagAbciClientType = "abci-client-type" // state sync-related flags FlagStateSyncSnapshotInterval = "state-sync.snapshot-interval" @@ -82,6 +84,11 @@ const ( flagGRPCWebAddress = "grpc-web.address" ) +const ( + abciClientTypeCommitting = "committing" + abciClientTypeLocal = "local" +) + // StartCmd runs the service passed in, either stand-alone or in-process with // Tendermint. func StartCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command { @@ -142,9 +149,18 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. }) } + abciClientType, err := cmd.Flags().GetString(FlagAbciClientType) + if err != nil { + return err + } + clientCreator, err := getAbciClientCreator(abciClientType) + if err != nil { + return err + } + // amino is needed here for backwards compatibility of REST routes err = wrapCPUProfile(serverCtx, func() error { - return startInProcess(serverCtx, clientCtx, appCreator) + return startInProcess(serverCtx, clientCtx, appCreator, clientCreator) }) errCode, ok := err.(ErrorCode) if !ok { @@ -194,6 +210,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. cmd.Flags().Uint32(FlagStateSyncSnapshotKeepRecent, 2, "State sync snapshot to keep") cmd.Flags().Bool(FlagDisableIAVLFastNode, false, "Disable fast node for IAVL tree") + cmd.Flags().String(FlagAbciClientType, abciClientTypeCommitting, fmt.Sprintf(`Type of ABCI client ("%s" or "%s")`, abciClientTypeCommitting, abciClientTypeLocal)) // add support for all Tendermint-specific command line options tcmd.AddNodeFlags(cmd) @@ -254,7 +271,9 @@ func startStandAlone(ctx *Context, appCreator types.AppCreator) error { return WaitForQuitSignals() } -func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.AppCreator) error { +type abciClientCreator func(abcitypes.Application) proxy.ClientCreator + +func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.AppCreator, clientCreator abciClientCreator) error { cfg := ctx.Config home := cfg.RootDir @@ -302,7 +321,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App cfg, pvm.LoadOrGenFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()), nodeKey, - proxy.NewCommittingClientCreator(app), + clientCreator(app), genDocProvider, node.DefaultDBProvider, node.DefaultMetricsProvider(cfg.Instrumentation), @@ -501,6 +520,16 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App return WaitForQuitSignals() } +func getAbciClientCreator(abciClientType string) (abciClientCreator, error) { + switch abciClientType { + case abciClientTypeCommitting: + return proxy.NewCommittingClientCreator, nil + case abciClientTypeLocal: + return proxy.NewLocalClientCreator, nil + } + return nil, fmt.Errorf(`unknown ABCI client type "%s"`, abciClientType) +} + func startTelemetry(cfg serverconfig.Config) (*telemetry.Metrics, error) { if !cfg.Telemetry.Enabled { return nil, nil diff --git a/server/start_test.go b/server/start_test.go new file mode 100644 index 00000000000..8e546a9ace6 --- /dev/null +++ b/server/start_test.go @@ -0,0 +1,46 @@ +package server + +import ( + "reflect" + "runtime" + "testing" +) + +func TestAbciClientType(t *testing.T) { + for _, tt := range []struct { + clientType string + creatorName string + wantErr bool + }{ + { + clientType: "committing", + creatorName: "github.com/tendermint/tendermint/proxy.NewCommittingClientCreator", + }, + { + clientType: "local", + creatorName: "github.com/tendermint/tendermint/proxy.NewLocalClientCreator", + }, + { + clientType: "cool ranch", + wantErr: true, + }, + } { + t.Run(tt.clientType, func(t *testing.T) { + creator, err := getAbciClientCreator(tt.clientType) + if tt.wantErr { + if err == nil { + t.Error("wanted error, got none") + } + } else { + if err != nil { + t.Errorf("unexpected error %v", err) + } else { + creatorName := runtime.FuncForPC(reflect.ValueOf(creator).Pointer()).Name() + if creatorName != tt.creatorName { + t.Errorf(`want creator "%s", got "%s"`, tt.creatorName, creatorName) + } + } + } + }) + } +}