Skip to content

Commit

Permalink
Merge pull request #770 from comdex-official/feature/dev
Browse files Browse the repository at this point in the history
Feature/dev
  • Loading branch information
dheerajkd30 authored May 31, 2023
2 parents 20a7735 + 1b81c97 commit 4e3cfda
Show file tree
Hide file tree
Showing 45 changed files with 3,269 additions and 356 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/[email protected].0
uses: actions/[email protected].1
with:
go-version: 1.19
id: go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/[email protected].0
- uses: actions/[email protected].1
with:
go-version: 1.19
# Initializes the CodeQL tools for scanning.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected].0
- uses: actions/[email protected].1
with:
go-version: 1.19 # we run the linter with go 1.19 to match dev laptops even though we use 1.18 for the chain (don't update the chain to 1.19 please-- there is an issue in golang causing 1.19 to output some hashes differently from 1.18)
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- os: macos-latest
steps:
- name: Set up Go 1.x
uses: actions/[email protected].0
uses: actions/[email protected].1
with:
go-version: 1.19
id: go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
uses: actions/checkout@v3
-
name: Setup Golang
uses: actions/[email protected].0
uses: actions/[email protected].1
with:
go-version: 1.19
-
Expand Down
25 changes: 12 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ import (
cwasm "github.com/comdex-official/comdex/app/wasm"

mv11 "github.com/comdex-official/comdex/app/upgrades/mainnet/v11"
tv11 "github.com/comdex-official/comdex/app/upgrades/testnet/v11"
tv11_2 "github.com/comdex-official/comdex/app/upgrades/testnet/v11_2"
)

