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

feat(rollback): enable rollback support (#656) #676

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion server/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

// add Rollapp commands
func AddRollappCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter, addStartFlags types.ModuleInitFlags) {
func AddRollappCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter) {
dymintCmd := &cobra.Command{
Use: "dymint",
Short: "dymint subcommands",
Expand Down
7 changes: 6 additions & 1 deletion server/commands/liteblockmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ func liteBlockManager(cfg *config.Config, dymintConf *dymintconf.NodeConfig, gen
return nil, fmt.Errorf("starting proxy app connections: %w", err)
}

baseKV := store.NewDefaultInMemoryKVStore()
var baseKV store.KV
if dymintConf.RootDir == "" && dymintConf.DBPath == "" { // this is used for testing
baseKV = store.NewDefaultInMemoryKVStore()
} else {
baseKV = store.NewDefaultKVStore(dymintConf.RootDir, dymintConf.DBPath, "dymint")
}
mainKV := store.NewPrefixKV(baseKV, []byte{0})
s := store.New(mainKV)

Expand Down
45 changes: 43 additions & 2 deletions server/commands/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/dymensionxyz/dymension-rdk/utils"
)

const skipStorePruningFlag = "skip-store-pruning"

// RollbackCmd rollbacks the app multistore to specific height and updates dymint state according to it
func RollbackCmd(appCreator types.AppCreator) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -74,19 +76,58 @@ func RollbackCmd(appCreator types.AppCreator) *cobra.Command {
return fmt.Errorf("app rollback to specific height: %w", err)
}

fmt.Printf("RollApp state moved back to height %d successfully.\n", heightInt)

block, err := blockManager.Store.LoadBlock(uint64(heightInt))
if err != nil {
return fmt.Errorf("load block header: %w", err)
}

currentHeight := blockManager.State.Height()

// rollback dymint state according to the app
if err := blockManager.UpdateStateFromApp(block); err != nil {
return fmt.Errorf("updating dymint from app state: %w", err)
}
fmt.Printf("RollApp state moved back to height %d successfully.\n", heightInt)

_, err = blockManager.Store.SaveState(blockManager.State, nil)
if err != nil {
return fmt.Errorf("save state: %w", err)
}

skipStorePruning := ctx.Viper.GetBool(skipStorePruningFlag)

if skipStorePruning {
return nil
}

fmt.Printf("Pruning store from height %d \n", heightInt+1)

// we try to prune height + 2, to prune all blocks in case a block its been already produced but not applied.
pruned, err := blockManager.Store.PruneHeights(uint64(heightInt+1), currentHeight+2, ctx.Logger)
if err != nil {
ctx.Logger.Error("Error pruning block store.", "Error", err)
}

fmt.Println("Pruned blocks:", pruned)

baseHeight, err := blockManager.Store.LoadBaseHeight()
if err != nil {
return nil
}
if baseHeight <= uint64(heightInt) {
return nil
}

err = blockManager.Store.SaveBaseHeight(uint64(heightInt))
if err != nil {
ctx.Logger.Error("saving base height", "error", err)
}

return err
},
}

cmd.Flags().Bool(skipStorePruningFlag, false, "rollback only app without pruning dymint store blocks")
dymintconf.AddNodeFlags(cmd)
return cmd
}
1 change: 1 addition & 0 deletions server/commands/validateinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

dymintconf "github.com/dymensionxyz/dymint/config"

"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/node"

Expand Down
Loading