From 386b739eacec508a2484d94ab95b971f97d9d940 Mon Sep 17 00:00:00 2001 From: yihuang Date: Wed, 27 Apr 2022 18:05:51 +0800 Subject: [PATCH] Problem: feemarket parameters are not correct after upgrade (#440) * Problem: feemarket parameters are not correct after upgrade Closes: #333 Solution: - set correct parameters in upgrade handler * add integration test --- app/app.go | 31 ++++++++++++------- .../configs/upgrade-test-package.nix | 1 - integration_tests/test_upgrade.py | 12 ++++++- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/app/app.go b/app/app.go index 87af496143..485e4ed01b 100644 --- a/app/app.go +++ b/app/app.go @@ -2,6 +2,7 @@ package app import ( "io" + "math/big" "net/http" "os" "path/filepath" @@ -705,17 +706,25 @@ func New( // upgrade handlers plan0_7_0 := "v0.7.0" app.UpgradeKeeper.SetUpgradeHandler(plan0_7_0, func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // The default genesis parameters of `feemarket` module are fine, because the `InitialBaseFee (1000000000)` is much lower than the current minimal gas price, - // so it don't have effect at the beginning, we can always adjust the parameters through the governance later. - return app.mm.RunMigrations(ctx, app.configurator, fromVM) - }) - // this upgrade is for breaking bug fixes on testnet - plan0_7_0Rc3HotfixTestnet := "v0.7.0-rc3-hotfix-testnet" - app.UpgradeKeeper.SetUpgradeHandler(plan0_7_0Rc3HotfixTestnet, func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - cp := ctx.ConsensusParams() - cp.Block.MaxGas = 10000000 - app.StoreConsensusParams(ctx, cp) - return app.mm.RunMigrations(ctx, app.configurator, fromVM) + updatedVM, err := app.mm.RunMigrations(ctx, app.configurator, fromVM) + if err != nil { + return nil, err + } + // Override feemarket parameters + initialBaseFee := int64(5000000000000) + app.FeeMarketKeeper.SetParams(ctx, feemarkettypes.Params{ + NoBaseFee: false, + BaseFeeChangeDenominator: 100000000, + ElasticityMultiplier: 2, + InitialBaseFee: initialBaseFee, + EnableHeight: 0, + }) + app.FeeMarketKeeper.SetBaseFee(ctx, big.NewInt(initialBaseFee)) + evmParams := app.EvmKeeper.GetParams(ctx) + zeroInt := sdk.ZeroInt() + evmParams.ChainConfig.LondonBlock = &zeroInt + app.EvmKeeper.SetParams(ctx, evmParams) + return updatedVM, nil }) upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() diff --git a/integration_tests/configs/upgrade-test-package.nix b/integration_tests/configs/upgrade-test-package.nix index 3ce0e60769..5b413c66e3 100644 --- a/integration_tests/configs/upgrade-test-package.nix +++ b/integration_tests/configs/upgrade-test-package.nix @@ -7,4 +7,3 @@ pkgs.linkFarm "upgrade-test-package" [ { name = "genesis"; path = released; } { name = "v0.7.0"; path = current; } ] - diff --git a/integration_tests/test_upgrade.py b/integration_tests/test_upgrade.py index 803e83958d..799c29da69 100644 --- a/integration_tests/test_upgrade.py +++ b/integration_tests/test_upgrade.py @@ -6,10 +6,11 @@ import pytest from dateutil.parser import isoparse +from pystarport import ports from pystarport.cluster import SUPERVISOR_CONFIG_FILE from .network import Cronos, setup_custom_cronos -from .utils import parse_events, wait_for_block, wait_for_block_time +from .utils import parse_events, wait_for_block, wait_for_block_time, wait_for_port def init_cosmovisor(home): @@ -113,3 +114,12 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos): # block should pass the target height wait_for_block(cli, target_height + 2, timeout=480) + + # check feemarket is enabled correctly + wait_for_port(ports.evmrpc_port(custom_cronos.base_port(0))) + w3 = custom_cronos.w3 + # check base fee values + fee1 = 5000000000000 - 5000000000000 // 100000000 + fee2 = fee1 - fee1 // 100000000 + assert w3.eth.get_block(target_height).baseFeePerGas == fee1 + assert w3.eth.get_block(target_height + 1).baseFeePerGas == fee2