fix: rollback command don't actually delete multistore versions (#11361)
* rollback command don't actually delete multistore versions Closes: #11333 - add unit tests - use LoadVersionForOverwriting - update tendermint dependency to 0.35.x release branch Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> flushMetadata after rollback Update server/rollback.go Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> fix build gofumpt * fix unit test
This commit is contained in:
co-authored by
Aleksandr Bezobchuk
parent
f8b55ff8ee
commit
51d2de582d
@@ -144,6 +144,10 @@ func (ms multiStore) Restore(
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (ms multiStore) RollbackToVersion(version int64) error {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
var _ sdk.KVStore = kvStore{}
|
||||
|
||||
type kvStore struct {
|
||||
|
||||
+7
-4
@@ -4,13 +4,13 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/store/rootmulti"
|
||||
"github.com/cosmos/cosmos-sdk/server/types"
|
||||
"github.com/spf13/cobra"
|
||||
tmcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||
)
|
||||
|
||||
// NewRollbackCmd creates a command to rollback tendermint and multistore state by one height.
|
||||
func NewRollbackCmd(defaultNodeHome string) *cobra.Command {
|
||||
func NewRollbackCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "rollback",
|
||||
Short: "rollback cosmos-sdk and tendermint state by one height",
|
||||
@@ -30,14 +30,17 @@ application.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
app := appCreator(ctx.Logger, db, nil, ctx.Viper)
|
||||
// rollback tendermint state
|
||||
height, hash, err := tmcmd.RollbackState(ctx.Config)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to rollback tendermint state: %w", err)
|
||||
}
|
||||
// rollback the multistore
|
||||
cms := rootmulti.NewStore(db, ctx.Logger)
|
||||
cms.RollbackToVersion(height)
|
||||
|
||||
if err := app.CommitMultiStore().RollbackToVersion(height); err != nil {
|
||||
return fmt.Errorf("failed to rollback to version: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Rolled back state to height %d and hash %X", height, hash)
|
||||
return nil
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/server/api"
|
||||
"github.com/cosmos/cosmos-sdk/server/config"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// ServerStartTime defines the time duration that the server need to stay running after startup
|
||||
@@ -51,6 +52,9 @@ type (
|
||||
|
||||
// RegisterTendermintService registers the gRPC Query service for tendermint queries.
|
||||
RegisterTendermintService(clientCtx client.Context)
|
||||
|
||||
// Return the multistore instance
|
||||
CommitMultiStore() sdk.CommitMultiStore
|
||||
}
|
||||
|
||||
// AppCreator is a function that allows us to lazily initialize an
|
||||
|
||||
+1
-1
@@ -290,7 +290,7 @@ func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator type
|
||||
tendermintCmd,
|
||||
ExportCmd(appExport, defaultNodeHome),
|
||||
version.NewVersionCommand(),
|
||||
NewRollbackCmd(defaultNodeHome),
|
||||
NewRollbackCmd(appCreator, defaultNodeHome),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user