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

feat: eip target gas from consensus params #7270

Merged
merged 12 commits into from
Jan 9, 2024
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Features

* [#6993](https://github.com/osmosis-labs/osmosis/pull/6993) feat(math): add mutative api for BigDec.BigInt()
* [#7270](https://github.com/osmosis-labs/osmosis/pull/7270) feat: eip target gas from consensus params

### Misc Improvements

Expand All @@ -64,7 +65,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Bug Fixes

* [#7245](https://github.com/osmosis-labs/osmosis/pull/7245) fix: correcting json tag value for `SwapAmountOutSplitRouteWrapper.OutDenom`
* [#7233](https://github.com/osmosis-labs/osmosis/pull/7233) fix: config overwrite ignores app.toml values
* [#7233](https://github.com/osmosis-labs/osmosis/pull/7233) fix: config overwrite ignores app.toml values
* [#7243](https://github.com/osmosis-labs/osmosis/pull/7243) fix: chore: update gov metadata length from 256 to 10200
* [#7246](https://github.com/osmosis-labs/osmosis/pull/7246) fix: config overwrite fails with exit code 1 if wrong permissions
* [#7267](https://github.com/osmosis-labs/osmosis/pull/7267) fix: support CL pools in tx fee module
Expand Down
1 change: 1 addition & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.PoolManagerKeeper,
appKeepers.ProtoRevKeeper,
appKeepers.DistrKeeper,
appKeepers.ConsensusParamsKeeper,
dataDir,
)
appKeepers.TxFeesKeeper = &txFeesKeeper
Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,15 @@ replace (
// https://github.com/osmosis-labs/wasmd/releases/tag/v0.45.0-osmo
github.com/CosmWasm/wasmd => github.com/osmosis-labs/wasmd v0.45.0-osmo

// fork of cometbft which allows for better app hash logging
github.com/cometbft/cometbft => github.com/osmosis-labs/cometbft v0.0.0-20240103055822-28da358e3146

// v1.0.0-beta.3 is incompatible, so we use v1.0.0-beta.2
github.com/cosmos/cosmos-proto => github.com/cosmos/cosmos-proto v1.0.0-beta.2

// Our cosmos-sdk branch is: https://github.com/osmosis-labs/cosmos-sdk/tree/osmo/v0.47.5, current branch: osmo/v0.47.5. Direct commit link: https://github.com/osmosis-labs/cosmos-sdk/commit/cc29414c72c73d567e0c75b4a0800961a26d7af4
// https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-osmo-4
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.6-0.20240103225327-6652b67a6ae8
// Our cosmos-sdk branch is: https://github.com/osmosis-labs/cosmos-sdk/tree/osmo/v0.47.5, current branch: osmo/v0.47.5. Direct commit link: https://github.com/osmosis-labs/cosmos-sdk/commit/65d7acfdc2a94cc49837bb9abec462f129029540
// https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-v21-osmo-6
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.5-v21-osmo-6
github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.10
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,6 @@ github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/coinbase/rosetta-sdk-go/types v1.0.0 h1:jpVIwLcPoOeCR6o1tU+Xv7r5bMONNbHU7MuEHboiFuA=
github.com/coinbase/rosetta-sdk-go/types v1.0.0/go.mod h1:eq7W2TMRH22GTW0N0beDnN931DW0/WOI1R2sdHNHG4c=
github.com/cometbft/cometbft v0.37.2 h1:XB0yyHGT0lwmJlFmM4+rsRnczPlHoAKFX6K8Zgc2/Jc=
github.com/cometbft/cometbft v0.37.2/go.mod h1:Y2MMMN//O5K4YKd8ze4r9jmk4Y7h0ajqILXbH5JQFVs=
github.com/cometbft/cometbft-db v0.8.0 h1:vUMDaH3ApkX8m0KZvOFFy9b5DZHBAjsnEuo9AKVZpjo=
github.com/cometbft/cometbft-db v0.8.0/go.mod h1:6ASCP4pfhmrCBpfk01/9E1SI29nD3HfVHrY4PG8x5c0=
github.com/confio/ics23/go v0.9.1 h1:3MV46eeWwO3xCauKyAtuAdJYMyPnnchW4iLr2bTw6/U=
Expand Down Expand Up @@ -1461,8 +1459,10 @@ github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnh
github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA=
github.com/ory/dockertest/v3 v3.10.0 h1:4K3z2VMe8Woe++invjaTB7VRyQXQy5UY+loujO4aNE4=
github.com/ory/dockertest/v3 v3.10.0/go.mod h1:nr57ZbRWMqfsdGdFNLHz5jjNdDb7VVFnzAeW1n5N1Lg=
github.com/osmosis-labs/cosmos-sdk v0.47.6-0.20240103225327-6652b67a6ae8 h1:rKsGBYTfP0XMsEddGJhBkVtQZeeGMwjZ47U69Y5G4ic=
github.com/osmosis-labs/cosmos-sdk v0.47.6-0.20240103225327-6652b67a6ae8/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c=
github.com/osmosis-labs/cometbft v0.0.0-20240103055822-28da358e3146 h1:Qkshh58fZCRoHSzbyW8NJf1wBhf9bg1MPFZEuyuI9lE=
github.com/osmosis-labs/cometbft v0.0.0-20240103055822-28da358e3146/go.mod h1:Y2MMMN//O5K4YKd8ze4r9jmk4Y7h0ajqILXbH5JQFVs=
github.com/osmosis-labs/cosmos-sdk v0.47.5-v21-osmo-6 h1:80nco4oGzcrS5XGdg6UoAKn961Ra9UpE+W9YvBJ2h2E=
github.com/osmosis-labs/cosmos-sdk v0.47.5-v21-osmo-6/go.mod h1:4BNXIoS9XecywMSdPr/DIwCgH2/Qjyr2+qhrHu8YSEo=
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:YlmchqTmlwdWSmrRmXKR+PcU96ntOd8u10vTaTZdcNY=
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI=
github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20240108040604-9632b2b8af1b h1:SU5mAiRgXoTJ73C9mmtDJzYmmSLcZ07zD9KNUPh/Cvc=
Expand Down
6 changes: 3 additions & 3 deletions osmomath/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ replace (
// v1.0.0-beta.3 is incompatible, so we use v1.0.0-beta.2
github.com/cosmos/cosmos-proto => github.com/cosmos/cosmos-proto v1.0.0-beta.2

// Our cosmos-sdk branch is: https://github.com/osmosis-labs/cosmos-sdk/tree/osmo/v0.47.5, current branch: osmo/v0.47.5. Direct commit link: https://github.com/osmosis-labs/cosmos-sdk/commit/cc29414c72c73d567e0c75b4a0800961a26d7af4
// https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-osmo-4
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.6-0.20240103225327-6652b67a6ae8
// Our cosmos-sdk branch is: https://github.com/osmosis-labs/cosmos-sdk/tree/osmo/v0.47.5, current branch: osmo/v0.47.5. Direct commit link: https://github.com/osmosis-labs/cosmos-sdk/commit/65d7acfdc2a94cc49837bb9abec462f129029540
// https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-v21-osmo-6
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.5-v21-osmo-6
github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.10
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

Expand Down
9 changes: 6 additions & 3 deletions osmoutils/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,18 @@ replace (
// v1.0.0-beta.3 is incompatible, so we use v1.0.0-beta.2
github.com/cosmos/cosmos-proto => github.com/cosmos/cosmos-proto v1.0.0-beta.2

// Our cosmos-sdk branch is: https://github.com/osmosis-labs/cosmos-sdk/tree/osmo/v0.47.5, current branch: osmo/v0.47.5. Direct commit link: https://github.com/osmosis-labs/cosmos-sdk/commit/cc29414c72c73d567e0c75b4a0800961a26d7af4
// https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-osmo-4
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.6-0.20240103225327-6652b67a6ae8
// Our cosmos-sdk branch is: https://github.com/osmosis-labs/cosmos-sdk/tree/osmo/v0.47.5, current branch: osmo/v0.47.5. Direct commit link: https://github.com/osmosis-labs/cosmos-sdk/commit/65d7acfdc2a94cc49837bb9abec462f129029540
// https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-v21-osmo-6
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.5-v21-osmo-6
github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.10
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

// newer versions of exp treat sorting differently, which is incompatible with the current version of cosmos-sdk
golang.org/x/exp => golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb

// fork of cometbft which allows for better app hash logging
github.com/cometbft/cometbft => github.com/osmosis-labs/cometbft v0.0.0-20240103055822-28da358e3146

// Local replaces commented for development
// github.com/osmosis-labs/osmosis/osmomath => ../osmomath
// github.com/osmosis-labs/osmosis/v21 => ./../
Expand Down
9 changes: 6 additions & 3 deletions x/epochs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,18 @@ replace (
// v1.0.0-beta.3 is incompatible, so we use v1.0.0-beta.2
github.com/cosmos/cosmos-proto => github.com/cosmos/cosmos-proto v1.0.0-beta.2

// Our cosmos-sdk branch is: https://github.com/osmosis-labs/cosmos-sdk/tree/osmo/v0.47.5, current branch: osmo/v0.47.5. Direct commit link: https://github.com/osmosis-labs/cosmos-sdk/commit/cc29414c72c73d567e0c75b4a0800961a26d7af4
// https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-osmo-4
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.6-0.20240103225327-6652b67a6ae8
// Our cosmos-sdk branch is: https://github.com/osmosis-labs/cosmos-sdk/tree/osmo/v0.47.5, current branch: osmo/v0.47.5. Direct commit link: https://github.com/osmosis-labs/cosmos-sdk/commit/65d7acfdc2a94cc49837bb9abec462f129029540
// https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-v21-osmo-6
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.5-v21-osmo-6
github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.10
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

// newer versions of exp treat sorting differently, which is incompatible with the current version of cosmos-sdk
golang.org/x/exp => golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb

// fork of cometbft which allows for better app hash logging
github.com/cometbft/cometbft => github.com/osmosis-labs/cometbft v0.0.0-20240103055822-28da358e3146

// Local replaces commented for development
// github.com/osmosis-labs/osmosis/osmoutils => ../../osmoutils
)
9 changes: 6 additions & 3 deletions x/ibc-hooks/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,18 @@ replace (

// v1.0.0-beta.3 is incompatible, so we use v1.0.0-beta.2
github.com/cosmos/cosmos-proto => github.com/cosmos/cosmos-proto v1.0.0-beta.2
// Our cosmos-sdk branch is: https://github.com/osmosis-labs/cosmos-sdk/tree/osmo/v0.47.5, current branch: osmo/v0.47.5. Direct commit link: https://github.com/osmosis-labs/cosmos-sdk/commit/cc29414c72c73d567e0c75b4a0800961a26d7af4
// https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-osmo-4
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.6-0.20240103225327-6652b67a6ae8
// Our cosmos-sdk branch is: https://github.com/osmosis-labs/cosmos-sdk/tree/osmo/v0.47.5, current branch: osmo/v0.47.5. Direct commit link: https://github.com/osmosis-labs/cosmos-sdk/commit/65d7acfdc2a94cc49837bb9abec462f129029540
// https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-v21-osmo-6
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.5-v21-osmo-6
github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.10
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

// newer versions of exp treat sorting differently, which is incompatible with the current version of cosmos-sdk
golang.org/x/exp => golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb

// fork of cometbft which allows for better app hash logging
github.com/cometbft/cometbft => github.com/osmosis-labs/cometbft v0.0.0-20240103055822-28da358e3146

// Local replaces commented for development
// github.com/osmosis-labs/osmosis/osmoutils => ../../osmoutils
// github.com/osmosis-labs/osmosis/v19 => ./../
Expand Down
15 changes: 15 additions & 0 deletions x/txfees/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/osmosis-labs/osmosis/v21/x/txfees/types"

storetypes "github.com/cosmos/cosmos-sdk/store/types"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
)

type Keeper struct {
Expand All @@ -21,6 +23,7 @@ type Keeper struct {
poolManager types.PoolManager
protorevKeeper types.ProtorevKeeper
distributionKeeper types.DistributionKeeper
consensusKeeper types.ConsensusKeeper
dataDir string
}

Expand All @@ -33,6 +36,7 @@ func NewKeeper(
poolManager types.PoolManager,
protorevKeeper types.ProtorevKeeper,
distributionKeeper types.DistributionKeeper,
consensusKeeper types.ConsensusKeeper,
dataDir string,
) Keeper {
return Keeper{
Expand All @@ -42,6 +46,7 @@ func NewKeeper(
poolManager: poolManager,
protorevKeeper: protorevKeeper,
distributionKeeper: distributionKeeper,
consensusKeeper: consensusKeeper,
dataDir: dataDir,
}
}
Expand All @@ -54,3 +59,13 @@ func (k Keeper) GetFeeTokensStore(ctx sdk.Context) sdk.KVStore {
store := ctx.KVStore(k.storeKey)
return prefix.NewStore(store, types.FeeTokensStorePrefix)
}

// GetParamsNoUnmarshal returns the current consensus parameters from the consensus params store as raw bytes.
func (k Keeper) GetParamsNoUnmarshal(ctx sdk.Context) []byte {
return k.consensusKeeper.GetParamsNoUnmarshal(ctx)
}

// UnmarshalParamBytes unmarshals the consensus params bytes to the consensus params type.
func (k Keeper) UnmarshalParamBytes(ctx sdk.Context, bz []byte) (*tmproto.ConsensusParams, error) {
return k.consensusKeeper.UnmarshalParamBytes(ctx, bz)
}
52 changes: 50 additions & 2 deletions x/txfees/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ only specify their tx fee parameters for a single "base" asset.
package txfees

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand All @@ -31,8 +32,9 @@ import (
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
cachedConsParamBytes []byte
)

const ModuleName = types.ModuleName
Expand Down Expand Up @@ -151,6 +153,10 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
// BeginBlock executes all ABCI BeginBlock logic respective to the txfees module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
mempool1559.BeginBlockCode(ctx)

// Check if the block gas limit has changed.
// If it has, update the target gas for eip1559.
am.CheckAndSetTargetGas(ctx)
}

// EndBlock executes all ABCI EndBlock logic respective to the txfees module. It
Expand All @@ -162,3 +168,45 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 1 }

// On start, we unmarshal the consensus params once and cache them.
// Then, on every block, we check if the current consensus param bytes have changed in comparison to the cached value.
// If they have, we unmarshal the current consensus params, update the target gas, and cache the value.
// This is done to improve performance by not having to fetch and unmarshal the consensus params on every block.
func (am AppModule) CheckAndSetTargetGas(ctx sdk.Context) {
// Check if the block gas limit has changed.
// If it has, update the target gas for eip1559.
consParamsBytes := am.keeper.GetParamsNoUnmarshal(ctx)

// If cachedConsParamBytes is nil, set equal to consParamsBytes and set the target gas.
if cachedConsParamBytes == nil {
cachedConsParamBytes = consParamsBytes
newConsensusParams, err := am.keeper.UnmarshalParamBytes(ctx, consParamsBytes)
if err != nil {
panic(err)
}

// Check if newConsensusParams.Block is nil to prevent panic
if newConsensusParams.Block == nil || newConsensusParams.Block.MaxGas == 0 {
return
}

newBlockMaxGas := newConsensusParams.Block.MaxGas
mempool1559.TargetGas = newBlockMaxGas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't right, it should be max gas times .625

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here d148048

return
}

// If the consensus params have changed, unmarshal and update the target gas.
if !bytes.Equal(consParamsBytes, cachedConsParamBytes) {
newConsensusParams, err := am.keeper.UnmarshalParamBytes(ctx, consParamsBytes)
if err != nil {
panic(err)
}

// Sure, its possible that the thing that changes in consensus params was something other than the block gas limit,
// but just double setting it here is fine instead of doing more logic to see what actually changed.
newBlockMaxGas := newConsensusParams.Block.MaxGas
mempool1559.TargetGas = newBlockMaxGas
cachedConsParamBytes = consParamsBytes
}
}
61 changes: 61 additions & 0 deletions x/txfees/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ package txfees_test
import (
"encoding/json"
"testing"
"time"

abci "github.com/cometbft/cometbft/abci/types"
abcitypes "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

osmosisapp "github.com/osmosis-labs/osmosis/v21/app"

simapp "github.com/osmosis-labs/osmosis/v21/app"
mempool1559 "github.com/osmosis-labs/osmosis/v21/x/txfees/keeper/mempool-1559"
)

func TestSetBaseDenomOnInitBlock(t *testing.T) {
Expand All @@ -38,3 +41,61 @@ func TestSetBaseDenomOnInitBlock(t *testing.T) {
require.Nil(t, err)
require.NotEmpty(t, baseDenom)
}

func TestBeginBlock(t *testing.T) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{ChainID: "osmosis-1", Height: 1})

genesisState := osmosisapp.GenesisStateWithValSet(app)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
panic(err)
}

app.InitChain(
abcitypes.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: sims.DefaultConsensusParams,
AppStateBytes: stateBytes,
ChainId: "osmosis-1",
},
)

// Begin block hasn't happened yet, target gas should be equal to hard coded default value
hardCodedGasTarget := int64(75_000_000)
require.Equal(t, hardCodedGasTarget, mempool1559.TargetGas)

// Run begin block
ctx = RunBeginBlock(ctx, app)

// Target gas should be updated to the value set in InitChain
defaultBlockMaxGas := sims.DefaultConsensusParams.Block.MaxGas
require.Equal(t, defaultBlockMaxGas, mempool1559.TargetGas)

// Run begin block again, should not update target gas
ctx = RunBeginBlock(ctx, app)
require.Equal(t, defaultBlockMaxGas, mempool1559.TargetGas)

// Update the consensus params
newDefaultBlockMaxGas := int64(300_000_000)
newConsensusParams := *sims.DefaultConsensusParams
newConsensusParams.Block.MaxGas = newDefaultBlockMaxGas
app.ConsensusParamsKeeper.Set(ctx, &newConsensusParams)

// Ensure that the consensus params have not been updated yet
require.Equal(t, defaultBlockMaxGas, mempool1559.TargetGas)

// Run begin block again, should update target gas
RunBeginBlock(ctx, app)
require.Equal(t, newDefaultBlockMaxGas, mempool1559.TargetGas)
}

func RunBeginBlock(ctx sdk.Context, app *simapp.OsmosisApp) sdk.Context {
oldHeight := ctx.BlockHeight()
oldHeader := ctx.BlockHeader()
app.Commit()
newHeader := tmproto.Header{Height: oldHeight + 1, ChainID: oldHeader.ChainID, Time: oldHeader.Time.Add(time.Second)}
app.BeginBlock(abci.RequestBeginBlock{Header: newHeader})
ctx = app.GetBaseApp().NewContext(false, newHeader)
return ctx
}
7 changes: 7 additions & 0 deletions x/txfees/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

"github.com/osmosis-labs/osmosis/osmomath"
poolmanagertypes "github.com/osmosis-labs/osmosis/v21/x/poolmanager/types"
)
Expand Down Expand Up @@ -87,3 +89,8 @@ type ProtorevKeeper interface {
type DistributionKeeper interface {
FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error
}

type ConsensusKeeper interface {
GetParamsNoUnmarshal(ctx sdk.Context) []byte
UnmarshalParamBytes(ctx sdk.Context, bz []byte) (*tmproto.ConsensusParams, error)
}