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

Add support for iavl options in cosmos config #9426

Merged
merged 2 commits into from
May 31, 2024

Conversation

mhofman
Copy link
Member

@mhofman mhofman commented May 30, 2024

closes: #9424

Description

Plumb the iavl options into the cosmos baseapp.

Copied by comparing to DefaultBaseappOptions in cosmos-sdk server/util.go, which we should likely use directly instead (see #9425), but this is a minimal change we can easily adopt now.

Security Considerations

None

Scaling Considerations

None

Documentation Considerations

None. Change should explicitly be part of the release notes

Testing Considerations

Unsure about how to test this

Upgrade Considerations

Chain software, not consensus affecting.

Copy link
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that sure is a different kind of architecture we're dealing with. 🙃

Additional thoughts:

NewAgoricApp is also called by appExport; should that support/send DisableFastNode?

We should have protection against this kind of lapse in the future... maybe a test that imports "github.com/cosmos/cosmos-sdk/server" and uses its functions to see what flags exist:

import (
	"io"
	"os"
	"testing"

	"github.com/cosmos/cosmos-sdk/server"
	servertypes "github.com/cosmos/cosmos-sdk/server/types"
	"github.com/spf13/pflag"
	"github.com/tendermint/tendermint/libs/log"
	dbm "github.com/tendermint/tm-db"

	gaia "github.com/Agoric/agoric-sdk/golang/cosmos/app"
)

type appOptionsFromFn func(string) interface{}

func (fn appOptionsFromFn) Get(name string) interface{} {
	return fn(name)
}

func TestCLIFlags(t *testing.T) {
	expectedFlagNames := map[string]interface{}{
		"abci":                                   "",
		"abci-client-type":                       "",
		"address":                                "",
		"api.address":                            "",
		"api.enable":                             "",
		"api.enabled-unsafe-cors":                "",
		"api.max-open-connections":               "",
		"api.rpc-max-body-bytes":                 "",
		"api.rpc-read-timeout":                   "",
		"api.rpc-write-timeout":                  "",
		"api.swagger":                            "",
		"app-db-backend":                         "",
		"consensus.create_empty_blocks":          "",
		"consensus.create_empty_blocks_interval": "",
		"consensus.double_sign_check_height":     "",
		"cpu-profile":                            "",
		"db_backend":                             "",
		"db_dir":                                 "",
		"fast_sync":                              "",
		"genesis_hash":                           "",
		"grpc-only":                              "",
		"grpc-web.address":                       "",
		"grpc-web.enable":                        "",
		"grpc.address":                           "",
		"grpc.enable":                            "",
		"halt-height":                            "",
		"halt-time":                              "",
		"home":                                   "",
		"iavl-cache-size":                        "",
		"iavl-disable-fastnode":                  "",
		"iavl-lazy-loading":                      "",
		"index-events":                           "",
		"inter-block-cache":                      "",
		"inv-check-period":                       "",
		"min-retain-blocks":                      "",
		"minimum-gas-prices":                     "",
		"moniker":                                "",
		"p2p.external-address":                   "",
		"p2p.laddr":                              "",
		"p2p.persistent_peers":                   "",
		"p2p.pex":                                "",
		"p2p.private_peer_ids":                   "",
		"p2p.seed_mode":                          "",
		"p2p.seeds":                              "",
		"p2p.unconditional_peer_ids":             "",
		"p2p.upnp":                               "",
		"priv_validator_laddr":                   "",
		"proxy_app":                              "",
		"pruning":                                "default",
		"pruning-interval":                       "",
		"pruning-keep-recent":                    "",
		"rpc.grpc_laddr":                         "",
		"rpc.laddr":                              "",
		"rpc.pprof_laddr":                        "",
		"rpc.unsafe":                             "",
		"state-sync.snapshot-interval":           "",
		"state-sync.snapshot-keep-recent":        "",
		"trace":                                  "",
		"trace-store":                            "",
		"transport":                              "",
		"unsafe-skip-upgrades":                   "",
		"with-tendermint":                        "",
	}
	unknownFlagNames := []string{}
	missingFlagNames := map[string]bool{}
	for name, _ := range expectedFlagNames {
		missingFlagNames[name] = true
	}
	readFlag := func(name string) interface{} {
		if defaultValue, found := expectedFlagNames[name]; found {
			delete(missingFlagNames, name)
			return defaultValue
		}
		unknownFlagNames = append(unknownFlagNames, name)
		return nil
	}

	homeDir, err := os.MkdirTemp("", "cosmos-sdk-home")
	if err != nil {
		panic(err)
	}
	defer os.RemoveAll(homeDir)
	dummyAppCreator := func(
		logger log.Logger,
		db dbm.DB,
		traceStore io.Writer,
		appOpts servertypes.AppOptions,
	) servertypes.Application {
		return new(gaia.GaiaApp)
	}
	cmd := server.StartCmd(dummyAppCreator, homeDir)
	flags := cmd.Flags()
	flags.SortFlags = true
	flags.VisitAll(func(flag *pflag.Flag) {
		readFlag(flag.Name)
	})
	readBaseOptions := func() {
		flagsRead := []string{}
		logAndReadFlag := func(name string) interface{} {
			flagsRead = append(flagsRead, name)
			return readFlag(name)
		}
		defer func() {
			if r := recover(); r != nil {
				t.Error("panic after reading flags", flagsRead)
				panic(r)
			}
		}()
		server.DefaultBaseappOptions(appOptionsFromFn(logAndReadFlag))
	}
	readBaseOptions()

	if len(unknownFlagNames) != 0 {
		t.Error(
			"unknown CLI flags in cosmos-sdk; incorporate as needed and update this test",
			unknownFlagNames,
		)
	}
	if len(missingFlagNames) != 0 {
		missing := []string{}
		for name, _ := range missingFlagNames {
			missing = append(missing, name)
		}
		t.Error(
			"expected CLI flags missing from cosmos-sdk; remove from this test",
			missing,
		)
	}
}

@mhofman
Copy link
Member Author

mhofman commented May 30, 2024

We should have protection against this kind of lapse in the future...

We should, let's address that in #9425

Copy link

cloudflare-workers-and-pages bot commented May 31, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6afa658
Status: ✅  Deploy successful!
Preview URL: https://ca68ca35.agoric-sdk.pages.dev
Branch Preview URL: https://mhofman-9424-plumb-iavl-conf.agoric-sdk.pages.dev

View logs

@mhofman mhofman requested a review from gibson042 May 31, 2024 01:26
@mhofman
Copy link
Member Author

mhofman commented May 31, 2024

maybe a test that imports "github.com/cosmos/cosmos-sdk/server" and uses its functions to see what flags exist

@gibson042 I ended up tweaking your test to parse the default config file generated from template to get the full list of default options. PTAL

Copy link
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested a text/template simplification, but LGTM!

golang/cosmos/daemon/cmd/root_test.go Outdated Show resolved Hide resolved
@mhofman mhofman changed the title fix(cosmos): Add support for iavl options Add support for iavl options in cosmos config May 31, 2024
@mhofman mhofman added the automerge:rebase Automatically rebase updates, then merge label May 31, 2024
@mhofman mhofman force-pushed the mhofman/9424-plumb-iavl-config branch from 4c6c083 to 6afa658 Compare May 31, 2024 05:02
@mergify mergify bot merged commit 074abce into master May 31, 2024
63 checks passed
@mergify mergify bot deleted the mhofman/9424-plumb-iavl-config branch May 31, 2024 05:35
mhofman pushed a commit that referenced this pull request Jun 23, 2024
closes: #9424

## Description

Plumb the iavl options into the cosmos baseapp.

Copied by comparing to `DefaultBaseappOptions` in cosmos-sdk
`server/util.go`, which we should likely use directly instead (see
#9425), but this is a minimal change we can easily adopt now.

### Security Considerations

None

### Scaling Considerations

None

### Documentation Considerations

None. Change should explicitly be part of the release notes

### Testing Considerations

Unsure about how to test this

### Upgrade Considerations

Chain software, not consensus affecting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

iavl options and flags are not applied
2 participants