Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: no upgrade handler for v2.0.0-testnet3 #842

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [cronos#781](https://github.com/crypto-org-chain/cronos/pull/781) Add prune command.
- [cronos#830](https://github.com/crypto-org-chain/cronos/pull/830) Upgrade gravity bridge for latest bugfixes, patching two important DOS vulnerabilities
- [cronos#834](https://github.com/crypto-org-chain/cronos/pull/834) Remove unsafe experimental flag.
- [cronos#842](https://github.com/crypto-org-chain/cronos/pull/842) Add upgrade handler for v2.0.0-testnet3.
- [cronos#795](https://github.com/crypto-org-chain/cronos/pull/795) Support permissions in cronos.

### Bug Fixes
Expand Down
46 changes: 8 additions & 38 deletions app/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,26 @@
package app

import (
"fmt"

sdkmath "cosmossdk.io/math"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibcfeetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types"
)

func (app *App) RegisterUpgradeHandlers() {
upgradeHandlerV1 := func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
upgradeHandlerV2 := func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
m, err := app.mm.RunMigrations(ctx, app.configurator, fromVM)
if err != nil {
return m, err
}
// clear extra_eips from evm parameters
// Ref: https://github.com/crypto-org-chain/cronos/issues/755
params := app.EvmKeeper.GetParams(ctx)
params.ExtraEIPs = []int64{}

// fix the incorrect value on testnet parameters
zero := sdkmath.ZeroInt()
params.ChainConfig.LondonBlock = &zero

app.EvmKeeper.SetParams(ctx, params)
gravParams := app.GravityKeeper.GetParams(ctx)
gravParams.GravityId = "cronos_gravity_testnet"
// can be activated later on
gravParams.BridgeActive = false
app.GravityKeeper.SetParams(ctx, gravParams)
return m, nil
}
// `v1.0.0` upgrade plan will clear the `extra_eips` parameters, and upgrade ibc-go to v5.2.0.
planName := "v1.0.0"
app.UpgradeKeeper.SetUpgradeHandler(planName, upgradeHandlerV1)
// "v1.0.0-testnet3-2" is another coordinated upgrade on testnet3 to upgrade ibc-go to "v5.2.0".
planNameTestnet3 := "v1.0.0-testnet3-2"
app.UpgradeKeeper.SetUpgradeHandler(planNameTestnet3, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

if !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
if upgradeInfo.Name == planName {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{ibcfeetypes.StoreKey},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
planName := "v2.0.0-testnet3"
app.UpgradeKeeper.SetUpgradeHandler(planName, upgradeHandlerV2)
}
1 change: 0 additions & 1 deletion integration_tests/configs/cosmovisor.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ config {
params+: {
no_base_fee: false,
base_fee:: super.base_fee,
initial_base_fee: super.base_fee,
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/configs/upgrade-test-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ let
shortRev = builtins.substring 0 7 rev;
};
}).defaultNix;
released = (fetchFlake "crypto-org-chain/cronos" "2f2cc88b501b47149690fdef05afbbbe5bc116c9").default;
released = (fetchFlake "crypto-org-chain/cronos" "b3da22dcff6176ec5120c84e446a79fb54e3d9de").default;
current = pkgs.callPackage ../../. { };
in
pkgs.linkFarm "upgrade-test-package" [
{ name = "genesis"; path = released; }
{ name = "v1.0.0"; path = current; }
{ name = "v2.0.0-testnet3"; path = current; }
]
43 changes: 26 additions & 17 deletions integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,8 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos):
)
print("old values", old_height, old_balance, old_base_fee)

# estimateGas for an erc20 transfer tx
old_gas = contract.functions.transfer(ADDRS["community"], 100).build_transaction(
{"from": ADDRS["validator"]}
)["gas"]

plan_name = "v1.0.0"
rsp = cli.gov_propose_v0_7(
plan_name = "v2.0.0-testnet3"
rsp = cli.gov_propose_legacy(
"community",
"software-upgrade",
{
Expand All @@ -124,7 +119,6 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos):

# get proposal_id
ev = parse_events(rsp["logs"])["submit_proposal"]
assert ev["proposal_type"] == "SoftwareUpgrade", rsp
proposal_id = ev["proposal_id"]

rsp = cli.gov_vote("validator", proposal_id, "yes")
Expand Down Expand Up @@ -175,12 +169,27 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos):
ADDRS["validator"]
)

assert not cli.evm_params()["params"]["extra_eips"]

# check the gas cost is lower after upgrade
assert (
old_gas - 3700
== contract.functions.transfer(ADDRS["community"], 100).build_transaction(
{"from": ADDRS["validator"]}
)["gas"]
)
# check gravity params
assert cli.query_gravity_params() == {
"params": {
"gravity_id": "cronos_gravity_testnet",
"contract_source_hash": "",
"bridge_ethereum_address": "0x0000000000000000000000000000000000000000",
"bridge_chain_id": "0",
"signed_signer_set_txs_window": "10000",
"signed_batches_window": "10000",
"ethereum_signatures_window": "10000",
"target_eth_tx_timeout": "43200000",
"average_block_time": "5000",
"average_ethereum_block_time": "15000",
"slash_fraction_signer_set_tx": "0.001000000000000000",
"slash_fraction_batch": "0.001000000000000000",
"slash_fraction_ethereum_signature": "0.001000000000000000",
"slash_fraction_conflicting_ethereum_signature": "0.001000000000000000",
"unbond_slashing_signer_set_txs_window": "10000",
"bridge_active": False,
"batch_creation_period": "10",
"batch_max_element": "100",
"observe_ethereum_height_period": "50",
}
}