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

Remove max gas #188

Closed
wants to merge 2 commits into from
Closed
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
1 change: 0 additions & 1 deletion x/wasm/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const (
CustomEventType = types.CustomEventType
AttributeKeyContractAddr = types.AttributeKeyContractAddr
GasMultiplier = keeper.GasMultiplier
MaxGas = keeper.MaxGas
QueryListContractByCode = keeper.QueryListContractByCode
QueryGetContract = keeper.QueryGetContract
QueryGetContractState = keeper.QueryGetContractState
Expand Down
9 changes: 1 addition & 8 deletions x/wasm/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import (
// Rough timing have 88k gas at 90us, which is equal to 1k sdk gas... (one read)
const GasMultiplier = 100

// MaxGas for a contract is 900 million (enforced in rust)
const MaxGas = 900_000_000

// InstanceCost is how much SDK gas we charge each time we load a WASM instance.
// Creating a new instance is costly, and this helps put a recursion limit to contracts calling contracts.
const InstanceCost uint64 = 40_000
Expand Down Expand Up @@ -528,11 +525,7 @@ func (k Keeper) dispatchMessages(ctx sdk.Context, contractAddr sdk.AccAddress, m

func gasForContract(ctx sdk.Context) uint64 {
meter := ctx.GasMeter()
remaining := (meter.Limit() - meter.GasConsumed()) * GasMultiplier
if remaining > MaxGas {
return MaxGas
}
return remaining
return (meter.Limit() - meter.GasConsumed()) * GasMultiplier
}

func consumeGas(ctx sdk.Context, gas uint64) {
Expand Down
5 changes: 5 additions & 0 deletions x/wasm/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"testing"
Expand Down Expand Up @@ -299,13 +300,17 @@ func TestInstantiate(t *testing.T) {
require.NoError(t, err)

gasBefore := ctx.GasMeter().GasConsumed()
fmt.Printf("limit: %d\n", ctx.GasMeter().Limit())
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: t.Logf should be preferred to fmt.Printf for test debug output

fmt.Printf("before: %d\n", gasBefore)

// create with no balance is also legal
addr, err := keeper.Instantiate(ctx, contractID, creator, nil, initMsgBz, "demo contract 1", nil)
require.NoError(t, err)
require.Equal(t, "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", addr.String())

gasAfter := ctx.GasMeter().GasConsumed()
fmt.Printf("limit: %d\n", ctx.GasMeter().Limit())
fmt.Printf("after: %d\n", gasAfter)
require.Equal(t, uint64(0x11542), gasAfter-gasBefore)

// ensure it is stored properly
Expand Down