Skip to content

Commit

Permalink
fix: hotfix v8.2.0 (#998)
Browse files Browse the repository at this point in the history
* add evidence store upgrade to setup handler

* Changed smoketest to use pebbledb

* fix log level unmarshalling

* chore: add a function to rollback application state , to a given height  (#1006)

---------

Co-authored-by: brewmaster012 <>
Co-authored-by: Tanmay <tanmay@zetachain.com>
Co-authored-by: CharlieM <31941002+CharlieMc0@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 21, 2023
1 parent 3647012 commit 3faa41a
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 30 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- develop
- athens2-develop
- hotfix-v8.2.0
tags:
- "*"
pull_request:
Expand Down
11 changes: 8 additions & 3 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
zetaObserverModuleTypes "github.com/zeta-chain/zetacore/x/observer/types"
)

const releaseVersion = "v8.0.0"
const releaseVersion = "v8.1.0"

func SetupHandlers(app *App) {
app.UpgradeKeeper.SetUpgradeHandler(releaseVersion, func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
Expand All @@ -17,7 +18,11 @@ func SetupHandlers(app *App) {
for m, mb := range app.mm.Modules {
vm[m] = mb.ConsensusVersion()
}

oldParams := app.ZetaObserverKeeper.GetParamsIfExists(ctx)
newParams := zetaObserverModuleTypes.DefaultParams()
newParams.ObserverParams = oldParams.ObserverParams
newParams.AdminPolicy = oldParams.AdminPolicy
app.ZetaObserverKeeper.SetParams(ctx, newParams)
return app.mm.RunMigrations(ctx, app.configurator, vm)
})

Expand All @@ -27,7 +32,7 @@ func SetupHandlers(app *App) {
}
if upgradeInfo.Name == releaseVersion && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
// Added: []string{},
//Added: []string{evidencetypes.ModuleName},
}
// Use upgrade store loader for the initial loading of all stores when app starts,
// it checks if version == upgradeHeight and applies store upgrades before loading the stores,
Expand Down
1 change: 1 addition & 0 deletions cmd/inspector/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package inspector
2 changes: 1 addition & 1 deletion cmd/zetaclientd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func Initialize(_ *cobra.Command, _ []string) error {
configData.ZetaCoreURL = initArgs.zetacoreURL
configData.AuthzHotkey = initArgs.authzHotkey
configData.AuthzGranter = initArgs.authzGranter
configData.LogLevel = zerolog.Level(initArgs.level)
configData.LogLevel = initArgs.level
configData.LogFormat = initArgs.logFormat
configData.LogSampler = initArgs.logSampler
configData.P2PDiagnostic = initArgs.p2pDiagnostic
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetaclientd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func InitLogger(cfg *config.Config) zerolog.Logger {
var logger zerolog.Logger
switch cfg.LogFormat {
case "json":
logger = zerolog.New(os.Stdout).Level(cfg.LogLevel).With().Timestamp().Logger()
logger = zerolog.New(os.Stdout).Level(zerolog.Level(cfg.LogLevel)).With().Timestamp().Logger()
case "text":
logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}).Level(cfg.LogLevel).With().Timestamp().Logger()
logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}).Level(zerolog.Level(cfg.LogLevel)).With().Timestamp().Logger()
default:
logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339})
}
Expand Down
188 changes: 188 additions & 0 deletions cmd/zetacored/repair_store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
package main

import (
"fmt"
"os"
"path/filepath"
"strconv"

"github.com/cosmos/cosmos-sdk/client/flags"
pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types"
"github.com/cosmos/cosmos-sdk/server"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/store/iavl"
"github.com/cosmos/cosmos-sdk/store/rootmulti"
"github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/group"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
zetaCoreModuleTypes "github.com/zeta-chain/zetacore/x/crosschain/types"
emissionsModuleTypes "github.com/zeta-chain/zetacore/x/emissions/types"
fungibleModuleTypes "github.com/zeta-chain/zetacore/x/fungible/types"
zetaObserverModuleTypes "github.com/zeta-chain/zetacore/x/observer/types"

"github.com/spf13/cobra"
)

