From c5a51475b27888e203f60cae369533c480cba7ac Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Fri, 29 Dec 2023 21:07:13 -0600 Subject: [PATCH] chore: catch up main to v21.1.x (#7215) * Reduce discrepancy in fee simulation * Update * State compatible applyFuncIfNoError event reduction * Update osmoutils/epochs versions * Update SDK version * One more epoch speedup * Speedup core loop of epoch * fix test (#7197) * refactor: auto-set timeout-commit to 4s for faster block times (#7196) * updates (#7192) * refactor: auto-set timeout-commit to 4s for faster block times (backport #7180) * changelog * Revert "updates (#7192)" This reverts commit 6cc26f91b9fcc2f890aaad6fb07b13f31e45c7f9. * lint * Update changelog * Update changelog * changelog * Speedup multiplication * Try scratch slice * refactor: arb filter for new authz exec swap (#7210) * refactor: arb filter for new authz exec swap * updates * updates * updates * clean up * Auto: update go.mod after push to adam/v21.1.x-merge-to-main that modified dependencies locally * add 21.1.5 to changelog * update comment --------- Co-authored-by: Dev Ojha Co-authored-by: Roman Co-authored-by: github-actions --- CHANGELOG.md | 33 +++++- go.mod | 14 +-- go.sum | 20 ++-- osmomath/go.mod | 6 +- osmomath/go.sum | 4 +- osmoutils/cache_ctx.go | 27 +++++ osmoutils/go.mod | 6 +- tests/cl-genesis-positions/go.mod | 6 +- tests/cl-go-client/go.mod | 6 +- x/epochs/go.mod | 6 +- x/epochs/types/hooks.go | 2 +- x/epochs/types/hooks_test.go | 4 +- x/ibc-hooks/go.mod | 6 +- x/incentives/keeper/distribute.go | 28 +++-- x/incentives/keeper/iterator.go | 5 +- x/incentives/keeper/iterator_test.go | 3 +- x/superfluid/keeper/epoch.go | 6 +- x/txfees/keeper/feedecorator.go | 20 +++- x/txfees/keeper/feedecorator_test.go | 3 + x/txfees/keeper/txfee_filters/arb_tx.go | 108 +++++++++++++++++-- x/txfees/keeper/txfee_filters/arb_tx_test.go | 30 ++++++ 21 files changed, 271 insertions(+), 72 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e30e43a4d72..b3bb8655f3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,23 +42,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased -### Config - -* [#7180](https://github.com/osmosis-labs/osmosis/pull/7180) Change `consensus.timeout-commit` from 5s to 4s in `config.toml`. Overwrites the existing value on start-up. Default is set to 4s. - ### API * [#6991](https://github.com/osmosis-labs/osmosis/pull/6991) Fix: total liquidity poolmanager grpc gateway query * [#7149](https://github.com/osmosis-labs/osmosis/pull/7149) Fix double emitting CacheCtx events (e.g. Epoch, Superfluid, CL) ### Features -* [#6804](https://github.com/osmosis-labs/osmosis/pull/6993) feat(math): add mutative api for BigDec.BigInt() + +* [#6993](https://github.com/osmosis-labs/osmosis/pull/6993) feat(math): add mutative api for BigDec.BigInt() ### Misc Improvements + * [#7106](https://github.com/osmosis-labs/osmosis/pull/7106) Halve the time of log2 calculation (speeds up TWAP code) * [#7093](https://github.com/osmosis-labs/osmosis/pull/7093),[#7100](https://github.com/osmosis-labs/osmosis/pull/7100),[#7172](https://github.com/osmosis-labs/osmosis/pull/7172) Lower CPU overheads of the Osmosis epoch. * [#7203](https://github.com/osmosis-labs/osmosis/pull/7203) Make a maximum number of pools of 100 billion. +## v21.1.5 + +* [#7210](https://github.com/osmosis-labs/osmosis/pull/7210) Arb filter for new authz exec swap. + +## v21.1.4 + +* [#7180](https://github.com/osmosis-labs/osmosis/pull/7180) Change `consensus.timeout-commit` from 5s to 4s in `config.toml`. Overwrites the existing value on start-up. Default is set to 4s. + +## v21.1.3 + +Epoch and CPU time optimizations + +* [#7093](https://github.com/osmosis-labs/osmosis/pull/7093),[#7100](https://github.com/osmosis-labs/osmosis/pull/7100),[#7172](https://github.com/osmosis-labs/osmosis/pull/7172),[#7174](https://github.com/osmosis-labs/osmosis/pull/7174),[#7186](https://github.com/osmosis-labs/osmosis/pull/7186), [#7192](https://github.com/osmosis-labs/osmosis/pull/7192) Lower CPU overheads of the Osmosis epoch. +* [#7106](https://github.com/osmosis-labs/osmosis/pull/7106) Halve the time of log2 calculation (speeds up TWAP code) + +## v21.1.2 + +* [#7170](https://github.com/osmosis-labs/osmosis/pull/7170) Update mempool-eip1559 params to cause less base fee spikes on mainnet. +* [#7093](https://github.com/osmosis-labs/osmosis/pull/7093),[#7100](https://github.com/osmosis-labs/osmosis/pull/7100),[#7172](https://github.com/osmosis-labs/osmosis/pull/7172),[#7174](https://github.com/osmosis-labs/osmosis/pull/7174),[#7186](https://github.com/osmosis-labs/osmosis/pull/7186), [#7192](https://github.com/osmosis-labs/osmosis/pull/7186) Lower CPU overheads of the Osmosis epoch. +* [#7106](https://github.com/osmosis-labs/osmosis/pull/7106) Halve the time of log2 calculation (speeds up TWAP code) + +## v21.1.1 + +Epoch optimizations are in this release, see a subset of PR links in v21.1.3 section. + ## v21.0.0 ### API diff --git a/go.mod b/go.mod index 0c7cb2fa727..f5afbfa8d38 100644 --- a/go.mod +++ b/go.mod @@ -29,10 +29,10 @@ require ( github.com/mattn/go-sqlite3 v1.14.17 github.com/ory/dockertest/v3 v3.10.0 github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 - github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231215070550-ca294af82738 - github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231211161501-28475581c846 - github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20231211161501-28475581c846 - github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.9-0.20231211161501-28475581c846 + github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231229191315-aff18520757d + github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231229191315-aff18520757d + github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20231229191315-aff18520757d + github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.9-0.20231229191315-aff18520757d github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 github.com/redis/go-redis/v9 v9.3.0 @@ -383,9 +383,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/15259ccd2249d2f3f413e0de7b8e27fe4cc6169a - // https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-osmo - github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.5-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.5-osmo-4 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 5ef7b949245..e79335334b7 100644 --- a/go.sum +++ b/go.sum @@ -1462,18 +1462,18 @@ 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.5-osmo h1:Nud33/nOZvkVguLS3IwKR0vgz/0jEOixHxHnXF7eDvE= -github.com/osmosis-labs/cosmos-sdk v0.47.5-osmo/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c= +github.com/osmosis-labs/cosmos-sdk v0.47.5-osmo-4 h1:RCd53Gnnn9yrjjdh8sBkhitqTz/dHEvwkEqs12Y0ELU= +github.com/osmosis-labs/cosmos-sdk v0.47.5-osmo-4/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c= 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.20231215070550-ca294af82738 h1:60wdzrarvo9BlI7R5aCIEpOAThDpsr/aVJe68aEayVw= -github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231215070550-ca294af82738/go.mod h1:FQ45vPTc2l+NUA/gk7wZTxUh/hrDRWrRwZj8Ua5cpSU= -github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231211161501-28475581c846 h1:+xo3n7+SwSiH0VZSYSSHWPkXx8XD/l01OnTEfYafAFw= -github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231211161501-28475581c846/go.mod h1:BsZRNH2ypxCdG8VObfFzbzjSflX5umvCziyBTAS9Ftw= -github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20231211161501-28475581c846 h1:ZnZKvZGVcirtNYZ+nk+qr0GO4ljxGe/z7X5+7+UklsM= -github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20231211161501-28475581c846/go.mod h1:lFy4X89dA7UUm+//XXTtIfJnq/zxkqIUOwxdMx+HD5k= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.9-0.20231211161501-28475581c846 h1:/phDqythG9OvuobKmEkeHHRHGjhEl/AIc4YQYM372xw= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.9-0.20231211161501-28475581c846/go.mod h1:7BvLeObF9vnhXU/iGOxCKA6n/dGRLojBYMQwqXbO80E= +github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231229191315-aff18520757d h1:/vmj70Yv4D4PbPmNxLRxj80aVmHllT0UD4ThvjbRChA= +github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231229191315-aff18520757d/go.mod h1:CfSV2Zn8fYu+Jwv1zNhb45dbG4O79cZ/VM3ey79+Xq8= +github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231229191315-aff18520757d h1:VKMEmZBVt6VrrjBA9dMsxqWJlbrzqbMXX69iOjuevRc= +github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231229191315-aff18520757d/go.mod h1:Jg/goBqOHnJSr4qgDLtVC88eU7MgtLhyc5+plNEj1Ag= +github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20231229191315-aff18520757d h1:hEwBZm3JibS2RSZat6YQ68RF6ocL1zxdbNgN7viM8K8= +github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20231229191315-aff18520757d/go.mod h1:1SJlKmf6tgG0fto/vKK/o07gV5zar/XEn9s9HzyFuoY= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.9-0.20231229191315-aff18520757d h1:0+gAf1ls/qfyPD57g0lNKJuUeGgSot/lC8XkRdaCQyw= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.9-0.20231229191315-aff18520757d/go.mod h1:k0KAmphBh45V/5ISLaoqRLLKbF2DPH+Uy7J6apdfT4w= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= github.com/osmosis-labs/wasmd v0.45.0-osmo/go.mod h1:J6eRvwii5T1WxhetZkBg1kOJS3GTn1Bw2OLyZBb8EVU= github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw= diff --git a/osmomath/go.mod b/osmomath/go.mod index 39dbbb1c4c4..078a670d2c4 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/15259ccd2249d2f3f413e0de7b8e27fe4cc6169a - // https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-osmo - github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.5-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.5-osmo-4 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 diff --git a/osmomath/go.sum b/osmomath/go.sum index 3c0e9c4abb9..00e00a08ac5 100644 --- a/osmomath/go.sum +++ b/osmomath/go.sum @@ -286,8 +286,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= -github.com/osmosis-labs/cosmos-sdk v0.47.6-0.20231124185741-15259ccd2249 h1:WXgQVDkydvC/5a2F/QJ7tTcsb1AsULqsX8e9BdgGROE= -github.com/osmosis-labs/cosmos-sdk v0.47.6-0.20231124185741-15259ccd2249/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c= +github.com/osmosis-labs/cosmos-sdk v0.47.6-0.20231221164451-f7c8120bc8d5 h1:RrzcJZgG5ruPKxPjwVdk+MFGZpeg6WRMMgSDgBNytiM= +github.com/osmosis-labs/cosmos-sdk v0.47.6-0.20231221164451-f7c8120bc8d5/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230911115719-1d5a34978fe1 h1:mQlIqW3xBc7XOyDUqrqsPf47hQBrja9iKi4aRBUq3ws= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230911115719-1d5a34978fe1/go.mod h1:7VoXHwrSSx8Sii0UFc9YIixF6C/9XfV1pdU2Dliu4WA= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= diff --git a/osmoutils/cache_ctx.go b/osmoutils/cache_ctx.go index b5653ae305e..71a178e2ca3 100644 --- a/osmoutils/cache_ctx.go +++ b/osmoutils/cache_ctx.go @@ -42,6 +42,33 @@ func ApplyFuncIfNoError(ctx sdk.Context, f func(ctx sdk.Context) error) (err err return err } +// This function only exists because somehow events are edge-case gas metered. +// TODO: This should become ApplyFuncIfNoError next upgrade. +func UnmeteredApplyFuncIfNoError(ctx sdk.Context, f func(ctx sdk.Context) error) (err error) { + // Add a panic safeguard + defer func() { + if recoveryError := recover(); recoveryError != nil { + if isErr, _ := IsOutOfGasError(recoveryError); isErr { + // We panic with the same error, to replicate the normal tx execution flow. + panic(recoveryError) + } else { + PrintPanicRecoveryError(ctx, recoveryError) + err = errors.New("panic occurred during execution") + } + } + }() + // makes a new cache context, which all state changes get wrapped inside of. + cacheCtx, write := ctx.CacheContext() + err = f(cacheCtx) + if err != nil { + ctx.Logger().Error(err.Error()) + } else { + // no error, write the output of f + write() + } + return err +} + // Frustratingly, this has to return the error descriptor, not an actual error itself // because the SDK errors here are not actually errors. (They don't implement error interface) func IsOutOfGasError(err any) (bool, string) { diff --git a/osmoutils/go.mod b/osmoutils/go.mod index c56d4b8daf1..7425a356de9 100644 --- a/osmoutils/go.mod +++ b/osmoutils/go.mod @@ -158,9 +158,9 @@ require ( ) replace ( - // 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/15259ccd2249d2f3f413e0de7b8e27fe4cc6169a - // https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-osmo - github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.5-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.5-osmo-4 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 diff --git a/tests/cl-genesis-positions/go.mod b/tests/cl-genesis-positions/go.mod index cbd8b383bd8..039daa13ee3 100644 --- a/tests/cl-genesis-positions/go.mod +++ b/tests/cl-genesis-positions/go.mod @@ -197,9 +197,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/15259ccd2249d2f3f413e0de7b8e27fe4cc6169a - // https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-osmo - github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.5-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.5-osmo-4 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/tests/cl-go-client/go.mod b/tests/cl-go-client/go.mod index 778206c6abc..0d8777b5ab4 100644 --- a/tests/cl-go-client/go.mod +++ b/tests/cl-go-client/go.mod @@ -171,9 +171,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/15259ccd2249d2f3f413e0de7b8e27fe4cc6169a - // https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-osmo - github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.5-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.5-osmo-4 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 44b2fd10084..b6df7c202d1 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -190,9 +190,9 @@ require ( ) replace ( - // 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/15259ccd2249d2f3f413e0de7b8e27fe4cc6169a - // https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-osmo - github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.5-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.5-osmo-4 // 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 diff --git a/x/epochs/types/hooks.go b/x/epochs/types/hooks.go index ad9e456a25b..2212a66b036 100644 --- a/x/epochs/types/hooks.go +++ b/x/epochs/types/hooks.go @@ -50,7 +50,7 @@ func panicCatchingEpochHook( return hookFn(ctx, epochIdentifier, epochNumber) } // TODO: Thread info for which hook this is, may be dependent on larger hook system refactoring - err := osmoutils.ApplyFuncIfNoError(ctx, wrappedHookFn) + err := osmoutils.UnmeteredApplyFuncIfNoError(ctx, wrappedHookFn) if err != nil { ctx.Logger().Error(fmt.Sprintf("error in epoch hook %v", err)) } diff --git a/x/epochs/types/hooks_test.go b/x/epochs/types/hooks_test.go index da6d5d2c7d0..fb2ec23754b 100644 --- a/x/epochs/types/hooks_test.go +++ b/x/epochs/types/hooks_test.go @@ -95,10 +95,10 @@ func (s *KeeperTestSuite) TestHooksPanicRecovery() { expectedCounterValues []int lenEvents int }{ - {[]dummyEpochHook{noPanicHook}, []int{1}, 2}, + {[]dummyEpochHook{noPanicHook}, []int{1}, 1}, {[]dummyEpochHook{panicHook}, []int{0}, 0}, {[]dummyEpochHook{errorHook}, []int{0}, 0}, - {simpleHooks, []int{0, 1, 0, 1}, 4}, + {simpleHooks, []int{0, 1, 0, 1}, 2}, } for tcIndex, tc := range tests { diff --git a/x/ibc-hooks/go.mod b/x/ibc-hooks/go.mod index c99ca05f49e..b1cbf9775ca 100644 --- a/x/ibc-hooks/go.mod +++ b/x/ibc-hooks/go.mod @@ -191,9 +191,9 @@ require ( ) replace ( - // 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/15259ccd2249d2f3f413e0de7b8e27fe4cc6169a - // https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-osmo - github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.47.5-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.5-osmo-4 // 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 diff --git a/x/incentives/keeper/distribute.go b/x/incentives/keeper/distribute.go index 68a6b4a8f9b..f43801f8b2b 100644 --- a/x/incentives/keeper/distribute.go +++ b/x/incentives/keeper/distribute.go @@ -3,6 +3,7 @@ package keeper import ( "errors" "fmt" + "math/big" "time" db "github.com/cometbft/cometbft-db" @@ -14,6 +15,8 @@ import ( "github.com/osmosis-labs/osmosis/v21/x/incentives/types" lockuptypes "github.com/osmosis-labs/osmosis/v21/x/lockup/types" poolmanagertypes "github.com/osmosis-labs/osmosis/v21/x/poolmanager/types" + + sdkmath "cosmossdk.io/math" ) var ( @@ -670,13 +673,15 @@ func (k Keeper) distributeInternal( // too expensive + verbose even in debug mode. // ctx.Logger().Debug("distributeInternal, distribute to lock", "module", types.ModuleName, "gaugeId", gauge.Id, "lockId", lock.ID, "remainCons", remainCoins, "height", ctx.BlockHeight()) - denomLockAmt := guaranteedNonzeroCoinAmountOf(lock.Coins, denom) + denomLockAmt := guaranteedNonzeroCoinAmountOf(lock.Coins, denom).BigIntMut() for _, coin := range remainCoins { - // distribution amount = gauge_size * denom_lock_amount / (total_denom_lock_amount * remain_epochs) - amtInt := coin.Amount.Mul(denomLockAmt) + amtInt := sdkmath.NewIntFromBigInt(denomLockAmt) amtIntBi := amtInt.BigIntMut() + // distribution amount = gauge_size * denom_lock_amount / (total_denom_lock_amount * remain_epochs) + amtIntBi = amtIntBi.Mul(amtIntBi, coin.Amount.BigIntMut()) + checkBigInt(amtIntBi) amtIntBi.Quo(amtIntBi, lockSumTimesRemainingEpochsBi) - if amtInt.IsPositive() { + if amtInt.Sign() == 1 { newlyDistributedCoin := sdk.Coin{Denom: coin.Denom, Amount: amtInt} distrCoins = distrCoins.Add(newlyDistributedCoin) } @@ -708,8 +713,14 @@ func (k Keeper) distributeInternal( return totalDistrCoins, err } +func checkBigInt(bi *big.Int) { + if bi.BitLen() > sdkmath.MaxBitLen { + panic("overflow") + } +} + // faster coins.AmountOf if we know that coins must contain the denom. -// returns a new sdk int that can be mutated. +// returns a new big int that can be mutated. func guaranteedNonzeroCoinAmountOf(coins sdk.Coins, denom string) osmomath.Int { if coins.Len() == 1 { return coins[0].Amount @@ -762,7 +773,7 @@ func (k Keeper) handleGroupPostDistribute(ctx sdk.Context, groupGauge types.Gaug } // getDistributeToBaseLocks takes a gauge along with cached period locks by denom and returns locks that must be distributed to -func (k Keeper) getDistributeToBaseLocks(ctx sdk.Context, gauge types.Gauge, cache map[string][]lockuptypes.PeriodLock) []*lockuptypes.PeriodLock { +func (k Keeper) getDistributeToBaseLocks(ctx sdk.Context, gauge types.Gauge, cache map[string][]lockuptypes.PeriodLock, scratchSlice *[]*lockuptypes.PeriodLock) []*lockuptypes.PeriodLock { // if gauge is empty, don't get the locks if gauge.Coins.Empty() { return []*lockuptypes.PeriodLock{} @@ -777,7 +788,7 @@ func (k Keeper) getDistributeToBaseLocks(ctx sdk.Context, gauge types.Gauge, cac // get this from memory instead of hitting iterators / underlying stores. // due to many details of cacheKVStore, iteration will still cause expensive IAVL reads. allLocks := cache[distributeBaseDenom] - return FilterLocksByMinDuration(allLocks, gauge.DistributeTo.Duration) + return FilterLocksByMinDuration(allLocks, gauge.DistributeTo.Duration, scratchSlice) } // Distribute distributes coins from an array of gauges to all eligible locks and pools in the case of "NoLock" gauges. @@ -788,10 +799,11 @@ func (k Keeper) Distribute(ctx sdk.Context, gauges []types.Gauge) (sdk.Coins, er locksByDenomCache := make(map[string][]lockuptypes.PeriodLock) totalDistributedCoins := sdk.NewCoins() + scratchSlice := make([]*lockuptypes.PeriodLock, 0, 10000) for _, gauge := range gauges { var gaugeDistributedCoins sdk.Coins - filteredLocks := k.getDistributeToBaseLocks(ctx, gauge, locksByDenomCache) + filteredLocks := k.getDistributeToBaseLocks(ctx, gauge, locksByDenomCache, &scratchSlice) // send based on synthetic lockup coins if it's distributing to synthetic lockups var err error if lockuptypes.IsSyntheticDenom(gauge.DistributeTo.Denom) { diff --git a/x/incentives/keeper/iterator.go b/x/incentives/keeper/iterator.go index 649fca91c68..c88816df68b 100644 --- a/x/incentives/keeper/iterator.go +++ b/x/incentives/keeper/iterator.go @@ -63,8 +63,9 @@ func (k Keeper) FinishedGaugesIterator(ctx sdk.Context) sdk.Iterator { } // FilterLocksByMinDuration returns locks whose lock duration is greater than the provided minimum duration. -func FilterLocksByMinDuration(locks []lockuptypes.PeriodLock, minDuration time.Duration) []*lockuptypes.PeriodLock { - filteredLocks := make([]*lockuptypes.PeriodLock, 0, len(locks)) +func FilterLocksByMinDuration(locks []lockuptypes.PeriodLock, minDuration time.Duration, scratchSlice *[]*lockuptypes.PeriodLock) []*lockuptypes.PeriodLock { + *scratchSlice = (*scratchSlice)[:0] + filteredLocks := *scratchSlice for i := range locks { if locks[i].Duration >= minDuration { filteredLocks = append(filteredLocks, &locks[i]) diff --git a/x/incentives/keeper/iterator_test.go b/x/incentives/keeper/iterator_test.go index fe008a80c13..0b5de60ff53 100644 --- a/x/incentives/keeper/iterator_test.go +++ b/x/incentives/keeper/iterator_test.go @@ -27,7 +27,8 @@ func TestFilterLocksByMinDuration(t *testing.T) { } } - filteredLocks := keeper.FilterLocksByMinDuration(locks, minDuration) + scratchSlice := []*lockuptypes.PeriodLock{} + filteredLocks := keeper.FilterLocksByMinDuration(locks, minDuration, &scratchSlice) require.Equal(t, len(locks), len(filteredLocks)) diff --git a/x/superfluid/keeper/epoch.go b/x/superfluid/keeper/epoch.go index 0bd9bfcc100..503847ac721 100644 --- a/x/superfluid/keeper/epoch.go +++ b/x/superfluid/keeper/epoch.go @@ -33,7 +33,7 @@ func (k Keeper) AfterEpochStartBeginBlock(ctx sdk.Context) { ctx.Logger().Info("Distribute Superfluid gauges") //nolint:errcheck - osmoutils.ApplyFuncIfNoError(ctx, func(cacheCtx sdk.Context) error { + osmoutils.UnmeteredApplyFuncIfNoError(ctx, func(cacheCtx sdk.Context) error { k.distributeSuperfluidGauges(cacheCtx) return nil }) @@ -70,7 +70,7 @@ func (k Keeper) MoveSuperfluidDelegationRewardToGauges(ctx sdk.Context) { // To avoid unexpected issues on WithdrawDelegationRewards and AddToGaugeRewards // we use cacheCtx and apply the changes later - _ = osmoutils.ApplyFuncIfNoError(ctx, func(cacheCtx sdk.Context) error { + _ = osmoutils.UnmeteredApplyFuncIfNoError(ctx, func(cacheCtx sdk.Context) error { _, err := k.ck.WithdrawDelegationRewards(cacheCtx, addr, valAddr) if errors.Is(err, distributiontypes.ErrEmptyDelegationDistInfo) { ctx.Logger().Debug("no swaps occurred in this pool between last epoch and this epoch") @@ -80,7 +80,7 @@ func (k Keeper) MoveSuperfluidDelegationRewardToGauges(ctx sdk.Context) { }) // Send delegation rewards to gauges - _ = osmoutils.ApplyFuncIfNoError(ctx, func(cacheCtx sdk.Context) error { + _ = osmoutils.UnmeteredApplyFuncIfNoError(ctx, func(cacheCtx sdk.Context) error { // Note! We only send the bond denom (osmo), to avoid attack vectors where people // send many different denoms to the intermediary account, and make a resource exhaustion attack on end block. bondDenom := k.sk.BondDenom(cacheCtx) diff --git a/x/txfees/keeper/feedecorator.go b/x/txfees/keeper/feedecorator.go index 680e27e60c0..68075e8d2cd 100644 --- a/x/txfees/keeper/feedecorator.go +++ b/x/txfees/keeper/feedecorator.go @@ -244,16 +244,30 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo return ctx, errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "fee payer address: %s does not exist", deductFeesFrom) } + fees := feeTx.GetFee() + + // if we are simulating, set the fees to 1 uosmo as they don't matter. + // set it as coming from the burn addr + if simulate && fees.IsZero() { + fees = sdk.NewCoins(sdk.NewInt64Coin("uosmo", 1)) + burnAcctAddr, _ := sdk.AccAddressFromBech32("osmo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmcn030") + // were doing 1 extra get account call alas + burnAcct := dfd.ak.GetAccount(ctx, burnAcctAddr) + if burnAcct != nil { + deductFeesFromAcc = burnAcct + } + } + // deducts the fees and transfer them to the module account - if !feeTx.GetFee().IsZero() { - err = DeductFees(dfd.txFeesKeeper, dfd.bankKeeper, ctx, deductFeesFromAcc, feeTx.GetFee()) + if !fees.IsZero() { + err = DeductFees(dfd.txFeesKeeper, dfd.bankKeeper, ctx, deductFeesFromAcc, fees) if err != nil { return ctx, err } } ctx.EventManager().EmitEvents(sdk.Events{sdk.NewEvent(sdk.EventTypeTx, - sdk.NewAttribute(sdk.AttributeKeyFee, feeTx.GetFee().String()), + sdk.NewAttribute(sdk.AttributeKeyFee, fees.String()), )}) return next(ctx, tx, simulate) diff --git a/x/txfees/keeper/feedecorator_test.go b/x/txfees/keeper/feedecorator_test.go index 07b5a3ce8ea..e2918040577 100644 --- a/x/txfees/keeper/feedecorator_test.go +++ b/x/txfees/keeper/feedecorator_test.go @@ -146,6 +146,9 @@ func (s *KeeperTestSuite) TestFeeDecorator() { // reset pool and accounts for each test s.SetupTest(false) s.Run(tc.name, func() { + // See DeductFeeDecorator AnteHandler for how this is used + s.FundAcc(sdk.MustAccAddressFromBech32("osmo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmcn030"), sdk.NewCoins(sdk.NewInt64Coin("uosmo", 1))) + preFeeDecoratorTxFeeTrackerValue := s.App.TxFeesKeeper.GetTxFeesTrackerValue(s.Ctx) err := s.SetupTxFeeAnteHandlerAndChargeFee(s.clientCtx, tc.minGasPrices, tc.gasRequested, tc.isCheckTx, tc.isSimulate, tc.txFee) if tc.expectPass { diff --git a/x/txfees/keeper/txfee_filters/arb_tx.go b/x/txfees/keeper/txfee_filters/arb_tx.go index 00928422e70..8c8179a5825 100644 --- a/x/txfees/keeper/txfee_filters/arb_tx.go +++ b/x/txfees/keeper/txfee_filters/arb_tx.go @@ -52,6 +52,42 @@ func (m AffiliateSwapMsg) TokenOutDenom() string { var _ poolmanagertypes.SwapMsgRoute = AffiliateSwapMsg{} +type InputCoin struct { + Denom string `json:"denom"` + Amount string `json:"amount"` +} + +type Slippage struct { + MinOutputAmount string `json:"min_output_amount"` +} + +type ContractSwap struct { + InputCoin InputCoin `json:"input_coin"` + OutputDenom string `json:"output_denom"` + Slippage Slippage `json:"slippage"` +} + +type ContractSwapMsg struct { + ContractSwap `json:"swap"` +} + +// TokenDenomsOnPath implements types.SwapMsgRoute. +func (c ContractSwapMsg) TokenDenomsOnPath() []string { + return []string{c.InputCoin.Denom, c.OutputDenom} +} + +// TokenInDenom implements types.SwapMsgRoute. +func (c ContractSwapMsg) TokenInDenom() string { + return c.InputCoin.Denom +} + +// TokenOutDenom implements types.SwapMsgRoute. +func (c ContractSwapMsg) TokenOutDenom() string { + return c.OutputDenom +} + +var _ poolmanagertypes.SwapMsgRoute = ContractSwapMsg{} + // We check if a tx is an arbitrage for the mempool right now by seeing: // 1) does start token of a msg = final token of msg (definitionally correct) // 2) does it have multiple swap messages, with different tx ins. If so, we assume its an arb. @@ -107,21 +143,47 @@ func isArbTxLooseAuthz(msg sdk.Msg, swapInDenom string, lpTypesSeen map[gammtype contractMessage := msgExecuteContract.GetMsg() // Check that the contract message is an affiliate swap message - if ok := isAffiliateSwapMsg(contractMessage); !ok { + isAffliliateSwap := isAffiliateSwapMsg(contractMessage) + isContractSwap := isContractSwapContractMsg(contractMessage) + + if !isAffliliateSwap && !isContractSwap { return swapInDenom, false } - var affiliateSwapMsg AffiliateSwapMsg - if err := json.Unmarshal(contractMessage, &affiliateSwapMsg); err != nil { - // If we can't unmarshal it, it's not an affiliate swap message - return swapInDenom, false + if isAffliliateSwap { + var affiliateSwapMsg AffiliateSwapMsg + if err := json.Unmarshal(contractMessage, &affiliateSwapMsg); err != nil { + // If we can't unmarshal it, it's not an affiliate swap message + return swapInDenom, false + } + + // Otherwise, we have an affiliate swap message, so we check if it's an arb + affiliateSwapMsg.TokenIn = tokenIn.Denom + swapInDenom, isArb := isArbTxLooseSwapMsg(affiliateSwapMsg, swapInDenom) + if isArb { + return swapInDenom, true + } } - // Otherwise, we have an affiliate swap message, so we check if it's an arb - affiliateSwapMsg.TokenIn = tokenIn.Denom - swapInDenom, isArb := isArbTxLooseSwapMsg(affiliateSwapMsg, swapInDenom) - if isArb { - return swapInDenom, true + if isContractSwap { + var contractSwapMsg ContractSwapMsg + if err := json.Unmarshal(contractMessage, &contractSwapMsg); err != nil { + // If we can't unmarshal it, it's not a contract swap message + return swapInDenom, false + } + + // Otherwise, we have a contract swap message, so we check if it's an arb + swapInDenom, isArb := isArbTxLooseSwapMsg(contractSwapMsg, swapInDenom) + if isArb { + return swapInDenom, true + } + + // Also, check sent tokenIn just in case. + contractSwapMsg.InputCoin.Denom = tokenIn.Denom + swapInDenom, isArb = isArbTxLooseSwapMsg(contractSwapMsg, swapInDenom) + if isArb { + return swapInDenom, true + } } return swapInDenom, false @@ -195,3 +257,29 @@ func isAffiliateSwapMsg(msg []byte) bool { return true } + +// check if this: https://celatone.osmosis.zone/osmosis-1/txs/8D20755D4E009CB72C763963A76886BCCCC5C2EBFC3F57266332710216A0D10D +func isContractSwapContractMsg(msg []byte) bool { + // Check that the contract message is a valid JSON object + jsonObject := make(map[string]interface{}) + err := json.Unmarshal(msg, &jsonObject) + if err != nil { + return false + } + + // check the main key is "swap" + swap, ok := jsonObject["swap"].(map[string]interface{}) + if !ok { + return false + } + + if input_coin, ok := swap["input_coin"].(map[string]interface{}); !ok || len(input_coin) == 0 { + return false + } + + if outputDenom, ok := swap["output_denom"].(string); !ok || len(outputDenom) == 0 { + return false + } + + return true +} diff --git a/x/txfees/keeper/txfee_filters/arb_tx_test.go b/x/txfees/keeper/txfee_filters/arb_tx_test.go index 1c7f24e822a..4268944b702 100644 --- a/x/txfees/keeper/txfee_filters/arb_tx_test.go +++ b/x/txfees/keeper/txfee_filters/arb_tx_test.go @@ -65,6 +65,36 @@ func (suite *KeeperTestSuite) TestIsArbTxLooseAuthz_AffiliateSwapMsg() { suite.Require().True(isArb) } +// Tests that the arb filter is enabled on swap msg. +func (suite *KeeperTestSuite) TestIsArbTxLooseAuthz_SwapMsg() { + contractSwapMsg := &txfee_filters.ContractSwapMsg{ + ContractSwap: txfee_filters.ContractSwap{ + InputCoin: txfee_filters.InputCoin{ + Amount: "2775854", + Denom: "ibc/D1542AA8762DB13087D8364F3EA6509FD6F009A34F00426AF9E4F9FA85CBBF1F", + }, + OutputDenom: "ibc/D1542AA8762DB13087D8364F3EA6509FD6F009A34F00426AF9E4F9FA85CBBF1F", + Slippage: txfee_filters.Slippage{ + MinOutputAmount: "2775854", + }, + }, + } + + msgBz, err := json.Marshal(contractSwapMsg) + suite.Require().NoError(err) + + // https://celatone.osmosis.zone/osmosis-1/txs/8D20755D4E009CB72C763963A76886BCCCC5C2EBFC3F57266332710216A0D10D + executeMsg := &wasmtypes.MsgExecuteContract{ + Contract: "osmo1etpha3a65tds0hmn3wfjeag6wgxgrkuwg2zh94cf5hapz7mz04dq6c25s5", + Sender: "osmo1dldrxz5p8uezxz3qstpv92de7wgfp7hvr72dcm", + Funds: sdk.NewCoins(sdk.NewCoin("ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", sdk.NewInt(217084399))), + Msg: msgBz, + } + + _, isArb := txfee_filters.IsArbTxLooseAuthz(executeMsg, executeMsg.Funds[0].Denom, map[types.LiquidityChangeType]bool{}) + suite.Require().True(isArb) +} + func (suite *KeeperTestSuite) TestIsArbTxLooseAuthz_OtherMsg() { otherMsg := []byte(`{"update_feed": {}}`)