From 8308da5dba6de6d6e6e64f725ad7d00872a2a1f4 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 8 Jan 2024 12:48:52 -0700 Subject: [PATCH 1/9] eip target gas from consensus params --- app/keepers/keepers.go | 1 + go.mod | 6 ++-- go.sum | 4 +-- osmomath/go.mod | 6 ++-- osmoutils/go.mod | 6 ++-- x/epochs/go.mod | 6 ++-- x/ibc-hooks/go.mod | 6 ++-- x/txfees/keeper/keeper.go | 15 ++++++++++ x/txfees/module.go | 46 ++++++++++++++++++++++++++++-- x/txfees/types/expected_keepers.go | 7 +++++ 10 files changed, 84 insertions(+), 19 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index b8b05171b7b..79740100bca 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -403,6 +403,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers( appKeepers.GAMMKeeper, appKeepers.ProtoRevKeeper, appKeepers.DistrKeeper, + appKeepers.ConsensusParamsKeeper, dataDir, ) appKeepers.TxFeesKeeper = &txFeesKeeper diff --git a/go.mod b/go.mod index 01f32053aff..435ed73ff0b 100644 --- a/go.mod +++ b/go.mod @@ -382,9 +382,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 diff --git a/go.sum b/go.sum index bb75477ec57..6aff221ae2c 100644 --- a/go.sum +++ b/go.sum @@ -1461,8 +1461,8 @@ 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/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= diff --git a/osmomath/go.mod b/osmomath/go.mod index 071adae98cd..310c0e2004f 100644 --- a/osmomath/go.mod +++ b/osmomath/go.mod @@ -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 diff --git a/osmoutils/go.mod b/osmoutils/go.mod index 9cc5f41d62c..4ffed6fa8e7 100644 --- a/osmoutils/go.mod +++ b/osmoutils/go.mod @@ -166,9 +166,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 diff --git a/x/epochs/go.mod b/x/epochs/go.mod index 98f89b91b3c..cf379cd4596 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -199,9 +199,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 diff --git a/x/ibc-hooks/go.mod b/x/ibc-hooks/go.mod index 35c6fb51e36..4c5360995f8 100644 --- a/x/ibc-hooks/go.mod +++ b/x/ibc-hooks/go.mod @@ -198,9 +198,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 diff --git a/x/txfees/keeper/keeper.go b/x/txfees/keeper/keeper.go index f6d2b440127..1479b4d6f4f 100644 --- a/x/txfees/keeper/keeper.go +++ b/x/txfees/keeper/keeper.go @@ -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 { @@ -22,6 +24,7 @@ type Keeper struct { spotPriceCalculator types.SpotPriceCalculator protorevKeeper types.ProtorevKeeper distributionKeeper types.DistributionKeeper + consensusKeeper types.ConsensusKeeper dataDir string } @@ -35,6 +38,7 @@ func NewKeeper( spotPriceCalculator types.SpotPriceCalculator, protorevKeeper types.ProtorevKeeper, distributionKeeper types.DistributionKeeper, + consensusKeeper types.ConsensusKeeper, dataDir string, ) Keeper { return Keeper{ @@ -45,6 +49,7 @@ func NewKeeper( spotPriceCalculator: spotPriceCalculator, protorevKeeper: protorevKeeper, distributionKeeper: distributionKeeper, + consensusKeeper: consensusKeeper, dataDir: dataDir, } } @@ -57,3 +62,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) +} diff --git a/x/txfees/module.go b/x/txfees/module.go index 462d8d97812..6c24f455219 100644 --- a/x/txfees/module.go +++ b/x/txfees/module.go @@ -10,6 +10,7 @@ only specify their tx fee parameters for a single "base" asset. package txfees import ( + "bytes" "context" "encoding/json" "fmt" @@ -31,8 +32,9 @@ import ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + cachedConsParamBytes []byte ) const ModuleName = types.ModuleName @@ -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 @@ -162,3 +168,39 @@ 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) + } + newBlockMaxGas := newConsensusParams.Block.MaxGas + mempool1559.TargetGas = newBlockMaxGas + 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 + } +} diff --git a/x/txfees/types/expected_keepers.go b/x/txfees/types/expected_keepers.go index 9e1634ec94c..f1b3219c423 100644 --- a/x/txfees/types/expected_keepers.go +++ b/x/txfees/types/expected_keepers.go @@ -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" ) @@ -80,3 +82,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) +} From a3cac03e7a1c31172c60d6f66270b86645b44d68 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 8 Jan 2024 12:50:21 -0700 Subject: [PATCH 2/9] changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfc1b521d35..ecdaf8b8238 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 From 63a4a4c8e7a9615c4d1ac27101dd87472a4a9c50 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 8 Jan 2024 12:59:44 -0700 Subject: [PATCH 3/9] add comet replace --- go.mod | 3 +++ go.sum | 4 ++-- osmoutils/go.mod | 3 +++ x/epochs/go.mod | 3 +++ x/ibc-hooks/go.mod | 3 +++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 435ed73ff0b..ef3cd2d5812 100644 --- a/go.mod +++ b/go.mod @@ -379,6 +379,9 @@ 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 diff --git a/go.sum b/go.sum index 6aff221ae2c..ac2fc4f3ec4 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -1461,6 +1459,8 @@ 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/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= diff --git a/osmoutils/go.mod b/osmoutils/go.mod index 4ffed6fa8e7..5540c2cc59f 100644 --- a/osmoutils/go.mod +++ b/osmoutils/go.mod @@ -175,6 +175,9 @@ replace ( // 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 => ./../ diff --git a/x/epochs/go.mod b/x/epochs/go.mod index cf379cd4596..ff439c61dcf 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -208,6 +208,9 @@ replace ( // 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 ) diff --git a/x/ibc-hooks/go.mod b/x/ibc-hooks/go.mod index 4c5360995f8..3cbbb615429 100644 --- a/x/ibc-hooks/go.mod +++ b/x/ibc-hooks/go.mod @@ -207,6 +207,9 @@ replace ( // 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 => ./../ From f6832ce69a44cd1facbb6d7133b7472ae5ac58cb Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 8 Jan 2024 13:37:13 -0700 Subject: [PATCH 4/9] test maxGas override --- x/txfees/module_test.go | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/x/txfees/module_test.go b/x/txfees/module_test.go index 1e33838057b..250ef732131 100644 --- a/x/txfees/module_test.go +++ b/x/txfees/module_test.go @@ -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) { @@ -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 +} From 4df6ee2fb742e0746b6c40c670496c9f4550842d Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 8 Jan 2024 14:04:18 -0700 Subject: [PATCH 5/9] prevent panics --- x/txfees/module.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x/txfees/module.go b/x/txfees/module.go index 6c24f455219..6b7c2ee63c3 100644 --- a/x/txfees/module.go +++ b/x/txfees/module.go @@ -185,6 +185,12 @@ func (am AppModule) CheckAndSetTargetGas(ctx sdk.Context) { 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 return From d148048eb9fbc70814d843236240e73f30787ebd Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 8 Jan 2024 16:58:38 -0700 Subject: [PATCH 6/9] target block space percent --- x/txfees/keeper/mempool-1559/code.go | 5 +++-- x/txfees/module.go | 2 +- x/txfees/module_test.go | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/x/txfees/keeper/mempool-1559/code.go b/x/txfees/keeper/mempool-1559/code.go index 53089173da8..0d1d8ba4043 100644 --- a/x/txfees/keeper/mempool-1559/code.go +++ b/x/txfees/keeper/mempool-1559/code.go @@ -47,8 +47,9 @@ var ( // Max increase per block is a factor of 1.06, max decrease is 9/10 // If recovering at ~30M gas per block, decrease is .94 - MaxBlockChangeRate = sdk.NewDec(1).Quo(sdk.NewDec(10)) - TargetGas = int64(75_000_000) + MaxBlockChangeRate = sdk.NewDec(1).Quo(sdk.NewDec(10)) + TargetGas = int64(187_500_000) + TargetBlockSpacePercent = sdk.MustNewDecFromStr("0.625") // In face of continuous spam, will take ~19 blocks from base fee > spam cost, to mempool eviction // ceil(log_{1.06}(RecheckFeeConstant)) // So potentially 1.8 minutes of impaired UX from 1559 nodes on top of time to get to base fee > spam. diff --git a/x/txfees/module.go b/x/txfees/module.go index 6b7c2ee63c3..88dd648c393 100644 --- a/x/txfees/module.go +++ b/x/txfees/module.go @@ -191,7 +191,7 @@ func (am AppModule) CheckAndSetTargetGas(ctx sdk.Context) { return } - newBlockMaxGas := newConsensusParams.Block.MaxGas + newBlockMaxGas := mempool1559.TargetBlockSpacePercent.Mul(sdk.NewDec(newConsensusParams.Block.MaxGas)).TruncateInt().Int64() mempool1559.TargetGas = newBlockMaxGas return } diff --git a/x/txfees/module_test.go b/x/txfees/module_test.go index 250ef732131..f6d9e2645aa 100644 --- a/x/txfees/module_test.go +++ b/x/txfees/module_test.go @@ -62,19 +62,19 @@ func TestBeginBlock(t *testing.T) { ) // Begin block hasn't happened yet, target gas should be equal to hard coded default value - hardCodedGasTarget := int64(75_000_000) + hardCodedGasTarget := int64(187_500_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) + defaultBlockTargetGas := mempool1559.TargetBlockSpacePercent.Mul(sdk.NewDec(sims.DefaultConsensusParams.Block.MaxGas)).TruncateInt().Int64() + require.Equal(t, defaultBlockTargetGas, mempool1559.TargetGas) // Run begin block again, should not update target gas ctx = RunBeginBlock(ctx, app) - require.Equal(t, defaultBlockMaxGas, mempool1559.TargetGas) + require.Equal(t, defaultBlockTargetGas, mempool1559.TargetGas) // Update the consensus params newDefaultBlockMaxGas := int64(300_000_000) @@ -83,7 +83,7 @@ func TestBeginBlock(t *testing.T) { app.ConsensusParamsKeeper.Set(ctx, &newConsensusParams) // Ensure that the consensus params have not been updated yet - require.Equal(t, defaultBlockMaxGas, mempool1559.TargetGas) + require.Equal(t, defaultBlockTargetGas, mempool1559.TargetGas) // Run begin block again, should update target gas RunBeginBlock(ctx, app) From f9fbf18cf751fa4db9fcd936d75c0b51b63db2a4 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 8 Jan 2024 18:56:00 -0700 Subject: [PATCH 7/9] handle -1 case --- x/txfees/module.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/x/txfees/module.go b/x/txfees/module.go index 88dd648c393..2a8a23f023d 100644 --- a/x/txfees/module.go +++ b/x/txfees/module.go @@ -191,6 +191,10 @@ func (am AppModule) CheckAndSetTargetGas(ctx sdk.Context) { return } + if newConsensusParams.Block.MaxGas == -1 { + return + } + newBlockMaxGas := mempool1559.TargetBlockSpacePercent.Mul(sdk.NewDec(newConsensusParams.Block.MaxGas)).TruncateInt().Int64() mempool1559.TargetGas = newBlockMaxGas return @@ -203,9 +207,13 @@ func (am AppModule) CheckAndSetTargetGas(ctx sdk.Context) { panic(err) } + if newConsensusParams.Block.MaxGas == -1 { + return + } + // 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 + newBlockMaxGas := mempool1559.TargetBlockSpacePercent.Mul(sdk.NewDec(newConsensusParams.Block.MaxGas)).TruncateInt().Int64() mempool1559.TargetGas = newBlockMaxGas cachedConsParamBytes = consParamsBytes } From b08c639813942558c9a29dd5d1decd139d00ebe2 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 8 Jan 2024 18:57:17 -0700 Subject: [PATCH 8/9] fix test --- x/txfees/module_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/txfees/module_test.go b/x/txfees/module_test.go index f6d9e2645aa..28d32dfe528 100644 --- a/x/txfees/module_test.go +++ b/x/txfees/module_test.go @@ -87,7 +87,8 @@ func TestBeginBlock(t *testing.T) { // Run begin block again, should update target gas RunBeginBlock(ctx, app) - require.Equal(t, newDefaultBlockMaxGas, mempool1559.TargetGas) + expectedNewBlockTargetGas := mempool1559.TargetBlockSpacePercent.Mul(sdk.NewDec(newDefaultBlockMaxGas)).TruncateInt().Int64() + require.Equal(t, expectedNewBlockTargetGas, mempool1559.TargetGas) } func RunBeginBlock(ctx sdk.Context, app *simapp.OsmosisApp) sdk.Context { From a986310d32c3032828a472b44a365e497e13215c Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 8 Jan 2024 19:04:55 -0700 Subject: [PATCH 9/9] fix main --- x/ibc-hooks/go.mod | 3 --- 1 file changed, 3 deletions(-) diff --git a/x/ibc-hooks/go.mod b/x/ibc-hooks/go.mod index 06fe37ee226..95b1c5d9b16 100644 --- a/x/ibc-hooks/go.mod +++ b/x/ibc-hooks/go.mod @@ -195,9 +195,6 @@ replace ( // adds expedited proposal support and 1000MB cache default // 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 - // 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 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1