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

fix: charge gas when querying cw contracts #7209

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ Epoch and CPU time optimizations

Epoch optimizations are in this release, see a subset of PR links in v21.1.3 section.

### Bug Fixes

* [#7209](https://github.com/osmosis-labs/osmosis/pull/7209) Charge gas on input context when querying cw contracts.

## v21.0.0

### API
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
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.20240109034818-d2a4cb704d18
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20240109034818-d2a4cb704d18
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20240109065741-1aea8952d330
github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20240109034818-d2a4cb704d18
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.9-0.20240109034818-d2a4cb704d18
github.com/osmosis-labs/sqs v0.0.0-20240108192026-6ccc0a29f77d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1491,8 +1491,8 @@ github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:Ylmch
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.20240109034818-d2a4cb704d18 h1:yK4tv3+4C+SebP1LeTkle4EuLAOSKsqpaXenlDwysrU=
github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20240109034818-d2a4cb704d18/go.mod h1:qhaCO81Ur3+qyO/jZ5qeiLsB0qlCLB2GiAEkUOzf1Jk=
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20240109034818-d2a4cb704d18 h1:gLVliRJfS5obrBtc90bUcxuCM9agyX8ASuEq9xW9YcE=
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20240109034818-d2a4cb704d18/go.mod h1:YwgF7dbNF/toLe0TcL3EruyuDzugRDtISFed40Z/95g=
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20240109065741-1aea8952d330 h1:EKLwhlS2gUTE5RtmUS2VB6fkuazy4sIdJ7rx3c1adL4=
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20240109065741-1aea8952d330/go.mod h1:g6QOo3cvOHn0lZtzX1c+qiHUIx4d79hvhGSAhWDa4DQ=
github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20240109034818-d2a4cb704d18 h1:wGgEPQXXeCH+l7QBFSs9VpY+nUOEyShcaI8oL5DYnYo=
github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20240109034818-d2a4cb704d18/go.mod h1:YgoPyLVFXeY/ekpmAHUeydkhRFR+TW2f2zIapeFIGjQ=
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.9-0.20240109034818-d2a4cb704d18 h1:QYAC/o4u1UXBJiqo0UqM/38osA/78pXREQCnYR3KQ7Q=
Expand Down
6 changes: 4 additions & 2 deletions osmoutils/cosmwasm/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ func Query[T any, K any](ctx sdk.Context, wasmKeeper WasmKeeper, contractAddress
return response, err
}

ctx = ctx.WithGasMeter(storetypes.NewGasMeter(wasmKeeper.QueryGasLimit()))
responseBz, err := wasmKeeper.QuerySmart(ctx, sdk.MustAccAddressFromBech32(contractAddress), bz)
childCtx := ctx.WithGasMeter(storetypes.NewGasMeter(wasmKeeper.QueryGasLimit()))
responseBz, err := wasmKeeper.QuerySmart(childCtx, sdk.MustAccAddressFromBech32(contractAddress), bz)
if err != nil {
return response, err
}

ctx.GasMeter().ConsumeGas(childCtx.GasMeter().GasConsumed(), "query smart")

if err := json.Unmarshal(responseBz, &response); err != nil {
return response, err
}
Expand Down
11 changes: 8 additions & 3 deletions x/cosmwasmpool/model/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package model_test
import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"

"github.com/osmosis-labs/osmosis/osmomath"
Expand Down Expand Up @@ -41,15 +42,19 @@ func (s *CosmWasmPoolSuite) TestGetSpreadFactor() {

// TestSpotPrice validates that spot price is returned as one.
func (s *CosmWasmPoolSuite) TestSpotPrice() {
var (
expectedSpotPrice = osmomath.OneBigDec()
)
var expectedSpotPrice = osmomath.OneBigDec()

pool := s.PrepareCosmWasmPool()

s.Ctx = s.Ctx.WithGasMeter(sdk.NewGasMeter(1000000))

actualSpotPrice, err := pool.SpotPrice(s.Ctx, denomA, denomB)
s.Require().NoError(err)

// Validate that the gas was charged on the input context
endGas := s.Ctx.GasMeter().GasConsumed()
s.Require().NotZero(endGas)

s.Require().Equal(expectedSpotPrice, actualSpotPrice)

actualSpotPrice, err = pool.SpotPrice(s.Ctx, denomB, denomA)
Expand Down