diff --git a/app/app.go b/app/app.go index 6281d446ce..7cfa3644b1 100644 --- a/app/app.go +++ b/app/app.go @@ -941,7 +941,7 @@ func NewAccNonceHandler(ak auth.AccountKeeper) sdk.AccNonceHandler { func PreRun(ctx *server.Context, cmd *cobra.Command) error { // check start flag conflicts - err := sanity.CheckStart() + err := sanity.CheckStart(ctx) if err != nil { return err } diff --git a/app/utils/sanity/start.go b/app/utils/sanity/start.go index af95522782..971f23de24 100644 --- a/app/utils/sanity/start.go +++ b/app/utils/sanity/start.go @@ -1,6 +1,9 @@ package sanity import ( + "fmt" + "strings" + "github.com/spf13/viper" "github.com/okex/exchain/app/config" @@ -11,6 +14,7 @@ import ( "github.com/okex/exchain/libs/tendermint/consensus" "github.com/okex/exchain/libs/tendermint/state" "github.com/okex/exchain/libs/tendermint/types" + db "github.com/okex/exchain/libs/tm-db" "github.com/okex/exchain/x/evm/watcher" "github.com/okex/exchain/x/infura" ) @@ -108,7 +112,7 @@ var ( ) // CheckStart check start command.If it has conflict pair above. then return the conflict error -func CheckStart() error { +func CheckStart(ctx *server.Context) error { if viper.GetBool(FlagDisableSanity) { return nil } @@ -129,5 +133,51 @@ func CheckStart() error { } } + rocksDBMisspelling(ctx) return nil } + +func rocksDBMisspelling(ctx *server.Context) { + //A copy of all the constant variables indicating rocksDB option parameters + //in exchain/libs/tm-db/rocksdb.go + rocksDBConst := []string{ + "block_size", + "block_cache", + "statistics", + "max_open_files", + "allow_mmap_reads", + "allow_mmap_writes", + "unordered_write", + "pipelined_write", + } + params := parseOptParams(viper.GetString(db.FlagRocksdbOpts)) + if params == nil { + return + } + for _, str := range rocksDBConst { + delete(params, str) + } + if len(params) != 0 { + for inputOpt, _ := range params { + ctx.Logger.Info(fmt.Sprintf("%s %s failed to set rocksDB parameters, please double-check the spelling", db.FlagRocksdbOpts, inputOpt)) + } + } + + return +} + +func parseOptParams(params string) map[string]struct{} { + if len(params) == 0 { + return nil + } + + opts := make(map[string]struct{}) + for _, s := range strings.Split(params, ",") { + opt := strings.Split(s, "=") + if len(opt) != 2 { + panic("Invalid options parameter, like this 'block_size=4kb,statistics=true") + } + opts[strings.TrimSpace(opt[0])] = struct{}{} + } + return opts +} diff --git a/app/utils/sanity/start_test.go b/app/utils/sanity/start_test.go index adea0929eb..07fa2a51e0 100644 --- a/app/utils/sanity/start_test.go +++ b/app/utils/sanity/start_test.go @@ -1,6 +1,10 @@ package sanity import ( + "testing" + + "github.com/spf13/cobra" + apptype "github.com/okex/exchain/app/types" "github.com/okex/exchain/libs/cosmos-sdk/server" "github.com/okex/exchain/libs/cosmos-sdk/store/types" @@ -9,8 +13,6 @@ import ( sm "github.com/okex/exchain/libs/tendermint/state" ttypes "github.com/okex/exchain/libs/tendermint/types" "github.com/okex/exchain/x/evm/watcher" - "github.com/spf13/cobra" - "testing" ) func getCommandNodeModeRpcPruningNothing() *cobra.Command { @@ -93,7 +95,7 @@ func TestCheckStart(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var err error tt.cmdFunc() - if err = CheckStart(); (err != nil) != tt.wantErr { + if err = CheckStart(nil); (err != nil) != tt.wantErr { t.Errorf("CheckStart() error = %v, wantErr %v", err, tt.wantErr) } t.Log(err) @@ -132,7 +134,7 @@ func TestCheckStartArchive(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var err error - if err = CheckStart(); (err != nil) != tt.wantErr { + if err = CheckStart(nil); (err != nil) != tt.wantErr { t.Errorf("CheckStart() error = %v, wantErr %v", err, tt.wantErr) } t.Log(err) diff --git a/cmd/exchaind/replay.go b/cmd/exchaind/replay.go index e1a2dc191b..84f43a575c 100644 --- a/cmd/exchaind/replay.go +++ b/cmd/exchaind/replay.go @@ -15,6 +15,9 @@ import ( "github.com/okex/exchain/x/evm/watcher" "github.com/gogo/protobuf/jsonpb" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "github.com/okex/exchain/app/config" okexchain "github.com/okex/exchain/app/types" "github.com/okex/exchain/app/utils/appstatus" @@ -36,8 +39,6 @@ import ( "github.com/okex/exchain/libs/tendermint/store" "github.com/okex/exchain/libs/tendermint/types" dbm "github.com/okex/exchain/libs/tm-db" - "github.com/spf13/cobra" - "github.com/spf13/viper" ) const ( @@ -66,7 +67,7 @@ func replayCmd(ctx *server.Context, registerAppFlagFn func(cmd *cobra.Command), PreRunE: func(cmd *cobra.Command, args []string) error { // set external package flags log.Println("--------- replay preRun ---------") - err := sanity.CheckStart() + err := sanity.CheckStart(ctx) if err != nil { fmt.Println(err) return err diff --git a/libs/ibc-go/testing/simapp/app.go b/libs/ibc-go/testing/simapp/app.go index 4c3565f429..bc212c4adf 100644 --- a/libs/ibc-go/testing/simapp/app.go +++ b/libs/ibc-go/testing/simapp/app.go @@ -1055,7 +1055,7 @@ func PreRun(ctx *server.Context) error { appconfig.RegisterDynamicConfig(ctx.Logger.With("module", "config")) // check start flag conflicts - err := sanity.CheckStart() + err := sanity.CheckStart(nil) if err != nil { return err }