From 38c61109bbac8f7309bbbd1e3357d41273a9278c Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 8 May 2024 14:32:11 -0600 Subject: [PATCH 01/23] [1760]: Turn off address caching in Test_TestnetCmd because it's caching addresses with the wrong hrp for other tests. This doesn't show up if running tests one file at a time, but causes panics when all the tests in that package are run together. --- cmd/provenanced/cmd/testnet_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/provenanced/cmd/testnet_test.go b/cmd/provenanced/cmd/testnet_test.go index 6b3e9c929c..6fcdfe333b 100644 --- a/cmd/provenanced/cmd/testnet_test.go +++ b/cmd/provenanced/cmd/testnet_test.go @@ -16,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" @@ -26,6 +27,9 @@ import ( ) func Test_TestnetCmd(t *testing.T) { + origCache := sdk.IsAddrCacheEnabled() + defer sdk.SetAddrCacheEnabled(origCache) + sdk.SetAddrCacheEnabled(false) home := t.TempDir() pioconfig.SetProvenanceConfig("", 0) logger := log.NewNopLogger() From 6ad34a5cff474f98c4fb4317c534e5031c906548 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 8 May 2024 16:21:27 -0600 Subject: [PATCH 02/23] [1760]: Fix some config unit tests that started failing because they were using fields that no longer exist. --- cmd/provenanced/cmd/config_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/provenanced/cmd/config_test.go b/cmd/provenanced/cmd/config_test.go index 89306a5350..dea265a779 100644 --- a/cmd/provenanced/cmd/config_test.go +++ b/cmd/provenanced/cmd/config_test.go @@ -243,13 +243,13 @@ func (s *ConfigTestSuite) TestConfigCmdGet() { {"app header", regexp.MustCompile(`(?m)^App Config: .*/config/` + s.BaseFNApp + ` \(or env\)$`)}, {"app halt-height", regexp.MustCompile(`(?m)^halt-height=0$`)}, {"app api.swagger", regexp.MustCompile(`(?m)^api.swagger=false$`)}, - {"app grpc.address", regexp.MustCompile(`(?m)^grpc.address="0.0.0.0:9090"$`)}, + {"app grpc.address", regexp.MustCompile(`(?m)^grpc.address="localhost:9090"$`)}, {"app telemetry.enabled", regexp.MustCompile(`(?m)^telemetry.enabled=false$`)}, - {"app rosetta.enable", regexp.MustCompile(`(?m)^rosetta.enable=false$`)}, + {"app statesync.enable", regexp.MustCompile(`(?m)^statesync.enable=false$`)}, // Tendermint header and a few entries. {"tendermint header", regexp.MustCompile(`(?m)^Tendermint Config: .*/config/` + s.BaseFNTM + ` \(or env\)$`)}, - {"tendermint fast_sync", regexp.MustCompile(`(?m)^fast_sync=true$`)}, + {"tendermint db_dir", regexp.MustCompile(`(?m)^db_dir="data"$`)}, {"tendermint consensus.timeout_commit", regexp.MustCompile(`(?m)^consensus.timeout_commit=` + fmt.Sprintf("%q", provconfig.DefaultConsensusTimeoutCommit) + `$`)}, {"tendermint mempool.size", regexp.MustCompile(`(?m)^mempool.size=5000$`)}, {"tendermint statesync.trust_period", regexp.MustCompile(`(?m)^statesync.trust_period="168h0m0s"$`)}, @@ -337,12 +337,12 @@ func (s *ConfigTestSuite) TestConfigGetMulti() { }{ { name: "three app config keys", - keys: []string{"min-retain-blocks", "rosetta.retries", "grpc.address"}, + keys: []string{"min-retain-blocks", "mempool.max-txs", "grpc.address"}, expected: s.makeMultiLine( s.makeAppConfigHeaderLines(), `min-retain-blocks=0`, - `grpc.address="0.0.0.0:9090"`, - `rosetta.retries=3`, + `grpc.address="localhost:9090"`, + `mempool.max-txs=5000`, ""), }, { @@ -367,11 +367,11 @@ func (s *ConfigTestSuite) TestConfigGetMulti() { }, { name: "two from each", - keys: []string{"rpc.cors_allowed_origins", "pruning", "node", "rosetta.offline", "chain-id", "priv_validator_state_file"}, + keys: []string{"rpc.cors_allowed_origins", "pruning", "node", "api.enable", "chain-id", "priv_validator_state_file"}, expected: s.makeMultiLine( s.makeAppConfigHeaderLines(), `pruning="default"`, - `rosetta.offline=false`, + `api.enable=false`, "", s.makeTMConfigHeaderLines(), `priv_validator_state_file="data/priv_validator_state.json"`, From 1bb59d3eeee5adfaf1b6d625b4c9be8868790347 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 8 May 2024 17:14:05 -0600 Subject: [PATCH 03/23] [1760]: Update the config get and changed sub-commands to check all the configs for entries, possibly outputting multiple. --- cmd/provenanced/cmd/config.go | 68 +++++++++++++++--------------- cmd/provenanced/cmd/config_test.go | 46 ++++++++++++++++++++ 2 files changed, 80 insertions(+), 34 deletions(-) diff --git a/cmd/provenanced/cmd/config.go b/cmd/provenanced/cmd/config.go index 4db0794e41..e9e29b5315 100644 --- a/cmd/provenanced/cmd/config.go +++ b/cmd/provenanced/cmd/config.go @@ -274,15 +274,23 @@ func runConfigGetCmd(cmd *cobra.Command, args []string) error { case "client": clientToOutput.AddEntriesFrom(clientFields) default: - entries, foundIn := findEntries(key, appFields, tmFields, clientFields) - switch foundIn { - case 0: - appToOutput.AddEntriesFrom(entries) - case 1: - tmToOutput.AddEntriesFrom(entries) - case 2: - clientToOutput.AddEntriesFrom(entries) - default: + var found bool + if fvm, ok := appFields.FindEntries(key); ok { + found = true + appToOutput.AddEntriesFrom(fvm) + } + + if fvm, ok := tmFields.FindEntries(key); ok { + found = true + tmToOutput.AddEntriesFrom(fvm) + } + + if fvm, ok := clientFields.FindEntries(key); ok { + found = true + clientToOutput.AddEntriesFrom(fvm) + } + + if !found { unknownKeyMap.SetToNil(key) } } @@ -492,19 +500,26 @@ func runConfigChangedCmd(cmd *cobra.Command, args []string) error { showClient = true clientDiffs.AddOrUpdateEntriesFrom(provconfig.MakeUpdatedFieldMap(allDefaults, clientFields, true)) default: - entries, foundIn := findEntries(key, appFields, tmFields, clientFields) - changes := provconfig.MakeUpdatedFieldMap(allDefaults, entries, false) - switch foundIn { - case 0: - showApp = true + var found bool + if fvm, ok := appFields.FindEntries(key); ok { + showApp, found = true, true + changes := provconfig.MakeUpdatedFieldMap(allDefaults, fvm, false) appDiffs.AddOrUpdateEntriesFrom(changes) - case 1: - showTm = true + } + + if fvm, ok := tmFields.FindEntries(key); ok { + showTm, found = true, true + changes := provconfig.MakeUpdatedFieldMap(allDefaults, fvm, false) tmDiffs.AddOrUpdateEntriesFrom(changes) - case 2: - showClient = true + } + + if fvm, ok := clientFields.FindEntries(key); ok { + showClient, found = true, true + changes := provconfig.MakeUpdatedFieldMap(allDefaults, fvm, false) clientDiffs.AddOrUpdateEntriesFrom(changes) - default: + } + + if !found { unknownKeyMap.SetToNil(key) } } @@ -574,21 +589,6 @@ func runConfigUnpackCmd(cmd *cobra.Command) error { return provconfig.UnpackConfig(cmd) } -// findEntries gets all entries that match a given key from the provided maps. -// If the key doesn't end in a period, findEntry is used first to find an exact match. -// If an exact match isn't found, a period is appended to the key (unless already there) and sub-entry matches are looked for. -// Maps are searched in the order provided and results are returned when they're first found. -// The second return value is the index of the provided map that the entries were found in (starting with 0). -// If it's equal to entryNotFound, no entries were found. -func findEntries(key string, maps ...provconfig.FieldValueMap) (provconfig.FieldValueMap, int) { - for i, m := range maps { - if fvm, ok := m.FindEntries(key); ok { - return fvm, i - } - } - return provconfig.FieldValueMap{}, entryNotFound -} - // makeFieldMapString makes a multi-line string with all the keys and values in the provided map. func makeFieldMapString(m provconfig.FieldValueMap) string { keys := m.GetSortedKeys() diff --git a/cmd/provenanced/cmd/config_test.go b/cmd/provenanced/cmd/config_test.go index dea265a779..f97b5f2825 100644 --- a/cmd/provenanced/cmd/config_test.go +++ b/cmd/provenanced/cmd/config_test.go @@ -382,6 +382,28 @@ func (s *ConfigTestSuite) TestConfigGetMulti() { `node="tcp://localhost:26657"`, ""), }, + { + name: "one category that is in two files", + keys: []string{"mempool"}, + expected: s.makeMultiLine( + s.makeAppConfigHeaderLines(), + `mempool.max-txs=5000`, + "", + s.makeTMConfigHeaderLines(), + `mempool.broadcast=true`, + `mempool.cache_size=10000`, + `mempool.experimental_max_gossip_connections_to_non_persistent_peers=0`, + `mempool.experimental_max_gossip_connections_to_persistent_peers=0`, + `mempool.keep-invalid-txs-in-cache=false`, + `mempool.max_batch_bytes=0`, + `mempool.max_tx_bytes=1048576`, + `mempool.max_txs_bytes=1073741824`, + `mempool.recheck=true`, + `mempool.size=5000`, + `mempool.type="flood"`, + `mempool.wal_dir=""`, + ""), + }, } for _, tc := range tests { @@ -499,7 +521,31 @@ func (s *ConfigTestSuite) TestConfigChanged() { "", ), }, + { + name: "changed mempool", + args: []string{"changed", "mempool"}, + out: s.makeMultiLine( + s.makeAppDiffHeaderLines(), + `mempool.max-txs=5000 (same as default)`, + "", + s.makeTMDiffHeaderLines(), + `mempool.broadcast=true (same as default)`, + `mempool.cache_size=10000 (same as default)`, + `mempool.experimental_max_gossip_connections_to_non_persistent_peers=0 (same as default)`, + `mempool.experimental_max_gossip_connections_to_persistent_peers=0 (same as default)`, + `mempool.keep-invalid-txs-in-cache=false (same as default)`, + `mempool.max_batch_bytes=0 (same as default)`, + `mempool.max_tx_bytes=1048576 (same as default)`, + `mempool.max_txs_bytes=1073741824 (same as default)`, + `mempool.recheck=true (same as default)`, + `mempool.size=5000 (same as default)`, + `mempool.type="flood" (same as default)`, + `mempool.wal_dir="" (same as default)`, + "", + ), + }, } + for _, tc := range equalAllTests { s.T().Run(tc.name, func(t *testing.T) { configCmd := s.getConfigCmd() From 535ffb62491b281260dcefbc0837808f6be573ff Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 8 May 2024 17:32:34 -0600 Subject: [PATCH 04/23] [1760]: Start renaming all the tendermint and tm stuff in the config command. Deprecate 'tendermint' and 'tm' as options for 'get' and 'changed', and add 'cometbft', 'comet', and 'cmt' as options. --- app/app.go | 2 +- cmd/provenanced/cmd/config.go | 130 ++++++------ cmd/provenanced/cmd/config_test.go | 265 +++++++++++------------- cmd/provenanced/cmd/docgen_test.go | 2 +- cmd/provenanced/cmd/init.go | 14 +- cmd/provenanced/cmd/pre_upgrade.go | 14 +- cmd/provenanced/cmd/pre_upgrade_test.go | 14 +- cmd/provenanced/cmd/testnet.go | 2 +- cmd/provenanced/config/filenames.go | 10 +- cmd/provenanced/config/interceptor.go | 4 +- cmd/provenanced/config/manager.go | 102 ++++----- cmd/provenanced/config/manager_test.go | 36 ++-- 12 files changed, 290 insertions(+), 305 deletions(-) diff --git a/app/app.go b/app/app.go index 0a7d688a05..62bde3ce3e 100644 --- a/app/app.go +++ b/app/app.go @@ -1296,7 +1296,7 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig serverconfig.API // Register new tx routes from grpc-gateway. authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) - // Register new tendermint queries routes from grpc-gateway. + // Register new queries routes from grpc-gateway. cmtservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) // Register node gRPC service for grpc-gateway. diff --git a/cmd/provenanced/cmd/config.go b/cmd/provenanced/cmd/config.go index e9e29b5315..071a219273 100644 --- a/cmd/provenanced/cmd/config.go +++ b/cmd/provenanced/cmd/config.go @@ -61,8 +61,8 @@ func ConfigGetCmd() *cobra.Command { Or they can be a type of config file: "cosmos", "app" -> %[2]s configuration values. e.g. %[1]s get app - "tendermint", "tm", "config" -> %[3]s configuration values. - e.g. %[1]s get tm + "cometbft", "comet", "cmt", "config" -> %[3]s configuration values. + e.g. %[1]s get cmt "client" -> %[4]s configuration values. e.g. %[1]s get client Or they can be the word "all" to get all configuration values. @@ -71,11 +71,11 @@ func ConfigGetCmd() *cobra.Command { Displayed values will reflect settings defined through environment variables. -`, configCmdStart, provconfig.AppConfFilename, provconfig.TmConfFilename, provconfig.ClientConfFilename), +`, configCmdStart, provconfig.AppConfFilename, provconfig.CmtConfFilename, provconfig.ClientConfFilename), Example: fmt.Sprintf(`$ %[1]s get telemetry.service-name moniker \ $ %[1]s get api consensus \ $ %[1]s get app \ -$ %[1]s get tm \ +$ %[1]s get cmt \ $ %[1]s get client \ $ %[1]s get all \ `, configCmdStart), @@ -147,8 +147,8 @@ Get just the configuration entries that are not default values: %[1]s changed [< Or they can be a type of config file: "cosmos", "app" -> %[2]s configuration values. e.g. %[1]s get app - "tendermint", "tm", "config" -> %[3]s configuration values. - e.g. %[1]s get tm + "cometbft", "comet", "cmt", "config" -> %[3]s configuration values. + e.g. %[1]s get cmt "client" -> %[4]s configuration values. e.g. %[1]s get client Or they can be the word "all" to get all configuration values. @@ -158,7 +158,7 @@ Get just the configuration entries that are not default values: %[1]s changed [< Displayed values will reflect settings defined through environment variables. -`, configCmdStart, provconfig.AppConfFilename, provconfig.TmConfFilename, provconfig.ClientConfFilename), +`, configCmdStart, provconfig.AppConfFilename, provconfig.CmtConfFilename, provconfig.ClientConfFilename), Example: fmt.Sprintf(`$ %[1]s changed \ $ %[1]s changed telemetry.service-name`, configCmdStart), RunE: func(cmd *cobra.Command, args []string) error { @@ -204,7 +204,7 @@ Combines the %[2]s, %[3]s, and %[4]s files into %[1]s. Settings defined through environment variables will be included in the packed file. Settings that are their default value will not be included. -`, provconfig.PackedConfFilename, provconfig.AppConfFilename, provconfig.TmConfFilename, provconfig.ClientConfFilename), +`, provconfig.PackedConfFilename, provconfig.AppConfFilename, provconfig.CmtConfFilename, provconfig.ClientConfFilename), Example: fmt.Sprintf(`$ %[1]s pack`, configCmdStart), Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, _ []string) error { @@ -228,7 +228,7 @@ Default values are filled in appropriately. This can also be used to update the config files using the current template so they include all current fields. -`, provconfig.PackedConfFilename, provconfig.AppConfFilename, provconfig.TmConfFilename, provconfig.ClientConfFilename), +`, provconfig.PackedConfFilename, provconfig.AppConfFilename, provconfig.CmtConfFilename, provconfig.ClientConfFilename), Example: fmt.Sprintf(`$ %[1]s unpack`, configCmdStart), Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, _ []string) error { @@ -244,9 +244,9 @@ func runConfigGetCmd(cmd *cobra.Command, args []string) error { if acerr != nil { return fmt.Errorf("could not get app config fields: %w", acerr) } - _, tmFields, tmcerr := provconfig.ExtractTmConfigAndMap(cmd) - if tmcerr != nil { - return fmt.Errorf("could not get tendermint config fields: %w", tmcerr) + _, cmtFields, cmtcerr := provconfig.ExtractCmtConfigAndMap(cmd) + if cmtcerr != nil { + return fmt.Errorf("could not get cometbft config fields: %w", cmtcerr) } _, clientFields, ccerr := provconfig.ExtractClientConfigAndMap(cmd) if ccerr != nil { @@ -258,19 +258,23 @@ func runConfigGetCmd(cmd *cobra.Command, args []string) error { } appToOutput := provconfig.FieldValueMap{} - tmToOutput := provconfig.FieldValueMap{} + cmtToOutput := provconfig.FieldValueMap{} clientToOutput := provconfig.FieldValueMap{} unknownKeyMap := provconfig.FieldValueMap{} for _, key := range args { switch key { case "all": appToOutput.AddEntriesFrom(appFields) - tmToOutput.AddEntriesFrom(tmFields) + cmtToOutput.AddEntriesFrom(cmtFields) clientToOutput.AddEntriesFrom(clientFields) case "app", "cosmos": appToOutput.AddEntriesFrom(appFields) - case "config", "tendermint", "tm": - tmToOutput.AddEntriesFrom(tmFields) + case "tendermint", "tm": + cmd.Printf("The %q option is deprecated and will be removed in a future version.\n", key) + cmd.Println("Use one of \"cometbft\", \"comet\", or \"cmt\" instead.") + fallthrough + case "config", "cometbft", "comet", "cmt": + cmtToOutput.AddEntriesFrom(cmtFields) case "client": clientToOutput.AddEntriesFrom(clientFields) default: @@ -280,9 +284,9 @@ func runConfigGetCmd(cmd *cobra.Command, args []string) error { appToOutput.AddEntriesFrom(fvm) } - if fvm, ok := tmFields.FindEntries(key); ok { + if fvm, ok := cmtFields.FindEntries(key); ok { found = true - tmToOutput.AddEntriesFrom(fvm) + cmtToOutput.AddEntriesFrom(fvm) } if fvm, ok := clientFields.FindEntries(key); ok { @@ -300,15 +304,15 @@ func runConfigGetCmd(cmd *cobra.Command, args []string) error { cmd.Println(makeAppConfigHeader(cmd, "", isPacked).String()) cmd.Println(makeFieldMapString(appToOutput)) } - if len(tmToOutput) > 0 { - cmd.Println(makeTmConfigHeader(cmd, "", isPacked).String()) - cmd.Println(makeFieldMapString(tmToOutput)) + if len(cmtToOutput) > 0 { + cmd.Println(makeCmtConfigHeader(cmd, "", isPacked).String()) + cmd.Println(makeFieldMapString(cmtToOutput)) } if len(clientToOutput) > 0 { cmd.Println(makeClientConfigHeader(cmd, "", isPacked).String()) cmd.Println(makeFieldMapString(clientToOutput)) } - if isPacked && (len(appToOutput) > 0 || len(tmToOutput) > 0 || len(clientToOutput) > 0) { + if isPacked && (len(appToOutput) > 0 || len(cmtToOutput) > 0 || len(clientToOutput) > 0) { cmd.Println(makeConfigIsPackedLine(cmd)) } if len(unknownKeyMap) > 0 { @@ -353,9 +357,9 @@ func runConfigSetCmd(cmd *cobra.Command, args []string) (bool, error) { if acerr != nil { return false, fmt.Errorf("couldn't get app config: %w", acerr) } - tmConfig, tmFields, tmcerr := provconfig.ExtractTmConfigAndMap(cmd) - if tmcerr != nil { - return false, fmt.Errorf("couldn't get tendermint config: %w", tmcerr) + cmtConfig, cmtFields, cmtcerr := provconfig.ExtractCmtConfigAndMap(cmd) + if cmtcerr != nil { + return false, fmt.Errorf("couldn't get cometbft config: %w", cmtcerr) } clientConfig, clientFields, ccerr := provconfig.ExtractClientConfigAndMap(cmd) if ccerr != nil { @@ -371,12 +375,12 @@ func runConfigSetCmd(cmd *cobra.Command, args []string) (bool, error) { } issueFound := false appUpdates := provconfig.UpdatedFieldMap{} - tmUpdates := provconfig.UpdatedFieldMap{} + cmtUpdates := provconfig.UpdatedFieldMap{} clientUpdates := provconfig.UpdatedFieldMap{} for i, key := range keys { var confMap provconfig.FieldValueMap foundIn := entryNotFound - for fvmi, fvm := range []provconfig.FieldValueMap{appFields, tmFields, clientFields} { + for fvmi, fvm := range []provconfig.FieldValueMap{appFields, cmtFields, clientFields} { if fvm.Has(key) { confMap = fvm foundIn = fvmi @@ -400,7 +404,7 @@ func runConfigSetCmd(cmd *cobra.Command, args []string) (bool, error) { case 0: appUpdates.AddOrUpdate(key, was, isNow) case 1: - tmUpdates.AddOrUpdate(key, was, isNow) + cmtUpdates.AddOrUpdate(key, was, isNow) case 2: clientUpdates.AddOrUpdate(key, was, isNow) } @@ -412,9 +416,9 @@ func runConfigSetCmd(cmd *cobra.Command, args []string) (bool, error) { issueFound = true } } - if len(tmUpdates) > 0 { - if err := tmConfig.ValidateBasic(); err != nil { - cmd.Printf("Tendermint config validation error: %v\n", err) + if len(cmtUpdates) > 0 { + if err := cmtConfig.ValidateBasic(); err != nil { + cmd.Printf("cometbft config validation error: %v\n", err) issueFound = true } } @@ -432,27 +436,27 @@ func runConfigSetCmd(cmd *cobra.Command, args []string) (bool, error) { if len(appUpdates) == 0 { appConfig = nil } - if len(tmUpdates) == 0 { - tmConfig = nil + if len(cmtUpdates) == 0 { + cmtConfig = nil } if len(clientUpdates) == 0 { clientConfig = nil } - provconfig.SaveConfigs(cmd, appConfig, tmConfig, clientConfig, false) + provconfig.SaveConfigs(cmd, appConfig, cmtConfig, clientConfig, false) isPacked := provconfig.IsPacked(cmd) if len(appUpdates) > 0 { cmd.Println(makeAppConfigHeader(cmd, addedLeadUpdated, isPacked).WithoutEnv().String()) cmd.Println(makeUpdatedFieldMapString(appUpdates, provconfig.UpdatedField.StringAsUpdate)) } - if len(tmUpdates) > 0 { - cmd.Println(makeTmConfigHeader(cmd, addedLeadUpdated, isPacked).WithoutEnv().String()) - cmd.Println(makeUpdatedFieldMapString(tmUpdates, provconfig.UpdatedField.StringAsUpdate)) + if len(cmtUpdates) > 0 { + cmd.Println(makeCmtConfigHeader(cmd, addedLeadUpdated, isPacked).WithoutEnv().String()) + cmd.Println(makeUpdatedFieldMapString(cmtUpdates, provconfig.UpdatedField.StringAsUpdate)) } if len(clientUpdates) > 0 { cmd.Println(makeClientConfigHeader(cmd, addedLeadUpdated, isPacked).WithoutEnv().String()) cmd.Println(makeUpdatedFieldMapString(clientUpdates, provconfig.UpdatedField.StringAsUpdate)) } - if isPacked && (len(appUpdates) > 0 || len(tmUpdates) > 0 || len(clientUpdates) > 0) { + if isPacked && (len(appUpdates) > 0 || len(cmtUpdates) > 0 || len(clientUpdates) > 0) { cmd.Println(makeConfigIsPackedLine(cmd)) } return false, nil @@ -464,9 +468,9 @@ func runConfigChangedCmd(cmd *cobra.Command, args []string) error { if acerr != nil { return fmt.Errorf("couldn't get app config: %w", acerr) } - _, tmFields, tmcerr := provconfig.ExtractTmConfigAndMap(cmd) - if tmcerr != nil { - return fmt.Errorf("couldn't get tendermint config: %w", tmcerr) + _, cmtFields, cmtcerr := provconfig.ExtractCmtConfigAndMap(cmd) + if cmtcerr != nil { + return fmt.Errorf("couldn't get cometbft config: %w", cmtcerr) } _, clientFields, ccerr := provconfig.ExtractClientConfigAndMap(cmd) if ccerr != nil { @@ -478,24 +482,28 @@ func runConfigChangedCmd(cmd *cobra.Command, args []string) error { } allDefaults := provconfig.GetAllConfigDefaults() - showApp, showTm, showClient := false, false, false + showApp, showCmt, showClient := false, false, false appDiffs := provconfig.UpdatedFieldMap{} - tmDiffs := provconfig.UpdatedFieldMap{} + cmtDiffs := provconfig.UpdatedFieldMap{} clientDiffs := provconfig.UpdatedFieldMap{} unknownKeyMap := provconfig.FieldValueMap{} for _, key := range args { switch key { case "all": - showApp, showTm, showClient = true, true, true + showApp, showCmt, showClient = true, true, true appDiffs.AddOrUpdateEntriesFrom(provconfig.MakeUpdatedFieldMap(allDefaults, appFields, true)) - tmDiffs.AddOrUpdateEntriesFrom(provconfig.MakeUpdatedFieldMap(allDefaults, tmFields, true)) + cmtDiffs.AddOrUpdateEntriesFrom(provconfig.MakeUpdatedFieldMap(allDefaults, cmtFields, true)) clientDiffs.AddOrUpdateEntriesFrom(provconfig.MakeUpdatedFieldMap(allDefaults, clientFields, true)) case "app", "cosmos": showApp = true appDiffs.AddOrUpdateEntriesFrom(provconfig.MakeUpdatedFieldMap(allDefaults, appFields, true)) - case "config", "tendermint", "tm": - showTm = true - tmDiffs.AddOrUpdateEntriesFrom(provconfig.MakeUpdatedFieldMap(allDefaults, tmFields, true)) + case "tendermint", "tm": + cmd.Printf("The %q option is deprecated and will be removed in a future version.\n", key) + cmd.Println("Use one of \"cometbft\", \"comet\", or \"cmt\" instead.") + fallthrough + case "config", "cometbft", "comet", "cmt": + showCmt = true + cmtDiffs.AddOrUpdateEntriesFrom(provconfig.MakeUpdatedFieldMap(allDefaults, cmtFields, true)) case "client": showClient = true clientDiffs.AddOrUpdateEntriesFrom(provconfig.MakeUpdatedFieldMap(allDefaults, clientFields, true)) @@ -507,10 +515,10 @@ func runConfigChangedCmd(cmd *cobra.Command, args []string) error { appDiffs.AddOrUpdateEntriesFrom(changes) } - if fvm, ok := tmFields.FindEntries(key); ok { - showTm, found = true, true + if fvm, ok := cmtFields.FindEntries(key); ok { + showCmt, found = true, true changes := provconfig.MakeUpdatedFieldMap(allDefaults, fvm, false) - tmDiffs.AddOrUpdateEntriesFrom(changes) + cmtDiffs.AddOrUpdateEntriesFrom(changes) } if fvm, ok := clientFields.FindEntries(key); ok { @@ -537,12 +545,12 @@ func runConfigChangedCmd(cmd *cobra.Command, args []string) error { } } - if showTm { - cmd.Println(makeTmConfigHeader(cmd, addedLeadChanged, isPacked).String()) - if len(tmDiffs) > 0 { - cmd.Println(makeUpdatedFieldMapString(tmDiffs, provconfig.UpdatedField.StringAsDefault)) + if showCmt { + cmd.Println(makeCmtConfigHeader(cmd, addedLeadChanged, isPacked).String()) + if len(cmtDiffs) > 0 { + cmd.Println(makeUpdatedFieldMapString(cmtDiffs, provconfig.UpdatedField.StringAsDefault)) } else { - cmd.Println("All tendermint config values equal the default config values.") + cmd.Println("All cometbft config values equal the default config values.") cmd.Println("") } } @@ -557,7 +565,7 @@ func runConfigChangedCmd(cmd *cobra.Command, args []string) error { } } - if isPacked && (showApp || showTm || showClient) { + if isPacked && (showApp || showCmt || showClient) { cmd.Println(makeConfigIsPackedLine(cmd)) } @@ -670,12 +678,12 @@ func makeAppConfigHeader(cmd *cobra.Command, addedLead string, isPacked bool) *s } } -// makeTmConfigHeader creates a section header string for tendermint config stuff. -func makeTmConfigHeader(cmd *cobra.Command, addedLead string, isPacked bool) *sectionHeader { +// makeCmtConfigHeader creates a section header string for cometbft config stuff. +func makeCmtConfigHeader(cmd *cobra.Command, addedLead string, isPacked bool) *sectionHeader { return §ionHeader{ - lead: "Tendermint Config", + lead: "CometBFT Config", addedLead: addedLead, - filename: provconfig.GetFullPathToTmConf(cmd), + filename: provconfig.GetFullPathToCmtConf(cmd), isPacked: isPacked, env: true, } diff --git a/cmd/provenanced/cmd/config_test.go b/cmd/provenanced/cmd/config_test.go index f97b5f2825..60852c9462 100644 --- a/cmd/provenanced/cmd/config_test.go +++ b/cmd/provenanced/cmd/config_test.go @@ -40,11 +40,11 @@ type ConfigTestSuite struct { EncodingConfig simappparams.EncodingConfig HeaderStrApp string - HeaderStrTM string + HeaderStrCMT string HeaderStrClient string BaseFNApp string - BaseFNTM string + BaseFNCMT string baseFNClient string } @@ -59,7 +59,7 @@ func (s *ConfigTestSuite) SetupTest() { WithCodec(s.EncodingConfig.Marshaler). WithHomeDir(s.Home) clientCtx.Viper = viper.New() - serverCtx := server.NewContext(clientCtx.Viper, provconfig.DefaultTmConfig(), log.NewNopLogger()) + serverCtx := server.NewContext(clientCtx.Viper, provconfig.DefaultCmtConfig(), log.NewNopLogger()) ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) @@ -70,11 +70,11 @@ func (s *ConfigTestSuite) SetupTest() { s.Context = &ctx s.HeaderStrApp = "App" - s.HeaderStrTM = "Tendermint" + s.HeaderStrCMT = "CometBFT" s.HeaderStrClient = "Client" s.BaseFNApp = "app.toml" - s.BaseFNTM = "config.toml" + s.BaseFNCMT = "config.toml" s.baseFNClient = "client.toml" s.ensureConfigFiles() @@ -111,13 +111,25 @@ func (s *ConfigTestSuite) ensureConfigFiles() { // Extract the individual config objects. appConfig, aerr := provconfig.ExtractAppConfig(configCmd) s.Require().NoError(aerr, "extracting app config") - tmConfig, terr := provconfig.ExtractTmConfig(configCmd) - s.Require().NoError(terr, "extracting tendermint config") + cmtConfig, terr := provconfig.ExtractCmtConfig(configCmd) + s.Require().NoError(terr, "extracting cometbft config") clientConfig, cerr := provconfig.ExtractClientConfig(configCmd) s.Require().NoError(cerr, "extracting client config") appConfig.MinGasPrices = pioconfig.GetProvenanceConfig().ProvenanceMinGasPrices // And then save them. - provconfig.SaveConfigs(configCmd, appConfig, tmConfig, clientConfig, false) + provconfig.SaveConfigs(configCmd, appConfig, cmtConfig, clientConfig, false) +} + +// executeConfigCmd executes the config command with the provided args, returning the command's output. +func (s *ConfigTestSuite) executeConfigCmd(args ...string) string { + configCmd := s.getConfigCmd() + configCmd.SetArgs(args) + b := applyMockIOOutErr(configCmd) + err := configCmd.Execute() + s.Require().NoError(err, "unexpected error executing %s %q", configCmd.Name(), args) + out, err := io.ReadAll(b) + s.Require().NoError(err, "unexpected error reading %s %q output", configCmd.Name(), args) + return string(out) } func (s *ConfigTestSuite) makeConfigHeaderLine(t, fn string) string { @@ -128,8 +140,8 @@ func (s *ConfigTestSuite) makeAppConfigHeaderLines() string { return s.makeConfigHeaderLine(s.HeaderStrApp, s.BaseFNApp) + "\n----------------" } -func (s *ConfigTestSuite) makeTMConfigHeaderLines() string { - return s.makeConfigHeaderLine(s.HeaderStrTM, s.BaseFNTM) + "\n-----------------------" +func (s *ConfigTestSuite) makeCMTConfigHeaderLines() string { + return s.makeConfigHeaderLine(s.HeaderStrCMT, s.BaseFNCMT) + "\n---------------------" } func (s *ConfigTestSuite) makeClientConfigHeaderLines() string { @@ -144,8 +156,8 @@ func (s *ConfigTestSuite) makeAppConfigUpdateLines() string { return s.makeConfigUpdatedLine(s.HeaderStrApp, s.BaseFNApp) + "\n------------------------" } -func (s *ConfigTestSuite) makeTMConfigUpdateLines() string { - return s.makeConfigUpdatedLine(s.HeaderStrTM, s.BaseFNTM) + "\n-------------------------------" +func (s *ConfigTestSuite) makeCMTConfigUpdateLines() string { + return s.makeConfigUpdatedLine(s.HeaderStrCMT, s.BaseFNCMT) + "\n-----------------------------" } func (s *ConfigTestSuite) makeClientConfigUpdateLines() string { @@ -160,14 +172,19 @@ func (s *ConfigTestSuite) makeAppDiffHeaderLines() string { return s.makeConfigDiffHeaderLine(s.HeaderStrApp, s.BaseFNApp) + "\n------------------------------------------" } -func (s *ConfigTestSuite) makeTMDiffHeaderLines() string { - return s.makeConfigDiffHeaderLine(s.HeaderStrTM, s.BaseFNTM) + "\n-------------------------------------------------" +func (s *ConfigTestSuite) makeCMTDiffHeaderLines() string { + return s.makeConfigDiffHeaderLine(s.HeaderStrCMT, s.BaseFNCMT) + "\n-----------------------------------------------" } func (s *ConfigTestSuite) makeClientDiffHeaderLines() string { return s.makeConfigDiffHeaderLine(s.HeaderStrClient, s.baseFNClient) + "\n---------------------------------------------" } +func (s *ConfigTestSuite) makeTmDeprecatedLines(opt string) string { + return "The \"" + opt + "\" option is deprecated and will be removed in a future version.\n" + + "Use one of \"cometbft\", \"comet\", or \"cmt\" instead.\n" +} + func (s *ConfigTestSuite) makeMultiLine(lines ...string) string { return strings.Join(lines, "\n") + "\n" } @@ -223,18 +240,10 @@ func (s *ConfigTestSuite) TestConfigBadArgs() { } func (s *ConfigTestSuite) TestConfigCmdGet() { - configCmd := s.getConfigCmd() - - configCmd.SetArgs([]string{"get"}) - b := applyMockIOOutErr(configCmd) - err := configCmd.Execute() - s.Require().NoError(err, "%s - unexpected error executing configCmd", configCmd.Name()) - out, err := io.ReadAll(b) - s.Require().NoError(err, "%s - unexpected error reading configCmd output", configCmd.Name()) - outStr := string(out) + noArgsOut := s.executeConfigCmd("get") // Only spot-checking instead of checking the entire 100+ lines exactly because I don't want this to needlessly break - // if comsos or tendermint adds a new configuration field/section. + // if comsos or cometbft adds a new configuration field/section. expectedRegexpMatches := []struct { name string re *regexp.Regexp @@ -247,13 +256,13 @@ func (s *ConfigTestSuite) TestConfigCmdGet() { {"app telemetry.enabled", regexp.MustCompile(`(?m)^telemetry.enabled=false$`)}, {"app statesync.enable", regexp.MustCompile(`(?m)^statesync.enable=false$`)}, - // Tendermint header and a few entries. - {"tendermint header", regexp.MustCompile(`(?m)^Tendermint Config: .*/config/` + s.BaseFNTM + ` \(or env\)$`)}, - {"tendermint db_dir", regexp.MustCompile(`(?m)^db_dir="data"$`)}, - {"tendermint consensus.timeout_commit", regexp.MustCompile(`(?m)^consensus.timeout_commit=` + fmt.Sprintf("%q", provconfig.DefaultConsensusTimeoutCommit) + `$`)}, - {"tendermint mempool.size", regexp.MustCompile(`(?m)^mempool.size=5000$`)}, - {"tendermint statesync.trust_period", regexp.MustCompile(`(?m)^statesync.trust_period="168h0m0s"$`)}, - {"tendermint p2p.recv_rate", regexp.MustCompile(`(?m)^p2p.recv_rate=5120000$`)}, + // CometBFT header and a few entries. + {"cometbft header", regexp.MustCompile(`(?m)^CometBFT Config: .*/config/` + s.BaseFNCMT + ` \(or env\)$`)}, + {"cometbft db_dir", regexp.MustCompile(`(?m)^db_dir="data"$`)}, + {"cometbft consensus.timeout_commit", regexp.MustCompile(`(?m)^consensus.timeout_commit=` + fmt.Sprintf("%q", provconfig.DefaultConsensusTimeoutCommit) + `$`)}, + {"cometbft mempool.size", regexp.MustCompile(`(?m)^mempool.size=5000$`)}, + {"cometbft statesync.trust_period", regexp.MustCompile(`(?m)^statesync.trust_period="168h0m0s"$`)}, + {"cometbft p2p.recv_rate", regexp.MustCompile(`(?m)^p2p.recv_rate=5120000$`)}, // Client config header all the entries. {"client header", regexp.MustCompile(`(?m)^Client Config: .*/config/` + s.baseFNClient + ` \(or env\)$`)}, @@ -265,66 +274,41 @@ func (s *ConfigTestSuite) TestConfigCmdGet() { } for _, tc := range expectedRegexpMatches { - s.T().Run(tc.name, func(t *testing.T) { - isMatch := tc.re.Match(out) - assert.True(t, isMatch, "`%s` matching:\n%s", tc.re.String(), out) + s.Run(tc.name, func() { + isMatch := tc.re.MatchString(noArgsOut) + s.Assert().True(isMatch, "`%s` matching:\n%s", tc.re.String(), noArgsOut) }) } - s.T().Run("with args get all", func(t *testing.T) { - configCmd2 := s.getConfigCmd() - args := []string{"get", "all"} - configCmd2.SetArgs(args) - b2 := applyMockIOOutErr(configCmd2) - err2 := configCmd2.Execute() - require.NoError(t, err2, "%s - unexpected error executing configCmd", configCmd2.Name()) - out2, err2 := io.ReadAll(b2) - require.NoError(t, err2, "%s - unexpected error reading configCmd output", configCmd2.Name()) - out2Str := string(out2) - require.Equal(t, outStr, out2Str, "output of no-args vs output of %s", args) + s.Run("with args get all", func() { + allOutStr := s.executeConfigCmd("get", "all") + s.Assert().Equal(noArgsOut, allOutStr, "output of get vs output of get all") }) - inOutTests := []struct { - name string - args []string - }{ - { - name: "get app", - args: []string{"get", "app"}, - }, - { - name: "get cosmos", - args: []string{"get", "cosmos"}, - }, - { - name: "get config", - args: []string{"get", "config"}, - }, - { - name: "get tendermint", - args: []string{"get", "tendermint"}, - }, - { - name: "get tm", - args: []string{"get", "tm"}, - }, - { - name: "get client", - args: []string{"get", "client"}, - }, + inOutTests := []string{ + "app", + "cosmos", + "config", + "cometbft", + "comet", + "cmt", + "client", } - for _, tc := range inOutTests { - s.T().Run(tc.name, func(t *testing.T) { - configCmd3 := s.getConfigCmd() - configCmd3.SetArgs(tc.args) - b3 := applyMockIOOutErr(configCmd3) - err3 := configCmd3.Execute() - require.NoError(t, err3, "%s - unexpected error executing configCmd", configCmd3.Name()) - out3, rerr3 := io.ReadAll(b3) - require.NoError(t, rerr3, "%s - unexpected error reading configCmd output", configCmd3.Name()) - out3Str := string(out3) - require.Contains(t, outStr, out3Str, "output of no-args vs output of %s", tc.args) + for _, opt := range inOutTests { + args := []string{"get", opt} + s.Run(strings.Join(args, " "), func() { + outStr := s.executeConfigCmd(args...) + s.Assert().Contains(noArgsOut, outStr, "output of get vs output of %q", args) + }) + } + + for _, opt := range []string{"tendermint", "tm"} { + args := []string{"get", opt} + s.Run(strings.Join(args, " "), func() { + expTMOut := s.makeTmDeprecatedLines(opt) + s.executeConfigCmd("get", "cmt") + outStr := s.executeConfigCmd(args...) + s.Assert().Equal(expTMOut, outStr) }) } } @@ -346,10 +330,10 @@ func (s *ConfigTestSuite) TestConfigGetMulti() { ""), }, { - name: "three tendermint config keys", + name: "three cometbft config keys", keys: []string{"p2p.send_rate", "genesis_file", "consensus.timeout_propose"}, expected: s.makeMultiLine( - s.makeTMConfigHeaderLines(), + s.makeCMTConfigHeaderLines(), `genesis_file="config/genesis.json"`, `consensus.timeout_propose="3s"`, `p2p.send_rate=5120000`, @@ -373,7 +357,7 @@ func (s *ConfigTestSuite) TestConfigGetMulti() { `pruning="default"`, `api.enable=false`, "", - s.makeTMConfigHeaderLines(), + s.makeCMTConfigHeaderLines(), `priv_validator_state_file="data/priv_validator_state.json"`, `rpc.cors_allowed_origins=[]`, "", @@ -389,7 +373,7 @@ func (s *ConfigTestSuite) TestConfigGetMulti() { s.makeAppConfigHeaderLines(), `mempool.max-txs=5000`, "", - s.makeTMConfigHeaderLines(), + s.makeCMTConfigHeaderLines(), `mempool.broadcast=true`, `mempool.cache_size=10000`, `mempool.experimental_max_gossip_connections_to_non_persistent_peers=0`, @@ -453,7 +437,7 @@ func (s *ConfigTestSuite) TestConfigGetMulti() { s.makeAppConfigHeaderLines(), `grpc.enable=true`, "", - s.makeTMConfigHeaderLines(), + s.makeCMTConfigHeaderLines(), `consensus.create_empty_blocks_interval="0s"`, "", ) + "Error: " + expectedError + "\n" @@ -480,9 +464,9 @@ func (s *ConfigTestSuite) TestConfigChanged() { allEqual("app"), "", } - expectedTMOutLines := []string{ - s.makeTMDiffHeaderLines(), - allEqual("tendermint"), + expectedCMTOutLines := []string{ + s.makeCMTDiffHeaderLines(), + allEqual("cometbft"), "", } expectedClientOutLines := []string{ @@ -492,28 +476,29 @@ func (s *ConfigTestSuite) TestConfigChanged() { } var expectedAllOutLines []string expectedAllOutLines = append(expectedAllOutLines, expectedAppOutLines...) - expectedAllOutLines = append(expectedAllOutLines, expectedTMOutLines...) + expectedAllOutLines = append(expectedAllOutLines, expectedCMTOutLines...) expectedAllOutLines = append(expectedAllOutLines, expectedClientOutLines...) expectedAppOut := s.makeMultiLine(expectedAppOutLines...) - expectedTMOut := s.makeMultiLine(expectedTMOutLines...) + expectedCMTOut := s.makeMultiLine(expectedCMTOutLines...) expectedClientOut := s.makeMultiLine(expectedClientOutLines...) expectedAll := s.makeMultiLine(expectedAllOutLines...) equalAllTests := []struct { - name string args []string out string }{ - {"changed", []string{"changed"}, expectedAll}, - {"changed all", []string{"changed", "all"}, expectedAll}, - {"changed app", []string{"changed", "app"}, expectedAppOut}, - {"changed cosmos", []string{"changed", "cosmos"}, expectedAppOut}, - {"changed config", []string{"changed", "config"}, expectedTMOut}, - {"changed tm", []string{"changed", "tm"}, expectedTMOut}, - {"changed tendermint", []string{"changed", "tendermint"}, expectedTMOut}, - {"changed client", []string{"changed", "client"}, expectedClientOut}, + {args: []string{"changed"}, out: expectedAll}, + {args: []string{"changed", "all"}, out: expectedAll}, + {args: []string{"changed", "app"}, out: expectedAppOut}, + {args: []string{"changed", "cosmos"}, out: expectedAppOut}, + {args: []string{"changed", "config"}, out: expectedCMTOut}, + {args: []string{"changed", "tm"}, out: s.makeTmDeprecatedLines("tm") + expectedCMTOut}, + {args: []string{"changed", "tendermint"}, out: s.makeTmDeprecatedLines("tendermint") + expectedCMTOut}, + {args: []string{"changed", "cometbft"}, out: expectedCMTOut}, + {args: []string{"changed", "comet"}, out: expectedCMTOut}, + {args: []string{"changed", "cmt"}, out: expectedCMTOut}, + {args: []string{"changed", "client"}, out: expectedClientOut}, { - name: "changed output", args: []string{"changed", "output"}, out: s.makeMultiLine( s.makeClientDiffHeaderLines(), @@ -522,13 +507,12 @@ func (s *ConfigTestSuite) TestConfigChanged() { ), }, { - name: "changed mempool", args: []string{"changed", "mempool"}, out: s.makeMultiLine( s.makeAppDiffHeaderLines(), `mempool.max-txs=5000 (same as default)`, "", - s.makeTMDiffHeaderLines(), + s.makeCMTDiffHeaderLines(), `mempool.broadcast=true (same as default)`, `mempool.cache_size=10000 (same as default)`, `mempool.experimental_max_gossip_connections_to_non_persistent_peers=0 (same as default)`, @@ -547,16 +531,9 @@ func (s *ConfigTestSuite) TestConfigChanged() { } for _, tc := range equalAllTests { - s.T().Run(tc.name, func(t *testing.T) { - configCmd := s.getConfigCmd() - configCmd.SetArgs(tc.args) - b := applyMockIOOutErr(configCmd) - err := configCmd.Execute() - require.NoError(t, err, "%s %s - unexpected error executing configCmd", configCmd.Name(), tc.args) - out, err := io.ReadAll(b) - require.NoError(t, err, "%s %s - unexpected error reading configCmd output", configCmd.Name(), tc.args) - outStr := string(out) - assert.Equal(t, tc.out, outStr, "%s %s - output", configCmd.Name(), tc.args) + s.Run(strings.Join(tc.args, " "), func() { + outStr := s.executeConfigCmd(tc.args...) + s.Assert().Equal(tc.out, outStr) }) } } @@ -573,9 +550,9 @@ func (s *ConfigTestSuite) TestConfigSetValidation() { out: `App config validation error: set min gas price in app.toml or flag or env variable: error in app.toml [cosmos/cosmos-sdk@v0.43.0/types/errors/errors.go:269]`, }, { - name: "set tendermint fails validation", + name: "set cometbft fails validation", args: []string{"set", "log_format", "crazy"}, - out: `Tendermint config validation error: unknown log_format (must be 'plain' or 'json')`, + out: `CometBFT config validation error: unknown log_format (must be 'plain' or 'json')`, }, { name: "set client fails validation", @@ -602,7 +579,7 @@ func (s *ConfigTestSuite) TestConfigSetValidation() { func (s *ConfigTestSuite) TestConfigCmdSet() { reAppConfigUpdated := regexp.MustCompile(`(?m)^App Config Updated: .*/config/` + s.BaseFNApp + `$`) - reTMConfigUpdated := regexp.MustCompile(`(?m)^Tendermint Config Updated: .*/config/` + s.BaseFNTM + `$`) + reCMTConfigUpdated := regexp.MustCompile(`(?m)^CometBFT Config Updated: .*/config/` + s.BaseFNCMT + `$`) reClientConfigUpdated := regexp.MustCompile(`(?m)^Client Config Updated: .*/config/` + s.baseFNClient + `$`) positiveTests := []struct { @@ -643,36 +620,36 @@ func (s *ConfigTestSuite) TestConfigCmdSet() { toMatch: []*regexp.Regexp{reAppConfigUpdated}, }, - // tendermint fields + // cometbft fields { name: "filter_peers", oldVal: `false`, newVal: `true`, - toMatch: []*regexp.Regexp{reTMConfigUpdated}, + toMatch: []*regexp.Regexp{reCMTConfigUpdated}, }, { name: "proxy_app", oldVal: `"tcp://127.0.0.1:26658"`, newVal: `"tcp://localhost:26658"`, - toMatch: []*regexp.Regexp{reTMConfigUpdated}, + toMatch: []*regexp.Regexp{reCMTConfigUpdated}, }, { name: "consensus.timeout_commit", oldVal: fmt.Sprintf("%q", provconfig.DefaultConsensusTimeoutCommit), newVal: `"2s"`, - toMatch: []*regexp.Regexp{reTMConfigUpdated}, + toMatch: []*regexp.Regexp{reCMTConfigUpdated}, }, { name: "mempool.cache_size", oldVal: `10000`, newVal: `10005`, - toMatch: []*regexp.Regexp{reTMConfigUpdated}, + toMatch: []*regexp.Regexp{reCMTConfigUpdated}, }, { name: "rpc.cors_allowed_methods", oldVal: `["HEAD", "GET", "POST"]`, newVal: `["POST", "HEAD", "GET"]`, - toMatch: []*regexp.Regexp{reTMConfigUpdated}, + toMatch: []*regexp.Regexp{reCMTConfigUpdated}, }, // Client fields @@ -745,10 +722,10 @@ func (s *ConfigTestSuite) TestConfigSetMulti() { ""), }, { - name: "two tendermint entries", + name: "two cometbft entries", args: []string{"set", "log_format", "json", "consensus.timeout_commit", "950ms"}, out: s.makeMultiLine( - s.makeTMConfigUpdateLines(), + s.makeCMTConfigUpdateLines(), s.makeKeyUpdatedLine("log_format", `"plain"`, `"json"`), s.makeKeyUpdatedLine("consensus.timeout_commit", fmt.Sprintf("%q", provconfig.DefaultConsensusTimeoutCommit), `"950ms"`), ""), @@ -776,7 +753,7 @@ func (s *ConfigTestSuite) TestConfigSetMulti() { s.makeKeyUpdatedLine("api.swagger", "false", "true"), s.makeKeyUpdatedLine("telemetry.service-name", `"blocky"`, `"blocky2"`), "", - s.makeTMConfigUpdateLines(), + s.makeCMTConfigUpdateLines(), s.makeKeyUpdatedLine("log_format", `"json"`, `"plain"`), s.makeKeyUpdatedLine("consensus.timeout_commit", `"950ms"`, `"951ms"`), "", @@ -826,9 +803,9 @@ func (s *ConfigTestSuite) TestPackUnpack() { appFile := provconfig.GetFullPathToAppConf(configCmd) assert.Contains(t, outStr, appFile, "app filename") assert.False(t, provconfig.FileExists(appFile), "file exists: app") - tmFile := provconfig.GetFullPathToAppConf(configCmd) - assert.Contains(t, outStr, tmFile, "tendermint filename") - assert.False(t, provconfig.FileExists(tmFile), "file exists: tendermint") + cmtFile := provconfig.GetFullPathToAppConf(configCmd) + assert.Contains(t, outStr, cmtFile, "cometbft filename") + assert.False(t, provconfig.FileExists(cmtFile), "file exists: cometbft") clientFile := provconfig.GetFullPathToAppConf(configCmd) assert.Contains(t, outStr, clientFile, "client filename") assert.False(t, provconfig.FileExists(clientFile), "file exists: client") @@ -851,9 +828,9 @@ func (s *ConfigTestSuite) TestPackUnpack() { appFile := provconfig.GetFullPathToAppConf(configCmd) assert.Contains(t, outStr, appFile, "app filename") assert.True(t, provconfig.FileExists(appFile), "file exists: app") - tmFile := provconfig.GetFullPathToAppConf(configCmd) - assert.Contains(t, outStr, tmFile, "tendermint filename") - assert.True(t, provconfig.FileExists(tmFile), "file exists: tendermint") + cmtFile := provconfig.GetFullPathToAppConf(configCmd) + assert.Contains(t, outStr, cmtFile, "cometbft filename") + assert.True(t, provconfig.FileExists(cmtFile), "file exists: cometbft") clientFile := provconfig.GetFullPathToAppConf(configCmd) assert.Contains(t, outStr, clientFile, "client filename") assert.True(t, provconfig.FileExists(clientFile), "file exists: client") @@ -897,12 +874,12 @@ func (s *ConfigTestSuite) TestUpdate() { configCmd := s.getConfigCmd() configDir := provconfig.GetFullPathToConfigDir(configCmd) uFile := provconfig.GetFullPathToUnmanagedConf(configCmd) - tFile := provconfig.GetFullPathToTmConf(configCmd) + tFile := provconfig.GetFullPathToCmtConf(configCmd) aFile := provconfig.GetFullPathToAppConf(configCmd) cFile := provconfig.GetFullPathToClientConf(configCmd) s.Require().NoError(os.MkdirAll(configDir, 0o755), "making config dir") s.Require().NoError(os.WriteFile(uFile, []byte(uFileContents), 0o644), "writing unmanaged config") - s.Require().NoError(os.WriteFile(tFile, []byte(tFileContents), 0o644), "writing tm config") + s.Require().NoError(os.WriteFile(tFile, []byte(tFileContents), 0o644), "writing cometbft config") s.Require().NoError(os.WriteFile(aFile, []byte(aFileContents), 0o644), "writing app config") s.Require().NoError(os.WriteFile(cFile, []byte(cFileContents), 0o644), "writing client config") @@ -924,12 +901,12 @@ func (s *ConfigTestSuite) TestUpdate() { s.Assert().Equal(uFileContents, string(actualUFileContents), "unmanaged file contents") }) - s.Run("tm file has been updated", func() { + s.Run("cometbft file has been updated", func() { actualTFileContents, err := os.ReadFile(tFile) - s.Require().NoError(err, "reading tm file: %s", tFile) - s.Assert().NotEqual(tFileContents, string(actualTFileContents), "tm file contents") + s.Require().NoError(err, "reading cometbft file: %s", tFile) + s.Assert().NotEqual(tFileContents, string(actualTFileContents), "cometbft file contents") lines := strings.Split(string(actualTFileContents), "\n") - s.Assert().Greater(len(lines), 2, "number of lines in tm file.") + s.Assert().Greater(len(lines), 2, "number of lines in cometbft file.") }) s.Run("app file has been updated", func() { @@ -951,10 +928,10 @@ func (s *ConfigTestSuite) TestUpdate() { err = provconfig.LoadConfigFromFiles(configCmd) s.Require().NoError(err, "loading config from files") - s.Run("tm db_backend value unchanged", func() { - tmConfig, err := provconfig.ExtractTmConfig(configCmd) - s.Require().NoError(err, "ExtractTmConfig") - actual := tmConfig.DBBackend + s.Run("cometbft db_backend value unchanged", func() { + cmtConfig, err := provconfig.ExtractCmtConfig(configCmd) + s.Require().NoError(err, "ExtractCmtConfig") + actual := cmtConfig.DBBackend s.Assert().Equal(dbBackend, actual, "DBBackend") }) diff --git a/cmd/provenanced/cmd/docgen_test.go b/cmd/provenanced/cmd/docgen_test.go index 3c652cad8b..c6d7dac825 100644 --- a/cmd/provenanced/cmd/docgen_test.go +++ b/cmd/provenanced/cmd/docgen_test.go @@ -136,7 +136,7 @@ func TestDocGen(t *testing.T) { } cfg, err := genutiltest.CreateDefaultCometConfig(home) - require.NoError(t, err, "Created default tendermint config") + require.NoError(t, err, "Created default cometbft config") logger := log.NewNopLogger() serverCtx := server.NewContext(viper.New(), cfg, logger) diff --git a/cmd/provenanced/cmd/init.go b/cmd/provenanced/cmd/init.go index 199302201a..7f3830136b 100644 --- a/cmd/provenanced/cmd/init.go +++ b/cmd/provenanced/cmd/init.go @@ -95,7 +95,7 @@ func Init( if err != nil { return err } - tmConfig, err := provconfig.ExtractTmConfig(cmd) + cmtConfig, err := provconfig.ExtractCmtConfig(cmd) if err != nil { return err } @@ -105,7 +105,7 @@ func Init( } // Stop now if the genesis file already exists and an overwrite wasn't requested. - genFile := tmConfig.GenesisFile() + genFile := cmtConfig.GenesisFile() if !doOverwrite && cmtos.FileExists(genFile) { return fmt.Errorf("genesis file already exists: %v", genFile) } @@ -113,7 +113,7 @@ func Init( // Set a few things in the configs. appConfig.MinGasPrices = pioconfig.GetProvenanceConfig().ProvenanceMinGasPrices - tmConfig.Moniker = moniker + cmtConfig.Moniker = moniker if len(chainID) == 0 { chainID = "provenance-chain-" + cmtrand.NewRand().Str(6) cmd.Printf("chain id: %s\n", chainID) @@ -125,7 +125,7 @@ func Init( timeoutCommit = 1 * time.Second } if timeoutCommit > 0 { - tmConfig.Consensus.TimeoutCommit = timeoutCommit + cmtConfig.Consensus.TimeoutCommit = timeoutCommit } // Gather the bip39 mnemonic if a recover was requested. @@ -143,19 +143,19 @@ func Init( } // Create and write the node validator files (node_key.json and priv_validator_key.json). - nodeID, _, err := genutil.InitializeNodeValidatorFilesFromMnemonic(tmConfig, mnemonic) + nodeID, _, err := genutil.InitializeNodeValidatorFilesFromMnemonic(cmtConfig, mnemonic) if err != nil { return err } cmd.Printf("node id: %s\n", nodeID) - clientConfig.Node = tmConfig.RPC.ListenAddress + clientConfig.Node = cmtConfig.RPC.ListenAddress // Create and write the genenis file. if err = createAndExportGenesisFile(cmd, client.GetClientContextFromCmd(cmd).Codec, mbm, isTestnet, chainID, genFile); err != nil { return err } // Save the configs. - provconfig.SaveConfigs(cmd, appConfig, tmConfig, clientConfig, true) + provconfig.SaveConfigs(cmd, appConfig, cmtConfig, clientConfig, true) return nil } diff --git a/cmd/provenanced/cmd/pre_upgrade.go b/cmd/provenanced/cmd/pre_upgrade.go index 3743cd43b8..61e8542bef 100644 --- a/cmd/provenanced/cmd/pre_upgrade.go +++ b/cmd/provenanced/cmd/pre_upgrade.go @@ -72,7 +72,7 @@ func UpdateConfig(cmd *cobra.Command) error { if err != nil { return err } - tmCfg, err := config.ExtractTmConfig(cmd) + cmtCfg, err := config.ExtractCmtConfig(cmd) if err != nil { return err } @@ -84,20 +84,20 @@ func UpdateConfig(cmd *cobra.Command) error { if clientCfg.ChainID == "pio-mainnet-1" { // Update the timeout commit. timeoutCommit := config.DefaultConsensusTimeoutCommit - if tmCfg.Consensus.TimeoutCommit != timeoutCommit { + if cmtCfg.Consensus.TimeoutCommit != timeoutCommit { cmd.Printf("Updating consensus.timeout_commit config value to %q (from %q)\n", - timeoutCommit, tmCfg.Consensus.TimeoutCommit) - tmCfg.Consensus.TimeoutCommit = timeoutCommit + timeoutCommit, cmtCfg.Consensus.TimeoutCommit) + cmtCfg.Consensus.TimeoutCommit = timeoutCommit } } - return SafeSaveConfigs(cmd, appCfg, tmCfg, clientCfg, true) + return SafeSaveConfigs(cmd, appCfg, cmtCfg, clientCfg, true) } // SafeSaveConfigs calls config.SaveConfigs but returns an error instead of panicking. func SafeSaveConfigs(cmd *cobra.Command, appConfig *serverconfig.Config, - tmConfig *cmtconfig.Config, + cmtConfig *cmtconfig.Config, clientConfig *config.ClientConfig, verbose bool, ) (err error) { @@ -110,6 +110,6 @@ func SafeSaveConfigs(cmd *cobra.Command, } } }() - config.SaveConfigs(cmd, appConfig, tmConfig, clientConfig, verbose) + config.SaveConfigs(cmd, appConfig, cmtConfig, clientConfig, verbose) return nil } diff --git a/cmd/provenanced/cmd/pre_upgrade_test.go b/cmd/provenanced/cmd/pre_upgrade_test.go index cdd2e0ff1f..5f1061d8d7 100644 --- a/cmd/provenanced/cmd/pre_upgrade_test.go +++ b/cmd/provenanced/cmd/pre_upgrade_test.go @@ -187,7 +187,7 @@ func makeDummyCmd(t *testing.T, cdc codec.Codec, home string) *cobra.Command { WithCodec(cdc). WithHomeDir(home) clientCtx.Viper = viper.New() - serverCtx := server.NewContext(clientCtx.Viper, config.DefaultTmConfig(), log.NewNopLogger()) + serverCtx := server.NewContext(clientCtx.Viper, config.DefaultCmtConfig(), log.NewNopLogger()) ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) @@ -244,16 +244,16 @@ func TestPreUpgradeCmd(t *testing.T) { } appCfgD := config.DefaultAppConfig() - tmCfgD := config.DefaultTmConfig() + tmCfgD := config.DefaultCmtConfig() clientCfgD := config.DefaultClientConfig() appCfgC := config.DefaultAppConfig() appCfgC.API.Enable = true appCfgC.API.Swagger = true - tmCfgLower := config.DefaultTmConfig() + tmCfgLower := config.DefaultCmtConfig() tmCfgLower.Consensus.TimeoutCommit = tmCfgD.Consensus.TimeoutCommit - 500*time.Millisecond tmCfgLower.LogLevel = "debug" - tmCfgHigher := config.DefaultTmConfig() + tmCfgHigher := config.DefaultCmtConfig() tmCfgHigher.Consensus.TimeoutCommit = tmCfgD.Consensus.TimeoutCommit + 500*time.Millisecond tmCfgHigher.LogLevel = "debug" clientCfgC := config.DefaultClientConfig() @@ -262,7 +262,7 @@ func TestPreUpgradeCmd(t *testing.T) { clientCfgMainnetC.Output = "json" clientCfgMainnetC.ChainID = "pio-mainnet-1" - tmCfgCFixed := config.DefaultTmConfig() + tmCfgCFixed := config.DefaultCmtConfig() tmCfgCFixed.LogLevel = "debug" successMsg := "pre-upgrade successful" @@ -514,9 +514,9 @@ func TestPreUpgradeCmd(t *testing.T) { if assert.NoError(t, err, "ExtractAppConfig") { assert.Equal(t, tc.expAppCfg, appCfg, "app config") } - tmCfg, err := config.ExtractTmConfig(dummyCmd) + tmCfg, err := config.ExtractCmtConfig(dummyCmd) tmCfg.SetRoot("") - if assert.NoError(t, err, "ExtractTmConfig") { + if assert.NoError(t, err, "ExtractCmtConfig") { assert.Equal(t, tc.expTmCfg, tmCfg, "tm config") } clientCfg, err := config.ExtractClientConfig(dummyCmd) diff --git a/cmd/provenanced/cmd/testnet.go b/cmd/provenanced/cmd/testnet.go index 5503267df5..ffbaebe726 100644 --- a/cmd/provenanced/cmd/testnet.go +++ b/cmd/provenanced/cmd/testnet.go @@ -58,7 +58,7 @@ const ( flagStartingIPAddress = "starting-ip-address" ) -// get cmd to initialize all files for tendermint testnet and application +// get cmd to initialize all files for testnet and application func testnetCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command { cmd := &cobra.Command{ Use: "testnet", diff --git a/cmd/provenanced/config/filenames.go b/cmd/provenanced/config/filenames.go index 338bbcd0be..27a82709f3 100644 --- a/cmd/provenanced/config/filenames.go +++ b/cmd/provenanced/config/filenames.go @@ -17,8 +17,8 @@ const ( ConfigSubDir = "config" // AppConfFilename is the filename of the app/cosmos configuration file. AppConfFilename = "app.toml" - // TmConfFilename is the filename of the tendermint configuration file. - TmConfFilename = "config.toml" + // CmtConfFilename is the filename of the cometbft configuration file. + CmtConfFilename = "config.toml" // ClientConfFilename is the filename of the client configuration file. ClientConfFilename = "client.toml" // UnmanagedConfFilename is the filename of the unmanaged configuration file. @@ -45,9 +45,9 @@ func GetFullPathToAppConf(cmd *cobra.Command) string { return filepath.Join(GetHomeDir(cmd), ConfigSubDir, AppConfFilename) } -// GetFullPathToTmConf gets the full path to the tendermint config file. -func GetFullPathToTmConf(cmd *cobra.Command) string { - return filepath.Join(GetHomeDir(cmd), ConfigSubDir, TmConfFilename) +// GetFullPathToCmtConf gets the full path to the cometbft config file. +func GetFullPathToCmtConf(cmd *cobra.Command) string { + return filepath.Join(GetHomeDir(cmd), ConfigSubDir, CmtConfFilename) } // GetFullPathToClientConf gets the full path to the client config file. diff --git a/cmd/provenanced/config/interceptor.go b/cmd/provenanced/config/interceptor.go index 0f0eb2bebf..d009929efb 100644 --- a/cmd/provenanced/config/interceptor.go +++ b/cmd/provenanced/config/interceptor.go @@ -25,7 +25,7 @@ const ( // It will finish setting up the client context and create the server context. // It will create a Viper literal and the configs will be read and parsed or created from defaults. // The viper literal is used to read and parse configurations. Command handlers can -// fetch the server or client contexts to get the Tendermint, App/Cosmos, or Client +// fetch the server or client contexts to get the CometBFT, App/Cosmos, or Client // configurations, or to get access to viper. func InterceptConfigsPreRunHandler(cmd *cobra.Command) error { // The result of client.GetClientContextFromCmd(cmd) is not a pointer. @@ -43,7 +43,7 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command) error { SetPioConfigFromFlags(cmd.Flags()) // Create a new Server context with the same viper as the client context, a default config, and no logger. - serverCtx := server.NewContext(vpr, DefaultTmConfig(), nil) + serverCtx := server.NewContext(vpr, DefaultCmtConfig(), nil) if err := server.SetCmdServerContext(cmd, serverCtx); err != nil { return err } diff --git a/cmd/provenanced/config/manager.go b/cmd/provenanced/config/manager.go index 55d1dc3bac..8444650b85 100644 --- a/cmd/provenanced/config/manager.go +++ b/cmd/provenanced/config/manager.go @@ -35,15 +35,15 @@ func UnpackConfig(cmd *cobra.Command) error { if appConfErr != nil { return fmt.Errorf("could not get app config values: %w", appConfErr) } - tmConfig, tmConfErr := ExtractTmConfig(cmd) - if tmConfErr != nil { - return fmt.Errorf("could not get tendermint config values: %w", tmConfErr) + cmtConfig, cmtConfErr := ExtractCmtConfig(cmd) + if cmtConfErr != nil { + return fmt.Errorf("could not get cometbft config values: %w", cmtConfErr) } clientConfig, clientConfErr := ExtractClientConfig(cmd) if clientConfErr != nil { return fmt.Errorf("could not get client config values: %w", clientConfErr) } - writeUnpackedConfig(cmd, appConfig, tmConfig, clientConfig, true) + writeUnpackedConfig(cmd, appConfig, cmtConfig, clientConfig, true) err := deletePackedConfig(cmd, true) return err } @@ -91,12 +91,12 @@ func DefaultAppConfig() *serverconfig.Config { return rv } -// ExtractTmConfig creates a tendermint config from the command context. -func ExtractTmConfig(cmd *cobra.Command) (*cmtconfig.Config, error) { +// ExtractCmtConfig creates a cometbft config from the command context. +func ExtractCmtConfig(cmd *cobra.Command) (*cmtconfig.Config, error) { v := server.GetServerContextFromCmd(cmd).Viper - conf := DefaultTmConfig() + conf := DefaultCmtConfig() if err := v.Unmarshal(conf); err != nil { - return nil, fmt.Errorf("error extracting tendermint config: %w", err) + return nil, fmt.Errorf("error extracting cometbft config: %w", err) } conf.SetRoot(GetHomeDir(cmd)) // When the RPCServers value is "", it gets read as []string{}. @@ -109,34 +109,34 @@ func ExtractTmConfig(cmd *cobra.Command) (*cmtconfig.Config, error) { return conf, nil } -// ExtractTmConfigAndMap from the command context, creates a tendermint config and related string->value map. -func ExtractTmConfigAndMap(cmd *cobra.Command) (*cmtconfig.Config, FieldValueMap, error) { - conf, err := ExtractTmConfig(cmd) +// ExtractCmtConfigAndMap from the command context, creates a cometbft config and related string->value map. +func ExtractCmtConfigAndMap(cmd *cobra.Command) (*cmtconfig.Config, FieldValueMap, error) { + conf, err := ExtractCmtConfig(cmd) if err != nil { return nil, nil, err } fields := MakeFieldValueMap(conf, true) - removeUndesirableTmConfigEntries(fields) + removeUndesirableCmtConfigEntries(fields) return conf, fields, nil } -func DefaultTmConfig() *cmtconfig.Config { +func DefaultCmtConfig() *cmtconfig.Config { rv := cmtconfig.DefaultConfig() rv.Consensus.TimeoutCommit = DefaultConsensusTimeoutCommit rv.TxIndex.Indexer = "null" return rv } -// removeUndesirableTmConfigEntries deletes some keys from the provided fields map that we don't want included. +// removeUndesirableCmtConfigEntries deletes some keys from the provided fields map that we don't want included. // The provided map is altered during this call. It is also returned from this func. -// There are several fields in the tendermint config struct that don't correspond to entries in the config files. +// There are several fields in the cometbft config struct that don't correspond to entries in the config files. // None of the "home" keys have entries in the config files: // "home", "consensus.home", "mempool.home", "p2p.home", "rpc.home" // There are several "p2p.test_" fields that should be ignored too. // "p2p.test_dial_fail", "p2p.test_fuzz", // "p2p.test_fuzz_config.*" ("maxdelay", "mode", "probdropconn", "probdroprw", "probsleep") // This info is accurate in Cosmos SDK 0.43 (on 2021-08-16). -func removeUndesirableTmConfigEntries(fields FieldValueMap) FieldValueMap { +func removeUndesirableCmtConfigEntries(fields FieldValueMap) FieldValueMap { delete(fields, "home") for k := range fields { if (len(k) > 5 && k[len(k)-5:] == ".home") || (len(k) > 9 && k[:9] == "p2p.test_") { @@ -171,7 +171,7 @@ func GetAllConfigDefaults() FieldValueMap { rv := FieldValueMap{} rv.AddEntriesFrom( MakeFieldValueMap(DefaultAppConfig(), false), - removeUndesirableTmConfigEntries(MakeFieldValueMap(DefaultTmConfig(), false)), + removeUndesirableCmtConfigEntries(MakeFieldValueMap(DefaultCmtConfig(), false)), MakeFieldValueMap(DefaultClientConfig(), false), ) return rv @@ -184,14 +184,14 @@ func GetAllConfigDefaults() FieldValueMap { func SaveConfigs( cmd *cobra.Command, appConfig *serverconfig.Config, - tmConfig *cmtconfig.Config, + cmtConfig *cmtconfig.Config, clientConfig *ClientConfig, verbose bool, ) { if IsPacked(cmd) { - generateAndWritePackedConfig(cmd, appConfig, tmConfig, clientConfig, verbose) + generateAndWritePackedConfig(cmd, appConfig, cmtConfig, clientConfig, verbose) } else { - writeUnpackedConfig(cmd, appConfig, tmConfig, clientConfig, verbose) + writeUnpackedConfig(cmd, appConfig, cmtConfig, clientConfig, verbose) } } @@ -201,7 +201,7 @@ func SaveConfigs( func writeUnpackedConfig( cmd *cobra.Command, appConfig *serverconfig.Config, - tmConfig *cmtconfig.Config, + cmtConfig *cmtconfig.Config, clientConfig *ClientConfig, verbose bool, ) { @@ -216,12 +216,12 @@ func writeUnpackedConfig( cmd.Printf("Done.\n") } } - if tmConfig != nil { - confFile := GetFullPathToTmConf(cmd) + if cmtConfig != nil { + confFile := GetFullPathToCmtConf(cmd) if verbose { - cmd.Printf("Writing tendermint config to: %s ... ", confFile) + cmd.Printf("Writing cometbft config to: %s ... ", confFile) } - cmtconfig.WriteConfigFile(confFile, tmConfig) + cmtconfig.WriteConfigFile(confFile, cmtConfig) if verbose { cmd.Printf("Done.\n") } @@ -245,7 +245,7 @@ func writeUnpackedConfig( func deleteUnpackedConfig(cmd *cobra.Command, verbose bool) error { configFiles := []string{ GetFullPathToAppConf(cmd), - GetFullPathToTmConf(cmd), + GetFullPathToCmtConf(cmd), GetFullPathToClientConf(cmd), } var rvErr error @@ -267,12 +267,12 @@ func deleteUnpackedConfig(cmd *cobra.Command, verbose bool) error { func generateAndWritePackedConfig( cmd *cobra.Command, appConfig *serverconfig.Config, - tmConfig *cmtconfig.Config, + cmtConfig *cmtconfig.Config, clientConfig *ClientConfig, verbose bool, ) { mustEnsureConfigDir(cmd) - var appConfMap, tmConfMap, clientConfMap FieldValueMap + var appConfMap, cmtConfMap, clientConfMap FieldValueMap if appConfig == nil { var err error _, appConfMap, err = ExtractAppConfigAndMap(cmd) @@ -282,14 +282,14 @@ func generateAndWritePackedConfig( } else { appConfMap = MakeFieldValueMap(appConfig, false) } - if tmConfig == nil { + if cmtConfig == nil { var err error - _, tmConfMap, err = ExtractTmConfigAndMap(cmd) + _, cmtConfMap, err = ExtractCmtConfigAndMap(cmd) if err != nil { - panic(fmt.Errorf("could not extract tm config values: %w", err)) + panic(fmt.Errorf("could not extract cometbft config values: %w", err)) } } else { - tmConfMap = MakeFieldValueMap(tmConfig, false) + cmtConfMap = MakeFieldValueMap(cmtConfig, false) } if clientConfig == nil { var err error @@ -301,7 +301,7 @@ func generateAndWritePackedConfig( clientConfMap = MakeFieldValueMap(clientConfig, false) } allConf := FieldValueMap{} - allConf.AddEntriesFrom(appConfMap, tmConfMap, clientConfMap) + allConf.AddEntriesFrom(appConfMap, cmtConfMap, clientConfMap) defaultConf := GetAllConfigDefaults() packed := map[string]string{} for key, info := range MakeUpdatedFieldMap(defaultConf, allConf, true) { @@ -421,27 +421,27 @@ func loadUnmanagedConfig(cmd *cobra.Command) error { // loadUnpackedConfig attempts to read the unpacked config files and apply them to the appropriate contexts. func loadUnpackedConfig(cmd *cobra.Command) error { appConfFile := GetFullPathToAppConf(cmd) - tmConfFile := GetFullPathToTmConf(cmd) + cmtConfFile := GetFullPathToCmtConf(cmd) clientConfFile := GetFullPathToClientConf(cmd) // Both the server context and client context should be using the same Viper, so this is good for both. vpr := server.GetServerContextFromCmd(cmd).Viper - // Load the tendermint config defaults, then file if it exists. - tdErr := addFieldMapToViper(vpr, MakeFieldValueMap(DefaultTmConfig(), false)) + // Load the cometbft config defaults, then file if it exists. + tdErr := addFieldMapToViper(vpr, MakeFieldValueMap(DefaultCmtConfig(), false)) if tdErr != nil { - return fmt.Errorf("tendermint config defaults load error: %w", tdErr) + return fmt.Errorf("cometbft config defaults load error: %w", tdErr) } - switch _, err := os.Stat(tmConfFile); { + switch _, err := os.Stat(cmtConfFile); { case os.IsNotExist(err): // Do nothing. case err != nil: - return fmt.Errorf("tendermint config file stat error: %w", err) + return fmt.Errorf("cometbft config file stat error: %w", err) default: - vpr.SetConfigFile(tmConfFile) + vpr.SetConfigFile(cmtConfFile) rerr := vpr.MergeInConfig() if rerr != nil { - return fmt.Errorf("tendermint config file read error: %w", rerr) + return fmt.Errorf("cometbft config file read error: %w", rerr) } } @@ -505,7 +505,7 @@ func loadPackedConfig(cmd *cobra.Command) error { // Start with the defaults appConfigMap := MakeFieldValueMap(DefaultAppConfig(), false) - tmConfigMap := MakeFieldValueMap(DefaultTmConfig(), false) + cmtConfigMap := MakeFieldValueMap(DefaultCmtConfig(), false) clientConfigMap := MakeFieldValueMap(DefaultClientConfig(), false) // Apply the packed config entries to the defaults. @@ -519,11 +519,11 @@ func loadPackedConfig(cmd *cobra.Command) error { rvErr = appendError(rvErr, fmt.Errorf("app config key: %s, value: %s, err: %w", k, v, err)) } } - if tmConfigMap.Has(k) { + if cmtConfigMap.Has(k) { found = true - err := tmConfigMap.SetFromString(k, v) + err := cmtConfigMap.SetFromString(k, v) if err != nil { - rvErr = appendError(rvErr, fmt.Errorf("tendermint config key: %s, value: %s, err: %w", k, v, err)) + rvErr = appendError(rvErr, fmt.Errorf("cometbft config key: %s, value: %s, err: %w", k, v, err)) } } if clientConfigMap.Has(k) { @@ -546,8 +546,8 @@ func loadPackedConfig(cmd *cobra.Command) error { // and a set value takes precedence over flags. So I guess defaults are what we go with. // The server and client should both have the same viper, so we only need the one. vpr := server.GetServerContextFromCmd(cmd).Viper - if lerr := addFieldMapToViper(vpr, tmConfigMap); lerr != nil { - return fmt.Errorf("tendermint packed config load error: %w", lerr) + if lerr := addFieldMapToViper(vpr, cmtConfigMap); lerr != nil { + return fmt.Errorf("cometbft packed config load error: %w", lerr) } if lerr := addFieldMapToViper(vpr, appConfigMap); lerr != nil { return fmt.Errorf("app packed config load error: %w", lerr) @@ -564,8 +564,8 @@ func addFieldMapToViper(vpr *viper.Viper, fvmap FieldValueMap) error { if err != nil { return err } - // The TM BaseConfig struct has a RootDir field with the mapstruct name "home". - // So the fvmap created from a TM config struct will have a "home" entry with a value of "". + // The CometBFT BaseConfig struct has a RootDir field with the mapstruct name "home". + // So the fvmap created from a CometBFT config struct will have a "home" entry with a value of "". // If we were to then include that when calling MergeConfigMap, it would tell viper that the "home" value is "". // This prevents the default value (defined with the --home flag) from being used. // Since the "home" value defines where the config files are, it's safe to assume none of the config @@ -596,11 +596,11 @@ func applyConfigsToContexts(cmd *cobra.Command) error { // Set the server context's config to what Viper has now. serverCtx := server.GetServerContextFromCmd(cmd) - tmConfig, err := ExtractTmConfig(cmd) + cmtConfig, err := ExtractCmtConfig(cmd) if err != nil { return err } - serverCtx.Config = tmConfig + serverCtx.Config = cmtConfig serverCtx.Config.SetRoot(clientCtx.HomeDir) // Set the server context's logger using what Viper has now. diff --git a/cmd/provenanced/config/manager_test.go b/cmd/provenanced/config/manager_test.go index 268383dd37..dbec32ac18 100644 --- a/cmd/provenanced/config/manager_test.go +++ b/cmd/provenanced/config/manager_test.go @@ -51,7 +51,7 @@ func (s *ConfigManagerTestSuite) makeDummyCmd() *cobra.Command { WithCodec(s.EncodingConfig.Marshaler). WithHomeDir(s.Home) clientCtx.Viper = viper.New() - serverCtx := server.NewContext(clientCtx.Viper, DefaultTmConfig(), log.NewNopLogger()) + serverCtx := server.NewContext(clientCtx.Viper, DefaultCmtConfig(), log.NewNopLogger()) ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) @@ -125,7 +125,7 @@ func (s *ConfigManagerTestSuite) TestPackedConfigCosmosLoadDefaults() { dCmd := s.makeDummyCmd() appConfig := DefaultAppConfig() - tmConfig := DefaultTmConfig() + tmConfig := DefaultCmtConfig() clientConfig := DefaultClientConfig() generateAndWritePackedConfig(dCmd, appConfig, tmConfig, clientConfig, false) s.Require().NoError(loadPackedConfig(dCmd)) @@ -145,7 +145,7 @@ func (s *ConfigManagerTestSuite) TestPackedConfigCosmosLoadGlobalLabels() { appConfig := serverconfig.DefaultConfig() appConfig.Telemetry.GlobalLabels = append(appConfig.Telemetry.GlobalLabels, []string{"key1", "value1"}) appConfig.Telemetry.GlobalLabels = append(appConfig.Telemetry.GlobalLabels, []string{"key2", "value2"}) - tmConfig := DefaultTmConfig() + tmConfig := DefaultCmtConfig() clientConfig := DefaultClientConfig() generateAndWritePackedConfig(dCmd, appConfig, tmConfig, clientConfig, false) s.Require().NoError(loadPackedConfig(dCmd)) @@ -184,13 +184,13 @@ func (s *ConfigManagerTestSuite) TestUnmanagedConfig() { vpr := ctx.Viper actual := vpr.GetString("db_backend") assert.Equal(t, "still bananas", actual, "unmanaged field value") - assert.NotEqual(t, DefaultTmConfig().DBBackend, actual, "unmanaged field default value") + assert.NotEqual(t, DefaultCmtConfig().DBBackend, actual, "unmanaged field default value") }) s.T().Run("unmanaged config is read with unpacked files", func(t *testing.T) { dCmd := s.makeDummyCmd() uFile := GetFullPathToUnmanagedConf(dCmd) - SaveConfigs(dCmd, DefaultAppConfig(), DefaultTmConfig(), DefaultClientConfig(), false) + SaveConfigs(dCmd, DefaultAppConfig(), DefaultCmtConfig(), DefaultClientConfig(), false) require.NoError(t, os.WriteFile(uFile, []byte("my-custom-entry = \"stuff\"\n"), 0o644), "writing unmanaged config") require.NoError(t, LoadConfigFromFiles(dCmd)) ctx := client.GetClientContextFromCmd(dCmd) @@ -203,7 +203,7 @@ func (s *ConfigManagerTestSuite) TestUnmanagedConfig() { dCmd := s.makeDummyCmd() uFile := GetFullPathToUnmanagedConf(dCmd) pFile := GetFullPathToPackedConf(dCmd) - SaveConfigs(dCmd, DefaultAppConfig(), DefaultTmConfig(), DefaultClientConfig(), false) + SaveConfigs(dCmd, DefaultAppConfig(), DefaultCmtConfig(), DefaultClientConfig(), false) require.NoError(t, os.WriteFile(uFile, []byte("my-custom-entry = \"stuff\"\n"), 0o644), "writing unmanaged config") require.NoError(t, os.WriteFile(pFile, []byte("kl234508923u5jl"), 0o644), "writing invalid data to packed config") require.EqualError(t, LoadConfigFromFiles(dCmd), "packed config file parse error: invalid character 'k' looking for beginning of value", "should throw error with invalid packed config") @@ -214,7 +214,7 @@ func (s *ConfigManagerTestSuite) TestUnmanagedConfig() { dCmd := s.makeDummyCmd() uFile := GetFullPathToUnmanagedConf(dCmd) pFile := GetFullPathToAppConf(dCmd) - SaveConfigs(dCmd, DefaultAppConfig(), DefaultTmConfig(), DefaultClientConfig(), false) + SaveConfigs(dCmd, DefaultAppConfig(), DefaultCmtConfig(), DefaultClientConfig(), false) require.NoError(t, os.WriteFile(uFile, []byte("my-custom-entry = \"stuff\"\n"), 0o644), "writing unmanaged config") require.NoError(t, os.WriteFile(pFile, []byte("kl234508923u5jl"), 0o644), "writing invalid data to app config") require.EqualError(t, LoadConfigFromFiles(dCmd), "app config file merge error: While parsing config: toml: expected = after a key, but the document ends there", "should throw error with invalid packed config") @@ -223,7 +223,7 @@ func (s *ConfigManagerTestSuite) TestUnmanagedConfig() { s.T().Run("unmanaged config is read with packed config", func(t *testing.T) { dCmd := s.makeDummyCmd() uFile := GetFullPathToUnmanagedConf(dCmd) - SaveConfigs(dCmd, DefaultAppConfig(), DefaultTmConfig(), DefaultClientConfig(), false) + SaveConfigs(dCmd, DefaultAppConfig(), DefaultCmtConfig(), DefaultClientConfig(), false) require.NoError(t, PackConfig(dCmd), "packing config") require.NoError(t, os.WriteFile(uFile, []byte("other-custom-entry = 8\n"), 0o644), "writing unmanaged config") require.NoError(t, LoadConfigFromFiles(dCmd)) @@ -283,7 +283,7 @@ func (s *ConfigManagerTestSuite) TestConfigMinGasPrices() { s.Run("tm and client files but no app file", func() { cmd1 := s.makeDummyCmd() - SaveConfigs(cmd1, nil, DefaultTmConfig(), DefaultClientConfig(), false) + SaveConfigs(cmd1, nil, DefaultCmtConfig(), DefaultClientConfig(), false) appCfgFile := GetFullPathToAppConf(cmd1) _, err := os.Stat(appCfgFile) fileExists := !os.IsNotExist(err) @@ -301,7 +301,7 @@ func (s *ConfigManagerTestSuite) TestConfigMinGasPrices() { cmd1 := s.makeDummyCmd() appCfg := DefaultAppConfig() appCfg.MinGasPrices = "" - SaveConfigs(cmd1, appCfg, DefaultTmConfig(), DefaultClientConfig(), false) + SaveConfigs(cmd1, appCfg, DefaultCmtConfig(), DefaultClientConfig(), false) appCfgFile := GetFullPathToAppConf(cmd1) _, err := os.Stat(appCfgFile) fileExists := !os.IsNotExist(err) @@ -319,7 +319,7 @@ func (s *ConfigManagerTestSuite) TestConfigMinGasPrices() { cmd1 := s.makeDummyCmd() appCfg := DefaultAppConfig() appCfg.MinGasPrices = "something else" - SaveConfigs(cmd1, appCfg, DefaultTmConfig(), DefaultClientConfig(), false) + SaveConfigs(cmd1, appCfg, DefaultCmtConfig(), DefaultClientConfig(), false) appCfgFile := GetFullPathToAppConf(cmd1) _, err := os.Stat(appCfgFile) fileExists := !os.IsNotExist(err) @@ -335,7 +335,7 @@ func (s *ConfigManagerTestSuite) TestConfigMinGasPrices() { s.Run("packed config without min-gas-prices", func() { cmd1 := s.makeDummyCmd() - SaveConfigs(cmd1, DefaultAppConfig(), DefaultTmConfig(), DefaultClientConfig(), false) + SaveConfigs(cmd1, DefaultAppConfig(), DefaultCmtConfig(), DefaultClientConfig(), false) s.Require().NoError(PackConfig(cmd1), "PackConfig") packedCfgFile := GetFullPathToPackedConf(cmd1) _, err := os.Stat(packedCfgFile) @@ -355,7 +355,7 @@ func (s *ConfigManagerTestSuite) TestConfigMinGasPrices() { s.Run("packed config with min-gas-prices", func() { cmd1 := s.makeDummyCmd() - SaveConfigs(cmd1, DefaultAppConfig(), DefaultTmConfig(), DefaultClientConfig(), false) + SaveConfigs(cmd1, DefaultAppConfig(), DefaultCmtConfig(), DefaultClientConfig(), false) s.Require().NoError(PackConfig(cmd1), "PackConfig") packedCfgFile := GetFullPathToPackedConf(cmd1) _, err := os.Stat(packedCfgFile) @@ -375,7 +375,7 @@ func (s *ConfigManagerTestSuite) TestConfigMinGasPrices() { } func (s *ConfigManagerTestSuite) TestDefaultTmConfig() { - cfg := DefaultTmConfig() + cfg := DefaultCmtConfig() s.Run("consensus.commit_timeout", func() { exp := 1500 * time.Millisecond @@ -389,7 +389,7 @@ func (s *ConfigManagerTestSuite) TestPackedConfigTmLoadDefaults() { dCmd.Flags().String("home", s.Home, "home dir") appConfig := DefaultAppConfig() - tmConfig := DefaultTmConfig() + tmConfig := DefaultCmtConfig() tmConfig.SetRoot(s.Home) clientConfig := DefaultClientConfig() generateAndWritePackedConfig(dCmd, appConfig, tmConfig, clientConfig, false) @@ -406,13 +406,13 @@ func (s *ConfigManagerTestSuite) TestPackedConfigTmLoadDefaults() { s.Assert().Equal(tmConfig, tmConfig2) }) - s.Run("ExtractTmConfig", func() { + s.Run("ExtractCmtConfig", func() { var tmConfig2 *cmtconfig.Config var err error s.Require().NotPanics(func() { - tmConfig2, err = ExtractTmConfig(dCmd) + tmConfig2, err = ExtractCmtConfig(dCmd) }) - s.Require().NoError(err, "ExtractTmConfig") + s.Require().NoError(err, "ExtractCmtConfig") s.Assert().Equal(tmConfig, tmConfig2) }) } From 46e0ade74be44273a4d787122258f7211d534ed1 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 9 May 2024 11:09:30 -0600 Subject: [PATCH 05/23] [1760]: Set the correct TMCoreSemVer variable when building. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b7a34cd5c7..40d798e1d6 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ endif BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null) BRANCH_PRETTY := $(subst /,-,$(BRANCH)) -TM_VERSION := $(shell $(GO) list -m github.com/tendermint/tendermint 2> /dev/null | sed 's:.* ::') # grab everything after the space in "github.com/tendermint/tendermint v0.34.7" +export CMTVERSION := $(shell $(GO) list -m github.com/cometbft/cometbft 2> /dev/null | sed 's:.* ::') COMMIT := $(shell git log -1 --format='%h' 2> /dev/null) # don't override user values ifeq (,$(VERSION)) @@ -108,7 +108,7 @@ ldflags = -w -s \ -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \ - -X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TM_VERSION) + -X github.com/cometbft/cometbft/version.TMCoreSemVer=$(CMTVERSION) ldflags += $(LDFLAGS) ldflags := $(strip $(ldflags)) From 075eda9de4675301e81207480011c533a86ad8b9 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 9 May 2024 11:17:44 -0600 Subject: [PATCH 06/23] [1760]: Take the tendermint libraries off the allowed import list. Update CONTRIBUTING and SECURITY for the change from tendermint to cometbft. --- .golangci.yml | 3 --- CONTRIBUTING.md | 3 --- SECURITY.md | 4 ++-- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index b6ecdeae8f..1570dfcd6a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -154,9 +154,6 @@ linters-settings: - github.com/cometbft/cometbft/types/time - github.com/cometbft/cometbft-db - - github.com/tendermint/tendermint - - github.com/tendermint/tm-db - - github.com/rs/zerolog test: files: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3113363453..d6cd4774ac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -63,9 +63,6 @@ not required to an open issue to submit a PR, but be aware that for more complex problems/features, if a PR is opened before an adequate design discussion has taken place in a github issue, that PR runs a high likelihood of being rejected. -Take a peek at our [coding repo](https://github.com/tendermint/coding) for -overall information on repository workflow and standards. Note, we use `make tools` for installing the linting tools. - Other notes: - Looking for a good place to start contributing? How about checking out some diff --git a/SECURITY.md b/SECURITY.md index 00e47812bc..a4177809a5 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -13,7 +13,7 @@ Please report security vulnerabilities to The Provenance team will send a response indicating the next steps in handling your report. After the initial reply to your report, the team will keep you informed of the progress towards remediation and may ask for additional -information or guidance.  For critical problems you may encrypt your report using the public key below. +information or guidance. For critical problems you may encrypt your report using the public key below. In addition, please include the following information along with your report: @@ -27,7 +27,7 @@ an email to **[security@provenance.io](mailto:security@provenance.io)**. The ema a short description of why it should be handled according to this security policy. -If you have found an issue with the Cosmos SDK or Tendermint modules not found in this repo you can report them through links found here. https://tendermint.com/security/ +If you have found an issue with the Cosmos SDK or CometBFT modules not found in this repo you can report them through links found here: . ## Disclosure Policy From 87292c50ffbcb6ae26cfdf3bd84e63f3a28ad7d6 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 9 May 2024 11:58:45 -0600 Subject: [PATCH 07/23] [1760]: Fix the rest of the tendermint references. --- app/test_helpers.go | 3 +- cmd/provenanced/cmd/pre_upgrade_test.go | 88 +++++++++++----------- cmd/provenanced/cmd/root.go | 2 +- cmd/provenanced/config/manager_test.go | 28 +++---- x/quarantine/client/testutil/query_test.go | 8 +- x/quarantine/client/testutil/tx_test.go | 4 +- 6 files changed, 66 insertions(+), 67 deletions(-) diff --git a/app/test_helpers.go b/app/test_helpers.go index 906240f8dd..51f3d7de61 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -45,8 +45,7 @@ import ( "github.com/provenance-io/provenance/internal/pioconfig" ) -// DefaultConsensusParams defines the default Tendermint consensus params used in -// SimApp testing. +// DefaultConsensusParams defines the default consensus params used in SimApp testing. var DefaultConsensusParams = &cmttmtypes.ConsensusParams{ Block: &cmttmtypes.BlockParams{ MaxBytes: 200000, diff --git a/cmd/provenanced/cmd/pre_upgrade_test.go b/cmd/provenanced/cmd/pre_upgrade_test.go index 5f1061d8d7..8a9e62c599 100644 --- a/cmd/provenanced/cmd/pre_upgrade_test.go +++ b/cmd/provenanced/cmd/pre_upgrade_test.go @@ -219,7 +219,7 @@ func TestPreUpgradeCmd(t *testing.T) { seenNames := make(map[string]bool) // newHome creates a new home directory and saves the configs. Returns full path to home and success. - newHome := func(t *testing.T, name string, appCfg *serverconfig.Config, tmCfg *cmtconfig.Config, clientCfg *config.ClientConfig) (string, bool) { + newHome := func(t *testing.T, name string, appCfg *serverconfig.Config, cmtCfg *cmtconfig.Config, clientCfg *config.ClientConfig) (string, bool) { require.False(t, seenNames[name], "dir name %q created in previous test", name) seenNames[name] = true home := filepath.Join(tmpDir, name) @@ -228,12 +228,12 @@ func TestPreUpgradeCmd(t *testing.T) { } dummyCmd := makeDummyCmd(t, cdc, home) - success := assert.NotPanics(t, func() { config.SaveConfigs(dummyCmd, appCfg, tmCfg, clientCfg, false) }, "SaveConfigs") + success := assert.NotPanics(t, func() { config.SaveConfigs(dummyCmd, appCfg, cmtCfg, clientCfg, false) }, "SaveConfigs") return home, success } // newHomePacked creates a new home directory, saves the configs, and packs them. Returns full path to home and success. - newHomePacked := func(t *testing.T, name string, appCfg *serverconfig.Config, tmCfg *cmtconfig.Config, clientCfg *config.ClientConfig) (string, bool) { - home, success := newHome(t, name, appCfg, tmCfg, clientCfg) + newHomePacked := func(t *testing.T, name string, appCfg *serverconfig.Config, cmtCfg *cmtconfig.Config, clientCfg *config.ClientConfig) (string, bool) { + home, success := newHome(t, name, appCfg, cmtCfg, clientCfg) if !success { return home, success } @@ -244,26 +244,26 @@ func TestPreUpgradeCmd(t *testing.T) { } appCfgD := config.DefaultAppConfig() - tmCfgD := config.DefaultCmtConfig() + cmtCfgD := config.DefaultCmtConfig() clientCfgD := config.DefaultClientConfig() appCfgC := config.DefaultAppConfig() appCfgC.API.Enable = true appCfgC.API.Swagger = true - tmCfgLower := config.DefaultCmtConfig() - tmCfgLower.Consensus.TimeoutCommit = tmCfgD.Consensus.TimeoutCommit - 500*time.Millisecond - tmCfgLower.LogLevel = "debug" - tmCfgHigher := config.DefaultCmtConfig() - tmCfgHigher.Consensus.TimeoutCommit = tmCfgD.Consensus.TimeoutCommit + 500*time.Millisecond - tmCfgHigher.LogLevel = "debug" + cmtCfgLower := config.DefaultCmtConfig() + cmtCfgLower.Consensus.TimeoutCommit = cmtCfgD.Consensus.TimeoutCommit - 500*time.Millisecond + cmtCfgLower.LogLevel = "debug" + cmtCfgHigher := config.DefaultCmtConfig() + cmtCfgHigher.Consensus.TimeoutCommit = cmtCfgD.Consensus.TimeoutCommit + 500*time.Millisecond + cmtCfgHigher.LogLevel = "debug" clientCfgC := config.DefaultClientConfig() clientCfgC.Output = "json" clientCfgMainnetC := config.DefaultClientConfig() clientCfgMainnetC.Output = "json" clientCfgMainnetC.ChainID = "pio-mainnet-1" - tmCfgCFixed := config.DefaultCmtConfig() - tmCfgCFixed.LogLevel = "debug" + cmtCfgCFixed := config.DefaultCmtConfig() + cmtCfgCFixed.LogLevel = "debug" successMsg := "pre-upgrade successful" updatingMsg := func(old time.Duration) string { @@ -290,7 +290,7 @@ func TestPreUpgradeCmd(t *testing.T) { expExitCode: 0, expInStdout: []string{successMsg}, expAppCfg: appCfgD, - expTmCfg: tmCfgD, + expTmCfg: cmtCfgD, expClientCfg: clientCfgD, }, { @@ -305,91 +305,91 @@ func TestPreUpgradeCmd(t *testing.T) { { name: "unpacked config with defaults", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHome(t, "defaults_unpacked", appCfgD, tmCfgD, clientCfgD) + home, success := newHome(t, "defaults_unpacked", appCfgD, cmtCfgD, clientCfgD) return home, nil, success }, expExitCode: 0, expInStdout: []string{successMsg}, expAppCfg: appCfgD, - expTmCfg: tmCfgD, + expTmCfg: cmtCfgD, expClientCfg: clientCfgD, }, { name: "packed config with defaults", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHomePacked(t, "defaults_packed", appCfgD, tmCfgD, clientCfgD) + home, success := newHomePacked(t, "defaults_packed", appCfgD, cmtCfgD, clientCfgD) return home, nil, success }, expExitCode: 0, expInStdout: []string{successMsg}, expAppCfg: appCfgD, - expTmCfg: tmCfgD, + expTmCfg: cmtCfgD, expClientCfg: clientCfgD, }, { name: "mainnet unpacked config lower than default", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHome(t, "mainnet_unpacked_lower", appCfgC, tmCfgLower, clientCfgMainnetC) + home, success := newHome(t, "mainnet_unpacked_lower", appCfgC, cmtCfgLower, clientCfgMainnetC) return home, nil, success }, expExitCode: 0, expInStdout: []string{ - updatingMsg(tmCfgLower.Consensus.TimeoutCommit), + updatingMsg(cmtCfgLower.Consensus.TimeoutCommit), successMsg, }, expAppCfg: appCfgC, - expTmCfg: tmCfgCFixed, + expTmCfg: cmtCfgCFixed, expClientCfg: clientCfgMainnetC, }, { name: "mainnet unpacked config higher than default", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHome(t, "mainnet_unpacked_higher", appCfgC, tmCfgHigher, clientCfgMainnetC) + home, success := newHome(t, "mainnet_unpacked_higher", appCfgC, cmtCfgHigher, clientCfgMainnetC) return home, nil, success }, expExitCode: 0, expInStdout: []string{ - updatingMsg(tmCfgHigher.Consensus.TimeoutCommit), + updatingMsg(cmtCfgHigher.Consensus.TimeoutCommit), successMsg, }, expAppCfg: appCfgC, - expTmCfg: tmCfgCFixed, + expTmCfg: cmtCfgCFixed, expClientCfg: clientCfgMainnetC, }, { name: "mainnet packed config lower than default", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHomePacked(t, "mainnet_packed_lower", appCfgC, tmCfgLower, clientCfgMainnetC) + home, success := newHomePacked(t, "mainnet_packed_lower", appCfgC, cmtCfgLower, clientCfgMainnetC) return home, nil, success }, expExitCode: 0, expInStdout: []string{ - updatingMsg(tmCfgLower.Consensus.TimeoutCommit), + updatingMsg(cmtCfgLower.Consensus.TimeoutCommit), successMsg, }, expAppCfg: appCfgC, - expTmCfg: tmCfgCFixed, + expTmCfg: cmtCfgCFixed, expClientCfg: clientCfgMainnetC, }, { name: "mainnet packed config higher than default", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHomePacked(t, "mainnet_packed_higher", appCfgC, tmCfgHigher, clientCfgMainnetC) + home, success := newHomePacked(t, "mainnet_packed_higher", appCfgC, cmtCfgHigher, clientCfgMainnetC) return home, nil, success }, expExitCode: 0, expInStdout: []string{ - updatingMsg(tmCfgHigher.Consensus.TimeoutCommit), + updatingMsg(cmtCfgHigher.Consensus.TimeoutCommit), successMsg, }, expAppCfg: appCfgC, - expTmCfg: tmCfgCFixed, + expTmCfg: cmtCfgCFixed, expClientCfg: clientCfgMainnetC, }, { name: "mainnet cannot write new file", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHomePacked(t, "mainnet_cannot_write", appCfgC, tmCfgLower, clientCfgMainnetC) + home, success := newHomePacked(t, "mainnet_cannot_write", appCfgC, cmtCfgLower, clientCfgMainnetC) if !success { return home, nil, success } @@ -403,65 +403,65 @@ func TestPreUpgradeCmd(t *testing.T) { return home, deferrable, success }, expExitCode: 30, - expInStdout: []string{updatingMsg(tmCfgLower.Consensus.TimeoutCommit)}, + expInStdout: []string{updatingMsg(cmtCfgLower.Consensus.TimeoutCommit)}, expInStderr: []string{"could not update config file(s):", "error saving config file(s):", "permission denied"}, }, { name: "other net unpacked config lower than default", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHome(t, "other_unpacked_lower", appCfgC, tmCfgLower, clientCfgC) + home, success := newHome(t, "other_unpacked_lower", appCfgC, cmtCfgLower, clientCfgC) return home, nil, success }, expExitCode: 0, expInStdout: []string{successMsg}, expNot: []string{"Updating consensus.timeout_commit config value"}, expAppCfg: appCfgC, - expTmCfg: tmCfgLower, + expTmCfg: cmtCfgLower, expClientCfg: clientCfgC, }, { name: "other net unpacked config higher than default", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHome(t, "other_unpacked_higher", appCfgC, tmCfgHigher, clientCfgC) + home, success := newHome(t, "other_unpacked_higher", appCfgC, cmtCfgHigher, clientCfgC) return home, nil, success }, expExitCode: 0, expInStdout: []string{successMsg}, expNot: []string{"Updating consensus.timeout_commit config value"}, expAppCfg: appCfgC, - expTmCfg: tmCfgHigher, + expTmCfg: cmtCfgHigher, expClientCfg: clientCfgC, }, { name: "other net packed config lower than default", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHomePacked(t, "other_packed_lower", appCfgC, tmCfgLower, clientCfgC) + home, success := newHomePacked(t, "other_packed_lower", appCfgC, cmtCfgLower, clientCfgC) return home, nil, success }, expExitCode: 0, expInStdout: []string{successMsg}, expNot: []string{"Updating consensus.timeout_commit config value"}, expAppCfg: appCfgC, - expTmCfg: tmCfgLower, + expTmCfg: cmtCfgLower, expClientCfg: clientCfgC, }, { name: "other net packed config higher than default", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHomePacked(t, "other_packed_higher", appCfgC, tmCfgHigher, clientCfgC) + home, success := newHomePacked(t, "other_packed_higher", appCfgC, cmtCfgHigher, clientCfgC) return home, nil, success }, expExitCode: 0, expInStdout: []string{successMsg}, expNot: []string{"Updating consensus.timeout_commit config value"}, expAppCfg: appCfgC, - expTmCfg: tmCfgHigher, + expTmCfg: cmtCfgHigher, expClientCfg: clientCfgC, }, { name: "other net cannot write new file", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHomePacked(t, "other_cannot_write", appCfgC, tmCfgLower, clientCfgC) + home, success := newHomePacked(t, "other_cannot_write", appCfgC, cmtCfgLower, clientCfgC) if !success { return home, nil, success } @@ -514,10 +514,10 @@ func TestPreUpgradeCmd(t *testing.T) { if assert.NoError(t, err, "ExtractAppConfig") { assert.Equal(t, tc.expAppCfg, appCfg, "app config") } - tmCfg, err := config.ExtractCmtConfig(dummyCmd) - tmCfg.SetRoot("") + cmtCfg, err := config.ExtractCmtConfig(dummyCmd) + cmtCfg.SetRoot("") if assert.NoError(t, err, "ExtractCmtConfig") { - assert.Equal(t, tc.expTmCfg, tmCfg, "tm config") + assert.Equal(t, tc.expTmCfg, cmtCfg, "cmt config") } clientCfg, err := config.ExtractClientConfig(dummyCmd) if assert.NoError(t, err, "ExtractClientConfig") { diff --git a/cmd/provenanced/cmd/root.go b/cmd/provenanced/cmd/root.go index 138cbbd941..fded8909de 100644 --- a/cmd/provenanced/cmd/root.go +++ b/cmd/provenanced/cmd/root.go @@ -142,7 +142,7 @@ func Execute(rootCmd *cobra.Command) error { // Create and set a client.Context on the command's Context. During the pre-run // of the root command, a default initialized client.Context is provided to // seed child command execution with values such as AccountRetriver, Keyring, - // and a Tendermint RPC. This requires the use of a pointer reference when + // and a CometBFT RPC. This requires the use of a pointer reference when // getting and setting the client.Context. Ideally, we utilize // https://github.com/spf13/cobra/pull/1118. ctx := context.Background() diff --git a/cmd/provenanced/config/manager_test.go b/cmd/provenanced/config/manager_test.go index dbec32ac18..18a4520776 100644 --- a/cmd/provenanced/config/manager_test.go +++ b/cmd/provenanced/config/manager_test.go @@ -125,9 +125,9 @@ func (s *ConfigManagerTestSuite) TestPackedConfigCosmosLoadDefaults() { dCmd := s.makeDummyCmd() appConfig := DefaultAppConfig() - tmConfig := DefaultCmtConfig() + cmtConfig := DefaultCmtConfig() clientConfig := DefaultClientConfig() - generateAndWritePackedConfig(dCmd, appConfig, tmConfig, clientConfig, false) + generateAndWritePackedConfig(dCmd, appConfig, cmtConfig, clientConfig, false) s.Require().NoError(loadPackedConfig(dCmd)) ctx := client.GetClientContextFromCmd(dCmd) @@ -145,9 +145,9 @@ func (s *ConfigManagerTestSuite) TestPackedConfigCosmosLoadGlobalLabels() { appConfig := serverconfig.DefaultConfig() appConfig.Telemetry.GlobalLabels = append(appConfig.Telemetry.GlobalLabels, []string{"key1", "value1"}) appConfig.Telemetry.GlobalLabels = append(appConfig.Telemetry.GlobalLabels, []string{"key2", "value2"}) - tmConfig := DefaultCmtConfig() + cmtConfig := DefaultCmtConfig() clientConfig := DefaultClientConfig() - generateAndWritePackedConfig(dCmd, appConfig, tmConfig, clientConfig, false) + generateAndWritePackedConfig(dCmd, appConfig, cmtConfig, clientConfig, false) s.Require().NoError(loadPackedConfig(dCmd)) ctx := client.GetClientContextFromCmd(dCmd) @@ -281,7 +281,7 @@ func (s *ConfigManagerTestSuite) TestConfigMinGasPrices() { s.Assert().Equal(defaultMinGasPrices, actual, "MinGasPrices") }) - s.Run("tm and client files but no app file", func() { + s.Run("cmt and client files but no app file", func() { cmd1 := s.makeDummyCmd() SaveConfigs(cmd1, nil, DefaultCmtConfig(), DefaultClientConfig(), false) appCfgFile := GetFullPathToAppConf(cmd1) @@ -389,30 +389,30 @@ func (s *ConfigManagerTestSuite) TestPackedConfigTmLoadDefaults() { dCmd.Flags().String("home", s.Home, "home dir") appConfig := DefaultAppConfig() - tmConfig := DefaultCmtConfig() - tmConfig.SetRoot(s.Home) + cmtConfig := DefaultCmtConfig() + cmtConfig.SetRoot(s.Home) clientConfig := DefaultClientConfig() - generateAndWritePackedConfig(dCmd, appConfig, tmConfig, clientConfig, false) + generateAndWritePackedConfig(dCmd, appConfig, cmtConfig, clientConfig, false) s.logFile(GetFullPathToPackedConf(dCmd)) s.Require().NoError(loadPackedConfig(dCmd), "loadPackedConfig") s.Run("cmtcmds.ParseConfig", func() { - var tmConfig2 *cmtconfig.Config + var cmtConfig2 *cmtconfig.Config var err error s.Require().NotPanics(func() { - tmConfig2, err = cmtcmds.ParseConfig(dCmd) + cmtConfig2, err = cmtcmds.ParseConfig(dCmd) }) s.Require().NoError(err, "cmtcmds.ParseConfig") - s.Assert().Equal(tmConfig, tmConfig2) + s.Assert().Equal(cmtConfig, cmtConfig2) }) s.Run("ExtractCmtConfig", func() { - var tmConfig2 *cmtconfig.Config + var cmtConfig2 *cmtconfig.Config var err error s.Require().NotPanics(func() { - tmConfig2, err = ExtractCmtConfig(dCmd) + cmtConfig2, err = ExtractCmtConfig(dCmd) }) s.Require().NoError(err, "ExtractCmtConfig") - s.Assert().Equal(tmConfig, tmConfig2) + s.Assert().Equal(cmtConfig, cmtConfig2) }) } diff --git a/x/quarantine/client/testutil/query_test.go b/x/quarantine/client/testutil/query_test.go index 74701e7482..878c1915f6 100644 --- a/x/quarantine/client/testutil/query_test.go +++ b/x/quarantine/client/testutil/query_test.go @@ -3,7 +3,7 @@ package testutil import ( "fmt" - tmcli "github.com/cometbft/cometbft/libs/cli" + cmtcli "github.com/cometbft/cometbft/libs/cli" "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/types/query" @@ -104,7 +104,7 @@ func (s *IntegrationTestSuite) TestQueryQuarantinedFundsCmd() { for _, tc := range tests { s.Run(tc.name, func() { cmd := client.QueryQuarantinedFundsCmd() - args := append(tc.args, fmt.Sprintf("--%s=json", tmcli.OutputFlag)) + args := append(tc.args, fmt.Sprintf("--%s=json", cmtcli.OutputFlag)) outBW, err := cli.ExecTestCLICmd(s.clientCtx, cmd, args) outBz := outBW.Bytes() s.T().Logf("Output:\n%s", string(outBz)) @@ -163,7 +163,7 @@ func (s *IntegrationTestSuite) TestQueryIsQuarantinedCmd() { for _, tc := range tests { s.Run(tc.name, func() { cmd := client.QueryIsQuarantinedCmd() - args := append(tc.args, fmt.Sprintf("--%s=json", tmcli.OutputFlag)) + args := append(tc.args, fmt.Sprintf("--%s=json", cmtcli.OutputFlag)) outBW, err := cli.ExecTestCLICmd(s.clientCtx, cmd, args) out := outBW.String() s.T().Logf("Output:\n%s", out) @@ -275,7 +275,7 @@ func (s *IntegrationTestSuite) TestQueryAutoResponsesCmd() { for _, tc := range tests { s.Run(tc.name, func() { cmd := client.QueryAutoResponsesCmd() - args := append(tc.args, fmt.Sprintf("--%s=json", tmcli.OutputFlag)) + args := append(tc.args, fmt.Sprintf("--%s=json", cmtcli.OutputFlag)) outBW, err := cli.ExecTestCLICmd(s.clientCtx, cmd, args) out := outBW.String() s.T().Logf("Output:\n%s", out) diff --git a/x/quarantine/client/testutil/tx_test.go b/x/quarantine/client/testutil/tx_test.go index 1dfec16b7e..5812b076d8 100644 --- a/x/quarantine/client/testutil/tx_test.go +++ b/x/quarantine/client/testutil/tx_test.go @@ -3,7 +3,7 @@ package testutil import ( "fmt" - tmcli "github.com/cometbft/cometbft/libs/cli" + cmtcli "github.com/cometbft/cometbft/libs/cli" "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" @@ -328,7 +328,7 @@ func (s *IntegrationTestSuite) TestSendAndAcceptQuarantinedFunds() { expFromAddr1Amt := 2000 - amt1 - 10 expFromAddr2Amt := 2000 - amt2 - 10 - asJSONFlag := fmt.Sprintf("--%s=json", tmcli.OutputFlag) + asJSONFlag := fmt.Sprintf("--%s=json", cmtcli.OutputFlag) s.Run("opt toAddr into quarantine", func() { testcli.NewCLITxExecutor(client.TxOptInCmd(), s.appendCommonFlagsTo(toAddr)).Execute(s.T(), s.network) From 8d9daf419636e3581a45c6c765e1a844d9e5b690 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 9 May 2024 12:24:13 -0600 Subject: [PATCH 08/23] [1760]: Tweak the config get tests to check the current output against a previous value in order to identify fields that were added, removed, renamed, or have new default values. --- cmd/provenanced/cmd/config_test.go | 215 ++++++++++++++++++++++------- 1 file changed, 166 insertions(+), 49 deletions(-) diff --git a/cmd/provenanced/cmd/config_test.go b/cmd/provenanced/cmd/config_test.go index 60852c9462..ee478dd0c2 100644 --- a/cmd/provenanced/cmd/config_test.go +++ b/cmd/provenanced/cmd/config_test.go @@ -242,71 +242,188 @@ func (s *ConfigTestSuite) TestConfigBadArgs() { func (s *ConfigTestSuite) TestConfigCmdGet() { noArgsOut := s.executeConfigCmd("get") - // Only spot-checking instead of checking the entire 100+ lines exactly because I don't want this to needlessly break - // if comsos or cometbft adds a new configuration field/section. - expectedRegexpMatches := []struct { - name string - re *regexp.Regexp - }{ - // App config header and a few entries. - {"app header", regexp.MustCompile(`(?m)^App Config: .*/config/` + s.BaseFNApp + ` \(or env\)$`)}, - {"app halt-height", regexp.MustCompile(`(?m)^halt-height=0$`)}, - {"app api.swagger", regexp.MustCompile(`(?m)^api.swagger=false$`)}, - {"app grpc.address", regexp.MustCompile(`(?m)^grpc.address="localhost:9090"$`)}, - {"app telemetry.enabled", regexp.MustCompile(`(?m)^telemetry.enabled=false$`)}, - {"app statesync.enable", regexp.MustCompile(`(?m)^statesync.enable=false$`)}, - - // CometBFT header and a few entries. - {"cometbft header", regexp.MustCompile(`(?m)^CometBFT Config: .*/config/` + s.BaseFNCMT + ` \(or env\)$`)}, - {"cometbft db_dir", regexp.MustCompile(`(?m)^db_dir="data"$`)}, - {"cometbft consensus.timeout_commit", regexp.MustCompile(`(?m)^consensus.timeout_commit=` + fmt.Sprintf("%q", provconfig.DefaultConsensusTimeoutCommit) + `$`)}, - {"cometbft mempool.size", regexp.MustCompile(`(?m)^mempool.size=5000$`)}, - {"cometbft statesync.trust_period", regexp.MustCompile(`(?m)^statesync.trust_period="168h0m0s"$`)}, - {"cometbft p2p.recv_rate", regexp.MustCompile(`(?m)^p2p.recv_rate=5120000$`)}, - - // Client config header all the entries. - {"client header", regexp.MustCompile(`(?m)^Client Config: .*/config/` + s.baseFNClient + ` \(or env\)$`)}, - {"client broadcast-mode", regexp.MustCompile(`(?m)^broadcast-mode="block"$`)}, - {"client chain-id", regexp.MustCompile(`(?m)^chain-id=""$`)}, - {"client keyring-backend", regexp.MustCompile(`(?m)^keyring-backend="test"$`)}, - {"client node", regexp.MustCompile(`(?m)^node="tcp://localhost:26657"$`)}, - {"client output", regexp.MustCompile(`(?m)^output="text"$`)}, - } + s.Run("all fields and defaults", func() { + expectedAll := s.makeMultiLine( + s.makeAppConfigHeaderLines(), + `app-db-backend="" +halt-height=0 +halt-time=0 +iavl-cache-size=781250 +iavl-disable-fastnode=true +index-events=[] +inter-block-cache=true +min-retain-blocks=0 +minimum-gas-prices="5confcoin" +pruning="default" +pruning-interval="0" +pruning-keep-recent="0" +query-gas-limit=0 +api.address="tcp://localhost:1317" +api.enable=false +api.enabled-unsafe-cors=false +api.max-open-connections=1000 +api.rpc-max-body-bytes=1000000 +api.rpc-read-timeout=10 +api.rpc-write-timeout=0 +api.swagger=false +grpc-web.enable=true +grpc.address="localhost:9090" +grpc.enable=true +grpc.max-recv-msg-size=10485760 +grpc.max-send-msg-size=2147483647 +mempool.max-txs=5000 +state-sync.snapshot-interval=0 +state-sync.snapshot-keep-recent=2 +streaming.abci.keys=[] +streaming.abci.plugin="" +streaming.abci.stop-node-on-err=true +telemetry.datadog-hostname="" +telemetry.enable-hostname=false +telemetry.enable-hostname-label=false +telemetry.enable-service-label=false +telemetry.enabled=false +telemetry.global-labels=[] +telemetry.metrics-sink="" +telemetry.prometheus-retention-time=0 +telemetry.service-name="" +telemetry.statsd-addr=""`, + "", + s.makeCMTConfigHeaderLines(), + `abci="socket" +db_backend="goleveldb" +db_dir="data" +filter_peers=false +genesis_file="config/genesis.json" +log_format="plain" +log_level="info" +moniker="F0796.localdomain" +node_key_file="config/node_key.json" +priv_validator_key_file="config/priv_validator_key.json" +priv_validator_laddr="" +priv_validator_state_file="data/priv_validator_state.json" +proxy_app="tcp://127.0.0.1:26658" +version="0.38.7" +blocksync.version="v0" +consensus.create_empty_blocks=true +consensus.create_empty_blocks_interval="0s" +consensus.double_sign_check_height=0 +consensus.peer_gossip_sleep_duration="100ms" +consensus.peer_query_maj23_sleep_duration="2s" +consensus.skip_timeout_commit=false +consensus.timeout_commit="1.5s" +consensus.timeout_precommit="1s" +consensus.timeout_precommit_delta="500ms" +consensus.timeout_prevote="1s" +consensus.timeout_prevote_delta="500ms" +consensus.timeout_propose="3s" +consensus.timeout_propose_delta="500ms" +consensus.wal_file="data/cs.wal/wal" +instrumentation.max_open_connections=3 +instrumentation.namespace="cometbft" +instrumentation.prometheus=false +instrumentation.prometheus_listen_addr=":26660" +mempool.broadcast=true +mempool.cache_size=10000 +mempool.experimental_max_gossip_connections_to_non_persistent_peers=0 +mempool.experimental_max_gossip_connections_to_persistent_peers=0 +mempool.keep-invalid-txs-in-cache=false +mempool.max_batch_bytes=0 +mempool.max_tx_bytes=1048576 +mempool.max_txs_bytes=1073741824 +mempool.recheck=true +mempool.size=5000 +mempool.type="flood" +mempool.wal_dir="" +p2p.addr_book_file="config/addrbook.json" +p2p.addr_book_strict=true +p2p.allow_duplicate_ip=false +p2p.dial_timeout="3s" +p2p.external_address="" +p2p.flush_throttle_timeout="100ms" +p2p.handshake_timeout="20s" +p2p.laddr="tcp://0.0.0.0:26656" +p2p.max_num_inbound_peers=40 +p2p.max_num_outbound_peers=10 +p2p.max_packet_msg_payload_size=1024 +p2p.persistent_peers="" +p2p.persistent_peers_max_dial_period="0s" +p2p.pex=true +p2p.private_peer_ids="" +p2p.recv_rate=5120000 +p2p.seed_mode=false +p2p.seeds="" +p2p.send_rate=5120000 +p2p.unconditional_peer_ids="" +rpc.cors_allowed_headers=["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time"] +rpc.cors_allowed_methods=["HEAD", "GET", "POST"] +rpc.cors_allowed_origins=[] +rpc.experimental_close_on_slow_client=false +rpc.experimental_subscription_buffer_size=200 +rpc.experimental_websocket_write_buffer_size=200 +rpc.grpc_laddr="" +rpc.grpc_max_open_connections=900 +rpc.laddr="tcp://127.0.0.1:26657" +rpc.max_body_bytes=1000000 +rpc.max_header_bytes=1048576 +rpc.max_open_connections=900 +rpc.max_subscription_clients=100 +rpc.max_subscriptions_per_client=5 +rpc.pprof_laddr="" +rpc.timeout_broadcast_tx_commit="10s" +rpc.tls_cert_file="" +rpc.tls_key_file="" +rpc.unsafe=false +statesync.chunk_fetchers=4 +statesync.chunk_request_timeout="10s" +statesync.discovery_time="15s" +statesync.enable=false +statesync.rpc_servers=[] +statesync.temp_dir="" +statesync.trust_hash="" +statesync.trust_height=0 +statesync.trust_period="168h0m0s" +storage.discard_abci_responses=false +tx_index.indexer="null" +tx_index.psql-conn=""`, + "", + s.makeClientConfigHeaderLines(), + `broadcast-mode="block" +chain-id="" +keyring-backend="test" +node="tcp://localhost:26657" +output="text"`, + "", + ) - for _, tc := range expectedRegexpMatches { - s.Run(tc.name, func() { - isMatch := tc.re.MatchString(noArgsOut) - s.Assert().True(isMatch, "`%s` matching:\n%s", tc.re.String(), noArgsOut) - }) - } + // This test compares the no-args output to a previously known result. + // If this test fails unexpectedly, we'll probably want to discuss how those changes + // affect us, and whether we'll need to make further changes to accommodate the updates. + s.Assert().Equal(expectedAll, noArgsOut) + }) - s.Run("with args get all", func() { + s.Run("get all", func() { allOutStr := s.executeConfigCmd("get", "all") s.Assert().Equal(noArgsOut, allOutStr, "output of get vs output of get all") }) - inOutTests := []string{ - "app", - "cosmos", - "config", - "cometbft", - "comet", - "cmt", - "client", - } - - for _, opt := range inOutTests { + // Test that the various sub-sections are in the no-args output. + var cmtOut string + for _, opt := range []string{"app", "cosmos", "config", "cometbft", "comet", "cmt", "client"} { args := []string{"get", opt} s.Run(strings.Join(args, " "), func() { outStr := s.executeConfigCmd(args...) s.Assert().Contains(noArgsOut, outStr, "output of get vs output of %q", args) + if opt == "cometbft" { + cmtOut = outStr + } }) } + // Test that the deprecated tendermint and tm options have both the deprecation message and the section content. for _, opt := range []string{"tendermint", "tm"} { args := []string{"get", opt} s.Run(strings.Join(args, " "), func() { - expTMOut := s.makeTmDeprecatedLines(opt) + s.executeConfigCmd("get", "cmt") + expTMOut := s.makeTmDeprecatedLines(opt) + cmtOut outStr := s.executeConfigCmd(args...) s.Assert().Equal(expTMOut, outStr) }) From 57c8707df559140fbe48e5d10d91177c8a17898d Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 9 May 2024 13:38:43 -0600 Subject: [PATCH 09/23] [1760]: Update pre-upgrade command to change the broadcast mode from block to sync. Make the client config defaults public variables (instead of private consts) so we can update them dynamically if needed. --- cmd/provenanced/cmd/config.go | 2 +- cmd/provenanced/cmd/pre_upgrade.go | 12 +++---- cmd/provenanced/config/client.go | 57 ++++++++++++++++++++---------- cmd/provenanced/config/toml.go | 16 ++++++--- 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/cmd/provenanced/cmd/config.go b/cmd/provenanced/cmd/config.go index 071a219273..d254b2eedd 100644 --- a/cmd/provenanced/cmd/config.go +++ b/cmd/provenanced/cmd/config.go @@ -418,7 +418,7 @@ func runConfigSetCmd(cmd *cobra.Command, args []string) (bool, error) { } if len(cmtUpdates) > 0 { if err := cmtConfig.ValidateBasic(); err != nil { - cmd.Printf("cometbft config validation error: %v\n", err) + cmd.Printf("CometBFT config validation error: %v\n", err) issueFound = true } } diff --git a/cmd/provenanced/cmd/pre_upgrade.go b/cmd/provenanced/cmd/pre_upgrade.go index 61e8542bef..061caee4d6 100644 --- a/cmd/provenanced/cmd/pre_upgrade.go +++ b/cmd/provenanced/cmd/pre_upgrade.go @@ -3,6 +3,7 @@ package cmd import ( "errors" "fmt" + "strings" "github.com/spf13/cobra" @@ -81,14 +82,9 @@ func UpdateConfig(cmd *cobra.Command) error { return err } - if clientCfg.ChainID == "pio-mainnet-1" { - // Update the timeout commit. - timeoutCommit := config.DefaultConsensusTimeoutCommit - if cmtCfg.Consensus.TimeoutCommit != timeoutCommit { - cmd.Printf("Updating consensus.timeout_commit config value to %q (from %q)\n", - timeoutCommit, cmtCfg.Consensus.TimeoutCommit) - cmtCfg.Consensus.TimeoutCommit = timeoutCommit - } + if strings.ToLower(clientCfg.BroadcastMode) == "block" { + cmd.Printf("Updating the broadcast_mode config value to \"sync\" (from %q, which is no longer an option).\n", clientCfg.BroadcastMode) + clientCfg.BroadcastMode = "sync" } return SafeSaveConfigs(cmd, appCfg, cmtCfg, clientCfg, true) diff --git a/cmd/provenanced/config/client.go b/cmd/provenanced/config/client.go index 244cab7e6f..1914ec69ca 100644 --- a/cmd/provenanced/config/client.go +++ b/cmd/provenanced/config/client.go @@ -10,13 +10,24 @@ import ( txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" ) -// Default constants -const ( - chainID = "" - keyringBackend = "test" - output = "text" - node = "tcp://localhost:26657" - broadcastMode = "block" +// This is similar to the content in the SDK's client/config/config.go file. +// Key Differences: +// - Our version allows us to change the defaults for testnets. +// - We have a validation method (like the other configs). +// - We can't use the SDK's ReadFromClientConfig: +// - That is restricted to only the client.toml file, which doesn't work with a packed config. +// - That writes the client.toml file if it doesn't exist, which we don't want. +// - We have the ApplyClientConfigToContext function which is mostly extracted from +// the SDK's ReadFromClientConfig with the addition of the signing mode. +// - The SDK's file writing stuff is all private, and they don't give a way to just write the file. +// - The way the SDK loads the config into viper stomps on previously loades stuff. + +var ( + DefaultChainID = "" + DefaultKeyringBackend = "test" + DefaultOutput = "text" + DefaultNode = "tcp://localhost:26657" + DefaultBroadcastMode = "sync" ) type ClientConfig struct { @@ -29,7 +40,13 @@ type ClientConfig struct { // DefaultClientConfig returns the reference to ClientConfig with default values. func DefaultClientConfig() *ClientConfig { - return &ClientConfig{chainID, keyringBackend, output, node, broadcastMode} + return &ClientConfig{ + ChainID: DefaultChainID, + KeyringBackend: DefaultKeyringBackend, + Output: DefaultOutput, + Node: DefaultNode, + BroadcastMode: DefaultBroadcastMode, + } } func (c *ClientConfig) SetChainID(chainID string) { @@ -64,7 +81,7 @@ func (c ClientConfig) ValidateBasic() error { return errors.New("unknown output (must be 'text' or 'json')") } switch c.BroadcastMode { - case "sync", "async", "block": + case "sync", "async": default: return errors.New("unknown broadcast-mode (must be one of 'sync' 'async' 'block')") } @@ -78,26 +95,26 @@ func ApplyClientConfigToContext(ctx client.Context, config *ClientConfig) (clien WithChainID(config.ChainID). WithKeyringDir(ctx.HomeDir) - keyring, krerr := client.NewKeyringFromBackend(ctx, config.KeyringBackend) - if krerr != nil { - return ctx, fmt.Errorf("couldn't get key ring backend %s: %w", config.KeyringBackend, krerr) + keyring, err := client.NewKeyringFromBackend(ctx, config.KeyringBackend) + if err != nil { + return ctx, fmt.Errorf("couldn't get keyring with backend %q: %w", config.KeyringBackend, err) } ctx = ctx.WithKeyring(keyring) // https://github.com/cosmos/cosmos-sdk/issues/8986 - clnt, nerr := client.NewClientFromNode(config.Node) - if nerr != nil { - return ctx, fmt.Errorf("couldn't get client from nodeURI: %w", nerr) + clnt, err := client.NewClientFromNode(config.Node) + if err != nil { + return ctx, fmt.Errorf("couldn't get client from nodeURI: %w", err) } ctx = ctx.WithNodeURI(config.Node). WithClient(clnt). WithBroadcastMode(config.BroadcastMode) - // This needs to go after ReadFromClientConfig, as that function - // sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode - // is only available if the client is online. + // This needs to go after the client has been set in the context. + // That client is needed for SIGN_MODE_TEXTUAL. + // This sign mode is only available if the client is online. if !ctx.Offline { enabledSignModes := tx.DefaultSignModes enabledSignModes = append(enabledSignModes, signing.SignMode_SIGN_MODE_TEXTUAL) @@ -105,7 +122,9 @@ func ApplyClientConfigToContext(ctx client.Context, config *ClientConfig) (clien EnabledSignModes: enabledSignModes, TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(ctx), } - txConfig, err := tx.NewTxConfigWithOptions( + + var txConfig client.TxConfig + txConfig, err = tx.NewTxConfigWithOptions( ctx.Codec, txConfigOpts, ) diff --git a/cmd/provenanced/config/toml.go b/cmd/provenanced/config/toml.go index 90f02fa816..a185c54742 100644 --- a/cmd/provenanced/config/toml.go +++ b/cmd/provenanced/config/toml.go @@ -2,16 +2,22 @@ package config import ( "bytes" + "os" "text/template" - - cmtos "github.com/cometbft/cometbft/libs/os" ) +// This is similar to the content in the SDK's client/config/toml.go file. +// The only difference in the defaultConfigTemplate is the fixed header border. +// This primarily exists, though, because the SDK's version isn't public, +// so we can't use that stuff to just write the file. +// Our WriteConfigToFile also panics instead of returning an error because +// the other two config file writers behave that way too. + const defaultConfigTemplate = `# This is a TOML config file. # For more information, see https://github.com/toml-lang/toml ############################################################################### -### Client Configuration ### +### Client Configuration ### ############################################################################### # The network chain ID @@ -45,5 +51,7 @@ func WriteConfigToFile(configFilePath string, config *ClientConfig) { panic(err) } - cmtos.MustWriteFile(configFilePath, buffer.Bytes(), 0644) + if err := os.WriteFile(configFilePath, buffer.Bytes(), 0644); err != nil { + panic(err) + } } From bed3749a79b52fd1b2a8d87ada98cdb70a7c25dc Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 9 May 2024 15:14:14 -0600 Subject: [PATCH 10/23] [1760]: Change the default keyring backend to os, but keep it as test for testnets. Add/Update unit tests for the broadcast mode and keyring backend changes, as well as for the pre-upgrade command changes." --- cmd/provenanced/cmd/config_test.go | 157 +++++++++++--------- cmd/provenanced/cmd/pre_upgrade.go | 3 +- cmd/provenanced/cmd/pre_upgrade_test.go | 184 +++++++++--------------- cmd/provenanced/cmd/root.go | 3 + cmd/provenanced/config/client.go | 2 +- 5 files changed, 158 insertions(+), 191 deletions(-) diff --git a/cmd/provenanced/cmd/config_test.go b/cmd/provenanced/cmd/config_test.go index ee478dd0c2..8fc3599157 100644 --- a/cmd/provenanced/cmd/config_test.go +++ b/cmd/provenanced/cmd/config_test.go @@ -88,21 +88,14 @@ func TestConfigTestSuite(t *testing.T) { // Test setup above. Test helpers below. // +// getConfigCmd gets the config command with the default config values loaded into viper. +// This is similar to the context the cmd would have when executed via the root command. func (s *ConfigTestSuite) getConfigCmd() *cobra.Command { - // What I really need here is a cobra.Command - // that already has a context. - // So I'm going to call --help on the config command - // while setting the context and getting the command back. configCmd := cmd.ConfigCmd() - configCmd.SetArgs([]string{"--help"}) - applyMockIODiscardOutErr(configCmd) - configCmd, err := configCmd.ExecuteContextC(*s.Context) - s.Require().NoError(err, "config help command to set context") - // Now this should work to load the defaults (or files) into the cmd. - s.Require().NoError( - provconfig.LoadConfigFromFiles(configCmd), - "loading config from files", - ) + configCmd.SetOut(io.Discard) + configCmd.SetErr(io.Discard) + configCmd.SetContext(*s.Context) + s.Require().NoError(provconfig.LoadConfigFromFiles(configCmd), "loading config from files") return configCmd } @@ -122,13 +115,17 @@ func (s *ConfigTestSuite) ensureConfigFiles() { // executeConfigCmd executes the config command with the provided args, returning the command's output. func (s *ConfigTestSuite) executeConfigCmd(args ...string) string { - configCmd := s.getConfigCmd() - configCmd.SetArgs(args) - b := applyMockIOOutErr(configCmd) - err := configCmd.Execute() - s.Require().NoError(err, "unexpected error executing %s %q", configCmd.Name(), args) + return s.executeCmd(s.getConfigCmd(), args...) +} + +// executeCmd executes the provided command with the provided args, returning the command's output. +func (s *ConfigTestSuite) executeCmd(cmd *cobra.Command, args ...string) string { + cmd.SetArgs(args) + b := applyMockIOOutErr(cmd) + err := cmd.Execute() + s.Require().NoError(err, "unexpected error executing %s %q", cmd.Name(), args) out, err := io.ReadAll(b) - s.Require().NoError(err, "unexpected error reading %s %q output", configCmd.Name(), args) + s.Require().NoError(err, "unexpected error reading %s %q output", cmd.Name(), args) return string(out) } @@ -193,13 +190,6 @@ func (s *ConfigTestSuite) makeKeyUpdatedLine(key, oldVal, newVal string) string return fmt.Sprintf("%s Was: %s, Is Now: %s", key, oldVal, newVal) } -func applyMockIODiscardOutErr(c *cobra.Command) *bytes.Buffer { - b := bytes.NewBufferString("") - c.SetOut(io.Discard) - c.SetErr(io.Discard) - return b -} - func applyMockIOOutErr(c *cobra.Command) *bytes.Buffer { b := bytes.NewBufferString("") c.SetOut(b) @@ -207,6 +197,20 @@ func applyMockIOOutErr(c *cobra.Command) *bytes.Buffer { return b } +// setDefaultKeyringBackend updates the global DefaultKeyringBackend value +// and returns a deferrable that will change it back. +// +// Standard usage: defer s.setDefaultKeyringBackend("test")() +func (s *ConfigTestSuite) setDefaultKeyringBackend(val string) func() { + oldVal := provconfig.DefaultKeyringBackend + s.T().Logf("Changing DefaultKeyringBackend to %q (from %q).", val, oldVal) + provconfig.DefaultKeyringBackend = val + return func() { + s.T().Logf("Changing DefaultKeyringBackend back to %q (from %q).", oldVal, val) + provconfig.DefaultKeyringBackend = oldVal + } +} + // // Test helpers above. Tests below. // @@ -387,9 +391,9 @@ tx_index.indexer="null" tx_index.psql-conn=""`, "", s.makeClientConfigHeaderLines(), - `broadcast-mode="block" + `broadcast-mode="sync" chain-id="" -keyring-backend="test" +keyring-backend="os" node="tcp://localhost:26657" output="text"`, "", @@ -461,8 +465,8 @@ func (s *ConfigTestSuite) TestConfigGetMulti() { keys: []string{"keyring-backend", "broadcast-mode", "output"}, expected: s.makeMultiLine( s.makeClientConfigHeaderLines(), - `broadcast-mode="block"`, - `keyring-backend="test"`, + `broadcast-mode="sync"`, + `keyring-backend="os"`, `output="text"`, ""), }, @@ -653,6 +657,20 @@ func (s *ConfigTestSuite) TestConfigChanged() { s.Assert().Equal(tc.out, outStr) }) } + + s.Run("diff default keyring backend", func() { + defer s.setDefaultKeyringBackend("test")() + + expOut := s.makeMultiLine( + s.makeClientDiffHeaderLines(), + "keyring-backend=\"os\" (default=\"test\")", + "", + ) + + args := []string{"changed", "keyring-backend"} + actOut := s.executeConfigCmd(args...) + s.Assert().Equal(expOut, actOut, "output of config %q", args) + }) } func (s *ConfigTestSuite) TestConfigSetValidation() { @@ -790,14 +808,14 @@ func (s *ConfigTestSuite) TestConfigCmdSet() { }, { name: "broadcast-mode", - oldVal: `"block"`, - newVal: `"sync"`, + oldVal: `"sync"`, + newVal: `"async"`, toMatch: []*regexp.Regexp{reClientConfigUpdated}, }, { name: "keyring-backend", - oldVal: `"test"`, - newVal: `"os"`, + oldVal: `"os"`, + newVal: `"file"`, toMatch: []*regexp.Regexp{reClientConfigUpdated}, }, } @@ -897,60 +915,59 @@ func (s *ConfigTestSuite) TestConfigSetMulti() { } func (s *ConfigTestSuite) TestPackUnpack() { - s.T().Run("pack", func(t *testing.T) { + s.Run("pack", func() { expectedPacked := map[string]string{} expectedPackedJSON, jerr := json.MarshalIndent(expectedPacked, "", " ") - require.NoError(t, jerr, "making expected json") + s.Require().NoError(jerr, "making expected json") expectedPackedJSONStr := string(expectedPackedJSON) + configCmd := s.getConfigCmd() - args := []string{"pack"} - configCmd.SetArgs(args) - b := applyMockIOOutErr(configCmd) - err := configCmd.Execute() - require.NoError(t, err, "%s %s - unexpected error in execution", configCmd.Name(), args) - out, rerr := io.ReadAll(b) - require.NoError(t, rerr, "%s %s - unexpected error in reading", configCmd.Name(), args) - outStr := string(out) + outStr := s.executeCmd(configCmd, "pack") - assert.Contains(t, outStr, expectedPackedJSONStr, "packed json") + s.Assert().Contains(outStr, expectedPackedJSONStr, "packed json") packedFile := provconfig.GetFullPathToPackedConf(configCmd) - assert.Contains(t, outStr, packedFile, "packed filename") - assert.True(t, provconfig.FileExists(packedFile), "file exists: packed") + s.Assert().Contains(outStr, packedFile, "packed filename") + s.Assert().True(provconfig.FileExists(packedFile), "file exists: packed") appFile := provconfig.GetFullPathToAppConf(configCmd) - assert.Contains(t, outStr, appFile, "app filename") - assert.False(t, provconfig.FileExists(appFile), "file exists: app") + s.Assert().Contains(outStr, appFile, "app filename") + s.Assert().False(provconfig.FileExists(appFile), "file exists: app") cmtFile := provconfig.GetFullPathToAppConf(configCmd) - assert.Contains(t, outStr, cmtFile, "cometbft filename") - assert.False(t, provconfig.FileExists(cmtFile), "file exists: cometbft") + s.Assert().Contains(outStr, cmtFile, "cometbft filename") + s.Assert().False(provconfig.FileExists(cmtFile), "file exists: cometbft") clientFile := provconfig.GetFullPathToAppConf(configCmd) - assert.Contains(t, outStr, clientFile, "client filename") - assert.False(t, provconfig.FileExists(clientFile), "file exists: client") + s.Assert().Contains(outStr, clientFile, "client filename") + s.Assert().False(provconfig.FileExists(clientFile), "file exists: client") }) - s.T().Run("unpack", func(t *testing.T) { + s.Run("unpack", func() { configCmd := s.getConfigCmd() - args := []string{"unpack"} - configCmd.SetArgs(args) - b := applyMockIOOutErr(configCmd) - err := configCmd.Execute() - require.NoError(t, err, "%s %s - unexpected error in execution", configCmd.Name(), args) - out, rerr := io.ReadAll(b) - require.NoError(t, rerr, "%s %s - unexpected error in reading", configCmd.Name(), args) - outStr := string(out) + outStr := s.executeCmd(configCmd, "unpack") packedFile := provconfig.GetFullPathToPackedConf(configCmd) - assert.Contains(t, outStr, packedFile, "packed filename") - assert.False(t, provconfig.FileExists(packedFile), "file exists: packed") + s.Assert().Contains(outStr, packedFile, "packed filename") + s.Assert().False(provconfig.FileExists(packedFile), "file exists: packed") appFile := provconfig.GetFullPathToAppConf(configCmd) - assert.Contains(t, outStr, appFile, "app filename") - assert.True(t, provconfig.FileExists(appFile), "file exists: app") + s.Assert().Contains(outStr, appFile, "app filename") + s.Assert().True(provconfig.FileExists(appFile), "file exists: app") cmtFile := provconfig.GetFullPathToAppConf(configCmd) - assert.Contains(t, outStr, cmtFile, "cometbft filename") - assert.True(t, provconfig.FileExists(cmtFile), "file exists: cometbft") + s.Assert().Contains(outStr, cmtFile, "cometbft filename") + s.Assert().True(provconfig.FileExists(cmtFile), "file exists: cometbft") clientFile := provconfig.GetFullPathToAppConf(configCmd) - assert.Contains(t, outStr, clientFile, "client filename") - assert.True(t, provconfig.FileExists(clientFile), "file exists: client") + s.Assert().Contains(outStr, clientFile, "client filename") + s.Assert().True(provconfig.FileExists(clientFile), "file exists: client") + }) + + s.Run("diff default keyring backend pack", func() { + defer s.setDefaultKeyringBackend("test")() + + expectedPacked := map[string]string{"keyring-backend": "os"} + expectedPackedJSON, jerr := json.MarshalIndent(expectedPacked, "", " ") + s.Require().NoError(jerr, "making expected json") + expectedPackedJSONStr := string(expectedPackedJSON) + + outStr := s.executeConfigCmd("pack") + s.Assert().Contains(outStr, expectedPackedJSONStr, "packed json should be in the output") }) } diff --git a/cmd/provenanced/cmd/pre_upgrade.go b/cmd/provenanced/cmd/pre_upgrade.go index 061caee4d6..f79a78b1b9 100644 --- a/cmd/provenanced/cmd/pre_upgrade.go +++ b/cmd/provenanced/cmd/pre_upgrade.go @@ -3,7 +3,6 @@ package cmd import ( "errors" "fmt" - "strings" "github.com/spf13/cobra" @@ -82,7 +81,7 @@ func UpdateConfig(cmd *cobra.Command) error { return err } - if strings.ToLower(clientCfg.BroadcastMode) == "block" { + if clientCfg.BroadcastMode == "block" { cmd.Printf("Updating the broadcast_mode config value to \"sync\" (from %q, which is no longer an option).\n", clientCfg.BroadcastMode) clientCfg.BroadcastMode = "sync" } diff --git a/cmd/provenanced/cmd/pre_upgrade_test.go b/cmd/provenanced/cmd/pre_upgrade_test.go index 8a9e62c599..d3abe9961f 100644 --- a/cmd/provenanced/cmd/pre_upgrade_test.go +++ b/cmd/provenanced/cmd/pre_upgrade_test.go @@ -250,25 +250,17 @@ func TestPreUpgradeCmd(t *testing.T) { appCfgC := config.DefaultAppConfig() appCfgC.API.Enable = true appCfgC.API.Swagger = true - cmtCfgLower := config.DefaultCmtConfig() - cmtCfgLower.Consensus.TimeoutCommit = cmtCfgD.Consensus.TimeoutCommit - 500*time.Millisecond - cmtCfgLower.LogLevel = "debug" - cmtCfgHigher := config.DefaultCmtConfig() - cmtCfgHigher.Consensus.TimeoutCommit = cmtCfgD.Consensus.TimeoutCommit + 500*time.Millisecond - cmtCfgHigher.LogLevel = "debug" + cmtCfgC := config.DefaultCmtConfig() + cmtCfgC.Consensus.TimeoutCommit = cmtCfgD.Consensus.TimeoutCommit + 123*time.Millisecond + cmtCfgC.LogLevel = "debug" clientCfgC := config.DefaultClientConfig() clientCfgC.Output = "json" - clientCfgMainnetC := config.DefaultClientConfig() - clientCfgMainnetC.Output = "json" - clientCfgMainnetC.ChainID = "pio-mainnet-1" - - cmtCfgCFixed := config.DefaultCmtConfig() - cmtCfgCFixed.LogLevel = "debug" + clientCfgC.ChainID = "pio-mainnet-1" + clientCfgAsync := config.DefaultClientConfig() + clientCfgAsync.BroadcastMode = "async" successMsg := "pre-upgrade successful" - updatingMsg := func(old time.Duration) string { - return fmt.Sprintf("Updating consensus.timeout_commit config value to %q (from %q)", config.DefaultConsensusTimeoutCommit, old) - } + updatingBlocksyncMsg := "Updating the broadcast_mode config value to \"sync\" (from \"block\", which is no longer an option)." tests := []struct { name string @@ -327,69 +319,9 @@ func TestPreUpgradeCmd(t *testing.T) { expClientCfg: clientCfgD, }, { - name: "mainnet unpacked config lower than default", + name: "cannot write new file", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHome(t, "mainnet_unpacked_lower", appCfgC, cmtCfgLower, clientCfgMainnetC) - return home, nil, success - }, - expExitCode: 0, - expInStdout: []string{ - updatingMsg(cmtCfgLower.Consensus.TimeoutCommit), - successMsg, - }, - expAppCfg: appCfgC, - expTmCfg: cmtCfgCFixed, - expClientCfg: clientCfgMainnetC, - }, - { - name: "mainnet unpacked config higher than default", - setup: func(t *testing.T) (string, func(), bool) { - home, success := newHome(t, "mainnet_unpacked_higher", appCfgC, cmtCfgHigher, clientCfgMainnetC) - return home, nil, success - }, - expExitCode: 0, - expInStdout: []string{ - updatingMsg(cmtCfgHigher.Consensus.TimeoutCommit), - successMsg, - }, - expAppCfg: appCfgC, - expTmCfg: cmtCfgCFixed, - expClientCfg: clientCfgMainnetC, - }, - { - name: "mainnet packed config lower than default", - setup: func(t *testing.T) (string, func(), bool) { - home, success := newHomePacked(t, "mainnet_packed_lower", appCfgC, cmtCfgLower, clientCfgMainnetC) - return home, nil, success - }, - expExitCode: 0, - expInStdout: []string{ - updatingMsg(cmtCfgLower.Consensus.TimeoutCommit), - successMsg, - }, - expAppCfg: appCfgC, - expTmCfg: cmtCfgCFixed, - expClientCfg: clientCfgMainnetC, - }, - { - name: "mainnet packed config higher than default", - setup: func(t *testing.T) (string, func(), bool) { - home, success := newHomePacked(t, "mainnet_packed_higher", appCfgC, cmtCfgHigher, clientCfgMainnetC) - return home, nil, success - }, - expExitCode: 0, - expInStdout: []string{ - updatingMsg(cmtCfgHigher.Consensus.TimeoutCommit), - successMsg, - }, - expAppCfg: appCfgC, - expTmCfg: cmtCfgCFixed, - expClientCfg: clientCfgMainnetC, - }, - { - name: "mainnet cannot write new file", - setup: func(t *testing.T) (string, func(), bool) { - home, success := newHomePacked(t, "mainnet_cannot_write", appCfgC, cmtCfgLower, clientCfgMainnetC) + home, success := newHomePacked(t, "mainnet_cannot_write", appCfgC, cmtCfgC, clientCfgC) if !success { return home, nil, success } @@ -403,79 +335,95 @@ func TestPreUpgradeCmd(t *testing.T) { return home, deferrable, success }, expExitCode: 30, - expInStdout: []string{updatingMsg(cmtCfgLower.Consensus.TimeoutCommit)}, expInStderr: []string{"could not update config file(s):", "error saving config file(s):", "permission denied"}, }, { - name: "other net unpacked config lower than default", + name: "packed config broadcast block", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHome(t, "other_unpacked_lower", appCfgC, cmtCfgLower, clientCfgC) + clientCfg := config.DefaultClientConfig() + clientCfg.BroadcastMode = "block" + home, success := newHomePacked(t, "packed_broadcast_block", appCfgD, cmtCfgD, clientCfg) return home, nil, success }, expExitCode: 0, - expInStdout: []string{successMsg}, - expNot: []string{"Updating consensus.timeout_commit config value"}, - expAppCfg: appCfgC, - expTmCfg: cmtCfgLower, - expClientCfg: clientCfgC, + expInStdout: []string{updatingBlocksyncMsg, successMsg}, + expAppCfg: appCfgD, + expTmCfg: cmtCfgD, + expClientCfg: clientCfgD, }, { - name: "other net unpacked config higher than default", + name: "packed config broadcast sync", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHome(t, "other_unpacked_higher", appCfgC, cmtCfgHigher, clientCfgC) + clientCfg := config.DefaultClientConfig() + clientCfg.BroadcastMode = "sync" + home, success := newHomePacked(t, "packed_broadcast_sync", appCfgD, cmtCfgD, clientCfg) return home, nil, success }, expExitCode: 0, expInStdout: []string{successMsg}, - expNot: []string{"Updating consensus.timeout_commit config value"}, - expAppCfg: appCfgC, - expTmCfg: cmtCfgHigher, - expClientCfg: clientCfgC, + expNot: []string{updatingBlocksyncMsg}, + expAppCfg: appCfgD, + expTmCfg: cmtCfgD, + expClientCfg: clientCfgD, }, { - name: "other net packed config lower than default", + name: "packed config broadcast async", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHomePacked(t, "other_packed_lower", appCfgC, cmtCfgLower, clientCfgC) + clientCfg := config.DefaultClientConfig() + clientCfg.BroadcastMode = "async" + home, success := newHomePacked(t, "packed_broadcast_async", appCfgD, cmtCfgD, clientCfg) return home, nil, success }, expExitCode: 0, expInStdout: []string{successMsg}, - expNot: []string{"Updating consensus.timeout_commit config value"}, - expAppCfg: appCfgC, - expTmCfg: cmtCfgLower, - expClientCfg: clientCfgC, + expNot: []string{updatingBlocksyncMsg}, + expAppCfg: appCfgD, + expTmCfg: cmtCfgD, + expClientCfg: clientCfgAsync, + }, + { + name: "unpacked config broadcast block", + setup: func(t *testing.T) (string, func(), bool) { + clientCfg := config.DefaultClientConfig() + clientCfg.BroadcastMode = "block" + home, success := newHome(t, "unpacked_broadcast_block", appCfgD, cmtCfgD, clientCfg) + return home, nil, success + }, + expExitCode: 0, + expInStdout: []string{updatingBlocksyncMsg, successMsg}, + expAppCfg: appCfgD, + expTmCfg: cmtCfgD, + expClientCfg: clientCfgD, }, { - name: "other net packed config higher than default", + name: "unpacked config broadcast sync", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHomePacked(t, "other_packed_higher", appCfgC, cmtCfgHigher, clientCfgC) + clientCfg := config.DefaultClientConfig() + clientCfg.BroadcastMode = "sync" + home, success := newHome(t, "unpacked_broadcast_sync", appCfgD, cmtCfgD, clientCfg) return home, nil, success }, expExitCode: 0, expInStdout: []string{successMsg}, - expNot: []string{"Updating consensus.timeout_commit config value"}, - expAppCfg: appCfgC, - expTmCfg: cmtCfgHigher, - expClientCfg: clientCfgC, + expNot: []string{updatingBlocksyncMsg}, + expAppCfg: appCfgD, + expTmCfg: cmtCfgD, + expClientCfg: clientCfgD, }, { - name: "other net cannot write new file", + name: "unpacked config broadcast async", setup: func(t *testing.T) (string, func(), bool) { - home, success := newHomePacked(t, "other_cannot_write", appCfgC, cmtCfgLower, clientCfgC) - if !success { - return home, nil, success - } - - dummyCmd := makeDummyCmd(t, cdc, home) - unwritableFile := config.GetFullPathToPackedConf(dummyCmd) - success = assert.NoError(t, os.Chmod(unwritableFile, 0o444), "Chmod") - deferrable := func() { - logIfError(t, os.Chmod(unwritableFile, 0o666), "Changing permissions on %s so it can be deleted", unwritableFile) - } - return home, deferrable, success + clientCfg := config.DefaultClientConfig() + clientCfg.BroadcastMode = "async" + home, success := newHome(t, "unpacked_broadcast_async", appCfgD, cmtCfgD, clientCfg) + return home, nil, success }, - expExitCode: 30, - expInStderr: []string{"could not update config file(s):", "error saving config file(s):", "permission denied"}, + expExitCode: 0, + expInStdout: []string{successMsg}, + expNot: []string{updatingBlocksyncMsg}, + expAppCfg: appCfgD, + expTmCfg: cmtCfgD, + expClientCfg: clientCfgAsync, }, } diff --git a/cmd/provenanced/cmd/root.go b/cmd/provenanced/cmd/root.go index fded8909de..bb85085e8d 100644 --- a/cmd/provenanced/cmd/root.go +++ b/cmd/provenanced/cmd/root.go @@ -116,6 +116,9 @@ func NewRootCmd(sealConfig bool) (*cobra.Command, params.EncodingConfig) { vpr := server.GetServerContextFromCmd(cmd).Viper testnet := vpr.GetBool(EnvTypeFlag) app.SetConfig(testnet, sealConfig) + if testnet { + config.DefaultKeyringBackend = "test" + } overwriteFlagDefaults(cmd, map[string]string{ // Override default value for coin-type to match our mainnet or testnet value. diff --git a/cmd/provenanced/config/client.go b/cmd/provenanced/config/client.go index 1914ec69ca..9eafb87628 100644 --- a/cmd/provenanced/config/client.go +++ b/cmd/provenanced/config/client.go @@ -24,7 +24,7 @@ import ( var ( DefaultChainID = "" - DefaultKeyringBackend = "test" + DefaultKeyringBackend = "os" DefaultOutput = "text" DefaultNode = "tcp://localhost:26657" DefaultBroadcastMode = "sync" From d5e501364f312c84877c0e8c210e0d20b8827f88 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 9 May 2024 15:42:00 -0600 Subject: [PATCH 11/23] [1760]: Move the setting of the default keyring backend to inside the interceptor so that it can get used when loading the files. --- cmd/provenanced/cmd/root.go | 3 --- cmd/provenanced/config/interceptor.go | 7 +++++++ cmd/provenanced/config/toml.go | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/provenanced/cmd/root.go b/cmd/provenanced/cmd/root.go index bb85085e8d..fded8909de 100644 --- a/cmd/provenanced/cmd/root.go +++ b/cmd/provenanced/cmd/root.go @@ -116,9 +116,6 @@ func NewRootCmd(sealConfig bool) (*cobra.Command, params.EncodingConfig) { vpr := server.GetServerContextFromCmd(cmd).Viper testnet := vpr.GetBool(EnvTypeFlag) app.SetConfig(testnet, sealConfig) - if testnet { - config.DefaultKeyringBackend = "test" - } overwriteFlagDefaults(cmd, map[string]string{ // Override default value for coin-type to match our mainnet or testnet value. diff --git a/cmd/provenanced/config/interceptor.go b/cmd/provenanced/config/interceptor.go index d009929efb..97ad5ce8c6 100644 --- a/cmd/provenanced/config/interceptor.go +++ b/cmd/provenanced/config/interceptor.go @@ -48,6 +48,13 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command) error { return err } + // If the testnet flag was provided (or env var set), set a different default keyring backend. + // This needs to be done before we load the config files for the cases when: + // 1. The files don't exist yet, and we're loading the defaults. + // 2. The config is packed and we're filling in the missing with defaults. + if vpr.GetBool("testnet") { + DefaultKeyringBackend = "test" + } // Read the configs into viper and the contexts. return LoadConfigFromFiles(cmd) } diff --git a/cmd/provenanced/config/toml.go b/cmd/provenanced/config/toml.go index a185c54742..3eefc40b42 100644 --- a/cmd/provenanced/config/toml.go +++ b/cmd/provenanced/config/toml.go @@ -51,7 +51,7 @@ func WriteConfigToFile(configFilePath string, config *ClientConfig) { panic(err) } - if err := os.WriteFile(configFilePath, buffer.Bytes(), 0644); err != nil { + if err := os.WriteFile(configFilePath, buffer.Bytes(), 0o644); err != nil { panic(err) } } From f5939cb146808e7d160858d658a9f61c510e95a6 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 9 May 2024 15:43:51 -0600 Subject: [PATCH 12/23] [1760]: Fix a gofmt thing in internal/handlers/aggregate_events_test.go. --- internal/handlers/aggregate_events_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/handlers/aggregate_events_test.go b/internal/handlers/aggregate_events_test.go index 818e8eaff7..dee7691cb5 100644 --- a/internal/handlers/aggregate_events_test.go +++ b/internal/handlers/aggregate_events_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" From 32404e934a4101b2f48d631546232c366a4eaf53 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 9 May 2024 15:50:24 -0600 Subject: [PATCH 13/23] [1760]: Add a comment to Test_TestnetCmd explaining why address caching is disabled. --- cmd/provenanced/cmd/testnet_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/provenanced/cmd/testnet_test.go b/cmd/provenanced/cmd/testnet_test.go index 6fcdfe333b..3a9f442037 100644 --- a/cmd/provenanced/cmd/testnet_test.go +++ b/cmd/provenanced/cmd/testnet_test.go @@ -27,6 +27,10 @@ import ( ) func Test_TestnetCmd(t *testing.T) { + // We need to disable address caching in here because this test goes a couple + // address conversions using a different HRP from most of the other tests in + // this package. With address caching on, those tests can randomly fail if + // they end up running after this test. origCache := sdk.IsAddrCacheEnabled() defer sdk.SetAddrCacheEnabled(origCache) sdk.SetAddrCacheEnabled(false) From 97e43c8202a765aa729dd7d90c1b8815c4422666 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 9 May 2024 18:15:40 -0600 Subject: [PATCH 14/23] [1760]: Make the config get and changed commands also look for sub-field matches and loose matches. --- cmd/provenanced/cmd/config.go | 66 ++++++----- cmd/provenanced/cmd/config_test.go | 75 ++++++++++++ cmd/provenanced/config/reflector.go | 100 +++++++++++++--- cmd/provenanced/config/reflector_test.go | 141 +++++++++++++++++++++++ 4 files changed, 333 insertions(+), 49 deletions(-) diff --git a/cmd/provenanced/cmd/config.go b/cmd/provenanced/cmd/config.go index d254b2eedd..2975e572a0 100644 --- a/cmd/provenanced/cmd/config.go +++ b/cmd/provenanced/cmd/config.go @@ -278,27 +278,29 @@ func runConfigGetCmd(cmd *cobra.Command, args []string) error { case "client": clientToOutput.AddEntriesFrom(clientFields) default: - var found bool - if fvm, ok := appFields.FindEntries(key); ok { - found = true - appToOutput.AddEntriesFrom(fvm) - } + appFVM, appFound, appExact := appFields.FindEntries(key) + cmtFVM, cmtFound, cmtExact := cmtFields.FindEntries(key) + clientFVM, clientFound, clientExact := clientFields.FindEntries(key) - if fvm, ok := cmtFields.FindEntries(key); ok { - found = true - cmtToOutput.AddEntriesFrom(fvm) + found := appFound || cmtFound || clientFound + if !found { + unknownKeyMap.SetToNil(key) + continue } - if fvm, ok := clientFields.FindEntries(key); ok { - found = true - clientToOutput.AddEntriesFrom(fvm) + haveExact := appExact || cmtExact || clientExact + if appFound && (!haveExact || appExact) { + appToOutput.AddEntriesFrom(appFVM) } - - if !found { - unknownKeyMap.SetToNil(key) + if cmtFound && (!haveExact || cmtExact) { + cmtToOutput.AddEntriesFrom(cmtFVM) + } + if clientFound && (!haveExact || clientExact) { + clientToOutput.AddEntriesFrom(clientFVM) } } } + isPacked := provconfig.IsPacked(cmd) if len(appToOutput) > 0 { cmd.Println(makeAppConfigHeader(cmd, "", isPacked).String()) @@ -508,28 +510,32 @@ func runConfigChangedCmd(cmd *cobra.Command, args []string) error { showClient = true clientDiffs.AddOrUpdateEntriesFrom(provconfig.MakeUpdatedFieldMap(allDefaults, clientFields, true)) default: - var found bool - if fvm, ok := appFields.FindEntries(key); ok { - showApp, found = true, true - changes := provconfig.MakeUpdatedFieldMap(allDefaults, fvm, false) - appDiffs.AddOrUpdateEntriesFrom(changes) + appFVM, appFound, appExact := appFields.FindEntries(key) + cmtFVM, cmtFound, cmtExact := cmtFields.FindEntries(key) + clientFVM, clientFound, clientExact := clientFields.FindEntries(key) + + found := appFound || cmtFound || clientFound + if !found { + unknownKeyMap.SetToNil(key) + continue } - if fvm, ok := cmtFields.FindEntries(key); ok { - showCmt, found = true, true - changes := provconfig.MakeUpdatedFieldMap(allDefaults, fvm, false) + haveExact := appExact || cmtExact || clientExact + if appFound && (!haveExact || appExact) { + showApp = true + changes := provconfig.MakeUpdatedFieldMap(allDefaults, appFVM, false) + appDiffs.AddOrUpdateEntriesFrom(changes) + } + if cmtFound && (!haveExact || cmtExact) { + showCmt = true + changes := provconfig.MakeUpdatedFieldMap(allDefaults, cmtFVM, false) cmtDiffs.AddOrUpdateEntriesFrom(changes) } - - if fvm, ok := clientFields.FindEntries(key); ok { - showClient, found = true, true - changes := provconfig.MakeUpdatedFieldMap(allDefaults, fvm, false) + if clientFound && (!haveExact || clientExact) { + showClient = true + changes := provconfig.MakeUpdatedFieldMap(allDefaults, clientFVM, false) clientDiffs.AddOrUpdateEntriesFrom(changes) } - - if !found { - unknownKeyMap.SetToNil(key) - } } } diff --git a/cmd/provenanced/cmd/config_test.go b/cmd/provenanced/cmd/config_test.go index 8fc3599157..5159d70ceb 100644 --- a/cmd/provenanced/cmd/config_test.go +++ b/cmd/provenanced/cmd/config_test.go @@ -509,6 +509,45 @@ func (s *ConfigTestSuite) TestConfigGetMulti() { `mempool.wal_dir=""`, ""), }, + { + name: "multiple sub-fields with same name", + keys: []string{"enable"}, + expected: s.makeMultiLine( + s.makeAppConfigHeaderLines(), + `api.enable=false`, + `grpc-web.enable=true`, + `grpc.enable=true`, + "", + s.makeCMTConfigHeaderLines(), + `statesync.enable=false`, + "", + ), + }, + { + name: "exact match in one but loose match on others", + keys: []string{"node"}, + expected: s.makeMultiLine( + s.makeClientConfigHeaderLines(), + `node="tcp://localhost:26657"`, + "", + ), + }, + { + name: "loose match", + keys: []string{"nod"}, + expected: s.makeMultiLine( + s.makeAppConfigHeaderLines(), + `iavl-disable-fastnode=true`, + `streaming.abci.stop-node-on-err=true`, + "", + s.makeCMTConfigHeaderLines(), + `node_key_file="config/node_key.json"`, + "", + s.makeClientConfigHeaderLines(), + `node="tcp://localhost:26657"`, + "", + ), + }, } for _, tc := range tests { @@ -649,6 +688,42 @@ func (s *ConfigTestSuite) TestConfigChanged() { "", ), }, + { + args: []string{"changed", "enable"}, + out: s.makeMultiLine( + s.makeAppDiffHeaderLines(), + `api.enable=false (same as default)`, + `grpc-web.enable=true (same as default)`, + `grpc.enable=true (same as default)`, + "", + s.makeCMTDiffHeaderLines(), + `statesync.enable=false (same as default)`, + "", + ), + }, + { + args: []string{"changed", "node"}, + out: s.makeMultiLine( + s.makeClientDiffHeaderLines(), + `node="tcp://localhost:26657" (same as default)`, + "", + ), + }, + { + args: []string{"changed", "nod"}, + out: s.makeMultiLine( + s.makeAppDiffHeaderLines(), + `iavl-disable-fastnode=true (same as default)`, + `streaming.abci.stop-node-on-err=true (same as default)`, + "", + s.makeCMTDiffHeaderLines(), + `node_key_file="config/node_key.json" (same as default)`, + "", + s.makeClientDiffHeaderLines(), + `node="tcp://localhost:26657" (same as default)`, + "", + ), + }, } for _, tc := range equalAllTests { diff --git a/cmd/provenanced/config/reflector.go b/cmd/provenanced/config/reflector.go index 3a321e00be..c971c1655e 100644 --- a/cmd/provenanced/config/reflector.go +++ b/cmd/provenanced/config/reflector.go @@ -140,34 +140,96 @@ func (m FieldValueMap) GetSortedKeys() []string { } // FindEntries looks for entries in this map that match the provided key. -// First, if the key doesn't end in a period, an exact entry match is looked for. -// If such an entry is found, only that entry will be returned. -// If no such entry is found, a period is added to the end of the key (if not already there). -// E.g. Providing "filter_peers" will get just the "filter_peers" entry. -// Providing "consensus." will bypass the exact key lookup, and return all fields that start with "consensus.". -// Providing "consensus" will look first for a field specifically called "consensus", -// then, if/when not found, will return all fields that start with "consensus.". -// Then, all entries with keys that start with the desired key are returned. -// The second return value indicates whether or not anything was found. -func (m FieldValueMap) FindEntries(key string) (FieldValueMap, bool) { +// The first returned boolean is true if one or more matches are found, false if zero. +// The second returned boolean is true if an exact match was found. +// +// This looks for matches in the following order: +// 1. A field that exactly equals the provided key. +// 2. Sections equal to the provided key. +// 3. Fields named the provided key in any section. +// 4. Fields with the provided key as a substring. +// +// When matches are found, they are returned, skipping any of the searches that would come after it. +// For example, if an exact field match is found, searches 2, 3, and 4 are skipped. +// +// Only one exact match is ever returned, but if there isn't an exact match, multiple entries can be returned. +// E.g. if there's a field named "corn" and a section named "corn", and the provided key is "corn", +// only the field named "corn" will be returned. If you want the section in this case, provide the key as "corn.". +// Or if you only want fields named "corn" that are in a section, provide ".corn". +// +// Examples: +// Providing "consensus": +// 1. First look for a field specifically named "consensus". +// 2. If nothing is found yet, it'll look for fields that start with "consensus.". +// 3. If nothing is found yet, it'll look for fields that end with ".consensus". +// 4. If nothing is found yet, it'll look for fields with "consensus" in them somewhere. +// +// Providing "consensus.": +// 1. First look for a field specifically named "consensus." (probably not going to find it). +// 2. If nothing is found yet, it'll look for fields that start with "consensus.". +// 3. Skip looking for fields that end with ".consensus." (no fields end with a period). +// 4. If nothing is found yet, it'll look for fields with "consensus." in them somewhere. +// +// Providing ".consensus": +// 1. First look for a field specifically named ".consensus" (probably not going to find it). +// 2. Skip looking for fields that start with ".consensus." (no fields start with a period). +// 3. If nothing is found yet, it'll look for fields that end with ".consensus". +// 4. If nothing is found yet, it'll look for fields with ".consensus" in them somewhere. +func (m FieldValueMap) FindEntries(key string) (FieldValueMap, bool, bool) { rv := FieldValueMap{} if len(key) == 0 { - return rv, false + return rv, false, false } - if key[len(key)-1:] != "." { - if val, ok := m[key]; ok { - rv[key] = val - return rv, true + + // Look for an exact entry. + if val, ok := m[key]; ok { + rv[key] = val + return rv, true, true + } + + startDot := strings.HasPrefix(key, ".") + endDot := strings.HasSuffix(key, ".") + + // Now look for section entries. + if !startDot { + sectKey := key + if !endDot { + sectKey += "." + } + for k, v := range m { + if strings.HasPrefix(k, sectKey) { + rv[k] = v + } + } + if len(rv) > 0 { + return rv, true, false + } + } + + // Now look for the field in any section. + if !endDot { + fieldKey := key + if !startDot { + fieldKey = "." + fieldKey + } + for k, v := range m { + if strings.HasSuffix(k, fieldKey) { + rv[k] = v + } + } + if len(rv) > 0 { + return rv, true, false } - key += "." } - keylen := len(key) + + // Still nothing found, just look for the key as a substring. for k, v := range m { - if len(k) > keylen && k[:keylen] == key { + if strings.Contains(k, key) { rv[k] = v } } - return rv, len(rv) > 0 + + return rv, len(rv) > 0, false } // GetStringOf gets a string representation of the value with the given key. diff --git a/cmd/provenanced/config/reflector_test.go b/cmd/provenanced/config/reflector_test.go index cac294795d..893067d9a1 100644 --- a/cmd/provenanced/config/reflector_test.go +++ b/cmd/provenanced/config/reflector_test.go @@ -3,6 +3,7 @@ package config import ( "fmt" "reflect" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -38,12 +39,19 @@ type SubThing2 struct { SomeStrings []string `mapstructure:"some-strings"` } +type SubThing3 struct { + SubSubThing1 *SubThing1 + Thing string +} + type MainThing struct { SquashedThing `mapstructure:",squash"` SThing1 SubThing1 `mapstructure:"main-sub-thing"` PSThing2 *SubThing2 DeepThing ******SubThing2 MainInt int `mapstructure:"main-int"` + AUint uint + ST3 SubThing3 } const ( @@ -54,6 +62,8 @@ const ( mainSubThingAnInt = -5 mainSubThingAUint = uint(5) mainInt = 2 + mainAUint = uint(13) + subThing1Other = "samesame" ) func DefaultMainThing() MainThing { @@ -73,6 +83,11 @@ func DefaultMainThing() MainThing { PSThing2: nil, DeepThing: nil, MainInt: mainInt, + AUint: mainAUint, + ST3: SubThing3{ + SubSubThing1: nil, + Thing: subThing1Other, + }, } } @@ -433,3 +448,129 @@ func (s *ReflectorTestSuit) TestAsConfigMapLotsMoreTimes() { } } } + +func (s *ReflectorTestSuit) TestFieldValueMap_FindEntries() { + thing := DefaultMainThing() + thingMap := MakeFieldValueMap(&thing, true) + s.T().Logf("All MainThing Keys:\n%s", strings.Join(thingMap.GetSortedKeys(), "\n")) + // All MainThing Keys: + // auint + // exported-field + // main-int + // deepthing.a-string + // deepthing.some-strings + // main-sub-thing.anint + // main-sub-thing.auint + // psthing2.a-string + // psthing2.some-strings + // squashed-sub-thing-1.anint + // squashed-sub-thing-1.auint + // st3.other + // st3.subsubthing1.anint + // st3.subsubthing1.auint + + tests := []struct { + name string + key string + expKeys []string + expExact bool + }{ + { + name: "exact entry unique base", + key: "main-int", + expKeys: []string{"main-int"}, + expExact: true, + }, + { + name: "exact entry unique in section", + key: "deepthing.some-strings", + expKeys: []string{"deepthing.some-strings"}, + expExact: true, + }, + { + name: "exact entry equal to some sub-entries", + key: "auint", + expKeys: []string{"auint"}, + expExact: true, + }, + { + name: "a section without period", + key: "deepthing", + expKeys: []string{"deepthing.a-string", "deepthing.some-strings"}, + }, + { + name: "a section with period", + key: "deepthing.", + expKeys: []string{"deepthing.a-string", "deepthing.some-strings"}, + }, + { + name: "a field in multiple sections anint", + key: "anint", + expKeys: []string{ + "main-sub-thing.anint", + "squashed-sub-thing-1.anint", + "st3.subsubthing1.anint", + }, + }, + { + name: "a field in multiple sections ignoring exact match", + key: ".auint", + expKeys: []string{ + "main-sub-thing.auint", + "squashed-sub-thing-1.auint", + "st3.subsubthing1.auint", + }, + }, + { + name: "only rough matches", + key: "thin", + expKeys: []string{ + "deepthing.a-string", + "deepthing.some-strings", + "main-sub-thing.anint", + "main-sub-thing.auint", + "psthing2.a-string", + "psthing2.some-strings", + "squashed-sub-thing-1.anint", + "squashed-sub-thing-1.auint", + "st3.subsubthing1.anint", + "st3.subsubthing1.auint", + "st3.thing", + }, + }, + { + name: "non-exact single match", + key: "exported", + expKeys: []string{"exported-field"}, + }, + { + name: "single sub-field", + key: "thing", + expKeys: []string{"st3.thing"}, + }, + { + name: "nothing found", + key: "thingy", + expKeys: []string{}, + }, + } + + for _, tc := range tests { + s.Run(tc.name, func() { + expFound := len(tc.expKeys) > 0 + + var fvm FieldValueMap + var found bool + var exact bool + testFunc := func() { + fvm, found, exact = thingMap.FindEntries(tc.key) + } + s.Require().NotPanics(testFunc, "FindEntries(%q)", tc.key) + + actKeys := fvm.GetSortedKeys() + s.Assert().Equal(tc.expKeys, actKeys, "FindEntries(%q) result keys", tc.key) + s.Assert().Equal(expFound, found, "FindEntries(%q) found bool", tc.key) + s.Assert().Equal(tc.expExact, exact, "FindEntries(%q) exact bool", tc.key) + }) + } +} From a1c018a3aea95553496bec133e926c01a1410954 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 9 May 2024 18:47:44 -0600 Subject: [PATCH 15/23] [1760]: Fix a couple unit tests that, when run together, were ending up with the wrong default keyring backend. --- cmd/provenanced/cmd/config_test.go | 1 + cmd/provenanced/cmd/pre_upgrade_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/provenanced/cmd/config_test.go b/cmd/provenanced/cmd/config_test.go index 5159d70ceb..e685d0fa2b 100644 --- a/cmd/provenanced/cmd/config_test.go +++ b/cmd/provenanced/cmd/config_test.go @@ -53,6 +53,7 @@ func (s *ConfigTestSuite) SetupTest() { s.T().Logf("%s Home: %s", s.T().Name(), s.Home) pioconfig.SetProvenanceConfig("confcoin", 5) + provconfig.DefaultKeyringBackend = "os" s.EncodingConfig = app.MakeTestEncodingConfig(s.T()) clientCtx := client.Context{}. diff --git a/cmd/provenanced/cmd/pre_upgrade_test.go b/cmd/provenanced/cmd/pre_upgrade_test.go index d3abe9961f..f0cecc3deb 100644 --- a/cmd/provenanced/cmd/pre_upgrade_test.go +++ b/cmd/provenanced/cmd/pre_upgrade_test.go @@ -98,6 +98,9 @@ type cmdResult struct { } func executeRootCmd(t *testing.T, home string, cmdArgs ...string) *cmdResult { + // Ensure the keyring backend doesn't get changed when we run this command. + t.Setenv("PIO_TESTNET", "false") + rv := &cmdResult{Home: home} cmdArgs = append([]string{"--home", home}, cmdArgs...) @@ -202,10 +205,7 @@ func makeDummyCmd(t *testing.T, cdc codec.Codec, home string) *cobra.Command { } dummyCmd.SetOut(io.Discard) dummyCmd.SetErr(io.Discard) - dummyCmd.SetArgs([]string{}) - var err error - dummyCmd, err = dummyCmd.ExecuteContextC(ctx) - require.NoError(t, err, "dummy command execution") + dummyCmd.SetContext(ctx) require.NoError(t, config.LoadConfigFromFiles(dummyCmd), "LoadConfigFromFiles") return dummyCmd } From 08b7cb5e2f019e71a61148a1ed1118f3c9809b9a Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 9 May 2024 19:00:31 -0600 Subject: [PATCH 16/23] [1760]: Remove cmd/provenanced/cmd from the expected failures in the test github action. --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6c226729a8..6a879ca74c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,7 +53,6 @@ jobs: run: | grep -vF \ -e 'github.com/provenance-io/provenance/app' \ - -e 'github.com/provenance-io/provenance/cmd/provenanced/cmd' \ -e 'github.com/provenance-io/provenance/internal/antewrapper' \ -e 'github.com/provenance-io/provenance/x/ibchooks' \ -e 'github.com/provenance-io/provenance/x/ibcratelimit/module' \ @@ -63,7 +62,6 @@ jobs: split -d -n l/3 pkgs.txt.tmp pkgs.txt.part. printf '%s\n' \ 'github.com/provenance-io/provenance/app' \ - 'github.com/provenance-io/provenance/cmd/provenanced/cmd' \ 'github.com/provenance-io/provenance/internal/antewrapper' \ 'github.com/provenance-io/provenance/x/ibchooks' \ 'github.com/provenance-io/provenance/x/ibcratelimit/module' \ From d2367f782241ded8031a9525a46bd0533a21d0dc Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 9 May 2024 19:08:48 -0600 Subject: [PATCH 17/23] [1760]: Add changelog entries. --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61391afeaa..3c4e629b93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,14 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Removes sync-info code for sdk v0.50 [#1760](https://github.com/provenance-io/provenance/issues/1760). * Fix most of the failing unit tests [#1943](https://github.com/provenance-io/provenance/pull/1943) * Clean up ReadFromClient [#1760](https://github.com/provenance-io/provenance/issues/1760). +* Enhance the config get and changed commands to make it easier to find fields [#1968](https://github.com/provenance-io/provenance/pull/1968). +* Change the default keyring backend to "os", but leave it as "test" for testnets [#1968](https://github.com/provenance-io/provenance/pull/1968). +* Change the default broadcast mode to "sync" [#1968](https://github.com/provenance-io/provenance/pull/1968). +* The pre-upgrade command now updates the client config's broadcast mode to "sync" if it's set to "block" [#1968](https://github.com/provenance-io/provenance/pull/1968). + +### Deprecated + +* In the config commands, the "tendermint" and "tm" options are deprecated, replaced with "cometbft", "comet", and "cmt" [#1968](https://github.com/provenance-io/provenance/pull/1968). ### Dependencies From 2e0f3abfa7914f50acfccf9d4349e2379ebfa0ea Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 10 May 2024 11:13:19 -0600 Subject: [PATCH 18/23] [1760]: Fix the config cmd tests that didn't work right because the moniker that gets chosen is different on different computers. --- cmd/provenanced/cmd/config_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/provenanced/cmd/config_test.go b/cmd/provenanced/cmd/config_test.go index e685d0fa2b..d982a4a28e 100644 --- a/cmd/provenanced/cmd/config_test.go +++ b/cmd/provenanced/cmd/config_test.go @@ -248,6 +248,12 @@ func (s *ConfigTestSuite) TestConfigCmdGet() { noArgsOut := s.executeConfigCmd("get") s.Run("all fields and defaults", func() { + // The moniker is different on different computers. We don't really care what it is though, just that it's there. + // We do care about the other values though. + monikerLineMatch := regexp.MustCompile(`(?m)^moniker="([^"]*)"$`).FindStringSubmatch(noArgsOut) + s.Require().Len(monikerLineMatch, 2, "moniker line regexp sub-matches") + moniker := monikerLineMatch[1] + expectedAll := s.makeMultiLine( s.makeAppConfigHeaderLines(), `app-db-backend="" @@ -300,9 +306,9 @@ db_dir="data" filter_peers=false genesis_file="config/genesis.json" log_format="plain" -log_level="info" -moniker="F0796.localdomain" -node_key_file="config/node_key.json" +log_level="info"`, + fmt.Sprintf("moniker=%q", moniker), + `node_key_file="config/node_key.json" priv_validator_key_file="config/priv_validator_key.json" priv_validator_laddr="" priv_validator_state_file="data/priv_validator_state.json" From 14dfa75bf5dab10c11ad38966456d33d3bfddbd7 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 10 May 2024 11:46:39 -0600 Subject: [PATCH 19/23] [1760]: Add canary test on the config files to ensure that all field names are unique accross the multiple configs. --- cmd/provenanced/config/manager_test.go | 36 +++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/cmd/provenanced/config/manager_test.go b/cmd/provenanced/config/manager_test.go index 18a4520776..10d7324311 100644 --- a/cmd/provenanced/config/manager_test.go +++ b/cmd/provenanced/config/manager_test.go @@ -66,10 +66,7 @@ func (s *ConfigManagerTestSuite) makeDummyCmd() *cobra.Command { } dummyCmd.SetOut(io.Discard) dummyCmd.SetErr(io.Discard) - dummyCmd.SetArgs([]string{}) - var err error - dummyCmd, err = dummyCmd.ExecuteContextC(ctx) - s.Require().NoError(err, "dummy command execution") + dummyCmd.SetContext(ctx) return dummyCmd } @@ -416,3 +413,34 @@ func (s *ConfigManagerTestSuite) TestPackedConfigTmLoadDefaults() { s.Assert().Equal(cmtConfig, cmtConfig2) }) } + +func (s *ConfigManagerTestSuite) TestEntryUniqueness() { + // This test is basically a canary. + // In the config commands, we've taken advantage of the fact that no two config files have a field with the same name. + // If this test fails, it means that that is not the case anymore, and we'll need to make changes to accommodate. + // That'd be pretty bad for us (and probably the SDK) since everything gets loaded into viper which can only have one entry for a field. + + dummyCmd := s.makeDummyCmd() + _, appMap, err := ExtractAppConfigAndMap(dummyCmd) + s.Require().NoError(err, "ExtractAppConfigAndMap") + _, cmtMap, err := ExtractCmtConfigAndMap(dummyCmd) + s.Require().NoError(err, "ExtractCmtConfigAndMap") + _, clientMap, err := ExtractClientConfigAndMap(dummyCmd) + s.Require().NoError(err, "ExtractClientConfigAndMap") + + // key = field name, value = list of config type names that have that value + allMap := make(map[string][]string) + for k := range appMap { + allMap[k] = append(allMap[k], "app") + } + for k := range cmtMap { + allMap[k] = append(allMap[k], "cometbft") + } + for k := range clientMap { + allMap[k] = append(allMap[k], "client") + } + + for field, configs := range allMap { + s.Assert().Len(configs, 1, "configs with field name = %q", field) + } +} From 8bd6de0043a1fd6d9f7d70407b38ad892ca080c0 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 10 May 2024 11:57:48 -0600 Subject: [PATCH 20/23] [1760]: Delete some unused functions from the msg_service_router_test. --- internal/handlers/msg_service_router_test.go | 55 -------------------- 1 file changed, 55 deletions(-) diff --git a/internal/handlers/msg_service_router_test.go b/internal/handlers/msg_service_router_test.go index df2cdce445..88bc37a127 100644 --- a/internal/handlers/msg_service_router_test.go +++ b/internal/handlers/msg_service_router_test.go @@ -11,7 +11,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - cmttypes "github.com/cometbft/cometbft/types" "cosmossdk.io/log" @@ -19,7 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -29,9 +27,6 @@ import ( authztypes "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/bank/testutil" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - piosimapp "github.com/provenance-io/provenance/app" simappparams "github.com/provenance-io/provenance/app/params" "github.com/provenance-io/provenance/internal/antewrapper" @@ -162,16 +157,6 @@ func jsonArrayJoin(entries ...string) string { return "[" + strings.Join(entries, ",") + "]" } -func getLastProposal(t *testing.T, ctx sdk.Context, app *piosimapp.App) *govtypesv1.Proposal { - propID, err := app.GovKeeper.ProposalID.Peek(ctx) - require.NoError(t, err, "app.GovKeeper.ProposalID.Peek(ctx)") - propID-- - require.NotEqual(t, 0, propID, "last proposal id") - rv, err := app.GovKeeper.Proposals.Get(ctx, propID) - require.NoError(t, err, "app.GovKeeper.Proposals.Get(ctx, %d)", propID) - return &rv -} - func TestRegisterMsgService(t *testing.T) { db := dbm.NewMemDB() @@ -975,27 +960,6 @@ func TestMsgServiceAssessMsgFeeNoRecipient(tt *testing.T) { }) } -// ContentFromProposalType returns a Content object based on the proposal type. -func ContentFromProposalType(title, desc, ty string) govtypesv1beta1.Content { - switch ty { - case govtypesv1beta1.ProposalTypeText: - return govtypesv1beta1.NewTextProposal(title, desc) - - default: - return nil - } -} - -func createValSet(t *testing.T, pubKeys ...cryptotypes.PubKey) *cmttypes.ValidatorSet { - validators := make([]*cmttypes.Validator, len(pubKeys)) - for i, key := range pubKeys { - pk, err := cryptocodec.ToTmPubKeyInterface(key) - require.NoError(t, err, "ToTmPubKeyInterface") - validators[i] = cmttypes.NewValidator(pk, 1) - } - return cmttypes.NewValidatorSet(validators) -} - func signAndGenTx( ctx sdk.Context, gaslimit uint64, @@ -1077,25 +1041,6 @@ func SignTxAndGetBytes( return txBytes, nil } -func SignTx( - ctx sdk.Context, - gaslimit uint64, - fees sdk.Coins, - encCfg simappparams.EncodingConfig, - pubKey cryptotypes.PubKey, - privKey cryptotypes.PrivKey, - acct authtypes.BaseAccount, - chainId string, - msg ...sdk.Msg, -) (sdk.Tx, error) { - txBuilder, err := signAndGenTx(ctx, gaslimit, fees, encCfg, pubKey, privKey, acct, chainId, msg) - if err != nil { - return nil, err - } - // Send the tx to the app - return txBuilder.GetTx(), nil -} - // NewTestGasLimit is a test fee gas limit. // they keep changing this value and our tests break, hence moving it to test. func NewTestGasLimit() uint64 { From 66daa31c4e2a3affe61bef0531726213a70d4162 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 10 May 2024 11:58:43 -0600 Subject: [PATCH 21/23] [1760]: Fix a couple places that still referred to tendermint, but should now refer to comet. --- cmd/provenanced/cmd/pre_upgrade_test.go | 22 +++++++++++----------- cmd/provenanced/config/manager_test.go | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd/provenanced/cmd/pre_upgrade_test.go b/cmd/provenanced/cmd/pre_upgrade_test.go index f0cecc3deb..3b11d1f241 100644 --- a/cmd/provenanced/cmd/pre_upgrade_test.go +++ b/cmd/provenanced/cmd/pre_upgrade_test.go @@ -271,7 +271,7 @@ func TestPreUpgradeCmd(t *testing.T) { expInStderr []string expNot []string expAppCfg *serverconfig.Config - expTmCfg *cmtconfig.Config + expCmtCfg *cmtconfig.Config expClientCfg *config.ClientConfig }{ { @@ -282,7 +282,7 @@ func TestPreUpgradeCmd(t *testing.T) { expExitCode: 0, expInStdout: []string{successMsg}, expAppCfg: appCfgD, - expTmCfg: cmtCfgD, + expCmtCfg: cmtCfgD, expClientCfg: clientCfgD, }, { @@ -303,7 +303,7 @@ func TestPreUpgradeCmd(t *testing.T) { expExitCode: 0, expInStdout: []string{successMsg}, expAppCfg: appCfgD, - expTmCfg: cmtCfgD, + expCmtCfg: cmtCfgD, expClientCfg: clientCfgD, }, { @@ -315,7 +315,7 @@ func TestPreUpgradeCmd(t *testing.T) { expExitCode: 0, expInStdout: []string{successMsg}, expAppCfg: appCfgD, - expTmCfg: cmtCfgD, + expCmtCfg: cmtCfgD, expClientCfg: clientCfgD, }, { @@ -348,7 +348,7 @@ func TestPreUpgradeCmd(t *testing.T) { expExitCode: 0, expInStdout: []string{updatingBlocksyncMsg, successMsg}, expAppCfg: appCfgD, - expTmCfg: cmtCfgD, + expCmtCfg: cmtCfgD, expClientCfg: clientCfgD, }, { @@ -363,7 +363,7 @@ func TestPreUpgradeCmd(t *testing.T) { expInStdout: []string{successMsg}, expNot: []string{updatingBlocksyncMsg}, expAppCfg: appCfgD, - expTmCfg: cmtCfgD, + expCmtCfg: cmtCfgD, expClientCfg: clientCfgD, }, { @@ -378,7 +378,7 @@ func TestPreUpgradeCmd(t *testing.T) { expInStdout: []string{successMsg}, expNot: []string{updatingBlocksyncMsg}, expAppCfg: appCfgD, - expTmCfg: cmtCfgD, + expCmtCfg: cmtCfgD, expClientCfg: clientCfgAsync, }, { @@ -392,7 +392,7 @@ func TestPreUpgradeCmd(t *testing.T) { expExitCode: 0, expInStdout: []string{updatingBlocksyncMsg, successMsg}, expAppCfg: appCfgD, - expTmCfg: cmtCfgD, + expCmtCfg: cmtCfgD, expClientCfg: clientCfgD, }, { @@ -407,7 +407,7 @@ func TestPreUpgradeCmd(t *testing.T) { expInStdout: []string{successMsg}, expNot: []string{updatingBlocksyncMsg}, expAppCfg: appCfgD, - expTmCfg: cmtCfgD, + expCmtCfg: cmtCfgD, expClientCfg: clientCfgD, }, { @@ -422,7 +422,7 @@ func TestPreUpgradeCmd(t *testing.T) { expInStdout: []string{successMsg}, expNot: []string{updatingBlocksyncMsg}, expAppCfg: appCfgD, - expTmCfg: cmtCfgD, + expCmtCfg: cmtCfgD, expClientCfg: clientCfgAsync, }, } @@ -465,7 +465,7 @@ func TestPreUpgradeCmd(t *testing.T) { cmtCfg, err := config.ExtractCmtConfig(dummyCmd) cmtCfg.SetRoot("") if assert.NoError(t, err, "ExtractCmtConfig") { - assert.Equal(t, tc.expTmCfg, cmtCfg, "cmt config") + assert.Equal(t, tc.expCmtCfg, cmtCfg, "cmt config") } clientCfg, err := config.ExtractClientConfig(dummyCmd) if assert.NoError(t, err, "ExtractClientConfig") { diff --git a/cmd/provenanced/config/manager_test.go b/cmd/provenanced/config/manager_test.go index 10d7324311..66c66db1e6 100644 --- a/cmd/provenanced/config/manager_test.go +++ b/cmd/provenanced/config/manager_test.go @@ -371,7 +371,7 @@ func (s *ConfigManagerTestSuite) TestConfigMinGasPrices() { }) } -func (s *ConfigManagerTestSuite) TestDefaultTmConfig() { +func (s *ConfigManagerTestSuite) TestDefaultCmtConfig() { cfg := DefaultCmtConfig() s.Run("consensus.commit_timeout", func() { @@ -381,7 +381,7 @@ func (s *ConfigManagerTestSuite) TestDefaultTmConfig() { }) } -func (s *ConfigManagerTestSuite) TestPackedConfigTmLoadDefaults() { +func (s *ConfigManagerTestSuite) TestPackedConfigCmtLoadDefaults() { dCmd := s.makeDummyCmd() dCmd.Flags().String("home", s.Home, "home dir") From 5a22e5c350ccb44157cdfd9e13be68607b1f15b9 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 10 May 2024 11:59:13 -0600 Subject: [PATCH 22/23] [1760]: Use HasSuffix and HasPrefix in removeUndesirableCmtConfigEntries instead of raw string slicing. --- cmd/provenanced/config/manager.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/provenanced/config/manager.go b/cmd/provenanced/config/manager.go index 8444650b85..f8d904ccaf 100644 --- a/cmd/provenanced/config/manager.go +++ b/cmd/provenanced/config/manager.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "os" + "strings" "time" "github.com/spf13/cobra" @@ -139,7 +140,7 @@ func DefaultCmtConfig() *cmtconfig.Config { func removeUndesirableCmtConfigEntries(fields FieldValueMap) FieldValueMap { delete(fields, "home") for k := range fields { - if (len(k) > 5 && k[len(k)-5:] == ".home") || (len(k) > 9 && k[:9] == "p2p.test_") { + if strings.HasSuffix(k, ".home") || strings.HasPrefix(k, "p2p.test_") { delete(fields, k) } } From 51248cca3663009265e89791c6715c440dd75668 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Mon, 13 May 2024 16:00:04 -0600 Subject: [PATCH 23/23] [1760]: Disable address caching in TestAddGenesisCustomMarketCmd because it was asking for an address previously encoded with the wrong hrp. --- cmd/provenanced/cmd/genaccounts_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/provenanced/cmd/genaccounts_test.go b/cmd/provenanced/cmd/genaccounts_test.go index 39f0dbcce5..8ff611d52f 100644 --- a/cmd/provenanced/cmd/genaccounts_test.go +++ b/cmd/provenanced/cmd/genaccounts_test.go @@ -41,6 +41,7 @@ var testMbm = module.NewBasicManager(genutil.AppModuleBasic{}) func TestAddGenesisAccountCmd(t *testing.T) { appCodec := app.MakeTestEncodingConfig(t).Marshaler _, _, addr1 := testdata.KeyTestPubAddr() + tests := []struct { name string addr string @@ -597,6 +598,10 @@ func TestMakeDefaultMarket(t *testing.T) { } func TestAddGenesisCustomMarketCmd(t *testing.T) { + origCache := sdk.IsAddrCacheEnabled() + defer sdk.SetAddrCacheEnabled(origCache) + sdk.SetAddrCacheEnabled(false) + cdc := app.MakeTestEncodingConfig(t).Marshaler tests := []struct {