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

Update main 2 #ntrn-566 #281

Merged
merged 32 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2a9333c
chore: upgraded ics to v1.2.0
May 5, 2023
6d22754
upgraded interchain-security v1.2.0-multiden-rc0
May 8, 2023
c236f10
chore: upgraded ics to v1.2.0-multiden
May 9, 2023
afc1897
Bump ibc-go to v4.3.1
pr0n00gler May 26, 2023
cc1694b
update init-neutrond.sh script
pr0n00gler May 26, 2023
8761e98
static builder
pr0n00gler May 26, 2023
3c8dde1
fix ENABLED_PROPOSALS
pr0n00gler May 26, 2023
152f348
feat: add wasmd flags
NeverHappened Jun 29, 2023
86a5efc
fix: cached context
Jul 3, 2023
51b6f26
more fixes
Jul 3, 2023
5a2b741
added checks on state reset during sudo call failures(ica tx, transfe…
swelf19 Jul 3, 2023
5c8d6f3
comments
pr0n00gler Jul 3, 2023
fbe35d0
fix createCachedContext for transfer keeper
pr0n00gler Jul 3, 2023
00c3bf0
Merge pull request #277 from neutron-org/fix/cached-context-state-reset
pr0n00gler Jul 3, 2023
1c70133
Merge pull request #278 from neutron-org/fix/chached-context
pr0n00gler Jul 3, 2023
4026883
Merge pull request #279 from neutron-org/feat/configure-wasmd
pr0n00gler Jul 4, 2023
9251c2f
Merge branch 'main' into update-main-2
NeverHappened Jul 5, 2023
69f84c6
fix emitting events from cached context
pr0n00gler Jul 13, 2023
29fd5fc
Merge branch 'main' into update-main-2
NeverHappened Jul 13, 2023
9ad4c24
Add conditional building tag
albertandrejev Jul 14, 2023
2adba11
remove not used target
albertandrejev Jul 14, 2023
e750736
remove decorator
albertandrejev Jul 14, 2023
5818da2
Merge pull request #287 from neutron-org/fix/ccv-filter-build-tag-1
pr0n00gler Jul 14, 2023
7494857
update contracts
pr0n00gler Jul 14, 2023
11ce26a
remove unnecessary contracts
pr0n00gler Jul 14, 2023
effbed1
Merge pull request #288 from neutron-org/chore/update-contracts
pr0n00gler Jul 14, 2023
d34f3df
Merge branch 'releases/v1.0.x' into fix/cache-ctx-emit-events
pr0n00gler Jul 17, 2023
6812658
Change mev_cometbft version
albertandrejev Jul 13, 2023
0dc37b4
Merge pull request #285 from neutron-org/chore/update_mev_cometbft
pr0n00gler Jul 17, 2023
7804860
Merge pull request #286 from neutron-org/fix/cache-ctx-emit-events
pr0n00gler Jul 18, 2023
3268fc6
Merge branch 'releases/v1.0.x' into update-main-2
NeverHappened Jul 27, 2023
6bedbce
update dao contracts from neutron-dao main branch
NeverHappened Jul 27, 2023
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
BINDIR ?= $(GOPATH)/bin
SIMAPP = ./app
ENABLED_PROPOSALS := SudoContract,UpdateAdmin,ClearAdmin,PinCodes,UnpinCodes
ENABLED_PROPOSALS := MigrateContract,SudoContract,UpdateAdmin,ClearAdmin,PinCodes,UnpinCodes
GO_VERSION=1.20.0
BUILDDIR ?= $(CURDIR)/build

Expand Down
10 changes: 5 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ import (

feetypes "github.com/neutron-org/neutron/x/feerefunder/types"

e2e "github.com/cosmos/interchain-security/testutil/integration"
e2e "github.com/cosmos/interchain-security/testutil/e2e"
ccvconsumer "github.com/cosmos/interchain-security/x/ccv/consumer"
ccvconsumerkeeper "github.com/cosmos/interchain-security/x/ccv/consumer/keeper"
ccvconsumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types"
Expand Down Expand Up @@ -1153,21 +1153,21 @@ func (app *App) GetConsumerKeeper() ccvconsumerkeeper.Keeper {
}

// GetE2eBankKeeper implements the ConsumerApp interface.
func (app *App) GetTestBankKeeper() e2e.TestBankKeeper {
func (app *App) GetE2eBankKeeper() e2e.E2eBankKeeper {
return app.BankKeeper
}

// GetE2eAccountKeeper implements the ConsumerApp interface.
func (app *App) GetTestAccountKeeper() e2e.TestAccountKeeper {
func (app *App) GetE2eAccountKeeper() e2e.E2eAccountKeeper {
return app.AccountKeeper
}

// GetE2eSlashingKeeper implements the ConsumerApp interface.
func (app *App) GetTestSlashingKeeper() e2e.TestSlashingKeeper {
func (app *App) GetE2eSlashingKeeper() e2e.E2eSlashingKeeper {
return app.SlashingKeeper
}

// GetE2eEvidenceKeeper implements the ConsumerApp interface.
func (app *App) GetTestEvidenceKeeper() e2e.TestEvidenceKeeper {
func (app *App) GetE2eEvidenceKeeper() e2e.E2eEvidenceKeeper {
return app.EvidenceKeeper
}
1 change: 1 addition & 0 deletions cmd/neutrond/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {

func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
wasm.AddModuleInitFlags(startCmd)
}

func queryCommand() *cobra.Command {
Expand Down
Binary file modified contracts/cwd_core.wasm
Binary file not shown.
Binary file modified contracts/cwd_pre_propose_multiple.wasm
Binary file not shown.
Binary file modified contracts/cwd_pre_propose_overrule.wasm
Binary file not shown.
Binary file modified contracts/cwd_pre_propose_single.wasm
Binary file not shown.
Binary file modified contracts/cwd_proposal_multiple.wasm
Binary file not shown.
Binary file modified contracts/cwd_proposal_single.wasm
Binary file not shown.
Binary file modified contracts/cwd_subdao_core.wasm
Binary file not shown.
Binary file modified contracts/cwd_subdao_pre_propose_single.wasm
Binary file not shown.
Binary file modified contracts/cwd_subdao_proposal_single.wasm
Binary file not shown.
Binary file modified contracts/cwd_subdao_timelock_single.wasm
Binary file not shown.
Binary file modified contracts/lockdrop_vault.wasm
Binary file not shown.
Binary file modified contracts/neutron_distribution.wasm
Binary file not shown.
Binary file modified contracts/neutron_reserve.wasm
Binary file not shown.
Binary file modified contracts/neutron_vault.wasm
Binary file not shown.
Binary file modified contracts/neutron_voting_registry.wasm
Binary file not shown.
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.45.15
github.com/cosmos/gaia/v8 v8.0.1
github.com/cosmos/ibc-go/v4 v4.3.0
github.com/cosmos/interchain-security v1.0.1-0.20230419165046-6089b6121c33
github.com/cosmos/ibc-go/v4 v4.3.1
github.com/cosmos/interchain-security v1.2.0-multiden
github.com/gogo/protobuf v1.3.3
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3
Expand Down Expand Up @@ -138,6 +138,7 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tendermint/spm v0.1.9 // indirect
github.com/tidwall/btree v1.5.0 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
Expand All @@ -162,6 +163,6 @@ replace (
github.com/cosmos/admin-module => github.com/Ethernal-Tech/admin-module v0.0.0-20221102105340-e693f4d379c3
github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.45.15-ics
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/tendermint/tendermint => github.com/skip-mev/mev-cometbft v0.34.27-mev.17
github.com/tendermint/tendermint => github.com/skip-mev/mev-cometbft v0.34.27-mev.18
google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
13 changes: 7 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -998,11 +998,11 @@ github.com/cosmos/iavl v0.19.5 h1:rGA3hOrgNxgRM5wYcSCxgQBap7fW82WZgY78V9po/iY=
github.com/cosmos/iavl v0.19.5/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
github.com/cosmos/ibc-go v1.2.2/go.mod h1:XmYjsRFOs6Q9Cz+CSsX21icNoH27vQKb3squgnCOCbs=
github.com/cosmos/ibc-go/v3 v3.0.0/go.mod h1:Mb+1NXiPOLd+CPFlOC6BKeAUaxXlhuWenMmRiUiSmwY=
github.com/cosmos/ibc-go/v4 v4.3.0 h1:yOzVsyZzsv4XPBux8gq+D0LhZn45yGWKjvT+6Vyo5no=
github.com/cosmos/ibc-go/v4 v4.3.0/go.mod h1:CcLvIoi9NNtIbNsxs4KjBGjYhlwqtsmXy1AKARKiMzQ=
github.com/cosmos/ibc-go/v4 v4.3.1 h1:xbg0CaCdxK3lvgGvSaI91ROOLd7s30UqEcexH6Ba4Ys=
github.com/cosmos/ibc-go/v4 v4.3.1/go.mod h1:89E+K9CxpkS/etLEcG026jPM/RSnVMcfesvRYp/0aKI=
github.com/cosmos/interchain-accounts v0.2.6 h1:TV2M2g1/Rb9MCNw1YePdBKE0rcEczNj1RGHT+2iRYas=
github.com/cosmos/interchain-security v1.0.1-0.20230419165046-6089b6121c33 h1:gGeyeocVM771mWQUngG+INMnZLRn04xtTP8eHUKv8Fs=
github.com/cosmos/interchain-security v1.0.1-0.20230419165046-6089b6121c33/go.mod h1:ux46JqLoUfPq7FKXYXkAiqwzSiIfcLEgtv+plrv9aRA=
github.com/cosmos/interchain-security v1.2.0-multiden h1:NACl8426o4hXWYJBm3g2CFJwyXtcEHT5oUmelrdTjKg=
github.com/cosmos/interchain-security v1.2.0-multiden/go.mod h1:Y4onDsQuqkemGS7UqfyohahlBLt5gh1i8OVbPeMcuhA=
github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY=
github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA=
github.com/cosmos/ledger-cosmos-go v0.12.2/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI=
Expand Down Expand Up @@ -2509,8 +2509,8 @@ github.com/sivchari/containedctx v1.0.2/go.mod h1:PwZOeqm4/DLoJOqMSIJs3aKqXRX4YO
github.com/sivchari/nosnakecase v1.7.0/go.mod h1:CwDzrzPea40/GB6uynrNLiorAlgFRvRbFSgJx2Gs+QY=
github.com/sivchari/tenv v1.7.0/go.mod h1:64yStXKSOxDfX47NlhVwND4dHwfZDdbp2Lyl018Icvg=
github.com/skeema/knownhosts v1.1.0/go.mod h1:sKFq3RD6/TKZkSWn8boUbDC7Qkgcv+8XXijpFO6roag=
github.com/skip-mev/mev-cometbft v0.34.27-mev.17 h1:Sti5vpx6jvUzmLcsi22Xv9hf8eByXz6fKrKS3tACckw=
github.com/skip-mev/mev-cometbft v0.34.27-mev.17/go.mod h1:BcCbhKv7ieM0KEddnYXvQZR+pZykTKReJJYf7YC7qhw=
github.com/skip-mev/mev-cometbft v0.34.27-mev.18 h1:xoZRzzW4u4Rr4jjXUz7y05AoDZu8W5dGvgeg7jxrt0U=
github.com/skip-mev/mev-cometbft v0.34.27-mev.18/go.mod h1:BcCbhKv7ieM0KEddnYXvQZR+pZykTKReJJYf7YC7qhw=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM=
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
Expand Down Expand Up @@ -2643,6 +2643,7 @@ github.com/tendermint/btcd v0.1.1/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrn
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk=
github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E=
github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
github.com/tendermint/spm v0.1.9 h1:O1DJF4evS8wgk5SZqRcO29irNNtKQmTpvQ0xFzUiczI=
github.com/tendermint/spm v0.1.9/go.mod h1:iHgfQ5YOI6ONc9E7ugGQolVdfSMHpeXfZ/OpXuN/42Q=
github.com/tendermint/tm-db v0.6.4/go.mod h1:dptYhIpJ2M5kUuenLr+Yyf3zQOv1SgBZcl8/BmWlMBw=
github.com/tendermint/tm-db v0.6.6/go.mod h1:wP8d49A85B7/erz/r4YbKssKw6ylsO/hKtFk7E1aWZI=
Expand Down
Binary file removed neutron_dao.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/e2e/interchain_security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
icssimapp "github.com/cosmos/interchain-security/testutil/ibc_testing"
"github.com/stretchr/testify/suite"

e2e "github.com/cosmos/interchain-security/tests/integration"
"github.com/cosmos/interchain-security/tests/e2e"

appConsumer "github.com/neutron-org/neutron/app"
"github.com/neutron-org/neutron/testutil"
Expand Down
4 changes: 2 additions & 2 deletions testutil/interchaintxs/keeper/interchaintxs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/neutron-org/neutron/x/interchaintxs/types"
)

func InterchainTxsKeeper(t testing.TB, managerKeeper types.ContractManagerKeeper, refunderKeeper types.FeeRefunderKeeper, icaControllerKeeper types.ICAControllerKeeper, channelKeeper types.ChannelKeeper, capabilityKeeper types.ScopedKeeper) (*keeper.Keeper, sdk.Context) {
func InterchainTxsKeeper(t testing.TB, managerKeeper types.ContractManagerKeeper, refunderKeeper types.FeeRefunderKeeper, icaControllerKeeper types.ICAControllerKeeper, channelKeeper types.ChannelKeeper, capabilityKeeper types.ScopedKeeper) (*keeper.Keeper, sdk.Context, *sdk.KVStoreKey) {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

Expand Down Expand Up @@ -54,5 +54,5 @@ func InterchainTxsKeeper(t testing.TB, managerKeeper types.ContractManagerKeeper
// Initialize params
k.SetParams(ctx, types.DefaultParams())

return k, ctx
return k, ctx, storeKey
}
9 changes: 5 additions & 4 deletions testutil/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (

clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types"
appProvider "github.com/cosmos/interchain-security/app/provider"
e2e "github.com/cosmos/interchain-security/testutil/integration"
e2e "github.com/cosmos/interchain-security/testutil/e2e"
ccvutils "github.com/cosmos/interchain-security/x/ccv/utils"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/neutron-org/neutron/app"
Expand Down Expand Up @@ -121,9 +122,9 @@ func (suite *IBCConnectionTestSuite) SetupTest() {
suite.Require().True(len(providerValUpdates) == len(consumerBValUpdates), "initial valset not matching")

for i := 0; i < len(providerValUpdates); i++ {
addr1, _ := ccv.TMCryptoPublicKeyToConsAddr(providerValUpdates[i].PubKey)
addr2, _ := ccv.TMCryptoPublicKeyToConsAddr(consumerAValUpdates[i].PubKey)
addr3, _ := ccv.TMCryptoPublicKeyToConsAddr(consumerBValUpdates[i].PubKey)
addr1, _ := ccvutils.TMCryptoPublicKeyToConsAddr(providerValUpdates[i].PubKey)
addr2, _ := ccvutils.TMCryptoPublicKeyToConsAddr(consumerAValUpdates[i].PubKey)
addr3, _ := ccvutils.TMCryptoPublicKeyToConsAddr(consumerBValUpdates[i].PubKey)
suite.Require().True(bytes.Equal(addr1, addr2), "validator mismatch")
suite.Require().True(bytes.Equal(addr1, addr3), "validator mismatch")
}
Expand Down
4 changes: 2 additions & 2 deletions testutil/transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/neutron-org/neutron/x/transfer/types"
)

func TransferKeeper(t testing.TB, managerKeeper types.ContractManagerKeeper, refunderKeeper types.FeeRefunderKeeper, channelKeeper types.ChannelKeeper, authKeeper types.AccountKeeper) (*keeper.KeeperTransferWrapper, sdk.Context) {
func TransferKeeper(t testing.TB, managerKeeper types.ContractManagerKeeper, refunderKeeper types.FeeRefunderKeeper, channelKeeper types.ChannelKeeper, authKeeper types.AccountKeeper) (*keeper.KeeperTransferWrapper, sdk.Context, *sdk.KVStoreKey) {
storeKey := sdk.NewKVStoreKey(transfertypes.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey("mem_" + transfertypes.StoreKey)

Expand Down Expand Up @@ -60,5 +60,5 @@ func TransferKeeper(t testing.TB, managerKeeper types.ContractManagerKeeper, ref
// Initialize params
k.SetParams(ctx, transfertypes.DefaultParams())

return &k, ctx
return &k, ctx, storeKey
}
2 changes: 1 addition & 1 deletion x/interchaintxs/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestGenesis(t *testing.T) {
Params: types.DefaultParams(),
}

k, ctx := keepertest.InterchainTxsKeeper(t, nil, nil, nil, nil, nil)
k, ctx, _ := keepertest.InterchainTxsKeeper(t, nil, nil, nil, nil, nil)
interchaintxs.InitGenesis(ctx, *k, genesisState)
got := interchaintxs.ExportGenesis(ctx, *k)
require.NotNil(t, got)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestKeeper_InterchainAccountAddress(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
icaKeeper := mock_types.NewMockICAControllerKeeper(ctrl)
keeper, ctx := testkeeper.InterchainTxsKeeper(t, nil, nil, icaKeeper, nil, nil)
keeper, ctx, _ := testkeeper.InterchainTxsKeeper(t, nil, nil, icaKeeper, nil, nil)
wctx := sdk.WrapSDKContext(ctx)

resp, err := keeper.InterchainAccountAddress(wctx, nil)
Expand Down
2 changes: 1 addition & 1 deletion x/interchaintxs/keeper/grpc_query_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestParamsQuery(t *testing.T) {
keeper, ctx := testkeeper.InterchainTxsKeeper(t, nil, nil, nil, nil, nil)
keeper, ctx, _ := testkeeper.InterchainTxsKeeper(t, nil, nil, nil, nil, nil)
wctx := sdk.WrapSDKContext(ctx)
params := types.DefaultParams()
keeper.SetParams(ctx, params)
Expand Down
50 changes: 35 additions & 15 deletions x/interchaintxs/keeper/ibc_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,46 @@ func (k *Keeper) outOfGasRecovery(

k.Logger(ctx).Debug("Out of gas", "Gas meter", gasMeter.String())
k.contractManagerKeeper.AddContractFailure(ctx, packet.SourceChannel, senderAddress.String(), packet.GetSequence(), failureAckType)
// FIXME: add distribution call
}
}

func (k *Keeper) createCachedContext(ctx sdk.Context) (cacheCtx sdk.Context, writeFn func(), newGasMeter sdk.GasMeter) {
gasLeft := ctx.GasMeter().Limit() - ctx.GasMeter().GasConsumed()
// createCachedContext creates a cached context for handling Sudo calls to CosmWasm smart-contracts.
// If there is an error during Sudo call, we can safely revert changes made in cached context.
func (k *Keeper) createCachedContext(ctx sdk.Context) (sdk.Context, func(), sdk.GasMeter) {
gasMeter := ctx.GasMeter()
// determines type of gas meter by its prefix:
// * BasicGasMeter - basic gas meter which is used for processing tx directly in block;
// * InfiniteGasMeter - is used to process txs during simulation calls. We don't need to create a limit for such meter,
// since it's infinite.
gasMeterIsLimited := strings.HasPrefix(ctx.GasMeter().String(), "BasicGasMeter")

cacheCtx, writeFn := ctx.CacheContext()

// if gas meter is limited:
// 1. calculate how much free gas left we have for a Sudo call;
// 2. If gasLeft less than reserved gas (GasReserved), we set gas limit for cached context to zero, meaning we can't
// process Sudo call;
// 3. If we have more gas left than reserved gas (GasReserved) for Sudo call, we set gas limit for cached context to
// difference between gas left and reserved gas: (gasLeft - GasReserve);
//
// GasReserve is the amount of gas on the context gas meter we need to reserve in order to add contract failure to keeper
// and process failed Sudo call
if gasMeterIsLimited {
gasLeft := gasMeter.Limit() - gasMeter.GasConsumed()

var newLimit uint64
if gasLeft < GasReserve {
newLimit = 0
} else {
newLimit = gasLeft - GasReserve
}

var newLimit uint64
if gasLeft < GasReserve {
newLimit = 0
} else {
newLimit = gasLeft - GasReserve
gasMeter = sdk.NewGasMeter(newLimit)
}

newGasMeter = sdk.NewGasMeter(newLimit)

cacheCtx, writeFn = ctx.CacheContext()
if strings.HasPrefix(ctx.GasMeter().String(), "BasicGasMeter") {
cacheCtx = ctx.WithGasMeter(newGasMeter)
}
cacheCtx = cacheCtx.WithGasMeter(gasMeter)

return
return cacheCtx, writeFn, gasMeter
}

// HandleAcknowledgement passes the acknowledgement data to the appropriate contract via a Sudo call.
Expand Down Expand Up @@ -93,6 +111,7 @@ func (k *Keeper) HandleAcknowledgement(ctx sdk.Context, packet channeltypes.Pack
k.contractManagerKeeper.AddContractFailure(ctx, packet.SourceChannel, icaOwner.GetContract().String(), packet.GetSequence(), "ack")
k.Logger(ctx).Debug("HandleAcknowledgement: failed to Sudo contract on packet acknowledgement", "error", err)
} else {
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events())
writeFn()
}

Expand Down Expand Up @@ -124,6 +143,7 @@ func (k *Keeper) HandleTimeout(ctx sdk.Context, packet channeltypes.Packet, rela
k.contractManagerKeeper.AddContractFailure(ctx, packet.SourceChannel, icaOwner.GetContract().String(), packet.GetSequence(), "timeout")
k.Logger(ctx).Error("HandleTimeout: failed to Sudo contract on packet timeout", "error", err)
} else {
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events())
writeFn()
}

Expand Down
Loading