Skip to content

Commit

Permalink
fix!: Upgrade SDK and IAVL (#307) (#308)
Browse files Browse the repository at this point in the history
* upgrade things

* add upgrade handler

(cherry picked from commit 7dc72cd)

Co-authored-by: Facundo Medica <[email protected]>
  • Loading branch information
github-actions[bot] and facundomedica authored Aug 28, 2024
1 parent 9febaa5 commit 1587525
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 52 deletions.
8 changes: 2 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ func (app *App) preBlocker(ph *ProposalHandler) func(sdk.Context, *abci.RequestF
}

func (app *App) RegisterUpgradeHandlers() {
const UpgradeName = "v0.4.2"
const UpgradeName = "v0.5.0"

app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
Expand All @@ -1008,11 +1008,7 @@ func (app *App) RegisterUpgradeHandlers() {
}

if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
globalfee.ModuleName,
},
}
storeUpgrades := storetypes.StoreUpgrades{}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
Expand Down
109 changes: 109 additions & 0 deletions cmd/layerd/cmd/module_hash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package cmd

import (
"encoding/hex"
"fmt"
"path/filepath"
"sort"
"strconv"
"strings"

dbm "github.com/cosmos/cosmos-db"
"github.com/spf13/cobra"

"cosmossdk.io/store/rootmulti"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/server"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/version"
)

// ModuleHashByHeightQuery retrieves the module hashes at a given height.
func ModuleHashByHeightQuery(appCreator servertypes.AppCreator) *cobra.Command {
cmd := &cobra.Command{
Use: "module-hash-by-height <height>",
Short: "Get module hashes at a given height",
Long: "Get module hashes at a given height. This command is useful for debugging and verifying the state of the application at a given height. Daemon should not be running when calling this command.",
Example: fmt.Sprintf("%s module-hash-by-height 16841115", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
heightToRetrieveString := args[0]

serverCtx := server.GetServerContextFromCmd(cmd)

height, err := strconv.ParseInt(heightToRetrieveString, 10, 64)
if err != nil {
return fmt.Errorf("invalid height: %w", err)
}

commitInfoForHeight, err := getModuleHashesAtHeight(serverCtx, appCreator, height)
if err != nil {
return err
}

clientCtx := client.GetClientContextFromCmd(cmd)
return clientCtx.PrintProto(commitInfoForHeight)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func getModuleHashesAtHeight(svrCtx *server.Context, appCreator servertypes.AppCreator, height int64) (*storetypes.CommitInfo, error) {
home := svrCtx.Config.RootDir
db, err := OpenDB(home, server.GetAppDBBackend(svrCtx.Viper))
if err != nil {
return nil, fmt.Errorf("error opening DB, make sure daemon is not running when calling this query: %w", err)
}
app := appCreator(svrCtx.Logger, db, nil, svrCtx.Viper)
rms, ok := app.CommitMultiStore().(*rootmulti.Store)
if !ok {
return nil, fmt.Errorf("expected rootmulti.Store, got %T", app.CommitMultiStore())
}

commitInfoForHeight, err := rms.GetCommitInfo(height)
if err != nil {
return nil, err
}

// Create a new slice of StoreInfos for storing the modified hashes.
storeInfos := make([]storetypes.StoreInfo, len(commitInfoForHeight.StoreInfos))

for i, storeInfo := range commitInfoForHeight.StoreInfos {
// Convert the hash to a hexadecimal string.
hash := strings.ToUpper(hex.EncodeToString(storeInfo.CommitId.Hash))

// Create a new StoreInfo with the modified hash.
storeInfos[i] = storetypes.StoreInfo{
Name: storeInfo.Name,
CommitId: storetypes.CommitID{
Version: storeInfo.CommitId.Version,
Hash: []byte(hash),
},
}
}

// Sort the storeInfos slice based on the module name.
sort.Slice(storeInfos, func(i, j int) bool {
return storeInfos[i].Name < storeInfos[j].Name
})

// Create a new CommitInfo with the modified StoreInfos.
commitInfoForHeight = &storetypes.CommitInfo{
Version: commitInfoForHeight.Version,
StoreInfos: storeInfos,
Timestamp: commitInfoForHeight.Timestamp,
}

return commitInfoForHeight, nil
}

func OpenDB(rootDir string, backendType dbm.BackendType) (dbm.DB, error) {
dataDir := filepath.Join(rootDir, "data")
return dbm.NewDB("application", backendType, dataDir)
}
1 change: 1 addition & 0 deletions cmd/layerd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func initRootCmd(
queryCommand(),
txCommand(),
keys.Commands(),
ModuleHashByHeightQuery(newApp),
)
}

Expand Down
31 changes: 16 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ require (
cosmossdk.io/client/v2 v2.0.0-beta.1
cosmossdk.io/collections v0.4.0
cosmossdk.io/core v0.12.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/depinject v1.0.0
cosmossdk.io/errors v1.0.1
cosmossdk.io/log v1.3.1
cosmossdk.io/math v1.3.0
cosmossdk.io/store v1.1.0
cosmossdk.io/x/evidence v0.1.0
cosmossdk.io/x/feegrant v0.1.0
cosmossdk.io/x/tx v0.13.3
cosmossdk.io/x/tx v0.13.4
cosmossdk.io/x/upgrade v0.1.1
github.com/agiledragon/gomonkey/v2 v2.12.0
github.com/bufbuild/buf v1.32.0
github.com/cometbft/cometbft v0.38.7
github.com/cometbft/cometbft v0.38.10
github.com/cosmos/cosmos-db v1.0.2
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.50.7-0.20240513151836-08fdfec9543b
github.com/cosmos/gogoproto v1.4.12
github.com/cosmos/cosmos-sdk v0.50.9
github.com/cosmos/gogoproto v1.5.0
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/v8 v8.0.0
github.com/ethereum/go-ethereum v1.10.22
Expand All @@ -46,12 +46,12 @@ require (
github.com/stretchr/testify v1.9.0
github.com/vektra/mockery/v2 v2.23.1
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
golang.org/x/text v0.15.0
golang.org/x/tools v0.21.0
golang.org/x/text v0.16.0
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d
google.golang.org/genproto/googleapis/api v0.0.0-20240515191416-fc5f0ca64291
google.golang.org/grpc v1.64.0
google.golang.org/grpc v1.64.1
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
google.golang.org/protobuf v1.34.1
google.golang.org/protobuf v1.34.2
gopkg.in/typ.v4 v4.3.0
gopkg.in/yaml.v2 v2.4.0
)
Expand Down Expand Up @@ -169,6 +169,7 @@ require (
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
Expand All @@ -186,7 +187,6 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.2 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.8.14 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
Expand Down Expand Up @@ -251,18 +251,18 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.169.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand All @@ -275,5 +275,6 @@ require (
replace (
cosmossdk.io/core => cosmossdk.io/core v0.11.0
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/cosmos/iavl => github.com/cosmos/iavl v1.2.0
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
Loading

0 comments on commit 1587525

Please sign in to comment.