Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: feature flag for ABCI client type #409

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-Agoric.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
35 changes: 32 additions & 3 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions server/start_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
})
}
}
Loading