diff --git a/cmd/cronosd/cmd/rollback_to_version.go b/cmd/cronosd/cmd/rollback_to_version.go new file mode 100644 index 00000000..de9f0e38 --- /dev/null +++ b/cmd/cronosd/cmd/rollback_to_version.go @@ -0,0 +1,52 @@ +package cmd + +import ( + "fmt" + "strconv" + + dbm "github.com/cosmos/cosmos-db" + "github.com/cosmos/cosmos-sdk/server" + "github.com/spf13/cobra" + + "github.com/crypto-org-chain/cronos/app" + "github.com/crypto-org-chain/cronos/cmd/cronosd/opendb" +) + +// RollbackToVersionCmd force-rolls the application multistore back to an explicit +// target version. Unlike the standard `rollback` command it loads the store at the +// target version instead of the latest, so it can recover a store left at mixed +// per-store versions by an interrupted `rollback` (where `LoadLatestVersion` then +// fails with "wanted to load target N but only found up to N-1"). +func RollbackToVersionCmd() *cobra.Command { + return &cobra.Command{ + Use: "rollback-to-version [height]", + Short: "Force-rollback the application multistore to a specific version (assumes rocksdb backend)", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + target, err := strconv.ParseInt(args[0], 10, 64) + if err != nil { + return err + } + + ctx := server.GetServerContextFromCmd(cmd) + db, err := opendb.OpenDB(ctx.Viper, ctx.Config.RootDir, dbm.RocksDBBackend) + if err != nil { + return err + } + defer db.Close() + + cronosApp := app.New(ctx.Logger, db, nil, false, ctx.Viper, server.DefaultBaseappOptions(ctx.Viper)...) + // Load at the target version (every store has it) to populate the loaded + // store set that RollbackToVersion iterates over. + if err := cronosApp.LoadHeight(target); err != nil { + return fmt.Errorf("load height %d: %w", target, err) + } + if err := cronosApp.CommitMultiStore().RollbackToVersion(target); err != nil { + return fmt.Errorf("rollback to version %d: %w", target, err) + } + + cmd.Printf("rolled back application multistore to version %d\n", target) + return nil + }, + } +} diff --git a/cmd/cronosd/cmd/root.go b/cmd/cronosd/cmd/root.go index c29e6a30..42c7abb5 100644 --- a/cmd/cronosd/cmd/root.go +++ b/cmd/cronosd/cmd/root.go @@ -184,6 +184,8 @@ func initRootCmd( rootCmd.AddCommand(changeSetCmd) } + rootCmd.AddCommand(RollbackToVersionCmd()) + // add keybase, auxiliary RPC, query, and tx child commands rootCmd.AddCommand( server.StatusCommand(), diff --git a/go.mod b/go.mod index 254a0de7..53a64969 100644 --- a/go.mod +++ b/go.mod @@ -306,7 +306,7 @@ replace ( // release/v1.15 github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20250815065500-a4fbafcae0dd // DeBank: ethermint-cronos fork carrying the trace_debankBlock emitter (branch v1.7.8, base = ethermint 2593e6ed). - github.com/evmos/ethermint => github.com/Chaintable/ethermint-cronos v0.22.1-0.20260627062305-d1c0639724fe + github.com/evmos/ethermint => github.com/Chaintable/ethermint-cronos v0.22.1-0.20260707133333-60189fd0e284 // Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0 diff --git a/go.sum b/go.sum index 4294dafd..dfca368f 100644 --- a/go.sum +++ b/go.sum @@ -657,8 +657,12 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25 github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/Chaintable/ethermint-cronos v0.22.1-0.20260627062305-d1c0639724fe h1:3jEp2sQJbj+WnalhNgww/OjLpx1Zqz4T+LEsZZ/an4Q= -github.com/Chaintable/ethermint-cronos v0.22.1-0.20260627062305-d1c0639724fe/go.mod h1:Y10y/8dKWLGVuJdDV0mfsqx3T4W9UcdWHYw0t3SDm34= +github.com/Chaintable/ethermint-cronos v0.22.1-0.20260707075724-8322beb468f7 h1:RiOPGigU7hnJMep5q6fLGdSyPtlEJlnpkNKt81IabGU= +github.com/Chaintable/ethermint-cronos v0.22.1-0.20260707075724-8322beb468f7/go.mod h1:sAlk6BoHuMuVsCpaO15q7FEfXZLL+fD9IPDtpjtSuvg= +github.com/Chaintable/ethermint-cronos v0.22.1-0.20260707123809-aa5017c763c6 h1:HENWuTWGz1ylVIH2aZmaNr4yCt6tAESS+LNvwn1zjcA= +github.com/Chaintable/ethermint-cronos v0.22.1-0.20260707123809-aa5017c763c6/go.mod h1:sAlk6BoHuMuVsCpaO15q7FEfXZLL+fD9IPDtpjtSuvg= +github.com/Chaintable/ethermint-cronos v0.22.1-0.20260707133333-60189fd0e284 h1:RsG1aNAjsAjck8YQLAETN13DuQ+Q5tyZXoXKpg2vlxw= +github.com/Chaintable/ethermint-cronos v0.22.1-0.20260707133333-60189fd0e284/go.mod h1:sAlk6BoHuMuVsCpaO15q7FEfXZLL+fD9IPDtpjtSuvg= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q= github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=