-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #770 from comdex-official/feature/dev
Feature/dev
- Loading branch information
Showing
45 changed files
with
3,269 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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":"" | ||
} | ||
}'` | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.