Skip to content
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
16 changes: 8 additions & 8 deletions x/dex/contract/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ func EndBlockerAtomic(ctx sdk.Context, keeper *keeper.Keeper, validContractsInfo
spanCtx, span := (*tracer).Start(tracingInfo.TracerContext, "DexEndBlockerAtomic")
defer span.End()
env := newEnv(ctx, validContractsInfo, keeper)
ctx, msCached := cacheAndDecorateContext(ctx, env)
memStateCopy := dexutils.GetMemState(ctx.Context()).DeepCopy()
cachedCtx, msCached := cacheAndDecorateContext(ctx, env)
memStateCopy := dexutils.GetMemState(cachedCtx.Context()).DeepCopy()

handleDeposits(ctx, env, keeper, tracer)
handleDeposits(cachedCtx, env, keeper, tracer)

runner := NewParallelRunner(func(contract types.ContractInfoV2) {
orderMatchingRunnable(spanCtx, ctx, env, keeper, contract, tracer)
}, validContractsInfo, ctx)
orderMatchingRunnable(spanCtx, cachedCtx, env, keeper, contract, tracer)
}, validContractsInfo, cachedCtx)
runner.Run()

handleSettlements(spanCtx, ctx, env, keeper, tracer)
handleUnfulfilledMarketOrders(spanCtx, ctx, env, keeper, tracer)
handleFinalizedBlocks(spanCtx, ctx, env, keeper, tracer)
handleSettlements(spanCtx, cachedCtx, env, keeper, tracer)
handleUnfulfilledMarketOrders(spanCtx, cachedCtx, env, keeper, tracer)
handleFinalizedBlocks(spanCtx, cachedCtx, env, keeper, tracer)

// No error is thrown for any contract. This should happen most of the time.
if env.failedContractAddresses.Size() == 0 {
Expand Down
2 changes: 2 additions & 0 deletions x/dex/keeper/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package keeper_test
import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
keepertest "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/dex/types"
"github.com/stretchr/testify/require"
)

func TestChargeRentForGas(t *testing.T) {
keeper, ctx := keepertest.DexKeeper(t)
keeper.SetParams(ctx, types.Params{SudoCallGasPrice: sdk.NewDecWithPrec(1, 1), PriceSnapshotRetention: 1})
err := keeper.SetContract(ctx, &types.ContractInfoV2{
Creator: keepertest.TestAccount,
ContractAddr: keepertest.TestContract,
Expand Down
10 changes: 6 additions & 4 deletions x/dex/keeper/utils/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ func getMsgType(msg interface{}) string {
func sudo(sdkCtx sdk.Context, k *keeper.Keeper, contractAddress []byte, wasmMsg []byte, msgType string) ([]byte, uint64, error) {
// Measure the time it takes to execute the contract in WASM
defer metrics.MeasureSudoExecutionDuration(time.Now(), msgType)
gasConsumedBefore := sdkCtx.GasMeter().GasConsumed()
// set up a tmp context to prevent race condition in reading gas consumed
tmpCtx := sdkCtx.WithGasMeter(sdk.NewInfiniteGasMeter())
data, err := k.WasmKeeper.Sudo(
sdkCtx, contractAddress, wasmMsg,
tmpCtx, contractAddress, wasmMsg,
)
gasConsumedAfter := sdkCtx.GasMeter().GasConsumed()
gasConsumed := tmpCtx.GasMeter().GasConsumed()
sdkCtx.GasMeter().ConsumeGas(gasConsumed, "sudo")
if hasErrInstantiatingWasmModuleDueToCPUFeature(err) {
panic(utils.DecorateHardFailError(err))
}
return data, gasConsumedAfter - gasConsumedBefore, err
return data, gasConsumed, err
}

func hasErrInstantiatingWasmModuleDueToCPUFeature(err error) bool {
Expand Down
2 changes: 1 addition & 1 deletion x/dex/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
DefaultPriceSnapshotRetention = 24 * 3600 // default to one day
)

var DefaultSudoCallGasPrice = sdk.NewDecWithPrec(1, 1) // 0.1
var DefaultSudoCallGasPrice = sdk.ZeroDec() // 0

var _ paramtypes.ParamSet = (*Params)(nil)

Expand Down