const (
Expand Down Expand Up @@ -591,6 +591,8 @@ func New(
app.cdc,
app.keys[assettypes.StoreKey],
app.GetSubspace(assettypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
&app.Rewardskeeper,
&app.VaultKeeper,
&app.BandoracleKeeper,
Expand Down Expand Up @@ -989,6 +991,7 @@ func New(
genutiltypes.ModuleName,
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
wasmtypes.ModuleName,
authz.ModuleName,
vestingtypes.ModuleName,
paramstypes.ModuleName,
Expand All @@ -1008,11 +1011,6 @@ func New(
rewardstypes.ModuleName,
crisistypes.ModuleName,
ibcratelimittypes.ModuleName,

// wasm after ibc transfer
wasmtypes.ModuleName,

// ibc_hooks after auth keeper
ibchookstypes.ModuleName,
packetforwardtypes.ModuleName,
)
Expand Down Expand Up @@ -1339,6 +1337,7 @@ func (a *App) ModuleAccountsPermissions() map[string][]string {
liquiditytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
rewardstypes.ModuleName: {authtypes.Minter, authtypes.Burner},
icatypes.ModuleName: nil,
assettypes.ModuleName: nil,
}
}

Expand All @@ -1352,10 +1351,10 @@ func (a *App) registerUpgradeHandlers() {
}

switch {
case upgradeInfo.Name == tv11.UpgradeName:
case upgradeInfo.Name == tv11_2.UpgradeName:
a.UpgradeKeeper.SetUpgradeHandler(
tv11.UpgradeName,
tv11.CreateUpgradeHandlerV11(a.mm, a.configurator),
tv11_2.UpgradeName,
tv11_2.CreateUpgradeHandlerV112(a.mm, a.configurator, a.AssetKeeper),
)
case upgradeInfo.Name == mv11.UpgradeName:
a.UpgradeKeeper.SetUpgradeHandler(
Expand All @@ -1376,14 +1375,14 @@ func (a *App) registerUpgradeHandlers() {

func upgradeHandlers(upgradeInfo storetypes.UpgradeInfo, a *App, storeUpgrades *storetypes.StoreUpgrades) *storetypes.StoreUpgrades {
switch {
case upgradeInfo.Name == tv11.UpgradeName && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
case upgradeInfo.Name == tv11_2.UpgradeName && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{ibchookstypes.StoreKey},
Added: []string{ibchookstypes.StoreKey, packetforwardtypes.StoreKey},
}
case upgradeInfo.Name == mv11.UpgradeName && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{ibchookstypes.StoreKey},
Added: []string{ibchookstypes.StoreKey, packetforwardtypes.StoreKey},
}
}
return storeUpgrades
}
}
2 changes: 1 addition & 1 deletion app/upgrades/mainnet/v11/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v11

const (
UpgradeName = "v11.0.1"
UpgradeName = "v11.3.0"
UpgradeHeight = ""
UpgradeInfo = `'{
"binaries": {
Expand Down
5 changes: 4 additions & 1 deletion app/upgrades/mainnet/v11/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v11

import (
assetkeeper "github.com/comdex-official/comdex/x/asset/keeper"
assettypes "github.com/comdex-official/comdex/x/asset/types"
auctiontypes "github.com/comdex-official/comdex/x/auction/types"
lendtypes "github.com/comdex-official/comdex/x/lend/types"
liquiditykeeper "github.com/comdex-official/comdex/x/liquidity/keeper"
Expand Down Expand Up @@ -90,7 +91,7 @@ func CreateUpgradeHandlerV11(
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {

ctx.Logger().Info("Applying main net upgrade - v.11.0.1")
ctx.Logger().Info("Applying main net upgrade - v.11.3.0")

fromVM[icatypes.ModuleName] = mm.Modules[icatypes.ModuleName].ConsensusVersion()

Expand Down Expand Up @@ -159,6 +160,8 @@ func CreateUpgradeHandlerV11(
}
icahostkeeper.SetParams(ctx, hostParams)

assetKeeper.SetParams(ctx, assettypes.NewParams())

vm, err := mm.RunMigrations(ctx, configurator, fromVM)
if err != nil {
return nil, err
Expand Down
15 changes: 15 additions & 0 deletions app/upgrades/testnet/v11_2/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v11_2 //nolint:revive,stylecheck

const (
UpgradeName = "v11.2.0"
UpgradeHeight = ""
UpgradeInfo = `'{
"binaries": {
"darwin/arm64":"",
"darwin/x86_64":"",
"linux/arm64":"",
"linux/x86_64":"",
"windows/x86_64":""
}
}'`
)
23 changes: 23 additions & 0 deletions app/upgrades/testnet/v11_2/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package v11_2 //nolint:revive,stylecheck

import (
assetkeeper "github.com/comdex-official/comdex/x/asset/keeper"
assettypes "github.com/comdex-official/comdex/x/asset/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func CreateUpgradeHandlerV112(
mm *module.Manager,
configurator module.Configurator,
assetKeeper assetkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {

assetKeeper.SetParams(ctx, assettypes.NewParams())

ctx.Logger().Info("Applying test net upgrade - v.11.2.0")
return mm.RunMigrations(ctx, configurator, fromVM)
}
}
32 changes: 32 additions & 0 deletions cmd/comdex/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"
)

func Migrate(appState types.AppMap, clientCtx client.Context) types.AppMap {
// Migrate packetfowardmiddleware.
if appState["packetfowardmiddleware"] != nil {
// unmarshal relative source genesis application state
var oldGovState packetforwardtypes.GenesisState
clientCtx.Codec.MustUnmarshalJSON(appState["packetfowardmiddleware"], &oldGovState)

// delete deprecated packetfowardmiddleware genesis state
delete(appState, "packetfowardmiddleware")

// Migrate relative source genesis application state and marshal it into
// the respective key.
appState["packetfowardmiddleware"] = clientCtx.Codec.MustMarshalJSON(MigrateJSON(&oldGovState))
}

return appState
}

func MigrateJSON(oldState *packetforwardtypes.GenesisState) *packetforwardtypes.GenesisState {
return &packetforwardtypes.GenesisState{
Params: oldState.Params,
InFlightPackets: oldState.InFlightPackets,
}
}
132 changes: 132 additions & 0 deletions cmd/comdex/migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package main

import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/pkg/errors"
"github.com/spf13/cobra"
tmjson "github.com/tendermint/tendermint/libs/json"
tmtypes "github.com/tendermint/tendermint/types"
"time"
)

