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

build: cherry-pick commits for v0.46.16-alpha.agoric.2.4 #420

Merged
merged 2 commits into from
Apr 19, 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
6 changes: 6 additions & 0 deletions CHANGELOG-Agoric.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (auth, bank) Agoric/agoric-sdk#8989 Remove deprecated lien support

## `v0.46.16-alpha.agoric.2.4` - 2024-04-19

### Improvements

* (server) [#419](https://github.com/agoric-labs/cosmos-sdk/pull/419) More unit tests for flag vs toml precedence for ABCI client type.

## `v0.46.16-alpha.agoric.2.3` - 2024-04-17

### Improvements
Expand Down
3 changes: 3 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ type BaseConfig struct {
IAVLLazyLoading bool `mapstructure:"iavl-lazy-loading"`

// ABCIClientType selects the type of ABCI client.
// Valid settings are "committing" (default) or "local".
// The committing client allows greater query parallelism,
// but the local client is more defensive.
ABCIClientType string `mapstructure:"abci-client-type"`

// AppDBBackend defines the type of Database to use for the application and snapshots databases.
Expand Down
4 changes: 3 additions & 1 deletion server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ iavl-disable-fastnode = {{ .BaseConfig.IAVLDisableFastNode }}
iavl-lazy-loading = {{ .BaseConfig.IAVLLazyLoading }}

# ABCIClientType selects the type of ABCI client.
# Default is "committing".
# Valid settings are "committing" (default) or "local".
# The committing client allows greater query parallelism,
# but the local client is more defensive.
abci-client-type = "{{ .BaseConfig.ABCIClientType }}"

# AppDBBackend defines the database backend type to use for the application and snapshots DBs.
Expand Down
88 changes: 88 additions & 0 deletions server/start_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package server

import (
"context"
"errors"
"fmt"
"os"
"path"
"reflect"
"runtime"
"testing"

"github.com/spf13/cobra"
tmcfg "github.com/tendermint/tendermint/config"
)

func TestAbciClientType(t *testing.T) {
Expand Down Expand Up @@ -44,3 +52,83 @@ func TestAbciClientType(t *testing.T) {
})
}
}

var errCancelledInPreRun = errors.New("cancelled in prerun")

func TestAbciClientPrecedence(t *testing.T) {
for i, tt := range []struct {
flag, toml, want string
}{
{
want: "committing",
},
{
flag: "foo",
want: "foo",
},
{
toml: "foo",
want: "foo",
},
{
flag: "foo",
toml: "bar",
want: "foo",
},
} {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
tempDir := t.TempDir()
err := os.Mkdir(path.Join(tempDir, "config"), os.ModePerm)
if err != nil {
t.Fatalf("creating config dir failed: %v", err)
}
appTomlPath := path.Join(tempDir, "config", "app.toml")

cmd := StartCmd(nil, tempDir)

if tt.flag != "" {
err = cmd.Flags().Set(FlagAbciClientType, tt.flag)
if err != nil {
t.Fatalf(`failed setting flag to "%s": %v`, tt.flag, err)
}
}

if tt.toml != "" {
writer, err := os.Create(appTomlPath)
if err != nil {
t.Fatalf(`failed creating "%s": %v`, appTomlPath, err)
}
_, err = writer.WriteString(fmt.Sprintf("%s = \"%s\"\n", FlagAbciClientType, tt.toml))
if err != nil {
t.Fatalf(`failed writing to app.toml: %v`, err)
}
err = writer.Close()
if err != nil {
t.Fatalf(`failed closing app.toml: %v`, err)
}
}

// Compare to tests in util_test.go
cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
err := InterceptConfigsPreRunHandler(cmd, "", nil, tmcfg.DefaultConfig())
if err != nil {
return err
}
return errCancelledInPreRun
}

serverCtx := NewDefaultContext()
ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx)
err = cmd.ExecuteContext(ctx)
if err != errCancelledInPreRun {
t.Fatal(err)
}

gotClientType := serverCtx.Viper.GetString(FlagAbciClientType)

if gotClientType != tt.want {
t.Errorf(`want client type "%s", got "%s"`, tt.want, gotClientType)
}
})
}
}
Loading