From a2c4683f10b8559137691348dbb260e977a78337 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Tue, 1 Oct 2024 09:53:09 -0400 Subject: [PATCH] Eip-1559 - target block gas used as param (#1873) * target block gas used as param * add to migration handler * fix tests * add block base fee metric * add print statement for block gas used * add upgrade version for testing purposes (revert later) * remove block height as label from base fee metric * remove test upgrade --- evmrpc/filter.go | 1 - go.mod | 2 + go.sum | 3 + precompiles/pointer/pointer_test.go | 2 +- proto/evm/params.proto | 1 + utils/metrics/metrics_util.go | 11 ++ x/evm/keeper/evm.go | 1 - x/evm/keeper/fee.go | 24 ++-- x/evm/keeper/fee_test.go | 61 +++++++++- x/evm/keeper/params.go | 4 + x/evm/migrations/migrate_eip_1559_params.go | 1 + .../migrate_eip_1559_params_test.go | 1 + x/evm/module.go | 7 +- x/evm/module_test.go | 2 +- x/evm/types/params.go | 18 +++ x/evm/types/params.pb.go | 112 ++++++++++++------ x/evm/types/params_test.go | 1 + 17 files changed, 196 insertions(+), 56 deletions(-) diff --git a/evmrpc/filter.go b/evmrpc/filter.go index 29be263ed..cd5714008 100644 --- a/evmrpc/filter.go +++ b/evmrpc/filter.go @@ -211,7 +211,6 @@ func (a *FilterAPI) GetFilterLogs( return logs, nil } -// JEREMYFLAG func (a *FilterAPI) GetLogs( ctx context.Context, crit filters.FilterCriteria, diff --git a/go.mod b/go.mod index fc71d4f6f..c2ab4851e 100644 --- a/go.mod +++ b/go.mod @@ -125,6 +125,7 @@ require ( github.com/fzipp/gocyclo v0.5.1 // indirect github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect + github.com/ghodss/yaml v1.0.0 // indirect github.com/go-critic/go-critic v0.6.3 // indirect github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.1 // indirect @@ -172,6 +173,7 @@ require ( github.com/gostaticanalysis/nilerr v0.1.1 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/go-bexpr v0.1.10 // indirect diff --git a/go.sum b/go.sum index 0f4715c55..8f85698e5 100644 --- a/go.sum +++ b/go.sum @@ -457,6 +457,7 @@ github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2Gihuqh github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc= github.com/getkin/kin-openapi v0.53.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4= github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= @@ -765,6 +766,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/guptarohit/asciigraph v0.5.5/go.mod h1:dYl5wwK4gNsnFf9Zp+l06rFiDZ5YtXM6x7SRWZ3KGag= diff --git a/precompiles/pointer/pointer_test.go b/precompiles/pointer/pointer_test.go index 18266466a..a8901cdf3 100644 --- a/precompiles/pointer/pointer_test.go +++ b/precompiles/pointer/pointer_test.go @@ -57,7 +57,7 @@ func TestAddNative(t *testing.T) { evm = vm.NewEVM(*blockCtx, vm.TxContext{}, statedb, cfg, vm.Config{}) ret, g, err := p.RunAndCalculateGas(evm, caller, caller, append(p.GetExecutor().(*pointer.PrecompileExecutor).AddNativePointerID, args...), suppliedGas, nil, nil, false, false) require.Nil(t, err) - require.Equal(t, uint64(8883738), g) + require.Equal(t, uint64(8881522), g) outputs, err := m.Outputs.Unpack(ret) require.Nil(t, err) addr := outputs[0].(common.Address) diff --git a/proto/evm/params.proto b/proto/evm/params.proto index 6d2868ade..54d5ba3ff 100644 --- a/proto/evm/params.proto +++ b/proto/evm/params.proto @@ -61,6 +61,7 @@ string minimum_fee_per_gas = 4 [ (gogoproto.nullable) = false, (gogoproto.jsontag) = "max_dynamic_base_fee_downward_adjustment" ]; + uint64 target_gas_used_per_block = 12; } message ParamsPreV580 { diff --git a/utils/metrics/metrics_util.go b/utils/metrics/metrics_util.go index 4252e4b96..0eca18118 100644 --- a/utils/metrics/metrics_util.go +++ b/utils/metrics/metrics_util.go @@ -357,3 +357,14 @@ func HistogramEvmEffectiveGasPrice(gasPrice *big.Int) { float32(gasPrice.Uint64()), ) } + +// Gauge for block base fee +// Metric Name: +// +// sei_evm_block_base_fee +func GaugeEvmBlockBaseFee(baseFee *big.Int, blockHeight int64) { + metrics.SetGauge( + []string{"sei", "evm", "block", "base", "fee"}, + float32(baseFee.Uint64()), + ) +} diff --git a/x/evm/keeper/evm.go b/x/evm/keeper/evm.go index a11c696df..1ec7f039d 100644 --- a/x/evm/keeper/evm.go +++ b/x/evm/keeper/evm.go @@ -103,7 +103,6 @@ func (k *Keeper) CallEVM(ctx sdk.Context, from common.Address, to *common.Addres SkipAccountChecks: false, From: from, } - fmt.Println("JEREMYDEBUG: calling apply evm message from CallEVM") res, err := k.applyEVMMessage(ctx, evmMsg, stateDB, gp) if err != nil { return nil, err diff --git a/x/evm/keeper/fee.go b/x/evm/keeper/fee.go index 6019a2f59..f53631c02 100644 --- a/x/evm/keeper/fee.go +++ b/x/evm/keeper/fee.go @@ -5,27 +5,31 @@ import ( "github.com/sei-protocol/sei-chain/x/evm/types" ) -// modified eip-1559 adjustment -func (k *Keeper) AdjustDynamicBaseFeePerGas(ctx sdk.Context, blockGasUsed uint64) { +// modified eip-1559 adjustment using target gas used +func (k *Keeper) AdjustDynamicBaseFeePerGas(ctx sdk.Context, blockGasUsed uint64) *sdk.Dec { if ctx.ConsensusParams() == nil || ctx.ConsensusParams().Block == nil { - return + return nil } currentBaseFee := k.GetDynamicBaseFeePerGas(ctx) minimumFeePerGas := k.GetParams(ctx).MinimumFeePerGas blockGasLimit := sdk.NewDec(ctx.ConsensusParams().Block.MaxGas) blockGasUsedDec := sdk.NewDec(int64(blockGasUsed)) + targetGasUsed := sdk.NewDec(int64(k.GetTargetGasUsedPerBlock(ctx))) - blockFullness := blockGasUsedDec.Quo(blockGasLimit) - - half := sdk.NewDec(1).Quo(sdk.NewDec(2)) // 0.5 var newBaseFee sdk.Dec - if blockFullness.GT(half) { + if blockGasUsedDec.GT(targetGasUsed) { // upward adjustment - adjustmentFactor := k.GetMaxDynamicBaseFeeUpwardAdjustment(ctx).Mul(blockFullness.Sub(half)).Quo(half) + numerator := blockGasUsedDec.Sub(targetGasUsed) + denominator := blockGasLimit.Sub(targetGasUsed) + percentageFull := numerator.Quo(denominator) + adjustmentFactor := k.GetMaxDynamicBaseFeeUpwardAdjustment(ctx).Mul(percentageFull) newBaseFee = currentBaseFee.Mul(sdk.NewDec(1).Add(adjustmentFactor)) } else { // downward adjustment - adjustmentFactor := k.GetMaxDynamicBaseFeeDownwardAdjustment(ctx).Mul(half.Sub(blockFullness)).Quo(half) + numerator := targetGasUsed.Sub(blockGasUsedDec) + denominator := targetGasUsed + percentageEmpty := numerator.Quo(denominator) + adjustmentFactor := k.GetMaxDynamicBaseFeeDownwardAdjustment(ctx).Mul(percentageEmpty) newBaseFee = currentBaseFee.Mul(sdk.NewDec(1).Sub(adjustmentFactor)) } @@ -36,6 +40,8 @@ func (k *Keeper) AdjustDynamicBaseFeePerGas(ctx sdk.Context, blockGasUsed uint64 // Set the new base fee for the next height k.SetDynamicBaseFeePerGas(ctx.WithBlockHeight(ctx.BlockHeight()+1), newBaseFee) + + return &newBaseFee } // dont have height be a prefix, just store the current base fee directly diff --git a/x/evm/keeper/fee_test.go b/x/evm/keeper/fee_test.go index 7495ea208..83f3e2fb0 100644 --- a/x/evm/keeper/fee_test.go +++ b/x/evm/keeper/fee_test.go @@ -27,39 +27,87 @@ func TestAdjustBaseFeePerGas(t *testing.T) { minimumFee float64 blockGasUsed uint64 blockGasLimit uint64 + upwardAdj sdk.Dec + downwardAdj sdk.Dec + targetGasUsed uint64 expectedBaseFee uint64 }{ { - name: "Block gas usage exactly half of limit, no fee change", + name: "Block gas usage exactly half of limit, 0% up, 0% down, no fee change", currentBaseFee: 100, minimumFee: 10, blockGasUsed: 500000, blockGasLimit: 1000000, + upwardAdj: sdk.NewDec(0), + downwardAdj: sdk.NewDec(0), + targetGasUsed: 500000, expectedBaseFee: 100, }, { - name: "Block gas usage 75%, base fee stays the same", + name: "Block gas usage 50%, 50% up, 50% down, no fee change", + currentBaseFee: 100, + minimumFee: 10, + blockGasUsed: 500000, + blockGasLimit: 1000000, + upwardAdj: sdk.NewDecWithPrec(5, 1), + downwardAdj: sdk.NewDecWithPrec(5, 1), + targetGasUsed: 500000, + expectedBaseFee: 100, + }, + { + name: "Block gas usage 75%, 0% up, 0% down, base fee stays the same", currentBaseFee: 10000, minimumFee: 10, blockGasUsed: 750000, blockGasLimit: 1000000, + upwardAdj: sdk.NewDec(0), + downwardAdj: sdk.NewDec(0), + targetGasUsed: 500000, expectedBaseFee: 10000, }, { - name: "Block gas usage 25%, base fee stays the same", + name: "Block gas usage 25%, 0% up, 0% down, base fee stays the same", currentBaseFee: 10000, minimumFee: 10, blockGasUsed: 250000, blockGasLimit: 1000000, + upwardAdj: sdk.NewDec(0), + downwardAdj: sdk.NewDec(0), + targetGasUsed: 500000, expectedBaseFee: 10000, }, + { + name: "Block gas usage 75%, 50% up, 0% down, base fee increases by 25%", + currentBaseFee: 10000, + minimumFee: 10, + blockGasUsed: 750000, + blockGasLimit: 1000000, + upwardAdj: sdk.NewDecWithPrec(5, 1), + downwardAdj: sdk.NewDec(0), + targetGasUsed: 500000, + expectedBaseFee: 12500, + }, + { + name: "Block gas usage 25%, 0% up, 50% down, base fee decreases by 25%", + currentBaseFee: 10000, + minimumFee: 10, + blockGasUsed: 250000, + blockGasLimit: 1000000, + upwardAdj: sdk.NewDec(0), + downwardAdj: sdk.NewDecWithPrec(5, 1), + targetGasUsed: 500000, + expectedBaseFee: 7500, + }, { name: "Block gas usage low, new base fee below minimum, set to minimum", currentBaseFee: 100, - minimumFee: 100, + minimumFee: 99, blockGasUsed: 0, blockGasLimit: 1000000, - expectedBaseFee: 100, // Should not go below the minimum fee + upwardAdj: sdk.NewDecWithPrec(5, 2), + downwardAdj: sdk.NewDecWithPrec(5, 2), + targetGasUsed: 500000, + expectedBaseFee: 99, // Should not go below the minimum fee }, } @@ -71,6 +119,9 @@ func TestAdjustBaseFeePerGas(t *testing.T) { k.SetDynamicBaseFeePerGas(ctx, sdk.NewDecFromInt(sdk.NewInt(int64(tc.currentBaseFee)))) p := k.GetParams(ctx) p.MinimumFeePerGas = sdk.NewDec(int64(tc.minimumFee)) + p.MaxDynamicBaseFeeUpwardAdjustment = tc.upwardAdj + p.MaxDynamicBaseFeeDownwardAdjustment = tc.downwardAdj + p.TargetGasUsedPerBlock = tc.targetGasUsed k.SetParams(ctx, p) k.AdjustDynamicBaseFeePerGas(ctx, tc.blockGasUsed) expected := sdk.NewDecFromInt(sdk.NewInt(int64(tc.expectedBaseFee))) diff --git a/x/evm/keeper/params.go b/x/evm/keeper/params.go index 1ce43a7c5..992a6390f 100644 --- a/x/evm/keeper/params.go +++ b/x/evm/keeper/params.go @@ -49,6 +49,10 @@ func (k *Keeper) GetMinimumFeePerGas(ctx sdk.Context) sdk.Dec { return k.GetParams(ctx).MinimumFeePerGas } +func (k *Keeper) GetTargetGasUsedPerBlock(ctx sdk.Context) uint64 { + return k.GetParams(ctx).TargetGasUsedPerBlock +} + func (k *Keeper) GetDeliverTxHookWasmGasLimit(ctx sdk.Context) uint64 { return k.GetParams(ctx).DeliverTxHookWasmGasLimit } diff --git a/x/evm/migrations/migrate_eip_1559_params.go b/x/evm/migrations/migrate_eip_1559_params.go index e6dba7b16..3009de98b 100644 --- a/x/evm/migrations/migrate_eip_1559_params.go +++ b/x/evm/migrations/migrate_eip_1559_params.go @@ -10,6 +10,7 @@ func MigrateEip1559Params(ctx sdk.Context, k *keeper.Keeper) error { keeperParams := k.GetParamsIfExists(ctx) keeperParams.MaxDynamicBaseFeeUpwardAdjustment = types.DefaultParams().MaxDynamicBaseFeeUpwardAdjustment keeperParams.MaxDynamicBaseFeeDownwardAdjustment = types.DefaultParams().MaxDynamicBaseFeeDownwardAdjustment + keeperParams.TargetGasUsedPerBlock = types.DefaultParams().TargetGasUsedPerBlock k.SetParams(ctx, keeperParams) return nil } diff --git a/x/evm/migrations/migrate_eip_1559_params_test.go b/x/evm/migrations/migrate_eip_1559_params_test.go index 256cccc62..6f703cc5d 100644 --- a/x/evm/migrations/migrate_eip_1559_params_test.go +++ b/x/evm/migrations/migrate_eip_1559_params_test.go @@ -26,4 +26,5 @@ func TestMigrateEip1559Params(t *testing.T) { require.Equal(t, keeperParams.BaseFeePerGas, sdk.NewDec(123)) require.Equal(t, keeperParams.MaxDynamicBaseFeeUpwardAdjustment, types.DefaultParams().MaxDynamicBaseFeeUpwardAdjustment) require.Equal(t, keeperParams.MaxDynamicBaseFeeDownwardAdjustment, types.DefaultParams().MaxDynamicBaseFeeDownwardAdjustment) + require.Equal(t, keeperParams.TargetGasUsedPerBlock, types.DefaultParams().TargetGasUsedPerBlock) } diff --git a/x/evm/module.go b/x/evm/module.go index 42c7c498c..e66ad94f2 100644 --- a/x/evm/module.go +++ b/x/evm/module.go @@ -24,6 +24,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/sei-protocol/sei-chain/utils" + "github.com/sei-protocol/sei-chain/utils/metrics" "github.com/sei-protocol/sei-chain/x/evm/client/cli" "github.com/sei-protocol/sei-chain/x/evm/keeper" "github.com/sei-protocol/sei-chain/x/evm/migrations" @@ -285,7 +286,11 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { // EndBlock executes all ABCI EndBlock logic respective to the evm module. It // returns no validator updates. func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate { - am.keeper.AdjustDynamicBaseFeePerGas(ctx, uint64(req.BlockGasUsed)) + fmt.Println("JEREMYDEBUG: block gas used", req.BlockGasUsed, ", block height", ctx.BlockHeight()) + newBaseFee := am.keeper.AdjustDynamicBaseFeePerGas(ctx, uint64(req.BlockGasUsed)) + if newBaseFee != nil { + metrics.GaugeEvmBlockBaseFee(newBaseFee.TruncateInt().BigInt(), req.Height) + } var coinbase sdk.AccAddress if am.keeper.EthBlockTestConfig.Enabled { blocks := am.keeper.BlockTest.Json.Blocks diff --git a/x/evm/module_test.go b/x/evm/module_test.go index dbab3540d..7158a632d 100644 --- a/x/evm/module_test.go +++ b/x/evm/module_test.go @@ -53,7 +53,7 @@ func TestModuleExportGenesis(t *testing.T) { module := evm.NewAppModule(nil, k) jsonMsg := module.ExportGenesis(ctx, types.ModuleCdc) jsonStr := string(jsonMsg) - assert.Equal(t, "{\"params\":{\"priority_normalizer\":\"1.000000000000000000\",\"base_fee_per_gas\":\"0.000000000000000000\",\"minimum_fee_per_gas\":\"100000000000.000000000000000000\",\"whitelisted_cw_code_hashes_for_delegate_call\":[],\"deliver_tx_hook_wasm_gas_limit\":\"300000\",\"max_dynamic_base_fee_upward_adjustment\":\"0.000000000000000000\",\"max_dynamic_base_fee_downward_adjustment\":\"0.000000000000000000\"},\"address_associations\":[{\"sei_address\":\"sei17xpfvakm2amg962yls6f84z3kell8c5la4jkdu\",\"eth_address\":\"0x27F7B8B8B5A4e71E8E9aA671f4e4031E3773303F\"}],\"codes\":[],\"states\":[],\"nonces\":[],\"serialized\":[{\"prefix\":\"Fg==\",\"key\":\"AwAC\",\"value\":\"AAAAAAAAAAM=\"},{\"prefix\":\"Fg==\",\"key\":\"BAAG\",\"value\":\"AAAAAAAAAAQ=\"}]}", jsonStr) + assert.Equal(t, "{\"params\":{\"priority_normalizer\":\"1.000000000000000000\",\"base_fee_per_gas\":\"0.000000000000000000\",\"minimum_fee_per_gas\":\"100000000000.000000000000000000\",\"whitelisted_cw_code_hashes_for_delegate_call\":[],\"deliver_tx_hook_wasm_gas_limit\":\"300000\",\"max_dynamic_base_fee_upward_adjustment\":\"0.000000000000000000\",\"max_dynamic_base_fee_downward_adjustment\":\"0.000000000000000000\",\"target_gas_used_per_block\":\"100000\"},\"address_associations\":[{\"sei_address\":\"sei17xpfvakm2amg962yls6f84z3kell8c5la4jkdu\",\"eth_address\":\"0x27F7B8B8B5A4e71E8E9aA671f4e4031E3773303F\"}],\"codes\":[],\"states\":[],\"nonces\":[],\"serialized\":[{\"prefix\":\"Fg==\",\"key\":\"AwAC\",\"value\":\"AAAAAAAAAAM=\"},{\"prefix\":\"Fg==\",\"key\":\"BAAG\",\"value\":\"AAAAAAAAAAQ=\"}]}", jsonStr) } func TestConsensusVersion(t *testing.T) { diff --git a/x/evm/types/params.go b/x/evm/types/params.go index fda1a8c63..b70c2ca92 100644 --- a/x/evm/types/params.go +++ b/x/evm/types/params.go @@ -15,6 +15,7 @@ var ( KeyDeliverTxHookWasmGasLimit = []byte("KeyDeliverTxHookWasmGasLimit") KeyMaxDynamicBaseFeeUpwardAdjustment = []byte("KeyMaxDynamicBaseFeeUpwardAdjustment") KeyMaxDynamicBaseFeeDownwardAdjustment = []byte("KeyMaxDynamicBaseFeeDownwardAdjustment") + KeyTargetGasUsedPerBlock = []byte("KeyTargetGasUsedPerBlock") // deprecated KeyBaseFeePerGas = []byte("KeyBaseFeePerGas") KeyWhitelistedCwCodeHashesForDelegateCall = []byte("KeyWhitelistedCwCodeHashesForDelegateCall") @@ -33,6 +34,7 @@ var DefaultWhitelistedCwCodeHashesForDelegateCall = generateDefaultWhitelistedCw var DefaultMaxDynamicBaseFeeUpwardAdjustment = sdk.NewDec(0) var DefaultMaxDynamicBaseFeeDownwardAdjustment = sdk.NewDec(0) +var DefaultTargetGasUsedPerBlock = uint64(100000) var _ paramtypes.ParamSet = (*Params)(nil) @@ -49,6 +51,7 @@ func DefaultParams() Params { MinimumFeePerGas: DefaultMinFeePerGas, DeliverTxHookWasmGasLimit: DefaultDeliverTxHookWasmGasLimit, WhitelistedCwCodeHashesForDelegateCall: DefaultWhitelistedCwCodeHashesForDelegateCall, + TargetGasUsedPerBlock: DefaultTargetGasUsedPerBlock, } } @@ -61,6 +64,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { paramtypes.NewParamSetPair(KeyMinFeePerGas, &p.MinimumFeePerGas, validateMinFeePerGas), paramtypes.NewParamSetPair(KeyWhitelistedCwCodeHashesForDelegateCall, &p.WhitelistedCwCodeHashesForDelegateCall, validateWhitelistedCwHashesForDelegateCall), paramtypes.NewParamSetPair(KeyDeliverTxHookWasmGasLimit, &p.DeliverTxHookWasmGasLimit, validateDeliverTxHookWasmGasLimit), + paramtypes.NewParamSetPair(KeyTargetGasUsedPerBlock, &p.TargetGasUsedPerBlock, validateTargetGasUsedPerBlock), } } @@ -86,9 +90,23 @@ func (p Params) Validate() error { if err := validateBaseFeeAdjustment(p.MaxDynamicBaseFeeDownwardAdjustment); err != nil { return fmt.Errorf("invalid max dynamic base fee downward adjustment: %s, err: %s", p.MaxDynamicBaseFeeDownwardAdjustment, err) } + if err := validateTargetGasUsedPerBlock(p.TargetGasUsedPerBlock); err != nil { + return err + } return validateWhitelistedCwHashesForDelegateCall(p.WhitelistedCwCodeHashesForDelegateCall) } +func validateTargetGasUsedPerBlock(i interface{}) error { + v, ok := i.(uint64) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + if v == 0 { + return fmt.Errorf("invalid target gas used per block: must be greater than 0, got %d", v) + } + return nil +} + func validateBaseFeeAdjustment(i interface{}) error { adjustment, ok := i.(sdk.Dec) if !ok { diff --git a/x/evm/types/params.pb.go b/x/evm/types/params.pb.go index 959b5b54f..fa42412a4 100644 --- a/x/evm/types/params.pb.go +++ b/x/evm/types/params.pb.go @@ -48,6 +48,7 @@ type Params struct { DeliverTxHookWasmGasLimit uint64 `protobuf:"varint,9,opt,name=deliver_tx_hook_wasm_gas_limit,json=deliverTxHookWasmGasLimit,proto3" json:"deliver_tx_hook_wasm_gas_limit,omitempty"` MaxDynamicBaseFeeUpwardAdjustment github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,10,opt,name=max_dynamic_base_fee_upward_adjustment,json=maxDynamicBaseFeeUpwardAdjustment,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"max_dynamic_base_fee_upward_adjustment" yaml:"max_dynamic_base_fee_upward_adjustment"` MaxDynamicBaseFeeDownwardAdjustment github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,11,opt,name=max_dynamic_base_fee_downward_adjustment,json=maxDynamicBaseFeeDownwardAdjustment,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"max_dynamic_base_fee_downward_adjustment" yaml:"max_dynamic_base_fee_downward_adjustment"` + TargetGasUsedPerBlock uint64 `protobuf:"varint,12,opt,name=target_gas_used_per_block,json=targetGasUsedPerBlock,proto3" json:"target_gas_used_per_block,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -96,6 +97,13 @@ func (m *Params) GetDeliverTxHookWasmGasLimit() uint64 { return 0 } +func (m *Params) GetTargetGasUsedPerBlock() uint64 { + if m != nil { + return m.TargetGasUsedPerBlock + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "seiprotocol.seichain.evm.Params") } @@ -103,43 +111,46 @@ func init() { func init() { proto.RegisterFile("evm/params.proto", fileDescriptor_9272f3679901ea94) } var fileDescriptor_9272f3679901ea94 = []byte{ - // 572 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xc1, 0x6b, 0x13, 0x4f, - 0x14, 0xc7, 0x33, 0xbf, 0x96, 0xf2, 0xeb, 0xaa, 0x50, 0xb6, 0x82, 0x6b, 0x0f, 0xbb, 0x75, 0x85, - 0x92, 0x83, 0xc9, 0x1e, 0x7a, 0xeb, 0xad, 0x49, 0x68, 0x7a, 0x10, 0x29, 0x8b, 0x22, 0x08, 0x32, - 0x4c, 0x76, 0x5f, 0x77, 0xc7, 0xec, 0xec, 0x2c, 0x33, 0x9b, 0x6c, 0xe2, 0x1f, 0x20, 0x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x57, 0x3d, 0x99, - 0x32, 0x88, 0x53, 0x43, 0x53, 0x23, 0x7b, 0x8b, 0x56, 0x9e, 0xd9, 0x92, 0x17, 0x4c, 0x72, 0xab, - 0x56, 0x8c, 0x71, 0x29, 0xde, 0x76, 0x1f, 0x30, 0x32, 0x68, 0xcd, 0xb8, 0xc6, 0xec, 0xab, 0x7b, - 0xa6, 0xa0, 0xc3, 0x39, 0xa3, 0xff, 0x42, 0x5a, 0xb5, 0xb4, 0x9d, 0xcf, 0xb3, 0xf8, 0xba, 0xc3, - 0x5b, 0xca, 0xe1, 0xbb, 0xd5, 0x1d, 0x2e, 0x7d, 0xc5, 0x24, 0xb7, 0x9c, 0xbf, 0x78, 0x2c, 0xa9, - 0xb0, 0xdd, 0x87, 0x37, 0x5c, 0xb6, 0x0a, 0x6c, 0xe1, 0xf3, 0x60, 0xfd, 0xf3, 0x17, 0xab, 0xd2, - 0x68, 0x9f, 0x8d, 0x4c, 0x74, 0x3e, 0x32, 0xd1, 0xcf, 0x91, 0x89, 0xde, 0x8f, 0xcd, 0xca, 0xf9, - 0xd8, 0xac, 0x7c, 0x1b, 0x9b, 0x95, 0x17, 0xb5, 0x2b, 0x5e, 0x24, 0xd0, 0xda, 0xe5, 0xba, 0x53, - 0x7f, 0xd4, 0xbe, 0x73, 0x06, 0xce, 0x74, 0x31, 0x2a, 0x5b, 0x9d, 0x0d, 0x95, 0xdf, 0xff, 0x1d, - 0x00, 0x00, 0xff, 0xff, 0x5f, 0xd6, 0xbc, 0x8c, 0x2c, 0x05, 0x00, 0x00, + // 609 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4f, 0x6b, 0x13, 0x4f, + 0x18, 0xc7, 0x33, 0xbf, 0x96, 0xf2, 0xeb, 0x5a, 0xa1, 0x6c, 0x15, 0xb7, 0x3d, 0xec, 0xd6, 0x15, + 0x4a, 0x0e, 0x26, 0x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, 0xa2, 0xf1, 0x93, 0x6a, 0x1b, 0xd2, 0x5c, + 0xb0, 0xf9, 0xcd, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xb7, 0x48, 0xda, 0x43, 0x66, 0x05, 0x00, + 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -162,6 +173,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.TargetGasUsedPerBlock != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.TargetGasUsedPerBlock)) + i-- + dAtA[i] = 0x60 + } { size := m.MaxDynamicBaseFeeDownwardAdjustment.Size() i -= size @@ -265,6 +281,9 @@ func (m *Params) Size() (n int) { n += 1 + l + sovParams(uint64(l)) l = m.MaxDynamicBaseFeeDownwardAdjustment.Size() n += 1 + l + sovParams(uint64(l)) + if m.TargetGasUsedPerBlock != 0 { + n += 1 + sovParams(uint64(m.TargetGasUsedPerBlock)) + } return n } @@ -524,6 +543,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 12: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TargetGasUsedPerBlock", wireType) + } + m.TargetGasUsedPerBlock = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TargetGasUsedPerBlock |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/evm/types/params_test.go b/x/evm/types/params_test.go index cfc9f4774..f07fa5f3c 100644 --- a/x/evm/types/params_test.go +++ b/x/evm/types/params_test.go @@ -18,6 +18,7 @@ func TestDefaultParams(t *testing.T) { WhitelistedCwCodeHashesForDelegateCall: types.DefaultWhitelistedCwCodeHashesForDelegateCall, MaxDynamicBaseFeeUpwardAdjustment: types.DefaultMaxDynamicBaseFeeUpwardAdjustment, MaxDynamicBaseFeeDownwardAdjustment: types.DefaultMaxDynamicBaseFeeDownwardAdjustment, + TargetGasUsedPerBlock: types.DefaultTargetGasUsedPerBlock, }, types.DefaultParams()) require.Nil(t, types.DefaultParams().Validate()) }