diff --git a/server/commands.go b/server/commands.go index 422a86c7..4efa0a7f 100644 --- a/server/commands.go +++ b/server/commands.go @@ -2,6 +2,8 @@ package server import ( "fmt" + "os" + "path/filepath" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/types" @@ -12,6 +14,7 @@ import ( "github.com/libp2p/go-libp2p" "github.com/spf13/cobra" tmcmd "github.com/tendermint/tendermint/cmd/cometbft/commands" + cmtos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/p2p" ) @@ -28,7 +31,7 @@ func AddRollappCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreat commands.InspectStateCmd(), ResetAll(), server.VersionCmd(), - tmcmd.ResetStateCmd, + ResetState(), ) rootCmd.AddCommand( @@ -83,3 +86,39 @@ func ResetAll() *cobra.Command { return resetAll } + +// ResetState removes all the block state stored in dymint +func ResetState() *cobra.Command { + return &cobra.Command{ + Use: "reset-state", + Aliases: []string{"reset_state"}, + Short: "Remove all the data and WAL", + RunE: func(cmd *cobra.Command, args []string) (err error) { + + config := server.GetServerContextFromCmd(cmd).Config + var paths []string + appdb := filepath.Join(config.DBDir(), "application.db") + dymintdb := filepath.Join(config.DBDir(), "dymint") + settlementdb := filepath.Join(config.DBDir(), "settlement") + paths = append(paths, appdb, dymintdb, settlementdb) + for _, path := range paths { + err := removePath(path) + if err != nil { + fmt.Printf("error removing %s with error %s\n", path, err) + } + } + return nil + }, + } +} + +func removePath(path string) error { + if cmtos.FileExists(path) { + if err := os.RemoveAll(path); err == nil { + fmt.Println("Path removed", "path", path) + } else { + return err + } + } + return nil +} diff --git a/testutil/app/app.go b/testutil/app/app.go index dab6b9e9..49b1c2ef 100644 --- a/testutil/app/app.go +++ b/testutil/app/app.go @@ -2,16 +2,14 @@ package app import ( "encoding/json" + "io" + "net/http" hubgenesis "github.com/dymensionxyz/dymension-rdk/x/hub-genesis" hubgenkeeper "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/keeper" hubgentypes "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" "github.com/cosmos/cosmos-sdk/std" - - "io" - "net/http" - "github.com/gorilla/mux" "github.com/rakyll/statik/fs" abci "github.com/tendermint/tendermint/abci/types"