const flagGenesisTime = "genesis-time"

const chainUpgradeGuide = "https://docs.cosmos.network/master/migrations/chain-upgrade-guide-040.html"

var migrationMap = types.MigrationMap{
"v11.1.0": Migrate,
}

// GetMigrationCallback returns a MigrationCallback for a given version.
func GetMigrationCallback(version string) types.MigrationCallback {
return migrationMap[version]
}

func MigrateStoreCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "migrate-store [target] [genesis-file]",
Short: "Migrate store to a specified target version",
Long: fmt.Sprintf(`Migrate the source genesis into the target version and print to STDOUT.
Example:
$ %s migrate v11.1.0 /path/to/genesis.json --chain-id=test-2 --genesis-time=2019-04-22T17:00:00Z
`, version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

var err error

target := args[0]
importGenesis := args[1]

genDoc, err := validateGenDoc(importGenesis)
if err != nil {
return err
}

// Since some default values are valid values, we just print to
// make sure the user didn't forget to update these values.
if genDoc.ConsensusParams.Evidence.MaxBytes == 0 {
fmt.Printf("Warning: consensus_params.evidence.max_bytes is set to 0. If this is"+
" deliberate, feel free to ignore this warning. If not, please have a look at the chain"+
" upgrade guide at %s.\n", chainUpgradeGuide)
}

var initialState types.AppMap
if err := json.Unmarshal(genDoc.AppState, &initialState); err != nil {
return errors.Wrap(err, "failed to JSON unmarshal initial genesis state")
}

migrationFunc := GetMigrationCallback(target)
if migrationFunc == nil {
return fmt.Errorf("unknown migration function for version: %s", target)
}

// TODO: handler error from migrationFunc call
newGenState := migrationFunc(initialState, clientCtx)

genDoc.AppState, err = json.Marshal(newGenState)
if err != nil {
return errors.Wrap(err, "failed to JSON marshal migrated genesis state")
}

genesisTime, _ := cmd.Flags().GetString(flagGenesisTime)
if genesisTime != "" {
var t time.Time

err := t.UnmarshalText([]byte(genesisTime))
if err != nil {
return errors.Wrap(err, "failed to unmarshal genesis time")
}

genDoc.GenesisTime = t
}

chainID, _ := cmd.Flags().GetString(flags.FlagChainID)
if chainID != "" {
genDoc.ChainID = chainID
}

bz, err := tmjson.Marshal(genDoc)
if err != nil {
return errors.Wrap(err, "failed to marshal genesis doc")
}

sortedBz, err := sdk.SortJSON(bz)
if err != nil {
return errors.Wrap(err, "failed to sort JSON genesis doc")
}

cmd.Println(string(sortedBz))
return nil
},
}

cmd.Flags().String(flagGenesisTime, "", "override genesis_time with this flag")
cmd.Flags().String(flags.FlagChainID, "", "override chain_id with this flag")

return cmd
}

// validateGenDoc reads a genesis file and validates that it is a correct
// Tendermint GenesisDoc. This function does not do any cosmos-related
// validation.
func validateGenDoc(importGenesisFile string) (*tmtypes.GenesisDoc, error) {
genDoc, err := tmtypes.GenesisDocFromFile(importGenesisFile)
if err != nil {
return nil, fmt.Errorf("%s. Make sure that"+
" you have correctly migrated all Tendermint consensus params, please see the"+
" chain migration guide at %s for more info",
err.Error(), chainUpgradeGuide,
)
}

return genDoc, nil
}
1 change: 1 addition & 0 deletions cmd/comdex/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func initRootCmd(rootCmd *cobra.Command, encoding comdex.EncodingConfig) {
// AddGenesisWasmMsgCmd(comdex.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
testnetCmd(comdex.ModuleBasics, banktypes.GenesisBalancesIterator{}),
MigrateStoreCmd(),
debug.Cmd(),
config.Cmd(),
)
Expand Down
Loading

0 comments on commit 4e3cfda

Please sign in to comment.