Skip to content

Commit

Permalink
refactor server rollback cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
roysc committed Apr 7, 2022
1 parent 305e802 commit 15d83b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions db/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ type DBConnection interface {
// Returns an error if any open DBWriter transactions exist.
Revert() error

// RevertTo reverts the DB state to the given version. Returns ErrVersionDoesNotExist for invalid versions.
// Returns an error if any open DBWriter transactions exist.
RevertTo(uint64) error

// Close closes the database connection.
Close() error
}
Expand Down
11 changes: 7 additions & 4 deletions server/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/store/rootmulti"
"github.com/spf13/cobra"
tmcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
)
Expand Down Expand Up @@ -35,9 +34,13 @@ application.
if err != nil {
return fmt.Errorf("failed to rollback tendermint state: %w", err)
}
// rollback the multistore
cms := rootmulti.NewStore(db)
cms.RollbackToVersion(height)
// rollback the database
if err = db.RevertTo(uint64(height)); err != nil {
panic(err)
}
if err = db.Close(); err != nil {
panic(err)
}

fmt.Printf("Rolled back state to height %d and hash %X", height, hash)
return nil
Expand Down

0 comments on commit 15d83b3

Please sign in to comment.