Skip to content

Commit

Permalink
Merge branch 'main' into loredana/fee-distribution
Browse files Browse the repository at this point in the history
* main:
  misc: changelog and fix test (evmos#460)
  deps: bump ethermint to v0.13.0 (evmos#458)
  fix: v3 migration (evmos#446)
  deps: bump Cosmos SDK to v0.45.2 (evmos#457)
  • Loading branch information
loredanacirstea committed Apr 6, 2022
2 parents 404b219 + f02e26c commit c6ba1ba
Show file tree
Hide file tree
Showing 34 changed files with 4,387 additions and 2,119 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

# Changelog

## Unreleased
## [v3.0.0] - 2022-04-05

### State Machine Breaking

Expand All @@ -54,7 +54,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

- (deps) [\#427](https://github.com/tharsis/evmos/pull/427) Bump Ethermint to [`v0.12.0`](https://github.com/tharsis/ethermint/releases/tag/v0.12.0)
- (deps) [\#458](https://github.com/tharsis/evmos/pull/458) Bump Ethermint to [`v0.13.0`](https://github.com/tharsis/ethermint/releases/tag/v0.13.0)
- (deps) [\#457](https://github.com/tharsis/evmos/pull/457) Bump Cosmos SDK to [`v0.45.2`](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.2)
- (cmd) [\#446](https://github.com/tharsis/evmos/pull/446) Update `migrate` command to migrate Evmos, Ethermint and Cosmos SDK modules.
- (app) [\#446](https://github.com/tharsis/evmos/pull/446) Refactor upgrade code.
- (ibc) [\#412](https://github.com/tharsis/evmos/pull/412) Introduce boilerplate struct for IBC applications.
- (deps) [\#402](https://github.com/tharsis/evmos/pull/402) Bump IBC go to [`v3.0.0`](https://github.com/cosmos/ibc-go/releases/tag/v3.0.0)
- (ibctesting) [\#388](https://github.com/tharsis/evmos/pull/388) Support Cosmos and EVM chains in IBC testing `Coordinator`.
Expand Down
51 changes: 49 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -100,13 +101,14 @@ import (
evmrest "github.com/tharsis/ethermint/x/evm/client/rest"
evmkeeper "github.com/tharsis/ethermint/x/evm/keeper"
evmtypes "github.com/tharsis/ethermint/x/evm/types"

"github.com/tharsis/ethermint/x/feemarket"
feemarketkeeper "github.com/tharsis/ethermint/x/feemarket/keeper"
feemarkettypes "github.com/tharsis/ethermint/x/feemarket/types"

"github.com/tharsis/evmos/v3/app/ante"
v2 "github.com/tharsis/evmos/v3/app/upgrades/v2"
v2 "github.com/tharsis/evmos/v3/app/upgrades/mainnet/v2"
v3 "github.com/tharsis/evmos/v3/app/upgrades/mainnet/v3"
tv3 "github.com/tharsis/evmos/v3/app/upgrades/testnet/v3"
"github.com/tharsis/evmos/v3/x/claims"
claimskeeper "github.com/tharsis/evmos/v3/x/claims/keeper"
claimstypes "github.com/tharsis/evmos/v3/x/claims/types"
Expand Down Expand Up @@ -152,6 +154,10 @@ func init() {
const (
// Name defines the application binary name
Name = "evmosd"
// MainnetChainID defines the Evmos EIP155 chain ID for mainnet
MainnetChainID = "evmos_9001"
// TestnetChainID defines the Evmos EIP155 chain ID for testnet
TestnetChainID = "evmos_9000"
)

var (
Expand Down Expand Up @@ -823,7 +829,9 @@ func (app *Evmos) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.R
if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}

app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())

return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
}

Expand Down Expand Up @@ -1023,4 +1031,43 @@ func (app *Evmos) setupUpgradeHandlers() {
v2.UpgradeName,
v2.CreateUpgradeHandler(app.mm, app.configurator),
)
// v3 handler upgrade is
app.UpgradeKeeper.SetUpgradeHandler(
v3.UpgradeName,
v3.CreateUpgradeHandler(app.mm, app.configurator),
)

// testnet v3 handler upgrade is
app.UpgradeKeeper.SetUpgradeHandler(
tv3.UpgradeName,
tv3.CreateUpgradeHandler(app.mm, app.configurator),
)

// When a planned update height is reached, the old binary will panic
// writing on disk the height and name of the update that triggered it
// This will read that value, and execute the preparations for the upgrade.
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

var storeUpgrades *storetypes.StoreUpgrades

switch {
case upgradeInfo.Name == v3.UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
// prepare store for v3
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{recoverytypes.ModuleName},
}
case upgradeInfo.Name == tv3.UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
// prepare store for testnet v3
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{recoverytypes.ModuleName},
}
}

if storeUpgrades != nil {
// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades))
}
}
2 changes: 1 addition & 1 deletion app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestEvmosExport(t *testing.T) {
// Initialize the chain
app.InitChain(
abci.RequestInitChain{
ChainId: "evmos_9001-1",
ChainId: MainnetChainID + "-1",
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
},
Expand Down
29 changes: 26 additions & 3 deletions app/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

v2 "github.com/tharsis/evmos/v3/app/upgrades/v2"
v2 "github.com/tharsis/evmos/v3/app/upgrades/mainnet/v2"
tv3 "github.com/tharsis/evmos/v3/app/upgrades/testnet/v3"
)

// BeginBlockForks executes any necessary fork logic based upon the current block height.
func BeginBlockForks(ctx sdk.Context, app *Evmos) {
switch ctx.BlockHeight() {
case v2.UpgradeHeight:
// NOTE: only run for mainnet
if !strings.HasPrefix(ctx.ChainID(), "evmos_9001-") {
if !strings.HasPrefix(ctx.ChainID(), MainnetChainID) {
return
}

Expand All @@ -23,7 +24,29 @@ func BeginBlockForks(ctx sdk.Context, app *Evmos) {
Info: v2.UpgradeInfo,
Height: v2.UpgradeHeight,
}
err := app.UpgradeKeeper.ScheduleUpgradeNoHeightCheck(ctx, upgradePlan)

// FIXME: upstream no validation logic
err := app.UpgradeKeeper.ScheduleUpgrade(ctx, upgradePlan)
if err != nil {
panic(err)
}

// NOTE: THIS UPGRADE PLAN SHOULD BE ADDED TO VERSION 1.0.0-beta1
// This will create the upgrade plan on the defined height
// and will stop the chain once the height is reached.
// The new version should have the upgrade migration logic under the upgradeName
case tv3.UpgradeHeight:
// NOTE: only run for testnet
if !strings.HasPrefix(ctx.ChainID(), TestnetChainID) {
return
}

upgradePlan := upgradetypes.Plan{
Name: tv3.UpgradeName,
Info: tv3.UpgradeInfo,
Height: tv3.UpgradeHeight + 1,
}
err := app.UpgradeKeeper.ScheduleUpgrade(ctx, upgradePlan)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Setup(
// Initialize the chain
app.InitChain(
abci.RequestInitChain{
ChainId: "evmos_9001-1",
ChainId: MainnetChainID + "-1",
Validators: []abci.ValidatorUpdate{},
ConsensusParams: DefaultConsensusParams,
AppStateBytes: stateBytes,
Expand Down
17 changes: 15 additions & 2 deletions app/upgrades/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Evmos Upgrade
# Evmos Upgrades

- v2 contains code to update the ERC20 EVM hook to `true`.
### Mainnet

- `v2`:
- updates the ERC20 EVM hook to `true`.
- `v3`:
- moves the `x/feemarket` `BaseFee` from the store to the parameters
- adds the `x/recovery` module

### Testnet

- `tv3`:
- moves the `x/feemarket` `BaseFee` from the store to the parameters
- adds claims `AuthorizedChannels` and `EVMChannels` param fields
- adds the `x/recovery` module
File renamed without changes.
File renamed without changes.
63 changes: 63 additions & 0 deletions app/upgrades/mainnet/v3/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package v3

import (
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

feemarketv010 "github.com/tharsis/ethermint/x/feemarket/migrations/v010"
feemarketv09types "github.com/tharsis/ethermint/x/feemarket/migrations/v09/types"
feemarkettypes "github.com/tharsis/ethermint/x/feemarket/types"
)

const UpgradeName = "v3"

// CreateUpgradeHandler creates an SDK upgrade handler for v3
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
// Refs:
// - https://docs.cosmos.network/master/building-modules/upgrade.html#registering-migrations
// - https://docs.cosmos.network/master/migrations/chain-upgrade-guide-044.html#chain-upgrade

// migrate fee market module, other modules are left as-is to
// avoid running InitGenesis.
vm[feemarkettypes.ModuleName] = 1

return mm.RunMigrations(ctx, configurator, vm)
}
}

// MigrateGenesis migrates exported state from v2 to v3 genesis state. It performs a no-op if the migration errors.
func MigrateGenesis(appState types.AppMap, clientCtx client.Context) types.AppMap {
// Migrate x/feemarket.
if appState[feemarkettypes.ModuleName] == nil {
return appState
}

// unmarshal relative source genesis application state
var oldFeeMarketState feemarketv09types.GenesisState
if err := clientCtx.Codec.UnmarshalJSON(appState[feemarkettypes.ModuleName], &oldFeeMarketState); err != nil {
return appState
}

// delete deprecated x/feemarket genesis state
delete(appState, feemarkettypes.ModuleName)

// Migrate relative source genesis application state and marshal it into
// the respective key.
newFeeMarketState := feemarketv010.MigrateJSON(oldFeeMarketState)

feeMarketBz, err := clientCtx.Codec.MarshalJSON(&newFeeMarketState)
if err != nil {
return appState
}

appState[feemarkettypes.ModuleName] = feeMarketBz

return appState
}
7 changes: 7 additions & 0 deletions app/upgrades/testnet/v3/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package v3

const (
UpgradeName = "tv3"
UpgradeHeight = 0
UpgradeInfo = ``
)
85 changes: 85 additions & 0 deletions app/upgrades/testnet/v3/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package v3

import (
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

feemarketv010 "github.com/tharsis/ethermint/x/feemarket/migrations/v010"
feemarketv09types "github.com/tharsis/ethermint/x/feemarket/migrations/v09/types"
feemarkettypes "github.com/tharsis/ethermint/x/feemarket/types"
v1claims "github.com/tharsis/evmos/v3/x/claims/migrations/v1/types"
v2claims "github.com/tharsis/evmos/v3/x/claims/migrations/v2"
claimstypes "github.com/tharsis/evmos/v3/x/claims/types"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v3
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
// Refs:
// - https://docs.cosmos.network/master/building-modules/upgrade.html#registering-migrations
// - https://docs.cosmos.network/master/migrations/chain-upgrade-guide-044.html#chain-upgrade

// migrate fee market module and the claims module
// avoid running InitGenesis.
vm[feemarkettypes.ModuleName] = 1
vm[claimstypes.ModuleName] = 1

return mm.RunMigrations(ctx, configurator, vm)
}
}

// MigrateGenesis migrates exported state from v2 to v3 genesis state. It performs a no-op if the migration errors.
func MigrateGenesis(appState types.AppMap, clientCtx client.Context) types.AppMap {
// Migrate x/feemarket.
if appState[feemarkettypes.ModuleName] == nil {
return appState
}

// unmarshal relative source genesis application state
var oldFeeMarketState feemarketv09types.GenesisState
if err := clientCtx.Codec.UnmarshalJSON(appState[feemarkettypes.ModuleName], &oldFeeMarketState); err != nil {
return appState
}

// delete deprecated x/feemarket genesis state
delete(appState, feemarkettypes.ModuleName)

// Migrate relative source genesis application state and marshal it into
// the respective key.
newFeeMarketState := feemarketv010.MigrateJSON(oldFeeMarketState)

feeMarketBz, err := clientCtx.Codec.MarshalJSON(&newFeeMarketState)
if err != nil {
return appState
}

appState[feemarkettypes.ModuleName] = feeMarketBz

// unmarshal relative source genesis application state
var oldClaimsState v1claims.GenesisState
if err := clientCtx.Codec.UnmarshalJSON(appState[claimstypes.ModuleName], &oldClaimsState); err != nil {
return appState
}

// delete deprecated x/feemarket genesis state
delete(appState, claimstypes.ModuleName)

// Migrate relative source genesis application state and marshal it into
// the respective key.
newClaimsState := v2claims.MigrateJSON(oldClaimsState)

claimsBz, err := clientCtx.Codec.MarshalJSON(&newClaimsState)
if err != nil {
return appState
}

appState[claimstypes.ModuleName] = claimsBz

return appState
}
9 changes: 5 additions & 4 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

Loading

0 comments on commit c6ba1ba

Please sign in to comment.