const FlagAppDBBackend = "app-db-backend"

// PruningCmd prunes the sdk root multi store history versions based on the pruning options
// specified by command flags.
func RepairStoreCmd(appCreator servertypes.AppCreator) *cobra.Command {
cmd := &cobra.Command{
Use: "repair-store",
Short: "Prune app history states by keeping the recent heights and deleting old heights",
Long: `Prune app history states by keeping the recent heights and deleting old heights.
The pruning option is provided via the '--pruning' flag or alternatively with '--pruning-keep-recent'
For '--pruning' the options are as follows:
default: the last 362880 states are kept
nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node)
everything: 2 latest states will be kept
custom: allow pruning options to be manually specified through 'pruning-keep-recent'.
besides pruning options, database home directory and database backend type should also be specified via flags
'--home' and '--app-db-backend'.
valid app-db-backend type includes 'goleveldb', 'cleveldb', 'rocksdb', 'boltdb', and 'badgerdb'.
`,
Example: "prune --home './' --app-db-backend 'goleveldb' --pruning 'custom' --pruning-keep-recent 100",
RunE: func(cmd *cobra.Command, _ []string) error {
vp := viper.New()
if err := vp.BindPFlags(cmd.Flags()); err != nil {
return err
}

home := vp.GetString(flags.FlagHome)
db, err := openDB(home, server.GetAppDBBackend(vp))
if err != nil {
return err
}

logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
app := appCreator(logger, db, nil, vp)
cms := app.CommitMultiStore()

rms, ok := cms.(*rootmulti.Store)
if !ok {
return fmt.Errorf("currently only support the pruning of rootmulti.Store type")
}
qms := sdk.MultiStore(rms)
latestVersion := qms.LatestVersion()

latestHeight := rootmulti.GetLatestVersion(db)
fmt.Printf("latest height of db/qms: %d %d\n", latestHeight, latestVersion)

cacheMS, err := qms.CacheMultiStoreWithVersion(latestVersion)
if err != nil {
panic(err)
}
_ = cacheMS

for name, key := range rms.StoreKeysByName() {
store := rms.GetCommitKVStore(key)
fmt.Printf("store name %s\n", name)
switch store.GetStoreType() {
case types.StoreTypeIAVL:
iavlStore, ok := store.(*iavl.Store)
if ok {
commitID := iavlStore.LastCommitID()
fmt.Printf(" version %d\n", commitID.Version)
}
}
}

keysByName := rms.StoreKeysByName()
evidenceKey, found := keysByName["evidence"]
if found {
store := rms.GetCommitKVStore(evidenceKey)
if store.GetStoreType() == types.StoreTypeIAVL {
iavlStore, ok := store.(*iavl.Store)
if !ok {
panic("can't convert to iavl store")
}
//st, err := iavlStore.GetImmutable(latestVersion)
_ = iavlStore
}

}

keys := sdk.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey,
group.StoreKey,
upgradetypes.StoreKey,
evidencetypes.StoreKey,
zetaCoreModuleTypes.StoreKey,
zetaObserverModuleTypes.StoreKey,
evmtypes.StoreKey, feemarkettypes.StoreKey,
fungibleModuleTypes.StoreKey,
emissionsModuleTypes.StoreKey,
authzkeeper.StoreKey,
)
_ = keys

return nil
},
}

cmd.Flags().String(flags.FlagHome, "", "The database home directory")
cmd.Flags().String(FlagAppDBBackend, "", "The type of database for application and snapshots databases")
cmd.Flags().String(server.FlagPruning, pruningtypes.PruningOptionDefault, "Pruning strategy (default|nothing|everything|custom)")
cmd.Flags().Uint64(server.FlagPruningKeepRecent, 0, "Number of recent heights to keep on disk (ignored if pruning is not 'custom')")
cmd.Flags().Uint64(server.FlagPruningInterval, 10,
`Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom'),
this is not used by this command but kept for compatibility with the complete pruning options`)

