Skip to content

Commit

Permalink
Problem: feemarket parameters are not correct after upgrade (#440)
Browse files Browse the repository at this point in the history
* Problem: feemarket parameters are not correct after upgrade

Closes: #333
Solution:
- set correct parameters in upgrade handler

* add integration test
  • Loading branch information
yihuang authored Apr 27, 2022
1 parent f405599 commit 386b739
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
31 changes: 20 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"io"
"math/big"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion integration_tests/configs/upgrade-test-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ pkgs.linkFarm "upgrade-test-package" [
{ name = "genesis"; path = released; }
{ name = "v0.7.0"; path = current; }
]

12 changes: 11 additions & 1 deletion integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

0 comments on commit 386b739

Please sign in to comment.