Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rollback command #1217

Merged
merged 5 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions cmd/heimdalld/service/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/store/rootmulti"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/maticnetwork/heimdall/app"
"github.com/maticnetwork/heimdall/helper"
stakingcli "github.com/maticnetwork/heimdall/staking/client/cli"
"github.com/spf13/cobra"
Expand All @@ -15,6 +16,8 @@ import (
"github.com/tendermint/tendermint/libs/cli"
)

const flagForce = "force"

func rollbackCmd(ctx *server.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "rollback",
Expand All @@ -27,8 +30,8 @@ The application also roll back to height n - 1. No blocks are removed, so upon
restarting Tendermint the transactions in block n will be re-executed against the
application.
`,
Args: cobra.NoArgs,
RunE: func(_ *cobra.Command, _ []string) error {
RunE: func(_ *cobra.Command, args []string) error {
forceRollback := viper.GetBool(flagForce)
config := ctx.Config
config.SetRoot(viper.GetString(cli.HomeFlag))

Expand All @@ -37,19 +40,28 @@ application.
return err
}

height, hash, err := commands.RollbackState(config)
height, hash, err := commands.RollbackState(config, forceRollback)

if err != nil {
return fmt.Errorf("failed to rollback tendermint state: %w", err)
}
// rollback the multistore
cms := rootmulti.NewStore(db)
cms.RollbackToVersion(height)
hApp := app.NewHeimdallApp(logger, db)
cms := hApp.BaseApp.GetCommitMultiStore()
rs, ok := cms.(*rootmulti.Store)
if !ok {
panic("store not of type rootmultistore")
}

if err := rs.RollbackToVersion(height); err != nil {
return err
}
fmt.Printf("Rolled back state to height %d and hash %X", height, hash)
return nil
},
}

cmd.Flags().Bool(flagForce, false, "force rollback")
cmd.Flags().String(cli.HomeFlag, helper.DefaultNodeHome, "Node's home directory")
cmd.Flags().String(helper.FlagClientHome, helper.DefaultCLIHome, "Client's home directory")
cmd.Flags().String(client.FlagChainID, "", "Genesis file chain-id, if left blank will be randomly created")
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/maticnetwork/heimdall

go 1.22
go 1.22.5

require (
github.com/RichardKnop/machinery v1.10.6
Expand Down Expand Up @@ -169,11 +169,11 @@ require (
gopkg.in/yaml.v3 v3.0.1
)

replace github.com/tendermint/tendermint => github.com/maticnetwork/tendermint v0.33.2
replace github.com/tendermint/tendermint => github.com/maticnetwork/tendermint v0.33.3

replace github.com/tendermint/tm-db => github.com/tendermint/tm-db v0.2.0

replace github.com/cosmos/cosmos-sdk => github.com/maticnetwork/cosmos-sdk v0.38.4
replace github.com/cosmos/cosmos-sdk => github.com/maticnetwork/cosmos-sdk v0.38.5-polygon

replace github.com/ethereum/go-ethereum => github.com/maticnetwork/bor v1.4.1

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2219,16 +2219,16 @@ github.com/mailgun/raymond/v2 v2.0.48/go.mod h1:lsgvL50kgt1ylcFJYZiULi5fjPBkkhNf
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/maticnetwork/bor v1.4.1 h1:IS6/ap7TgUYIEzM5uwq776NxOkx4rziyit32UZUPDyU=
github.com/maticnetwork/bor v1.4.1/go.mod h1:DSIYFopCa1PqDOI6f3cTunTbSCL2VpBhGwAsTFiYMbo=
github.com/maticnetwork/cosmos-sdk v0.38.4 h1:PAfkMXzHDHJoAf4bXQL4UWgwbu/U3yYuXoXxPhXdpBw=
github.com/maticnetwork/cosmos-sdk v0.38.4/go.mod h1:NbuVdUoqlRF6RrFJp27hpbqSoRB8cJJfUxCzUJWtaLA=
github.com/maticnetwork/cosmos-sdk v0.38.5-polygon h1:2KpGeMOYjhBlVlsa08LtTAhAu02haTA/1CuCCCYkEdA=
github.com/maticnetwork/cosmos-sdk v0.38.5-polygon/go.mod h1:pQ7A1CnHMIQko4QTD6EVj+Qp3EniTsR5C6utLPStDHI=
github.com/maticnetwork/crand v1.0.2 h1:Af0tAivC8zrxXDpGWNWVT/0s1fOz8w0eRbahZgURS8I=
github.com/maticnetwork/crand v1.0.2/go.mod h1:/NRNL3bj2eYdqpWmoIP5puxndTpi0XRxpj5ZKxfHjyg=
github.com/maticnetwork/heimdall v1.0.7/go.mod h1:+ANI5+VV28ahwfdl7oMzrcNwaTEs1Fn6z39BqBGcvaA=
github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
github.com/maticnetwork/polyproto v0.0.4 h1:qQ/qwcO6UNGS4mJlzlLJn1AUMfJK9Rqmf1v+KJgnPsk=
github.com/maticnetwork/polyproto v0.0.4/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
github.com/maticnetwork/tendermint v0.33.2 h1:R9M7jgAmON8K/LbzMvtWPDhtPkNcqzkUUHp1ict/h3s=
github.com/maticnetwork/tendermint v0.33.2/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk=
github.com/maticnetwork/tendermint v0.33.3 h1:s1/Ubxh7Axv2bClr+aFMWNn5qzbRKEHEw/uEVxLTc0I=
github.com/maticnetwork/tendermint v0.33.3/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk=
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down
Loading