Skip to content
Merged
52 changes: 52 additions & 0 deletions cmd/cronosd/cmd/rollback_to_version.go
Original file line number Diff line number Diff line change
@@ -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
},
}
}
2 changes: 2 additions & 0 deletions cmd/cronosd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
Loading