Skip to content

Commit 1508500

Browse files
authored
Merge pull request #80 from oraichain/fix-gas-less-sims
dang/fix out of gas when execute gasless contract
2 parents 40b7472 + cda797f commit 1508500

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

CHANGELOG_ORAI.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# CHANGELOG
22

3+
## v0.50.8
4+
5+
<!--
6+
Add a summary for the release here.
7+
8+
If you don't change this message, or if this file is empty, the release
9+
will not be created. -->
10+
Upgrade Oraichain mainnet to v0.50.8 to fix gasless contract bug out of gas when execute gasless contract.
11+
12+
### BUG FIXES
13+
14+
- Fix gasless contract out of gas ([\#80](https://github.com/oraichain/wasmd/pull/80))
15+
316
## v0.50.7
417

518
<!--

app/upgrades.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ import (
3535
v0505 "github.com/CosmWasm/wasmd/app/upgrades/v0505"
3636
v0506 "github.com/CosmWasm/wasmd/app/upgrades/v0506"
3737
v0507 "github.com/CosmWasm/wasmd/app/upgrades/v0507"
38+
v0508 "github.com/CosmWasm/wasmd/app/upgrades/v0508"
3839
v2 "github.com/CosmWasm/wasmd/x/wasm/migrations/v2"
3940
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
4041
)
4142

4243
// Upgrades list of chain upgrades
43-
var Upgrades = []upgrades.Upgrade{v050.Upgrade, v0501.Upgrade, v0502.Upgrade, v0503.Upgrade, v0504.Upgrade, v0505.Upgrade, v0506.Upgrade, v0507.Upgrade}
44+
var Upgrades = []upgrades.Upgrade{v050.Upgrade, v0501.Upgrade, v0502.Upgrade, v0503.Upgrade, v0504.Upgrade, v0505.Upgrade, v0506.Upgrade, v0507.Upgrade, v0508.Upgrade}
4445

4546
// RegisterUpgradeHandlers registers the chain upgrade handlers
4647
func (app *WasmApp) RegisterUpgradeHandlers() {

app/upgrades/v0508/upgrades.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package v0508
2+
3+
import (
4+
"context"
5+
6+
storetypes "cosmossdk.io/store/types"
7+
upgradetypes "cosmossdk.io/x/upgrade/types"
8+
9+
"github.com/CosmWasm/wasmd/app/upgrades"
10+
"github.com/cosmos/cosmos-sdk/codec"
11+
"github.com/cosmos/cosmos-sdk/types/module"
12+
)
13+
14+
// UpgradeName defines the on-chain upgrade name
15+
const UpgradeName = "v0.50.8"
16+
17+
var Upgrade = upgrades.Upgrade{
18+
UpgradeName: UpgradeName,
19+
CreateUpgradeHandler: CreateUpgradeHandler,
20+
StoreUpgrades: storetypes.StoreUpgrades{
21+
Added: []string{},
22+
Deleted: []string{},
23+
},
24+
}
25+
26+
func CreateUpgradeHandler(
27+
mm upgrades.ModuleManager,
28+
configurator module.Configurator,
29+
ak *upgrades.AppKeepers,
30+
keys map[string]*storetypes.KVStoreKey,
31+
cdc codec.BinaryCodec,
32+
) upgradetypes.UpgradeHandler {
33+
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
34+
return mm.RunMigrations(ctx, configurator, fromVM)
35+
}
36+
}

tests/interchaintest/wasm_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package interchaintest
22

33
import (
4+
"fmt"
45
"testing"
56

67
"cosmossdk.io/math"
@@ -80,6 +81,7 @@ func TestWasmGasLessContract(t *testing.T) {
8081
resAfter, err := orai.ExecuteContract(ctx, oraiUser.KeyName(), contractAddress, executeMsg, "--gas", "auto")
8182
require.NoError(t, err)
8283
require.Less(t, resAfter.GasUsed, resBefore.GasUsed) // after set gas less gas used should be less than before
84+
fmt.Println("Gas after: ", resAfter.GasUsed)
8385

8486
// Test unset gas less contract successfully
8587
proposalUnsetGasLessID, err := helpers.ProposalUnsetGasLessContracts(

x/wasm/keeper/keeper.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ func (k Keeper) execute(ctx context.Context, contractAddress, caller sdk.AccAddr
394394
// refund gas if we execute gasless contract
395395
if isGasLess {
396396
sdkCtx.GasMeter().RefundGas(sdkCtx.GasMeter().GasConsumed(), "refund gasless contract")
397-
k.Logger(sdkCtx).Info("execute gas less wasm contract")
398397
}
399398
contractInfo, codeInfo, prefixStore, err := k.contractInstance(ctx, contractAddress)
400399
if err != nil {
@@ -415,13 +414,11 @@ func (k Keeper) execute(ctx context.Context, contractAddress, caller sdk.AccAddr
415414
info := types.NewInfo(caller, coins)
416415

417416
// prepare querier
418-
querier := k.newQueryHandler(sdkCtx, contractAddress)
419-
var gasLeft uint64
420417
if isGasLess {
421-
gasLeft = math.MaxUint64
422-
} else {
423-
gasLeft = k.runtimeGasForContract(sdkCtx)
418+
sdkCtx = sdkCtx.WithGasMeter(storetypes.NewInfiniteGasMeter())
424419
}
420+
querier := k.newQueryHandler(sdkCtx, contractAddress)
421+
gasLeft := k.runtimeGasForContract(sdkCtx)
425422
res, gasUsed, execErr := k.wasmVM.Execute(codeInfo.CodeHash, env, info, msg, prefixStore, cosmwasmAPI, querier, k.gasMeter(sdkCtx), gasLeft, costJSONDeserialization)
426423
// consume gas wasmvm if it isn't gas less contract
427424
if !isGasLess {

0 commit comments

Comments
 (0)