return cmd
}

func openDB(rootDir string, backendType dbm.BackendType) (dbm.DB, error) {
dataDir := filepath.Join(rootDir, "data")
return dbm.NewDB("application", backendType, dataDir)
}

func NewRollbackCosmosCmd(appCreator servertypes.AppCreator, defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "rollback-cosmos [height]",
Short: "rollback cosmos-sdk app state to a specific height",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := server.GetServerContextFromCmd(cmd)
cfg := ctx.Config
home := cfg.RootDir
db, err := openDB(home, server.GetAppDBBackend(ctx.Viper))
if err != nil {
return err
}
app := appCreator(ctx.Logger, db, nil, ctx.Viper)

// rollback the multistore only. Tendermint state is not rolled back
height, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
return err
}
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", height)
return nil
},
}

cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
return cmd
}
21 changes: 12 additions & 9 deletions cmd/zetacored/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import (
"os"
"path/filepath"

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
"github.com/evmos/ethermint/client/debug"
tmcli "github.com/tendermint/tendermint/libs/cli"

appparams "github.com/cosmos/cosmos-sdk/simapp/params"
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
"github.com/evmos/ethermint/crypto/hd"
Expand All @@ -19,7 +24,6 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/server"
Expand All @@ -30,14 +34,10 @@ import (
"github.com/cosmos/cosmos-sdk/version"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"

ethermintclient "github.com/evmos/ethermint/client"
"github.com/spf13/cast"
"github.com/spf13/cobra"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
)
Expand Down Expand Up @@ -108,6 +108,10 @@ func initAppConfig() (string, interface{}) {
}

func initRootCmd(rootCmd *cobra.Command, encodingConfig appparams.EncodingConfig) {

ac := appCreator{
encCfg: encodingConfig,
}
rootCmd.AddCommand(
ethermintclient.ValidateChainID(
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
Expand All @@ -125,11 +129,10 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig appparams.EncodingConfig

debug.Cmd(),
config.Cmd(),
)

ac := appCreator{
encCfg: encodingConfig,
}
RepairStoreCmd(ac.newApp),
NewRollbackCosmosCmd(ac.newApp, app.DefaultNodeHome),
)
zevmserver.AddCommands(rootCmd, zevmserver.NewDefaultStartOptions(ac.newApp, app.DefaultNodeHome), ac.appExport, addModuleInitFlags)

// the ethermintserver one supercedes the sdk one
Expand Down
2 changes: 1 addition & 1 deletion contrib/localnet/zetacored/common/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fast_sync = true
# * badgerdb (uses github.com/dgraph-io/badger)
# - EXPERIMENTAL
# - use badgerdb build tag (go build -tags badgerdb)
db_backend = "goleveldb"
db_backend = "pebbledb"

# Database directory
db_dir = "data"
Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ require (
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
)

Expand Down Expand Up @@ -313,6 +313,8 @@ replace (
github.com/binance-chain/tss-lib => gitlab.com/thorchain/tss/tss-lib v0.0.0-20201118045712-70b2cb4bf916
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.22.3
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0

github.com/cosmos/cosmos-sdk => github.com/brewmaster012/cosmos-sdk v0.46.14-0.20230818184835-7b40e2ee9f2f
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
// replace broken goleveldb
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand All @@ -321,4 +323,7 @@ replace (
github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.28
github.com/tendermint/tm-db => github.com/BlockPILabs/cosmos-db v0.0.3
gitlab.com/thorchain/tss/go-tss => github.com/brewmaster012/go-tss v0.0.0-20230724230849-ce080275bbad

)

replace github.com/cometbft/cometbft-db => github.com/notional-labs/cometbft-db v0.0.0-20230321185329-6dc7c0ca6345
Loading

0 comments on commit 3faa41a

Please sign in to comment.