diff --git a/app/app.go b/app/app.go index 70239d7a1..5245d27eb 100644 --- a/app/app.go +++ b/app/app.go @@ -638,7 +638,7 @@ func New( ) app.CronKeeper = *cronkeeper.NewKeeper(appCodec, keys[crontypes.StoreKey], keys[crontypes.MemStoreKey], app.AccountKeeper) - wasmOpts = append(wasmbinding.RegisterCustomPlugins(&app.InterchainTxsKeeper, &app.InterchainQueriesKeeper, app.TransferKeeper, &app.AdminmoduleKeeper, app.FeeBurnerKeeper, app.FeeKeeper, &app.BankKeeper, app.TokenFactoryKeeper, &app.CronKeeper), wasmOpts...) + wasmOpts = append(wasmbinding.RegisterCustomPlugins(&app.InterchainTxsKeeper, &app.InterchainQueriesKeeper, app.TransferKeeper, &app.AdminmoduleKeeper, app.FeeBurnerKeeper, app.FeeKeeper, &app.BankKeeper, app.TokenFactoryKeeper, &app.CronKeeper, &app.ContractManagerKeeper), wasmOpts...) queryPlugins := wasmkeeper.WithQueryPlugins( &wasmkeeper.QueryPlugins{Stargate: wasmkeeper.AcceptListStargateQuerier(wasmbinding.AcceptedStargateQueries(), app.GRPCQueryRouter(), appCodec)}) @@ -995,14 +995,15 @@ func (app *App) setupUpgradeHandlers() { app.mm, app.configurator, &upgrades.UpgradeKeepers{ - FeeBurnerKeeper: app.FeeBurnerKeeper, - CronKeeper: app.CronKeeper, - IcqKeeper: app.InterchainQueriesKeeper, - TokenFactoryKeeper: app.TokenFactoryKeeper, - SlashingKeeper: app.SlashingKeeper, - ParamsKeeper: app.ParamsKeeper, - CapabilityKeeper: app.CapabilityKeeper, - GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName), + FeeBurnerKeeper: app.FeeBurnerKeeper, + CronKeeper: app.CronKeeper, + IcqKeeper: app.InterchainQueriesKeeper, + TokenFactoryKeeper: app.TokenFactoryKeeper, + SlashingKeeper: app.SlashingKeeper, + ParamsKeeper: app.ParamsKeeper, + CapabilityKeeper: app.CapabilityKeeper, + GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName), + CcvConsumerSubspace: app.GetSubspace(ccvconsumertypes.ModuleName), }, app, app.AppCodec(), diff --git a/app/upgrades/nextupgrade/upgrades.go b/app/upgrades/nextupgrade/upgrades.go index 3105809c6..656a5c8c6 100644 --- a/app/upgrades/nextupgrade/upgrades.go +++ b/app/upgrades/nextupgrade/upgrades.go @@ -3,10 +3,12 @@ package nextupgrade import ( "errors" - "github.com/cosmos/cosmos-sdk/codec" + ccvconsumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types" + ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -28,48 +30,85 @@ func CreateUpgradeHandler( return vm, err } - ctx.Logger().Info("Implementing GlobalFee Params...") - - if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyMinGasPrices) { - return vm, errors.New("minimum_gas_prices param not found") + err = migrateGlobalFees(ctx, keepers) + if err != nil { + ctx.Logger().Error("failed to migrate GlobalFees", "err", err) + return vm, err } - if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes) { - return vm, errors.New("bypass_min_fee_msg_types param not found") + err = migrateRewardDenoms(ctx, keepers) + if err != nil { + ctx.Logger().Error("failed to migrate reward denoms", "err", err) + return vm, err } - if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage) { - return vm, errors.New("max_total_bypass_min_fee_msg_gas_usage param not found") - } + ctx.Logger().Info("Upgrade complete") + return vm, err + } +} - // global fee is empty set, set global fee to equal to 0.05 USD (for 200k of gas) in appropriate coin - // As of June 22nd, 2023 this is - // 0.9untrn,0.026ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9,0.25ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349 - requiredGlobalFees := sdk.DecCoins{ - sdk.NewDecCoinFromDec("untrn", sdk.MustNewDecFromStr("0.9")), - sdk.NewDecCoinFromDec("ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", sdk.MustNewDecFromStr("0.026")), - sdk.NewDecCoinFromDec("ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349", sdk.MustNewDecFromStr("0.25")), - } - requiredGlobalFees = requiredGlobalFees.Sort() +func migrateGlobalFees(ctx sdk.Context, keepers *upgrades.UpgradeKeepers) error { + ctx.Logger().Info("Implementing GlobalFee Params...") - keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyMinGasPrices, &requiredGlobalFees) + if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyMinGasPrices) { + return errors.New("minimum_gas_prices param not found") + } - ctx.Logger().Info("Global fees was set successfully") + if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes) { + return errors.New("bypass_min_fee_msg_types param not found") + } - defaultBypassFeeMessages := []string{ - sdk.MsgTypeURL(&ibcchanneltypes.MsgRecvPacket{}), - sdk.MsgTypeURL(&ibcchanneltypes.MsgAcknowledgement{}), - sdk.MsgTypeURL(&ibcclienttypes.MsgUpdateClient{}), - } - keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes, &defaultBypassFeeMessages) + if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage) { + return errors.New("max_total_bypass_min_fee_msg_gas_usage param not found") + } - ctx.Logger().Info("Bypass min fee msg types was set successfully") + // global fee is empty set, set global fee to equal to 0.05 USD (for 200k of gas) in appropriate coin + // As of June 22nd, 2023 this is + // 0.9untrn,0.026ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9,0.25ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349 + requiredGlobalFees := sdk.DecCoins{ + sdk.NewDecCoinFromDec("untrn", sdk.MustNewDecFromStr("0.9")), + sdk.NewDecCoinFromDec("ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", sdk.MustNewDecFromStr("0.026")), + sdk.NewDecCoinFromDec("ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349", sdk.MustNewDecFromStr("0.25")), + } + requiredGlobalFees = requiredGlobalFees.Sort() - keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage, types.DefaultmaxTotalBypassMinFeeMsgGasUsage) + keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyMinGasPrices, &requiredGlobalFees) - ctx.Logger().Info("Max total bypass min fee msg gas usage set successfully") + ctx.Logger().Info("Global fees was set successfully") - ctx.Logger().Info("Upgrade complete") - return vm, err + defaultBypassFeeMessages := []string{ + sdk.MsgTypeURL(&ibcchanneltypes.MsgRecvPacket{}), + sdk.MsgTypeURL(&ibcchanneltypes.MsgAcknowledgement{}), + sdk.MsgTypeURL(&ibcclienttypes.MsgUpdateClient{}), } + keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes, &defaultBypassFeeMessages) + + ctx.Logger().Info("Bypass min fee msg types was set successfully") + + keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage, &types.DefaultmaxTotalBypassMinFeeMsgGasUsage) + + ctx.Logger().Info("Max total bypass min fee msg gas usage set successfully") + + return nil +} + +func migrateRewardDenoms(ctx sdk.Context, keepers *upgrades.UpgradeKeepers) error { + ctx.Logger().Info("Migrating reword denoms...") + + if !keepers.CcvConsumerSubspace.Has(ctx, ccvconsumertypes.KeyRewardDenoms) { + return errors.New("key_reward_denoms param not found") + } + + var denoms []string + keepers.CcvConsumerSubspace.Get(ctx, ccvconsumertypes.KeyRewardDenoms, &denoms) + + // add new axlr usdc denom + axlrDenom := "ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349" + denoms = append(denoms, axlrDenom) + + keepers.CcvConsumerSubspace.Set(ctx, ccvconsumertypes.KeyRewardDenoms, &denoms) + + ctx.Logger().Info("Finished migrating reward denoms") + + return nil } diff --git a/app/upgrades/nextupgrade/upgrades_test.go b/app/upgrades/nextupgrade/upgrades_test.go index 9da7aa2eb..4a056b036 100644 --- a/app/upgrades/nextupgrade/upgrades_test.go +++ b/app/upgrades/nextupgrade/upgrades_test.go @@ -3,13 +3,16 @@ package nextupgrade_test import ( "testing" - ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/neutron-org/neutron/app/params" + + ccvconsumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types" sdk "github.com/cosmos/cosmos-sdk/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/cosmos/gaia/v11/x/globalfee" globalfeetypes "github.com/cosmos/gaia/v11/x/globalfee/types" + ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" "github.com/neutron-org/neutron/app/upgrades/nextupgrade" "github.com/neutron-org/neutron/testutil" "github.com/stretchr/testify/suite" @@ -68,3 +71,34 @@ func (suite *UpgradeTestSuite) TestGlobalFeesUpgrade() { requiredTotalBypassMinFeeMsgGasUsage := uint64(1_000_000) suite.Require().Equal(requiredTotalBypassMinFeeMsgGasUsage, actualTotalBypassMinFeeMsgGasUsage) } + +func (suite *UpgradeTestSuite) TestRewardDenomsUpgrade() { + var ( + app = suite.GetNeutronZoneApp(suite.ChainA) + ccvConsumerSubspace = app.GetSubspace(ccvconsumertypes.ModuleName) + ctx = suite.ChainA.GetContext() + ) + + suite.Require().True(ccvConsumerSubspace.Has(ctx, ccvconsumertypes.KeyRewardDenoms)) + + // emulate mainnet/testnet state + ccvConsumerSubspace.Set(ctx, ccvconsumertypes.KeyRewardDenoms, &[]string{params.DefaultDenom}) + + var denomsBefore []string + ccvConsumerSubspace.Get(ctx, ccvconsumertypes.KeyRewardDenoms, &denomsBefore) + suite.Require().Equal(denomsBefore, []string{params.DefaultDenom}) + + upgrade := upgradetypes.Plan{ + Name: nextupgrade.UpgradeName, + Info: "some text here", + Height: 100, + } + app.UpgradeKeeper.ApplyUpgrade(ctx, upgrade) + + suite.Require().True(ccvConsumerSubspace.Has(ctx, ccvconsumertypes.KeyRewardDenoms)) + + var denoms []string + ccvConsumerSubspace.Get(ctx, ccvconsumertypes.KeyRewardDenoms, &denoms) + requiredDenoms := []string{params.DefaultDenom, "ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349"} + suite.Require().Equal(requiredDenoms, denoms) +} diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 91fe12f10..23f301405 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -43,7 +43,8 @@ type UpgradeKeepers struct { CapabilityKeeper *capabilitykeeper.Keeper BuilderKeeper builderkeeper.Keeper // subspaces - GlobalFeeSubspace paramtypes.Subspace + GlobalFeeSubspace paramtypes.Subspace + CcvConsumerSubspace paramtypes.Subspace } type StoreKeys interface { diff --git a/cmd/neutrond/util.go b/cmd/neutrond/util.go index a214bb7d1..a699abe57 100644 --- a/cmd/neutrond/util.go +++ b/cmd/neutrond/util.go @@ -1,8 +1,14 @@ package main import ( - "cosmossdk.io/log" "fmt" + "os" + "path" + "path/filepath" + "strings" + + "cosmossdk.io/log" + tmcfg "github.com/cometbft/cometbft/config" tmcli "github.com/cometbft/cometbft/libs/cli" tmlog "github.com/cometbft/cometbft/libs/log" @@ -14,10 +20,6 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/spf13/viper" - "os" - "path" - "path/filepath" - "strings" ) // NOTE: The functions below are copy-pasted from cosmos-sdk@v0.47.3 (see https://github.com/cosmos/cosmos-sdk/blob/v0.47.3/server/util.go#L122) diff --git a/proto/neutron/contractmanager/failure.proto b/proto/neutron/contractmanager/failure.proto new file mode 100644 index 000000000..2ac24a5a6 --- /dev/null +++ b/proto/neutron/contractmanager/failure.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; +package neutron.contractmanager; + +import "ibc/core/channel/v1/channel.proto"; + +option go_package = "github.com/neutron-org/neutron/x/contractmanager/types"; + +// Failure message contains information about ACK failures and can be used to +// replay ACK in case of requirement. +// Note that Failure means that sudo handler to cosmwasm contract failed for some reason +message Failure { + // Address of the failed contract + string address = 1; + // Id of the failure under specific address + uint64 id = 2; + // Acknowledgement type + string ack_type = 3; + // IBC Packet + ibc.core.channel.v1.Packet packet = 4; + // Acknowledgement + ibc.core.channel.v1.Acknowledgement ack = 5; +} diff --git a/proto/neutron/contractmanager/genesis.proto b/proto/neutron/contractmanager/genesis.proto index 3ac92eb55..bcbd3ea87 100644 --- a/proto/neutron/contractmanager/genesis.proto +++ b/proto/neutron/contractmanager/genesis.proto @@ -3,25 +3,11 @@ package neutron.contractmanager; import "gogoproto/gogo.proto"; import "neutron/contractmanager/params.proto"; +import "neutron/contractmanager/failure.proto"; // this line is used by starport scaffolding # genesis/proto/import option go_package = "github.com/neutron-org/neutron/x/contractmanager/types"; -// Failure message contains information about ACK failures and can be used to -// replay ACK in case of requirement. -message Failure { - // ChannelId - string channel_id = 1; - // Address of the failed contract - string address = 2; - // id of the failure under specific address - uint64 id = 3; - // ACK id to restore - uint64 ack_id = 4; - // Acknowledgement type - string ack_type = 5; -} - // GenesisState defines the contractmanager module's genesis state. message GenesisState { Params params = 1 [ (gogoproto.nullable) = false ]; diff --git a/proto/neutron/contractmanager/query.proto b/proto/neutron/contractmanager/query.proto index b517432e6..8ce870c3e 100644 --- a/proto/neutron/contractmanager/query.proto +++ b/proto/neutron/contractmanager/query.proto @@ -5,7 +5,7 @@ import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; import "neutron/contractmanager/params.proto"; -import "neutron/contractmanager/genesis.proto"; +import "neutron/contractmanager/failure.proto"; // this line is used by starport scaffolding # 1 option go_package = "github.com/neutron-org/neutron/x/contractmanager/types"; diff --git a/proto/neutron/contractmanager/v1/failure.proto b/proto/neutron/contractmanager/v1/failure.proto new file mode 100644 index 000000000..a60d8984a --- /dev/null +++ b/proto/neutron/contractmanager/v1/failure.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; +package neutron.contractmanager.v1; + +option go_package = "github.com/neutron-org/neutron/x/contractmanager/types/v1"; + +// Deprecated. Used only for migration purposes. +message Failure { + // ChannelId + string channel_id = 1; + // Address of the failed contract + string address = 2; + // id of the failure under specific address + uint64 id = 3; + // ACK id to restore + uint64 ack_id = 4; + // Acknowledgement type + string ack_type = 5; +} diff --git a/testutil/mocks/interchaintxs/types/expected_keepers.go b/testutil/mocks/interchaintxs/types/expected_keepers.go index 0c903226c..391c209d8 100644 --- a/testutil/mocks/interchaintxs/types/expected_keepers.go +++ b/testutil/mocks/interchaintxs/types/expected_keepers.go @@ -116,15 +116,15 @@ func (m *MockContractManagerKeeper) EXPECT() *MockContractManagerKeeperMockRecor } // AddContractFailure mocks base method. -func (m *MockContractManagerKeeper) AddContractFailure(ctx types.Context, channelID, address string, ackID uint64, ackType string) { +func (m *MockContractManagerKeeper) AddContractFailure(ctx types.Context, packet *types3.Packet, address, ackType string, ack *types3.Acknowledgement) { m.ctrl.T.Helper() - m.ctrl.Call(m, "AddContractFailure", ctx, channelID, address, ackID, ackType) + m.ctrl.Call(m, "AddContractFailure", ctx, packet, address, ackType, ack) } // AddContractFailure indicates an expected call of AddContractFailure. -func (mr *MockContractManagerKeeperMockRecorder) AddContractFailure(ctx, channelID, address, ackID, ackType interface{}) *gomock.Call { +func (mr *MockContractManagerKeeperMockRecorder) AddContractFailure(ctx, packet, address, ackType, ack interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddContractFailure", reflect.TypeOf((*MockContractManagerKeeper)(nil).AddContractFailure), ctx, channelID, address, ackID, ackType) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddContractFailure", reflect.TypeOf((*MockContractManagerKeeper)(nil).AddContractFailure), ctx, packet, address, ackType, ack) } // HasContractInfo mocks base method. diff --git a/testutil/mocks/transfer/types/expected_keepers.go b/testutil/mocks/transfer/types/expected_keepers.go index e7c4dfa3b..cbadbc2c2 100644 --- a/testutil/mocks/transfer/types/expected_keepers.go +++ b/testutil/mocks/transfer/types/expected_keepers.go @@ -38,15 +38,15 @@ func (m *MockContractManagerKeeper) EXPECT() *MockContractManagerKeeperMockRecor } // AddContractFailure mocks base method. -func (m *MockContractManagerKeeper) AddContractFailure(ctx types.Context, channelID, address string, ackID uint64, ackType string) { +func (m *MockContractManagerKeeper) AddContractFailure(ctx types.Context, packet *types1.Packet, address, ackType string, ack *types1.Acknowledgement) { m.ctrl.T.Helper() - m.ctrl.Call(m, "AddContractFailure", ctx, channelID, address, ackID, ackType) + m.ctrl.Call(m, "AddContractFailure", ctx, packet, address, ackType, ack) } // AddContractFailure indicates an expected call of AddContractFailure. -func (mr *MockContractManagerKeeperMockRecorder) AddContractFailure(ctx, channelID, address, ackID, ackType interface{}) *gomock.Call { +func (mr *MockContractManagerKeeperMockRecorder) AddContractFailure(ctx, packet, address, ackType, ack interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddContractFailure", reflect.TypeOf((*MockContractManagerKeeper)(nil).AddContractFailure), ctx, channelID, address, ackID, ackType) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddContractFailure", reflect.TypeOf((*MockContractManagerKeeper)(nil).AddContractFailure), ctx, packet, address, ackType, ack) } // HasContractInfo mocks base method. diff --git a/wasmbinding/bindings/msg.go b/wasmbinding/bindings/msg.go index e1b4fcff7..76e649b40 100644 --- a/wasmbinding/bindings/msg.go +++ b/wasmbinding/bindings/msg.go @@ -46,6 +46,10 @@ type NeutronMsg struct { // Cron types AddSchedule *AddSchedule `json:"add_schedule,omitempty"` RemoveSchedule *RemoveSchedule `json:"remove_schedule,omitempty"` + + // Contractmanager types + /// A contract that has failed acknowledgement can resubmit it + ResubmitFailure *ResubmitFailure `json:"resubmit_failure,omitempty"` } // SubmitTx submits interchain transaction on a remote chain. @@ -200,3 +204,11 @@ type MsgExecuteContract struct { // Msg json encoded message to be passed to the contract Msg string `json:"msg,omitempty"` } + +type ResubmitFailure struct { + FailureId uint64 `json:"failure_id"` +} + +type ResubmitFailureResponse struct { + FailureId uint64 `json:"failure_id"` +} diff --git a/wasmbinding/bindings/query.go b/wasmbinding/bindings/query.go index bdbf085d2..0d76a9ac2 100644 --- a/wasmbinding/bindings/query.go +++ b/wasmbinding/bindings/query.go @@ -3,6 +3,8 @@ package bindings import ( "encoding/json" + contractmanagertypes "github.com/neutron-org/neutron/x/contractmanager/types" + feerefundertypes "github.com/neutron-org/neutron/x/feerefunder/types" sdktypes "github.com/cosmos/cosmos-sdk/types" @@ -27,11 +29,14 @@ type NeutronQuery struct { // MinIbcFee MinIbcFee *QueryMinIbcFeeRequest `json:"min_ibc_fee,omitempty"` // Token Factory queries - /// Given a subdenom minted by a contract via `NeutronMsg::MintTokens`, - /// returns the full denom as used by `BankMsg::Send`. + // Given a subdenom minted by a contract via `NeutronMsg::MintTokens`, + // returns the full denom as used by `BankMsg::Send`. FullDenom *FullDenom `json:"full_denom,omitempty"` - /// Returns the admin of a denom, if the denom is a Token Factory denom. + // Returns the admin of a denom, if the denom is a Token Factory denom. DenomAdmin *DenomAdmin `json:"denom_admin,omitempty"` + // Contractmanager queries + // Query all failures for address + Failures *Failures `json:"failures,omitempty"` } /* Requests */ @@ -185,3 +190,12 @@ type DenomAdminResponse struct { type FullDenomResponse struct { Denom string `json:"denom"` } + +type Failures struct { + Address string `json:"address"` + Pagination *query.PageRequest `json:"pagination,omitempty"` +} + +type FailuresResponse struct { + Failures []contractmanagertypes.Failure `json:"failures"` +} diff --git a/wasmbinding/custom_querier.go b/wasmbinding/custom_querier.go index e4d717bc1..385ab69e8 100644 --- a/wasmbinding/custom_querier.go +++ b/wasmbinding/custom_querier.go @@ -128,6 +128,19 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag return bz, nil + case contractQuery.Failures != nil: + res, err := qp.GetFailures(ctx, contractQuery.Failures.Address, contractQuery.Failures.Pagination) + if err != nil { + return nil, errors.Wrap(err, "unable to get denom admin") + } + + bz, err := json.Marshal(res) + if err != nil { + return nil, errors.Wrap(err, "failed to JSON marshal FailuresResponse response") + } + + return bz, nil + default: return nil, wasmvmtypes.UnsupportedRequest{Kind: "unknown neutron query type"} } diff --git a/wasmbinding/message_plugin.go b/wasmbinding/message_plugin.go index 00041e3d2..ead5581ca 100644 --- a/wasmbinding/message_plugin.go +++ b/wasmbinding/message_plugin.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" + contractmanagerkeeper "github.com/neutron-org/neutron/x/contractmanager/keeper" + "cosmossdk.io/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -45,34 +47,37 @@ func CustomMessageDecorator( bankKeeper *bankkeeper.BaseKeeper, tokenFactoryKeeper *tokenfactorykeeper.Keeper, cronKeeper *cronkeeper.Keeper, + contractmanagerKeeper *contractmanagerkeeper.Keeper, ) func(messenger wasmkeeper.Messenger) wasmkeeper.Messenger { return func(old wasmkeeper.Messenger) wasmkeeper.Messenger { return &CustomMessenger{ - Keeper: *ictx, - Wrapped: old, - Ictxmsgserver: ictxkeeper.NewMsgServerImpl(*ictx), - Icqmsgserver: icqkeeper.NewMsgServerImpl(*icq), - transferKeeper: transferKeeper, - Adminserver: adminmodulekeeper.NewMsgServerImpl(*adminKeeper), - Bank: bankKeeper, - TokenFactory: tokenFactoryKeeper, - CronKeeper: cronKeeper, - AdminKeeper: adminKeeper, + Keeper: *ictx, + Wrapped: old, + Ictxmsgserver: ictxkeeper.NewMsgServerImpl(*ictx), + Icqmsgserver: icqkeeper.NewMsgServerImpl(*icq), + transferKeeper: transferKeeper, + Adminserver: adminmodulekeeper.NewMsgServerImpl(*adminKeeper), + Bank: bankKeeper, + TokenFactory: tokenFactoryKeeper, + CronKeeper: cronKeeper, + AdminKeeper: adminKeeper, + ContractmanagerKeeper: contractmanagerKeeper, } } } type CustomMessenger struct { - Keeper ictxkeeper.Keeper - Wrapped wasmkeeper.Messenger - Ictxmsgserver ictxtypes.MsgServer - Icqmsgserver icqtypes.MsgServer - transferKeeper transferwrapperkeeper.KeeperTransferWrapper - Adminserver admintypes.MsgServer - Bank *bankkeeper.BaseKeeper - TokenFactory *tokenfactorykeeper.Keeper - CronKeeper *cronkeeper.Keeper - AdminKeeper *adminmodulekeeper.Keeper + Keeper ictxkeeper.Keeper + Wrapped wasmkeeper.Messenger + Ictxmsgserver ictxtypes.MsgServer + Icqmsgserver icqtypes.MsgServer + transferKeeper transferwrapperkeeper.KeeperTransferWrapper + Adminserver admintypes.MsgServer + Bank *bankkeeper.BaseKeeper + TokenFactory *tokenfactorykeeper.Keeper + CronKeeper *cronkeeper.Keeper + AdminKeeper *adminmodulekeeper.Keeper + ContractmanagerKeeper *contractmanagerkeeper.Keeper } var _ wasmkeeper.Messenger = (*CustomMessenger)(nil) @@ -128,6 +133,9 @@ func (m *CustomMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre if contractMsg.RemoveSchedule != nil { return m.removeSchedule(ctx, contractAddr, contractMsg.RemoveSchedule) } + if contractMsg.ResubmitFailure != nil { + return m.resubmitFailure(ctx, contractAddr, contractMsg.ResubmitFailure) + } } return m.Wrapped.DispatchMsg(ctx, contractAddr, contractIBCPortID, msg) @@ -846,6 +854,35 @@ func (m *CustomMessenger) removeSchedule(ctx sdk.Context, contractAddr sdk.AccAd return nil, [][]byte{data}, nil } +func (m *CustomMessenger) resubmitFailure(ctx sdk.Context, contractAddr sdk.AccAddress, resubmitFailure *bindings.ResubmitFailure) ([]sdk.Event, [][]byte, error) { + failure, err := m.ContractmanagerKeeper.GetFailure(ctx, contractAddr, resubmitFailure.FailureId) + if err != nil { + return nil, nil, errors.Wrap(sdkerrors.ErrNotFound, "no failure found to resubmit") + } + + err = m.ContractmanagerKeeper.ResubmitFailure(ctx, contractAddr, failure) + + if err != nil { + ctx.Logger().Error("failed to resubmitFailure", + "from_address", contractAddr.String(), + "error", err, + ) + return nil, nil, errors.Wrap(err, "failed to resubmitFailure") + } + + resp := bindings.ResubmitFailureResponse{FailureId: failure.Id} + data, err := json.Marshal(&resp) + if err != nil { + ctx.Logger().Error("json.Marshal: failed to marshal remove resubmitFailure response to JSON", + "from_address", contractAddr.String(), + "error", err, + ) + return nil, nil, errors.Wrap(err, "marshal json failed") + } + + return nil, [][]byte{data}, nil +} + func (m *CustomMessenger) isAdmin(ctx sdk.Context, contractAddr sdk.AccAddress) bool { for _, admin := range m.AdminKeeper.GetAdmins(ctx) { if admin == contractAddr.String() { diff --git a/wasmbinding/queries.go b/wasmbinding/queries.go index efea939ca..ef5930b0d 100644 --- a/wasmbinding/queries.go +++ b/wasmbinding/queries.go @@ -4,6 +4,7 @@ import ( "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkquery "github.com/cosmos/cosmos-sdk/types/query" + contractmanagertypes "github.com/neutron-org/neutron/x/contractmanager/types" "github.com/neutron-org/neutron/wasmbinding/bindings" "github.com/neutron-org/neutron/x/interchainqueries/types" @@ -104,6 +105,18 @@ func (qp *QueryPlugin) GetMinIbcFee(ctx sdk.Context, _ *bindings.QueryMinIbcFeeR return &bindings.QueryMinIbcFeeResponse{MinFee: fee}, nil } +func (qp *QueryPlugin) GetFailures(ctx sdk.Context, address string, pagination *sdkquery.PageRequest) (*bindings.FailuresResponse, error) { + res, err := qp.contractmanagerKeeper.AddressFailures(ctx, &contractmanagertypes.QueryFailuresRequest{ + Address: address, + Pagination: pagination, + }) + if err != nil { + return nil, errors.Wrapf(err, "failed to get failures for address: %s", address) + } + + return &bindings.FailuresResponse{Failures: res.Failures}, nil +} + func mapGRPCRegisteredQueryToWasmBindings(grpcQuery types.RegisteredQuery) bindings.RegisteredQuery { return bindings.RegisteredQuery{ ID: grpcQuery.GetId(), diff --git a/wasmbinding/query_plugin.go b/wasmbinding/query_plugin.go index 22e9f9de7..1b8e346db 100644 --- a/wasmbinding/query_plugin.go +++ b/wasmbinding/query_plugin.go @@ -1,6 +1,7 @@ package wasmbinding import ( + contractmanagerkeeper "github.com/neutron-org/neutron/x/contractmanager/keeper" feeburnerkeeper "github.com/neutron-org/neutron/x/feeburner/keeper" feerefunderkeeper "github.com/neutron-org/neutron/x/feerefunder/keeper" icqkeeper "github.com/neutron-org/neutron/x/interchainqueries/keeper" @@ -10,20 +11,22 @@ import ( ) type QueryPlugin struct { - icaControllerKeeper *icacontrollerkeeper.Keeper - icqKeeper *icqkeeper.Keeper - feeBurnerKeeper *feeburnerkeeper.Keeper - feeRefunderKeeper *feerefunderkeeper.Keeper - tokenFactoryKeeper *tokenfactorykeeper.Keeper + icaControllerKeeper *icacontrollerkeeper.Keeper + icqKeeper *icqkeeper.Keeper + feeBurnerKeeper *feeburnerkeeper.Keeper + feeRefunderKeeper *feerefunderkeeper.Keeper + tokenFactoryKeeper *tokenfactorykeeper.Keeper + contractmanagerKeeper *contractmanagerkeeper.Keeper } // NewQueryPlugin returns a reference to a new QueryPlugin. -func NewQueryPlugin(icaControllerKeeper *icacontrollerkeeper.Keeper, icqKeeper *icqkeeper.Keeper, feeBurnerKeeper *feeburnerkeeper.Keeper, feeRefunderKeeper *feerefunderkeeper.Keeper, tfk *tokenfactorykeeper.Keeper) *QueryPlugin { +func NewQueryPlugin(icaControllerKeeper *icacontrollerkeeper.Keeper, icqKeeper *icqkeeper.Keeper, feeBurnerKeeper *feeburnerkeeper.Keeper, feeRefunderKeeper *feerefunderkeeper.Keeper, tfk *tokenfactorykeeper.Keeper, contractmanagerKeeper *contractmanagerkeeper.Keeper) *QueryPlugin { return &QueryPlugin{ - icaControllerKeeper: icaControllerKeeper, - icqKeeper: icqKeeper, - feeBurnerKeeper: feeBurnerKeeper, - feeRefunderKeeper: feeRefunderKeeper, - tokenFactoryKeeper: tfk, + icaControllerKeeper: icaControllerKeeper, + icqKeeper: icqKeeper, + feeBurnerKeeper: feeBurnerKeeper, + feeRefunderKeeper: feeRefunderKeeper, + tokenFactoryKeeper: tfk, + contractmanagerKeeper: contractmanagerKeeper, } } diff --git a/wasmbinding/stargate_allowlist.go b/wasmbinding/stargate_allowlist.go index 3f8697914..e054f0008 100644 --- a/wasmbinding/stargate_allowlist.go +++ b/wasmbinding/stargate_allowlist.go @@ -7,7 +7,6 @@ import ( ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" ibcconnectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" - contractmanagertypes "github.com/neutron-org/neutron/x/contractmanager/types" feeburnertypes "github.com/neutron-org/neutron/x/feeburner/types" interchainqueriestypes "github.com/neutron-org/neutron/x/interchainqueries/types" interchaintxstypes "github.com/neutron-org/neutron/x/interchaintxs/types" @@ -39,10 +38,6 @@ func AcceptedStargateQueries() wasmkeeper.AcceptedStargateQueries { "/cosmos.bank.v1beta1.Query/Params": &banktypes.QueryParamsResponse{}, "/cosmos.bank.v1beta1.Query/SupplyOf": &banktypes.QuerySupplyOfResponse{}, - // contractmanager - "/neutron.contractmanager.Query/AddressFailures": &contractmanagertypes.QueryFailuresResponse{}, - "/neutron.contractmanager.Query/Failures": &contractmanagertypes.QueryFailuresResponse{}, - // interchaintxs "/neutron.interchaintxs.Query/Params": &interchaintxstypes.QueryParamsResponse{}, diff --git a/wasmbinding/test/custom_message_test.go b/wasmbinding/test/custom_message_test.go index ada721a6a..d802dbe44 100644 --- a/wasmbinding/test/custom_message_test.go +++ b/wasmbinding/test/custom_message_test.go @@ -5,6 +5,10 @@ import ( "fmt" "testing" + contractmanagertypes "github.com/neutron-org/neutron/x/contractmanager/types" + + ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/stretchr/testify/suite" ictxtypes "github.com/neutron-org/neutron/x/interchaintxs/types" @@ -57,6 +61,7 @@ func (suite *CustomMessengerTestSuite) SetupTest() { suite.messenger.TokenFactory = suite.neutron.TokenFactoryKeeper suite.messenger.CronKeeper = &suite.neutron.CronKeeper suite.messenger.AdminKeeper = &suite.neutron.AdminmoduleKeeper + suite.messenger.ContractmanagerKeeper = &suite.neutron.ContractManagerKeeper suite.contractOwner = keeper.RandomAccountAddress(suite.T()) err := suite.messenger.TokenFactory.SetParams(suite.ctx, tokenfactorytypes.NewParams( @@ -593,6 +598,101 @@ func (suite *CustomMessengerTestSuite) TestAddRemoveSchedule() { suite.Equal([][]uint8{expected}, data) } +func (suite *CustomMessengerTestSuite) TestResubmitFailureAck() { + // Store code and instantiate reflect contract + codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm") + suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID) + suite.Require().NotEmpty(suite.contractAddress) + + // Add failure + packet := ibcchanneltypes.Packet{} + ack := ibcchanneltypes.Acknowledgement{ + Response: &ibcchanneltypes.Acknowledgement_Result{Result: []byte("Result")}, + } + failureID := suite.messenger.ContractmanagerKeeper.GetNextFailureIDKey(suite.ctx, suite.contractAddress.String()) + suite.messenger.ContractmanagerKeeper.AddContractFailure(suite.ctx, &packet, suite.contractAddress.String(), contractmanagertypes.Ack, &ack) + + // Craft message + msg, err := json.Marshal(bindings.NeutronMsg{ + ResubmitFailure: &bindings.ResubmitFailure{ + FailureId: failureID, + }, + }) + suite.NoError(err) + + // Dispatch + events, data, err := suite.messenger.DispatchMsg(suite.ctx, suite.contractAddress, suite.Path.EndpointA.ChannelConfig.PortID, types.CosmosMsg{ + Custom: msg, + }) + suite.NoError(err) + suite.Nil(events) + expected, err := json.Marshal(&bindings.ResubmitFailureResponse{}) + suite.NoError(err) + suite.Equal([][]uint8{expected}, data) +} + +func (suite *CustomMessengerTestSuite) TestResubmitFailureTimeout() { + // Store code and instantiate reflect contract + codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm") + suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID) + suite.Require().NotEmpty(suite.contractAddress) + + // Add failure + packet := ibcchanneltypes.Packet{} + ack := ibcchanneltypes.Acknowledgement{ + Response: &ibcchanneltypes.Acknowledgement_Error{Error: "Error"}, + } + failureID := suite.messenger.ContractmanagerKeeper.GetNextFailureIDKey(suite.ctx, suite.contractAddress.String()) + suite.messenger.ContractmanagerKeeper.AddContractFailure(suite.ctx, &packet, suite.contractAddress.String(), "timeout", &ack) + + // Craft message + msg, err := json.Marshal(bindings.NeutronMsg{ + ResubmitFailure: &bindings.ResubmitFailure{ + FailureId: failureID, + }, + }) + suite.NoError(err) + + // Dispatch + events, data, err := suite.messenger.DispatchMsg(suite.ctx, suite.contractAddress, suite.Path.EndpointA.ChannelConfig.PortID, types.CosmosMsg{ + Custom: msg, + }) + suite.NoError(err) + suite.Nil(events) + expected, err := json.Marshal(&bindings.ResubmitFailureResponse{FailureId: failureID}) + suite.NoError(err) + suite.Equal([][]uint8{expected}, data) +} + +func (suite *CustomMessengerTestSuite) TestResubmitFailureFromDifferentContract() { + // Store code and instantiate reflect contract + codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm") + suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID) + suite.Require().NotEmpty(suite.contractAddress) + + // Add failure + packet := ibcchanneltypes.Packet{} + ack := ibcchanneltypes.Acknowledgement{ + Response: &ibcchanneltypes.Acknowledgement_Error{Error: "Error"}, + } + failureID := suite.messenger.ContractmanagerKeeper.GetNextFailureIDKey(suite.ctx, testutil.TestOwnerAddress) + suite.messenger.ContractmanagerKeeper.AddContractFailure(suite.ctx, &packet, testutil.TestOwnerAddress, contractmanagertypes.Ack, &ack) + + // Craft message + msg, err := json.Marshal(bindings.NeutronMsg{ + ResubmitFailure: &bindings.ResubmitFailure{ + FailureId: failureID, + }, + }) + suite.NoError(err) + + // Dispatch + _, _, err = suite.messenger.DispatchMsg(suite.ctx, suite.contractAddress, suite.Path.EndpointA.ChannelConfig.PortID, types.CosmosMsg{ + Custom: msg, + }) + suite.ErrorContains(err, "no failure found to resubmit: not found") +} + func (suite *CustomMessengerTestSuite) executeCustomMsg(owner sdk.AccAddress, fullMsg bindings.NeutronMsg) (result [][]byte, msg []byte) { msg, err := json.Marshal(fullMsg) suite.NoError(err) diff --git a/wasmbinding/wasm.go b/wasmbinding/wasm.go index cb7be3872..cdb9ec5dd 100644 --- a/wasmbinding/wasm.go +++ b/wasmbinding/wasm.go @@ -4,6 +4,7 @@ import ( "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + contractmanagerkeeper "github.com/neutron-org/neutron/x/contractmanager/keeper" cronkeeper "github.com/neutron-org/neutron/x/cron/keeper" feeburnerkeeper "github.com/neutron-org/neutron/x/feeburner/keeper" feerefunderkeeper "github.com/neutron-org/neutron/x/feerefunder/keeper" @@ -27,14 +28,15 @@ func RegisterCustomPlugins( bank *bankkeeper.BaseKeeper, tfk *tokenfactorykeeper.Keeper, cronKeeper *cronkeeper.Keeper, + contractmanagerKeeper *contractmanagerkeeper.Keeper, ) []wasmkeeper.Option { - wasmQueryPlugin := NewQueryPlugin(ictxKeeper, icqKeeper, feeBurnerKeeper, feeRefunderKeeper, tfk) + wasmQueryPlugin := NewQueryPlugin(ictxKeeper, icqKeeper, feeBurnerKeeper, feeRefunderKeeper, tfk, contractmanagerKeeper) queryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{ Custom: CustomQuerier(wasmQueryPlugin), }) messagePluginOpt := wasmkeeper.WithMessageHandlerDecorator( - CustomMessageDecorator(ictxKeeper, icqKeeper, transfer, adminKeeper, bank, tfk, cronKeeper), + CustomMessageDecorator(ictxKeeper, icqKeeper, transfer, adminKeeper, bank, tfk, cronKeeper, contractmanagerKeeper), ) return []wasm.Option{ diff --git a/x/contractmanager/client/cli/query_failure_test.go b/x/contractmanager/client/cli/query_failure_test.go index a70cfd2a4..f76d69a44 100644 --- a/x/contractmanager/client/cli/query_failure_test.go +++ b/x/contractmanager/client/cli/query_failure_test.go @@ -6,6 +6,8 @@ import ( "strconv" "testing" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/neutron-org/neutron/app" tmcli "github.com/cometbft/cometbft/libs/cli" @@ -39,6 +41,7 @@ func networkWithFailureObjects(t *testing.T, n int) (*network.Network, []types.F acc := sdktypes.AccAddress(pub.Address()) failure := types.Failure{ Address: acc.String(), + Packet: &channeltypes.Packet{}, } nullify.Fill(&failure) state.FailuresList = append(state.FailuresList, failure) diff --git a/x/contractmanager/genesis.go b/x/contractmanager/genesis.go index 9786d40d9..35604dfe4 100644 --- a/x/contractmanager/genesis.go +++ b/x/contractmanager/genesis.go @@ -11,7 +11,7 @@ import ( func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { // Set all the failure for _, elem := range genState.FailuresList { - k.AddContractFailure(ctx, elem.ChannelId, elem.Address, elem.AckId, elem.AckType) + k.AddContractFailure(ctx, elem.Packet, elem.Address, elem.AckType, elem.Ack) } // this line is used by starport scaffolding # genesis/module/init err := k.SetParams(ctx, genState.Params) diff --git a/x/contractmanager/genesis_test.go b/x/contractmanager/genesis_test.go index acf2c55ac..feb3ff00a 100644 --- a/x/contractmanager/genesis_test.go +++ b/x/contractmanager/genesis_test.go @@ -3,6 +3,8 @@ package contractmanager_test import ( "testing" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/stretchr/testify/require" keepertest "github.com/neutron-org/neutron/testutil/contractmanager/keeper" @@ -19,10 +21,18 @@ func TestGenesis(t *testing.T) { { Address: "address1", Id: 1, + AckType: types.Ack, + Packet: &channeltypes.Packet{ + Sequence: 1, + }, }, { Address: "address1", Id: 2, + AckType: "timeout", + Packet: &channeltypes.Packet{ + Sequence: 2, + }, }, }, // this line is used by starport scaffolding # genesis/test/state diff --git a/x/contractmanager/keeper/failure.go b/x/contractmanager/keeper/failure.go index bf00afa66..308decb34 100644 --- a/x/contractmanager/keeper/failure.go +++ b/x/contractmanager/keeper/failure.go @@ -1,27 +1,28 @@ package keeper import ( + "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" "github.com/neutron-org/neutron/x/contractmanager/types" ) // AddContractFailure adds a specific failure to the store using address as the key -func (k Keeper) AddContractFailure(ctx sdk.Context, channelID, address string, ackID uint64, ackType string) { +func (k Keeper) AddContractFailure(ctx sdk.Context, packet *ibcchanneltypes.Packet, address, ackType string, ack *ibcchanneltypes.Acknowledgement) { failure := types.Failure{ - ChannelId: channelID, - Address: address, - AckId: ackID, - AckType: ackType, + Address: address, + AckType: ackType, + Packet: packet, + Ack: ack, } nextFailureID := k.GetNextFailureIDKey(ctx, failure.GetAddress()) + failure.Id = nextFailureID store := ctx.KVStore(k.storeKey) - - failure.Id = nextFailureID - b := k.cdc.MustMarshal(&failure) - store.Set(types.GetFailureKey(failure.GetAddress(), nextFailureID), b) + bz := k.cdc.MustMarshal(&failure) + store.Set(types.GetFailureKey(failure.GetAddress(), nextFailureID), bz) } func (k Keeper) GetNextFailureIDKey(ctx sdk.Context, address string) uint64 { @@ -43,7 +44,6 @@ func (k Keeper) GetNextFailureIDKey(ctx sdk.Context, address string) uint64 { func (k Keeper) GetAllFailures(ctx sdk.Context) (list []types.Failure) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.ContractFailuresKey) iterator := sdk.KVStorePrefixIterator(store, []byte{}) - defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -54,3 +54,57 @@ func (k Keeper) GetAllFailures(ctx sdk.Context) (list []types.Failure) { return } + +func (k Keeper) GetFailure(ctx sdk.Context, contractAddr sdk.AccAddress, id uint64) (*types.Failure, error) { + store := ctx.KVStore(k.storeKey) + key := types.GetFailureKey(contractAddr.String(), id) + + bz := store.Get(key) + if bz == nil { + return nil, errors.Wrapf(sdkerrors.ErrKeyNotFound, "no failure found for contractAddress = %s and failureId = %d", contractAddr.String(), id) + } + var res types.Failure + k.cdc.MustUnmarshal(bz, &res) + + return &res, nil +} + +// ResubmitFailure tries to call sudo handler for contract with same parameters as initially. +func (k Keeper) ResubmitFailure(ctx sdk.Context, contractAddr sdk.AccAddress, failure *types.Failure) error { + if failure.Packet == nil { + return errors.Wrapf(types.IncorrectFailureToResubmit, "cannot resubmit failure without packet info; failureId = %d", failure.Id) + } + + switch failure.GetAckType() { + case types.Ack: + if failure.GetAck() == nil { + return errors.Wrapf(types.IncorrectFailureToResubmit, "cannot resubmit failure without acknowledgement; failureId = %d", failure.Id) + } + if failure.GetAck().GetError() == "" { + if _, err := k.SudoResponse(ctx, contractAddr, *failure.Packet, failure.Ack.GetResult()); err != nil { + return errors.Wrapf(types.FailedToResubmitFailure, "cannot resubmit failure ack response; failureId = %d; err = %s", failure.Id, err) + } + } else { + if _, err := k.SudoError(ctx, contractAddr, *failure.Packet, failure.Ack.GetError()); err != nil { + return errors.Wrapf(types.FailedToResubmitFailure, "cannot resubmit failure ack error; failureId = %d; err = %s", failure.Id, err) + } + } + case types.Timeout: + if _, err := k.SudoTimeout(ctx, contractAddr, *failure.Packet); err != nil { + return errors.Wrapf(types.FailedToResubmitFailure, "cannot resubmit failure ack timeout; failureId = %d; err = %s", failure.Id, err) + } + default: + return errors.Wrapf(types.IncorrectAckType, "cannot resubmit failure with incorrect ackType = %s", failure.GetAckType()) + } + + // Cleanup failure since we resubmitted it successfully + k.removeFailure(ctx, contractAddr, failure.Id) + + return nil +} + +func (k Keeper) removeFailure(ctx sdk.Context, contractAddr sdk.AccAddress, id uint64) { + store := ctx.KVStore(k.storeKey) + failureKey := types.GetFailureKey(contractAddr.String(), id) + store.Delete(failureKey) +} diff --git a/x/contractmanager/keeper/failure_test.go b/x/contractmanager/keeper/failure_test.go index 7ef9c33d2..606db61c9 100644 --- a/x/contractmanager/keeper/failure_test.go +++ b/x/contractmanager/keeper/failure_test.go @@ -2,15 +2,23 @@ package keeper_test import ( "crypto/rand" + "encoding/json" + "fmt" "strconv" "testing" + "github.com/golang/mock/gomock" + "github.com/neutron-org/neutron/testutil" + mock_types "github.com/neutron-org/neutron/testutil/mocks/contractmanager/types" + + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/neutron-org/neutron/testutil/contractmanager/nullify" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" keepertest "github.com/neutron-org/neutron/testutil/contractmanager/keeper" - "github.com/neutron-org/neutron/testutil/contractmanager/nullify" "github.com/neutron-org/neutron/x/contractmanager/keeper" "github.com/neutron-org/neutron/x/contractmanager/types" ) @@ -29,10 +37,15 @@ func createNFailure(keeper *keeper.Keeper, ctx sdk.Context, addresses, failures acc := sdk.AccAddress(pub.Address()) for c := range items[i] { + p := channeltypes.Packet{ + Sequence: 0, + SourcePort: "port-n", + } items[i][c].Address = acc.String() items[i][c].Id = uint64(c) - - keeper.AddContractFailure(ctx, items[i][c].ChannelId, items[i][c].Address, 0, "") + items[i][c].Packet = &p + items[i][c].Ack = nil + keeper.AddContractFailure(ctx, &p, items[i][c].Address, "", nil) } } return items @@ -53,14 +66,175 @@ func flattenFailures(items [][]types.Failure) []types.Failure { } func TestGetAllFailures(t *testing.T) { - keeper, ctx := keepertest.ContractManagerKeeper(t, nil) - items := createNFailure(keeper, ctx, 10, 4) + k, ctx := keepertest.ContractManagerKeeper(t, nil) + items := createNFailure(k, ctx, 10, 4) flattenItems := flattenFailures(items) - allFailures := keeper.GetAllFailures(ctx) + allFailures := k.GetAllFailures(ctx) require.ElementsMatch(t, nullify.Fill(flattenItems), nullify.Fill(allFailures), ) } + +func TestAddGetFailure(t *testing.T) { + // test adding and getting failure + contractAddress := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + k, ctx := keepertest.ContractManagerKeeper(t, nil) + failureID := k.GetNextFailureIDKey(ctx, contractAddress.String()) + k.AddContractFailure(ctx, &channeltypes.Packet{}, contractAddress.String(), types.Ack, &channeltypes.Acknowledgement{}) + failure, err := k.GetFailure(ctx, contractAddress, failureID) + require.NoError(t, err) + require.Equal(t, failureID, failure.Id) + require.Equal(t, types.Ack, failure.AckType) + + // non-existent id + _, err = k.GetFailure(ctx, contractAddress, failureID+1) + require.Error(t, err) + + // non-existent contract address + _, err = k.GetFailure(ctx, sdk.MustAccAddressFromBech32("neutron1nseacn2aqezhj3ssatfg778ctcfjuknm8ucc0l"), failureID) + require.Error(t, err) +} + +func TestResubmitFailure(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + wk := mock_types.NewMockWasmKeeper(ctrl) + k, ctx := keepertest.ContractManagerKeeper(t, wk) + + contractAddr := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + data := []byte("Result") + ack := channeltypes.Acknowledgement{ + Response: &channeltypes.Acknowledgement_Result{Result: data}, + } + ackError := channeltypes.Acknowledgement{ + Response: &channeltypes.Acknowledgement_Error{Error: "not able to do IBC tx"}, + } + + // add ack failure + packet := channeltypes.Packet{} + failureID := k.GetNextFailureIDKey(ctx, contractAddr.String()) + k.AddContractFailure(ctx, &packet, contractAddr.String(), types.Ack, &ack) + + // success response + xSuc := types.MessageResponse{} + xSuc.Response.Data = data + xSuc.Response.Request = channeltypes.Packet{} + msgSuc, err := json.Marshal(xSuc) + require.NoError(t, err) + // error response + xErr := types.MessageError{} + xErr.Error.Request = channeltypes.Packet{} + xErr.Error.Details = "not able to do IBC tx" + msgErr, err := json.Marshal(xErr) + require.NoError(t, err) + // timeout response + xTimeout := types.MessageTimeout{} + xTimeout.Timeout.Request = channeltypes.Packet{} + msgTimeout, err := json.Marshal(xTimeout) + require.NoError(t, err) + + // case: successful resubmit with ack and ack = response + wk.EXPECT().HasContractInfo(gomock.AssignableToTypeOf(ctx), contractAddr).Return(true) + wk.EXPECT().Sudo(gomock.AssignableToTypeOf(ctx), contractAddr, msgSuc).Return([]byte{}, nil) + + failure, err := k.GetFailure(ctx, contractAddr, failureID) + require.NoError(t, err) + err = k.ResubmitFailure(ctx, contractAddr, failure) + require.NoError(t, err) + // failure should be deleted + _, err = k.GetFailure(ctx, contractAddr, failureID) + require.ErrorContains(t, err, "key not found") + + // case: failed resubmit with ack and ack = response + failureID2 := k.GetNextFailureIDKey(ctx, contractAddr.String()) + k.AddContractFailure(ctx, &packet, contractAddr.String(), types.Ack, &ack) + + wk.EXPECT().HasContractInfo(gomock.AssignableToTypeOf(ctx), contractAddr).Return(true) + wk.EXPECT().Sudo(gomock.AssignableToTypeOf(ctx), contractAddr, msgSuc).Return(nil, fmt.Errorf("failed to Sudo")) + + failure2, err := k.GetFailure(ctx, contractAddr, failureID2) + require.NoError(t, err) + err = k.ResubmitFailure(ctx, contractAddr, failure2) + require.ErrorContains(t, err, "cannot resubmit failure ack response") + // failure is still there + failureAfter2, err := k.GetFailure(ctx, contractAddr, failureID2) + require.NoError(t, err) + require.Equal(t, failureAfter2.Id, failure2.Id) + + // case: successful resubmit with ack and ack = error + // add error failure + failureID3 := k.GetNextFailureIDKey(ctx, contractAddr.String()) + k.AddContractFailure(ctx, &packet, contractAddr.String(), types.Ack, &ackError) + + wk.EXPECT().HasContractInfo(gomock.AssignableToTypeOf(ctx), contractAddr).Return(true) + wk.EXPECT().Sudo(gomock.AssignableToTypeOf(ctx), contractAddr, msgErr).Return([]byte{}, nil) + + failure3, err := k.GetFailure(ctx, contractAddr, failureID3) + require.NoError(t, err) + err = k.ResubmitFailure(ctx, contractAddr, failure3) + require.NoError(t, err) + // failure should be deleted + _, err = k.GetFailure(ctx, contractAddr, failureID3) + require.ErrorContains(t, err, "key not found") + + // case: failed resubmit with ack and ack = error + failureID4 := k.GetNextFailureIDKey(ctx, contractAddr.String()) + k.AddContractFailure(ctx, &packet, contractAddr.String(), types.Ack, &ackError) + + wk.EXPECT().HasContractInfo(gomock.AssignableToTypeOf(ctx), contractAddr).Return(true) + wk.EXPECT().Sudo(gomock.AssignableToTypeOf(ctx), contractAddr, msgErr).Return(nil, fmt.Errorf("failed to Sudo")) + + failure4, err := k.GetFailure(ctx, contractAddr, failureID4) + require.NoError(t, err) + err = k.ResubmitFailure(ctx, contractAddr, failure4) + require.ErrorContains(t, err, "cannot resubmit failure ack error") + // failure is still there + failureAfter4, err := k.GetFailure(ctx, contractAddr, failureID4) + require.NoError(t, err) + require.Equal(t, failureAfter4.Id, failure4.Id) + + // case: successful resubmit with timeout + // add error failure + failureID5 := k.GetNextFailureIDKey(ctx, contractAddr.String()) + k.AddContractFailure(ctx, &packet, contractAddr.String(), "timeout", nil) + + wk.EXPECT().HasContractInfo(gomock.AssignableToTypeOf(ctx), contractAddr).Return(true) + wk.EXPECT().Sudo(gomock.AssignableToTypeOf(ctx), contractAddr, msgTimeout).Return([]byte{}, nil) + + failure5, err := k.GetFailure(ctx, contractAddr, failureID5) + require.NoError(t, err) + err = k.ResubmitFailure(ctx, contractAddr, failure5) + require.NoError(t, err) + // failure should be deleted + _, err = k.GetFailure(ctx, contractAddr, failureID5) + require.ErrorContains(t, err, "key not found") + + // case: failed resubmit with timeout + failureID6 := k.GetNextFailureIDKey(ctx, contractAddr.String()) + k.AddContractFailure(ctx, &packet, contractAddr.String(), "timeout", nil) + + wk.EXPECT().HasContractInfo(gomock.AssignableToTypeOf(ctx), contractAddr).Return(true) + wk.EXPECT().Sudo(gomock.AssignableToTypeOf(ctx), contractAddr, msgTimeout).Return(nil, fmt.Errorf("failed to Sudo")) + + failure6, err := k.GetFailure(ctx, contractAddr, failureID6) + require.NoError(t, err) + err = k.ResubmitFailure(ctx, contractAddr, failure6) + require.ErrorContains(t, err, "cannot resubmit failure ack timeout") + // failure is still there + failureAfter6, err := k.GetFailure(ctx, contractAddr, failureID6) + require.NoError(t, err) + require.Equal(t, failureAfter6.Id, failure6.Id) + + // no Failure.Ack field found for ackType = 'ack' + failureID7 := k.GetNextFailureIDKey(ctx, contractAddr.String()) + k.AddContractFailure(ctx, &packet, contractAddr.String(), types.Ack, nil) + + failure7, err := k.GetFailure(ctx, contractAddr, failureID7) + require.NoError(t, err) + err = k.ResubmitFailure(ctx, contractAddr, failure7) + require.ErrorContains(t, err, "cannot resubmit failure without acknowledgement") +} diff --git a/x/contractmanager/keeper/migrations.go b/x/contractmanager/keeper/migrations.go new file mode 100644 index 000000000..3ec98b470 --- /dev/null +++ b/x/contractmanager/keeper/migrations.go @@ -0,0 +1,21 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + v2 "github.com/neutron-org/neutron/x/contractmanager/migrations/v2" +) + +// Migrator is a struct for handling in-place store migrations. +type Migrator struct { + keeper Keeper +} + +// NewMigrator returns a new Migrator. +func NewMigrator(keeper Keeper) Migrator { + return Migrator{keeper: keeper} +} + +// Migrate1to2 migrates from version 1 to 2. +func (m Migrator) Migrate1to2(ctx sdk.Context) error { + return v2.MigrateStore(ctx, m.keeper.storeKey) +} diff --git a/x/contractmanager/migrations/v2/store.go b/x/contractmanager/migrations/v2/store.go new file mode 100644 index 000000000..3b43d4be6 --- /dev/null +++ b/x/contractmanager/migrations/v2/store.go @@ -0,0 +1,43 @@ +package v2 + +import ( + "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/neutron-org/neutron/x/contractmanager/types" +) + +// MigrateStore performs in-place store migrations. +// The migration rearranges removes all old failures, +// since they do not have the necessary fields packet and ack for resubmission +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey) error { + return migrateFailures(ctx, storeKey) +} + +func migrateFailures(ctx sdk.Context, storeKey storetypes.StoreKey) error { + ctx.Logger().Info("Migrating failures...") + + // fetch list of all old failure keys + failureKeys := make([][]byte, 0) + iteratorStore := prefix.NewStore(ctx.KVStore(storeKey), types.ContractFailuresKey) + iterator := sdk.KVStorePrefixIterator(iteratorStore, []byte{}) + + for ; iterator.Valid(); iterator.Next() { + failureKeys = append(failureKeys, iterator.Key()) + } + + err := iterator.Close() + if err != nil { + return err + } + + // remove failures + store := prefix.NewStore(ctx.KVStore(storeKey), types.ContractFailuresKey) + for _, key := range failureKeys { + store.Delete(key) + } + + ctx.Logger().Info("Finished migrating failures") + + return nil +} diff --git a/x/contractmanager/migrations/v2/store_test.go b/x/contractmanager/migrations/v2/store_test.go new file mode 100644 index 000000000..19fddf3ec --- /dev/null +++ b/x/contractmanager/migrations/v2/store_test.go @@ -0,0 +1,69 @@ +package v2_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/neutron-org/neutron/testutil" + v2 "github.com/neutron-org/neutron/x/contractmanager/migrations/v2" + "github.com/neutron-org/neutron/x/contractmanager/types" + typesv1 "github.com/neutron-org/neutron/x/contractmanager/types/v1" + "github.com/stretchr/testify/suite" +) + +type V2ContractManagerMigrationTestSuite struct { + testutil.IBCConnectionTestSuite +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(V2ContractManagerMigrationTestSuite)) +} + +func (suite *V2ContractManagerMigrationTestSuite) TestFailuresUpgrade() { + var ( + app = suite.GetNeutronZoneApp(suite.ChainA) + storeKey = app.GetKey(types.StoreKey) + ctx = suite.ChainA.GetContext() + cdc = app.AppCodec() + ) + + addressOne := testutil.TestOwnerAddress + addressTwo := "neutron1fxudpred77a0grgh69u0j7y84yks5ev4n5050z45kecz792jnd6scqu98z" + + // Write old state + store := ctx.KVStore(storeKey) + var i uint64 + for i = 0; i < 4; i++ { + var addr string + if i < 2 { + addr = addressOne + } else { + addr = addressTwo + } + failure := typesv1.Failure{ + ChannelId: "channel-0", + Address: addr, + Id: i % 2, + AckType: types.Ack, + } + bz := cdc.MustMarshal(&failure) + store.Set(types.GetFailureKey(failure.Address, failure.Id), bz) + } + + // Run migration + suite.NoError(v2.MigrateStore(ctx, storeKey)) + + // Check elements should be empty + expected := app.ContractManagerKeeper.GetAllFailures(ctx) + suite.Require().ElementsMatch(expected, []types.Failure{}) + + // Non-existent returns error + _, err := app.ContractManagerKeeper.GetFailure(ctx, sdk.MustAccAddressFromBech32(addressTwo), 0) + suite.Require().Error(err) + + // Check next id key is reset + oneKey := app.ContractManagerKeeper.GetNextFailureIDKey(ctx, addressOne) + suite.Require().Equal(oneKey, uint64(0)) + twoKey := app.ContractManagerKeeper.GetNextFailureIDKey(ctx, addressTwo) + suite.Require().Equal(twoKey, uint64(0)) +} diff --git a/x/contractmanager/module.go b/x/contractmanager/module.go index cfecf7588..c9f11ba1b 100644 --- a/x/contractmanager/module.go +++ b/x/contractmanager/module.go @@ -128,6 +128,11 @@ func (AppModule) QuerierRoute() string { return types.RouterKey } // RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + + m := keeper.NewMigrator(am.keeper) + if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil { + panic(fmt.Sprintf("failed to migrate x/contractmanager from version 1 to 2: %v", err)) + } } // RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) @@ -151,7 +156,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 -func (AppModule) ConsensusVersion() uint64 { return 1 } +func (AppModule) ConsensusVersion() uint64 { return 2 } // BeginBlock contains the logic that is automatically triggered at the beginning of each block func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} diff --git a/x/contractmanager/types/errors.go b/x/contractmanager/types/errors.go index b846d3302..612d6742f 100644 --- a/x/contractmanager/types/errors.go +++ b/x/contractmanager/types/errors.go @@ -1,12 +1,12 @@ package types -// DONTCOVER - import ( "cosmossdk.io/errors" ) // x/contractmanager module sentinel errors var ( - ErrSample = errors.Register(ModuleName, 1100, "sample error") + IncorrectAckType = errors.Register(ModuleName, 1100, "incorrect acknowledgement type") + IncorrectFailureToResubmit = errors.Register(ModuleName, 1101, "incorrect failure to resubmit") + FailedToResubmitFailure = errors.Register(ModuleName, 1102, "failed to resubmit acknowledgement") ) diff --git a/x/contractmanager/types/failure.pb.go b/x/contractmanager/types/failure.pb.go new file mode 100644 index 000000000..abc19b1a4 --- /dev/null +++ b/x/contractmanager/types/failure.pb.go @@ -0,0 +1,539 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/contractmanager/failure.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + types "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Failure message contains information about ACK failures and can be used to +// replay ACK in case of requirement. +// Note that Failure means that sudo handler to cosmwasm contract failed for some reason +type Failure struct { + // Address of the failed contract + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // Id of the failure under specific address + Id uint64 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` + // Acknowledgement type + AckType string `protobuf:"bytes,3,opt,name=ack_type,json=ackType,proto3" json:"ack_type,omitempty"` + // IBC Packet + Packet *types.Packet `protobuf:"bytes,4,opt,name=packet,proto3" json:"packet,omitempty"` + // Acknowledgement + Ack *types.Acknowledgement `protobuf:"bytes,5,opt,name=ack,proto3" json:"ack,omitempty"` +} + +func (m *Failure) Reset() { *m = Failure{} } +func (m *Failure) String() string { return proto.CompactTextString(m) } +func (*Failure) ProtoMessage() {} +func (*Failure) Descriptor() ([]byte, []int) { + return fileDescriptor_fba0c26e85dad46e, []int{0} +} +func (m *Failure) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Failure) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Failure.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Failure) XXX_Merge(src proto.Message) { + xxx_messageInfo_Failure.Merge(m, src) +} +func (m *Failure) XXX_Size() int { + return m.Size() +} +func (m *Failure) XXX_DiscardUnknown() { + xxx_messageInfo_Failure.DiscardUnknown(m) +} + +var xxx_messageInfo_Failure proto.InternalMessageInfo + +func (m *Failure) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *Failure) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +func (m *Failure) GetAckType() string { + if m != nil { + return m.AckType + } + return "" +} + +func (m *Failure) GetPacket() *types.Packet { + if m != nil { + return m.Packet + } + return nil +} + +func (m *Failure) GetAck() *types.Acknowledgement { + if m != nil { + return m.Ack + } + return nil +} + +func init() { + proto.RegisterType((*Failure)(nil), "neutron.contractmanager.Failure") +} + +func init() { + proto.RegisterFile("neutron/contractmanager/failure.proto", fileDescriptor_fba0c26e85dad46e) +} + +var fileDescriptor_fba0c26e85dad46e = []byte{ + // 288 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0xb1, 0x4e, 0xeb, 0x30, + 0x14, 0x86, 0xeb, 0xb6, 0xb7, 0xbd, 0x18, 0x89, 0xc1, 0x0b, 0x06, 0x24, 0xab, 0x20, 0x90, 0xba, + 0x60, 0xab, 0x54, 0xea, 0x0e, 0x03, 0x73, 0x15, 0x31, 0xb1, 0x20, 0xe7, 0xe4, 0x90, 0x5a, 0x69, + 0xed, 0xc8, 0x75, 0x0b, 0x7d, 0x0b, 0xde, 0x87, 0x17, 0x60, 0xec, 0xc8, 0x88, 0x9a, 0x17, 0x41, + 0x49, 0x93, 0x05, 0xd8, 0x7e, 0x4b, 0xdf, 0xe7, 0x73, 0xce, 0x4f, 0xaf, 0x2c, 0xae, 0x82, 0x77, + 0x56, 0x81, 0xb3, 0xc1, 0x6b, 0x08, 0x0b, 0x6d, 0x75, 0x8a, 0x5e, 0x3d, 0x6b, 0x33, 0x5f, 0x79, + 0x94, 0xb9, 0x77, 0xc1, 0xb1, 0xe3, 0x1a, 0x93, 0x3f, 0xb0, 0xd3, 0x73, 0x13, 0x83, 0x02, 0xe7, + 0x51, 0xc1, 0x4c, 0x5b, 0x8b, 0x73, 0xb5, 0x1e, 0x35, 0x71, 0xef, 0x5e, 0xbc, 0x13, 0xda, 0xbf, + 0xdf, 0xff, 0xc6, 0x38, 0xed, 0xeb, 0x24, 0xf1, 0xb8, 0x5c, 0x72, 0x32, 0x20, 0xc3, 0x83, 0xa8, + 0x79, 0xb2, 0x23, 0xda, 0x36, 0x09, 0x6f, 0x0f, 0xc8, 0xb0, 0x1b, 0xb5, 0x4d, 0xc2, 0x4e, 0xe8, + 0x7f, 0x0d, 0xd9, 0x53, 0xd8, 0xe4, 0xc8, 0x3b, 0x35, 0x0a, 0xd9, 0xc3, 0x26, 0x47, 0x36, 0xa6, + 0xbd, 0x5c, 0x43, 0x86, 0x81, 0x77, 0x07, 0x64, 0x78, 0x78, 0x73, 0x26, 0x4d, 0x0c, 0xb2, 0x5c, + 0x42, 0x36, 0x93, 0xd7, 0x23, 0x39, 0xad, 0x90, 0xa8, 0x46, 0xd9, 0x84, 0x76, 0x34, 0x64, 0xfc, + 0x5f, 0x65, 0x5c, 0xfe, 0x69, 0xdc, 0x42, 0x66, 0xdd, 0xcb, 0x1c, 0x93, 0x14, 0x17, 0x68, 0x43, + 0x54, 0x0a, 0x77, 0xd3, 0x8f, 0x9d, 0x20, 0xdb, 0x9d, 0x20, 0x5f, 0x3b, 0x41, 0xde, 0x0a, 0xd1, + 0xda, 0x16, 0xa2, 0xf5, 0x59, 0x88, 0xd6, 0xe3, 0x24, 0x35, 0x61, 0xb6, 0x8a, 0x25, 0xb8, 0x85, + 0xaa, 0xeb, 0xb9, 0x76, 0x3e, 0x6d, 0xb2, 0x7a, 0xfd, 0xd5, 0x69, 0x79, 0xcc, 0x32, 0xee, 0x55, + 0xb5, 0x8c, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x40, 0x42, 0xfd, 0x80, 0x7b, 0x01, 0x00, 0x00, +} + +func (m *Failure) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Failure) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Failure) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Ack != nil { + { + size, err := m.Ack.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintFailure(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + if m.Packet != nil { + { + size, err := m.Packet.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintFailure(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + if len(m.AckType) > 0 { + i -= len(m.AckType) + copy(dAtA[i:], m.AckType) + i = encodeVarintFailure(dAtA, i, uint64(len(m.AckType))) + i-- + dAtA[i] = 0x1a + } + if m.Id != 0 { + i = encodeVarintFailure(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x10 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintFailure(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintFailure(dAtA []byte, offset int, v uint64) int { + offset -= sovFailure(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Failure) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovFailure(uint64(l)) + } + if m.Id != 0 { + n += 1 + sovFailure(uint64(m.Id)) + } + l = len(m.AckType) + if l > 0 { + n += 1 + l + sovFailure(uint64(l)) + } + if m.Packet != nil { + l = m.Packet.Size() + n += 1 + l + sovFailure(uint64(l)) + } + if m.Ack != nil { + l = m.Ack.Size() + n += 1 + l + sovFailure(uint64(l)) + } + return n +} + +func sovFailure(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozFailure(x uint64) (n int) { + return sovFailure(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Failure) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Failure: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Failure: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthFailure + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFailure + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AckType", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthFailure + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFailure + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AckType = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Packet", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthFailure + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthFailure + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Packet == nil { + m.Packet = &types.Packet{} + } + if err := m.Packet.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ack", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthFailure + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthFailure + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Ack == nil { + m.Ack = &types.Acknowledgement{} + } + if err := m.Ack.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipFailure(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthFailure + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipFailure(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowFailure + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowFailure + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowFailure + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthFailure + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupFailure + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthFailure + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthFailure = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowFailure = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupFailure = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/contractmanager/types/genesis.pb.go b/x/contractmanager/types/genesis.pb.go index e78a0b07c..a40d4edc0 100644 --- a/x/contractmanager/types/genesis.pb.go +++ b/x/contractmanager/types/genesis.pb.go @@ -23,89 +23,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// Failure message contains information about ACK failures and can be used to -// replay ACK in case of requirement. -type Failure struct { - // ChannelId - ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` - // Address of the failed contract - Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` - // id of the failure under specific address - Id uint64 `protobuf:"varint,3,opt,name=id,proto3" json:"id,omitempty"` - // ACK id to restore - AckId uint64 `protobuf:"varint,4,opt,name=ack_id,json=ackId,proto3" json:"ack_id,omitempty"` - // Acknowledgement type - AckType string `protobuf:"bytes,5,opt,name=ack_type,json=ackType,proto3" json:"ack_type,omitempty"` -} - -func (m *Failure) Reset() { *m = Failure{} } -func (m *Failure) String() string { return proto.CompactTextString(m) } -func (*Failure) ProtoMessage() {} -func (*Failure) Descriptor() ([]byte, []int) { - return fileDescriptor_cf4a1534315a7490, []int{0} -} -func (m *Failure) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Failure) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Failure.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Failure) XXX_Merge(src proto.Message) { - xxx_messageInfo_Failure.Merge(m, src) -} -func (m *Failure) XXX_Size() int { - return m.Size() -} -func (m *Failure) XXX_DiscardUnknown() { - xxx_messageInfo_Failure.DiscardUnknown(m) -} - -var xxx_messageInfo_Failure proto.InternalMessageInfo - -func (m *Failure) GetChannelId() string { - if m != nil { - return m.ChannelId - } - return "" -} - -func (m *Failure) GetAddress() string { - if m != nil { - return m.Address - } - return "" -} - -func (m *Failure) GetId() uint64 { - if m != nil { - return m.Id - } - return 0 -} - -func (m *Failure) GetAckId() uint64 { - if m != nil { - return m.AckId - } - return 0 -} - -func (m *Failure) GetAckType() string { - if m != nil { - return m.AckType - } - return "" -} - // GenesisState defines the contractmanager module's genesis state. type GenesisState struct { Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` @@ -117,7 +34,7 @@ func (m *GenesisState) Reset() { *m = GenesisState{} } func (m *GenesisState) String() string { return proto.CompactTextString(m) } func (*GenesisState) ProtoMessage() {} func (*GenesisState) Descriptor() ([]byte, []int) { - return fileDescriptor_cf4a1534315a7490, []int{1} + return fileDescriptor_cf4a1534315a7490, []int{0} } func (m *GenesisState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -161,7 +78,6 @@ func (m *GenesisState) GetFailuresList() []Failure { } func init() { - proto.RegisterType((*Failure)(nil), "neutron.contractmanager.Failure") proto.RegisterType((*GenesisState)(nil), "neutron.contractmanager.GenesisState") } @@ -170,82 +86,23 @@ func init() { } var fileDescriptor_cf4a1534315a7490 = []byte{ - // 335 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0x3f, 0x4f, 0x02, 0x31, - 0x18, 0xc6, 0xaf, 0xc7, 0x3f, 0x29, 0xe8, 0xd0, 0x68, 0x3c, 0x49, 0x3c, 0x2e, 0x44, 0x13, 0x16, - 0xef, 0x12, 0x4c, 0xdc, 0x5c, 0x18, 0x34, 0x44, 0x07, 0x82, 0x4e, 0x2e, 0xa4, 0xb4, 0xf5, 0x68, - 0x80, 0xf6, 0xd2, 0x96, 0x44, 0x76, 0x3f, 0x80, 0xb3, 0x9f, 0x88, 0x91, 0xd1, 0xc9, 0x18, 0xf8, - 0x22, 0xe6, 0xee, 0xca, 0xa2, 0xb9, 0xed, 0xed, 0xd3, 0xe7, 0xfd, 0xe5, 0x7d, 0x1e, 0x78, 0x29, - 0xd8, 0xd2, 0x28, 0x29, 0x22, 0x22, 0x85, 0x51, 0x98, 0x98, 0x05, 0x16, 0x38, 0x66, 0x2a, 0x8a, - 0x99, 0x60, 0x9a, 0xeb, 0x30, 0x51, 0xd2, 0x48, 0x74, 0x6a, 0x6d, 0xe1, 0x1f, 0x5b, 0xeb, 0x38, - 0x96, 0xb1, 0xcc, 0x3c, 0x51, 0x3a, 0xe5, 0xf6, 0xd6, 0x45, 0x11, 0x35, 0xc1, 0x0a, 0x2f, 0x2c, - 0xb4, 0xf3, 0x0e, 0x60, 0xed, 0x0e, 0xf3, 0xf9, 0x52, 0x31, 0x74, 0x0e, 0x21, 0x99, 0x62, 0x21, - 0xd8, 0x7c, 0xcc, 0xa9, 0x07, 0x02, 0xd0, 0xad, 0x8f, 0xea, 0x56, 0x19, 0x50, 0xe4, 0xc1, 0x1a, - 0xa6, 0x54, 0x31, 0xad, 0x3d, 0x37, 0xfb, 0xdb, 0x3f, 0xd1, 0x11, 0x74, 0x39, 0xf5, 0x4a, 0x01, - 0xe8, 0x96, 0x47, 0x2e, 0xa7, 0xe8, 0x04, 0x56, 0x31, 0x99, 0xa5, 0x90, 0x72, 0xa6, 0x55, 0x30, - 0x99, 0x0d, 0x28, 0x3a, 0x83, 0x07, 0xa9, 0x6c, 0x56, 0x09, 0xf3, 0x2a, 0x96, 0x40, 0x66, 0xcf, - 0xab, 0x84, 0x75, 0x3e, 0x01, 0x6c, 0xde, 0xe7, 0x69, 0x9f, 0x0c, 0x36, 0x0c, 0xdd, 0xc2, 0x6a, - 0x7e, 0x67, 0x76, 0x47, 0xa3, 0xd7, 0x0e, 0x0b, 0xd2, 0x87, 0xc3, 0xcc, 0xd6, 0x2f, 0xaf, 0xbf, - 0xdb, 0xce, 0xc8, 0x2e, 0xa1, 0x07, 0x78, 0xf8, 0x9a, 0xa7, 0xd2, 0xe3, 0x39, 0xd7, 0xc6, 0x73, - 0x83, 0x52, 0xb7, 0xd1, 0x0b, 0x0a, 0x29, 0xb6, 0x03, 0x8b, 0x69, 0xee, 0x97, 0x1f, 0xb9, 0x36, - 0xfd, 0xe1, 0x7a, 0xeb, 0x83, 0xcd, 0xd6, 0x07, 0x3f, 0x5b, 0x1f, 0x7c, 0xec, 0x7c, 0x67, 0xb3, - 0xf3, 0x9d, 0xaf, 0x9d, 0xef, 0xbc, 0xdc, 0xc4, 0xdc, 0x4c, 0x97, 0x93, 0x90, 0xc8, 0x45, 0x64, - 0xc9, 0x57, 0x52, 0xc5, 0xfb, 0x39, 0x7a, 0xfb, 0x57, 0x7e, 0x1a, 0x5e, 0x4f, 0xaa, 0x59, 0xf9, - 0xd7, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x88, 0x8d, 0x18, 0xf9, 0xfa, 0x01, 0x00, 0x00, -} - -func (m *Failure) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Failure) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Failure) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.AckType) > 0 { - i -= len(m.AckType) - copy(dAtA[i:], m.AckType) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.AckType))) - i-- - dAtA[i] = 0x2a - } - if m.AckId != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.AckId)) - i-- - dAtA[i] = 0x20 - } - if m.Id != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.Id)) - i-- - dAtA[i] = 0x18 - } - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.Address))) - i-- - dAtA[i] = 0x12 - } - if len(m.ChannelId) > 0 { - i -= len(m.ChannelId) - copy(dAtA[i:], m.ChannelId) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.ChannelId))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil + // 249 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcd, 0x4b, 0x2d, 0x2d, + 0x29, 0xca, 0xcf, 0xd3, 0x4f, 0xce, 0xcf, 0x2b, 0x29, 0x4a, 0x4c, 0x2e, 0xc9, 0x4d, 0xcc, 0x4b, + 0x4c, 0x4f, 0x2d, 0xd2, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, + 0xc9, 0x17, 0x12, 0x87, 0x2a, 0xd3, 0x43, 0x53, 0x26, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, + 0xa3, 0x0f, 0x62, 0x41, 0x94, 0x4b, 0xa9, 0xe0, 0x32, 0xb5, 0x20, 0xb1, 0x28, 0x31, 0x17, 0x6a, + 0xa8, 0x14, 0x4e, 0xbb, 0xd3, 0x12, 0x33, 0x73, 0x4a, 0x8b, 0x52, 0x21, 0xca, 0x94, 0x66, 0x31, + 0x72, 0xf1, 0xb8, 0x43, 0x5c, 0x13, 0x5c, 0x92, 0x58, 0x92, 0x2a, 0x64, 0xcb, 0xc5, 0x06, 0x31, + 0x47, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x48, 0x5e, 0x0f, 0x87, 0xeb, 0xf4, 0x02, 0xc0, 0xca, + 0x9c, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, 0x6a, 0x12, 0xf2, 0xe6, 0xe2, 0x85, 0x5a, 0x50, + 0x1c, 0x9f, 0x93, 0x59, 0x5c, 0x22, 0xc1, 0xa4, 0xc0, 0xac, 0xc1, 0x6d, 0xa4, 0x80, 0xd3, 0x14, + 0x37, 0x88, 0x6a, 0xa8, 0x31, 0x3c, 0x30, 0xcd, 0x3e, 0x99, 0xc5, 0x25, 0x4e, 0x01, 0x27, 0x1e, + 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, + 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0x65, 0x96, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, + 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0x35, 0x59, 0x37, 0xbf, 0x28, 0x1d, 0xc6, 0xd6, 0xaf, 0xc0, 0xf0, + 0x76, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0xd7, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, + 0xff, 0x20, 0x4a, 0xa0, 0xfc, 0x9a, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -306,33 +163,6 @@ func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *Failure) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ChannelId) - if l > 0 { - n += 1 + l + sovGenesis(uint64(l)) - } - l = len(m.Address) - if l > 0 { - n += 1 + l + sovGenesis(uint64(l)) - } - if m.Id != 0 { - n += 1 + sovGenesis(uint64(m.Id)) - } - if m.AckId != 0 { - n += 1 + sovGenesis(uint64(m.AckId)) - } - l = len(m.AckType) - if l > 0 { - n += 1 + l + sovGenesis(uint64(l)) - } - return n -} - func (m *GenesisState) Size() (n int) { if m == nil { return 0 @@ -356,190 +186,6 @@ func sovGenesis(x uint64) (n int) { func sozGenesis(x uint64) (n int) { return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *Failure) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Failure: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Failure: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ChannelId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Address = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) - } - m.Id = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Id |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field AckId", wireType) - } - m.AckId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.AckId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AckType", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.AckType = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipGenesis(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *GenesisState) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/contractmanager/types/query.pb.go b/x/contractmanager/types/query.pb.go index 4e5dd940b..a4eea203d 100644 --- a/x/contractmanager/types/query.pb.go +++ b/x/contractmanager/types/query.pb.go @@ -229,37 +229,37 @@ func init() { } var fileDescriptor_f9524a427f219917 = []byte{ - // 478 bytes of a gzipped FileDescriptorProto + // 475 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x93, 0x31, 0x6f, 0xd4, 0x30, - 0x14, 0xc7, 0xe3, 0x16, 0x8e, 0xe2, 0x0e, 0x48, 0xe6, 0x10, 0x51, 0x84, 0x72, 0xd7, 0x14, 0x68, + 0x1c, 0xc5, 0xe3, 0x16, 0x8e, 0xe2, 0x0e, 0x48, 0xe6, 0x10, 0xa7, 0x08, 0xe5, 0xda, 0x14, 0x68, 0xa1, 0x9c, 0xad, 0x5e, 0x25, 0x36, 0x06, 0x6e, 0x28, 0xeb, 0x11, 0x31, 0xb1, 0x39, 0xa9, 0x31, 0x91, 0x1a, 0x3b, 0xb5, 0x1d, 0xd4, 0x0a, 0xb1, 0x30, 0x33, 0x20, 0xc1, 0x47, 0x80, 0xef, 0xd2, - 0xb1, 0x12, 0x42, 0x62, 0x42, 0xe8, 0x8e, 0x0f, 0x82, 0xce, 0x76, 0x4a, 0xb9, 0x92, 0xb6, 0x53, - 0xb7, 0xc4, 0xf9, 0xbf, 0xf7, 0xff, 0xbd, 0xff, 0x73, 0xe0, 0xaa, 0x60, 0xb5, 0x51, 0x52, 0x90, - 0x5c, 0x0a, 0xa3, 0x68, 0x6e, 0x4a, 0x2a, 0x28, 0x67, 0x8a, 0xec, 0xd5, 0x4c, 0x1d, 0xe0, 0x4a, - 0x49, 0x23, 0xd1, 0x6d, 0x2f, 0xc2, 0x73, 0xa2, 0xa8, 0xcb, 0x25, 0x97, 0x56, 0x43, 0x66, 0x4f, - 0x4e, 0x1e, 0xdd, 0xe1, 0x52, 0xf2, 0x5d, 0x46, 0x68, 0x55, 0x10, 0x2a, 0x84, 0x34, 0xd4, 0x14, - 0x52, 0x68, 0xff, 0xf5, 0x61, 0x2e, 0x75, 0x29, 0x35, 0xc9, 0xa8, 0x66, 0xce, 0x85, 0xbc, 0xd9, - 0xcc, 0x98, 0xa1, 0x9b, 0xa4, 0xa2, 0xbc, 0x10, 0x56, 0xec, 0xb5, 0x77, 0xdb, 0xe8, 0x2a, 0xaa, - 0x68, 0xd9, 0x74, 0xbc, 0xd7, 0xa6, 0xe2, 0x4c, 0x30, 0x5d, 0x78, 0x59, 0xd2, 0x85, 0xe8, 0xf9, - 0xcc, 0x6e, 0x6c, 0x6b, 0x53, 0xb6, 0x57, 0x33, 0x6d, 0x92, 0x17, 0xf0, 0xe6, 0x3f, 0xa7, 0xba, - 0x92, 0x42, 0x33, 0xf4, 0x04, 0x76, 0x9c, 0x47, 0x08, 0xfa, 0x60, 0x7d, 0x79, 0xd8, 0xc3, 0x2d, - 0x19, 0x60, 0x57, 0x38, 0xba, 0x72, 0xf8, 0xb3, 0x17, 0xa4, 0xbe, 0x28, 0xd9, 0x87, 0x5d, 0xdb, - 0x75, 0x9b, 0x16, 0xbb, 0xb5, 0x62, 0x8d, 0x1b, 0x0a, 0xe1, 0x35, 0xba, 0xb3, 0xa3, 0x98, 0x76, - 0x7d, 0xaf, 0xa7, 0xcd, 0x2b, 0xda, 0x86, 0xf0, 0xef, 0xf8, 0xe1, 0x82, 0x35, 0xbd, 0x8f, 0x5d, - 0x56, 0x78, 0x96, 0x15, 0x76, 0x1b, 0xf1, 0x59, 0xe1, 0x31, 0xe5, 0xcc, 0x77, 0x4d, 0x4f, 0x54, - 0x26, 0x5f, 0x00, 0xbc, 0x35, 0x67, 0xed, 0x47, 0x1a, 0xc1, 0xa5, 0x57, 0xfe, 0x2c, 0x04, 0xfd, - 0xc5, 0xf5, 0xe5, 0x61, 0xbf, 0x75, 0x28, 0x5f, 0xec, 0xa7, 0x3a, 0xae, 0x43, 0xcf, 0xfe, 0x43, - 0xb9, 0x76, 0x2e, 0xa5, 0x03, 0x38, 0x89, 0x39, 0xfc, 0xbe, 0x08, 0xaf, 0x5a, 0x4c, 0xf4, 0x01, - 0xc0, 0x8e, 0xcb, 0x10, 0x6d, 0xb4, 0xf2, 0x9c, 0x5e, 0x5c, 0xf4, 0xe8, 0x62, 0x62, 0xe7, 0x9d, - 0xac, 0xbd, 0xff, 0xf6, 0xfb, 0xd3, 0xc2, 0x0a, 0xea, 0x91, 0xb3, 0xaf, 0x14, 0xfa, 0x0a, 0xe0, - 0x8d, 0xa7, 0x6e, 0x27, 0x4d, 0x82, 0x68, 0x70, 0xb6, 0xd5, 0xdc, 0x92, 0x23, 0x7c, 0x51, 0xb9, - 0x67, 0xdb, 0xb2, 0x6c, 0x03, 0xb4, 0xd1, 0xca, 0xd6, 0xe4, 0x4f, 0xde, 0xfa, 0xeb, 0xf2, 0x0e, - 0x7d, 0x06, 0x70, 0xe9, 0xb2, 0x00, 0x1f, 0x58, 0xc0, 0x55, 0xb4, 0x72, 0x2e, 0xe0, 0x68, 0x7c, - 0x38, 0x89, 0xc1, 0xd1, 0x24, 0x06, 0xbf, 0x26, 0x31, 0xf8, 0x38, 0x8d, 0x83, 0xa3, 0x69, 0x1c, - 0xfc, 0x98, 0xc6, 0xc1, 0xcb, 0xc7, 0xbc, 0x30, 0xaf, 0xeb, 0x0c, 0xe7, 0xb2, 0x6c, 0xda, 0x0c, - 0xa4, 0xe2, 0xc7, 0x2d, 0xf7, 0x4f, 0x35, 0x35, 0x07, 0x15, 0xd3, 0x59, 0xc7, 0xfe, 0xbd, 0x5b, - 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0xfd, 0xbf, 0xad, 0xfd, 0xaa, 0x04, 0x00, 0x00, + 0xb1, 0x12, 0x42, 0x62, 0x42, 0xe8, 0x8e, 0x0f, 0x82, 0x62, 0x3b, 0xa5, 0x5c, 0x49, 0xaf, 0x53, + 0xb7, 0xbb, 0xe4, 0xfd, 0xdf, 0xfb, 0xf9, 0xfd, 0x1d, 0xb8, 0x26, 0x58, 0x65, 0x94, 0x14, 0x24, + 0x93, 0xc2, 0x28, 0x9a, 0x99, 0x82, 0x0a, 0xca, 0x99, 0x22, 0xfb, 0x15, 0x53, 0x87, 0xb8, 0x54, + 0xd2, 0x48, 0x74, 0xdb, 0x8b, 0xf0, 0x8c, 0x28, 0xec, 0x72, 0xc9, 0xa5, 0xd5, 0x90, 0xfa, 0x97, + 0x93, 0x87, 0x77, 0xb8, 0x94, 0x7c, 0x8f, 0x11, 0x5a, 0xe6, 0x84, 0x0a, 0x21, 0x0d, 0x35, 0xb9, + 0x14, 0xda, 0xbf, 0x7d, 0x98, 0x49, 0x5d, 0x48, 0x4d, 0x52, 0xaa, 0x99, 0x4b, 0x21, 0x6f, 0xb6, + 0x52, 0x66, 0xe8, 0x16, 0x29, 0x29, 0xcf, 0x85, 0x15, 0x7b, 0xed, 0xdd, 0x36, 0xba, 0x92, 0x2a, + 0x5a, 0x34, 0x8e, 0xf7, 0xda, 0x54, 0xaf, 0x68, 0xbe, 0x57, 0x29, 0xe6, 0x64, 0x71, 0x17, 0xa2, + 0xe7, 0x75, 0xdc, 0xd8, 0xce, 0x26, 0x6c, 0xbf, 0x62, 0xda, 0xc4, 0x2f, 0xe0, 0xcd, 0x7f, 0x9e, + 0xea, 0x52, 0x0a, 0xcd, 0xd0, 0x13, 0xd8, 0x71, 0x19, 0x3d, 0xb0, 0x02, 0x36, 0x96, 0x87, 0x7d, + 0xdc, 0xd2, 0x01, 0x76, 0x83, 0xa3, 0x2b, 0x47, 0x3f, 0xfb, 0x41, 0xe2, 0x87, 0xe2, 0x03, 0xd8, + 0xb5, 0xae, 0x3b, 0x8e, 0xa0, 0x49, 0x43, 0x3d, 0x78, 0x8d, 0xee, 0xee, 0x2a, 0xa6, 0x9d, 0xef, + 0xf5, 0xa4, 0xf9, 0x8b, 0x76, 0x20, 0xfc, 0x7b, 0xfc, 0xde, 0x82, 0x0d, 0xbd, 0x8f, 0x5d, 0x57, + 0xb8, 0xee, 0x0a, 0xbb, 0x8d, 0xf8, 0xae, 0xf0, 0x98, 0x72, 0xe6, 0x5d, 0x93, 0x53, 0x93, 0xf1, + 0x17, 0x00, 0x6f, 0xcd, 0x44, 0xfb, 0x23, 0x8d, 0xe0, 0x92, 0x2f, 0xa4, 0x0e, 0x5f, 0xdc, 0x58, + 0x1e, 0xae, 0xb4, 0x1e, 0xca, 0x0f, 0xfb, 0x53, 0x9d, 0xcc, 0xa1, 0x67, 0xff, 0xa1, 0x5c, 0x9f, + 0x4b, 0xe9, 0x00, 0x4e, 0x63, 0x0e, 0xbf, 0x2f, 0xc2, 0xab, 0x16, 0x13, 0x7d, 0x00, 0xb0, 0xe3, + 0x3a, 0x44, 0x9b, 0xad, 0x3c, 0x67, 0x17, 0x17, 0x3e, 0xba, 0x98, 0xd8, 0x65, 0xc7, 0xeb, 0xef, + 0xbf, 0xfd, 0xfe, 0xb4, 0xb0, 0x8a, 0xfa, 0xe4, 0xfc, 0x2b, 0x85, 0xbe, 0x02, 0x78, 0xe3, 0xa9, + 0xdb, 0x49, 0xd3, 0x20, 0x1a, 0x9c, 0x1f, 0x35, 0xb3, 0xe4, 0x10, 0x5f, 0x54, 0xee, 0xd9, 0xb6, + 0x2d, 0xdb, 0x00, 0x6d, 0x92, 0x39, 0x17, 0x59, 0x93, 0xb7, 0xfe, 0xba, 0xbc, 0x43, 0x9f, 0x01, + 0x5c, 0xba, 0x2c, 0xc0, 0x07, 0x16, 0x70, 0x0d, 0xad, 0xce, 0x05, 0x1c, 0x8d, 0x8f, 0x26, 0x11, + 0x38, 0x9e, 0x44, 0xe0, 0xd7, 0x24, 0x02, 0x1f, 0xa7, 0x51, 0x70, 0x3c, 0x8d, 0x82, 0x1f, 0xd3, + 0x28, 0x78, 0xf9, 0x98, 0xe7, 0xe6, 0x75, 0x95, 0xe2, 0x4c, 0x16, 0x8d, 0xcd, 0x40, 0x2a, 0x7e, + 0x62, 0x79, 0x70, 0xc6, 0xd4, 0x1c, 0x96, 0x4c, 0xa7, 0x1d, 0xfb, 0xf5, 0x6e, 0xff, 0x09, 0x00, + 0x00, 0xff, 0xff, 0x05, 0x7b, 0x9c, 0xb2, 0xaa, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/contractmanager/types/types.go b/x/contractmanager/types/types.go index ab1254f4c..e7d6010f0 100644 --- a/x/contractmanager/types/types.go +++ b/x/contractmanager/types/types.go @@ -1 +1,6 @@ package types + +const ( + Ack = "ack" + Timeout = "timeout" +) diff --git a/x/contractmanager/types/v1/failure.pb.go b/x/contractmanager/types/v1/failure.pb.go new file mode 100644 index 000000000..df2ffd000 --- /dev/null +++ b/x/contractmanager/types/v1/failure.pb.go @@ -0,0 +1,500 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/contractmanager/v1/failure.proto + +package v1 + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Deprecated. Used only for migration purposes. +type Failure struct { + // ChannelId + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + // Address of the failed contract + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + // id of the failure under specific address + Id uint64 `protobuf:"varint,3,opt,name=id,proto3" json:"id,omitempty"` + // ACK id to restore + AckId uint64 `protobuf:"varint,4,opt,name=ack_id,json=ackId,proto3" json:"ack_id,omitempty"` + // Acknowledgement type + AckType string `protobuf:"bytes,5,opt,name=ack_type,json=ackType,proto3" json:"ack_type,omitempty"` +} + +func (m *Failure) Reset() { *m = Failure{} } +func (m *Failure) String() string { return proto.CompactTextString(m) } +func (*Failure) ProtoMessage() {} +func (*Failure) Descriptor() ([]byte, []int) { + return fileDescriptor_c0f2c436fd0f28b7, []int{0} +} +func (m *Failure) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Failure) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Failure.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Failure) XXX_Merge(src proto.Message) { + xxx_messageInfo_Failure.Merge(m, src) +} +func (m *Failure) XXX_Size() int { + return m.Size() +} +func (m *Failure) XXX_DiscardUnknown() { + xxx_messageInfo_Failure.DiscardUnknown(m) +} + +var xxx_messageInfo_Failure proto.InternalMessageInfo + +func (m *Failure) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func (m *Failure) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *Failure) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +func (m *Failure) GetAckId() uint64 { + if m != nil { + return m.AckId + } + return 0 +} + +func (m *Failure) GetAckType() string { + if m != nil { + return m.AckType + } + return "" +} + +func init() { + proto.RegisterType((*Failure)(nil), "neutron.contractmanager.v1.Failure") +} + +func init() { + proto.RegisterFile("neutron/contractmanager/v1/failure.proto", fileDescriptor_c0f2c436fd0f28b7) +} + +var fileDescriptor_c0f2c436fd0f28b7 = []byte{ + // 245 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xc8, 0x4b, 0x2d, 0x2d, + 0x29, 0xca, 0xcf, 0xd3, 0x4f, 0xce, 0xcf, 0x2b, 0x29, 0x4a, 0x4c, 0x2e, 0xc9, 0x4d, 0xcc, 0x4b, + 0x4c, 0x4f, 0x2d, 0xd2, 0x2f, 0x33, 0xd4, 0x4f, 0x4b, 0xcc, 0xcc, 0x29, 0x2d, 0x4a, 0xd5, 0x2b, + 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x82, 0xaa, 0xd4, 0x43, 0x53, 0xa9, 0x57, 0x66, 0xa8, 0xd4, + 0xc2, 0xc8, 0xc5, 0xee, 0x06, 0x51, 0x2d, 0x24, 0xcb, 0xc5, 0x95, 0x9c, 0x91, 0x98, 0x97, 0x97, + 0x9a, 0x13, 0x9f, 0x99, 0x22, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x19, 0xc4, 0x09, 0x15, 0xf1, 0x4c, + 0x11, 0x92, 0xe0, 0x62, 0x4f, 0x4c, 0x49, 0x29, 0x4a, 0x2d, 0x2e, 0x96, 0x60, 0x02, 0xcb, 0xc1, + 0xb8, 0x42, 0x7c, 0x5c, 0x4c, 0x99, 0x29, 0x12, 0xcc, 0x0a, 0x8c, 0x1a, 0x2c, 0x41, 0x4c, 0x99, + 0x29, 0x42, 0xa2, 0x5c, 0x6c, 0x89, 0xc9, 0xd9, 0x20, 0x43, 0x58, 0xc0, 0x62, 0xac, 0x89, 0xc9, + 0xd9, 0x9e, 0x29, 0x42, 0x92, 0x5c, 0x1c, 0x20, 0xe1, 0x92, 0xca, 0x82, 0x54, 0x09, 0x56, 0xa8, + 0x09, 0xc9, 0xd9, 0x21, 0x95, 0x05, 0xa9, 0x4e, 0xc1, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, + 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, + 0x2c, 0xc7, 0x10, 0x65, 0x99, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, + 0xf5, 0x87, 0x6e, 0x7e, 0x51, 0x3a, 0x8c, 0xad, 0x5f, 0x81, 0xe1, 0x7f, 0x90, 0xf9, 0xc5, 0xfa, + 0x65, 0x86, 0x49, 0x6c, 0x60, 0xef, 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x99, 0x53, 0x32, + 0xf9, 0x2a, 0x01, 0x00, 0x00, +} + +func (m *Failure) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Failure) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Failure) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.AckType) > 0 { + i -= len(m.AckType) + copy(dAtA[i:], m.AckType) + i = encodeVarintFailure(dAtA, i, uint64(len(m.AckType))) + i-- + dAtA[i] = 0x2a + } + if m.AckId != 0 { + i = encodeVarintFailure(dAtA, i, uint64(m.AckId)) + i-- + dAtA[i] = 0x20 + } + if m.Id != 0 { + i = encodeVarintFailure(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x18 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintFailure(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0x12 + } + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintFailure(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintFailure(dAtA []byte, offset int, v uint64) int { + offset -= sovFailure(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Failure) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovFailure(uint64(l)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovFailure(uint64(l)) + } + if m.Id != 0 { + n += 1 + sovFailure(uint64(m.Id)) + } + if m.AckId != 0 { + n += 1 + sovFailure(uint64(m.AckId)) + } + l = len(m.AckType) + if l > 0 { + n += 1 + l + sovFailure(uint64(l)) + } + return n +} + +func sovFailure(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozFailure(x uint64) (n int) { + return sovFailure(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Failure) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Failure: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Failure: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthFailure + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFailure + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthFailure + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFailure + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AckId", wireType) + } + m.AckId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AckId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AckType", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthFailure + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFailure + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AckType = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipFailure(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthFailure + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipFailure(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowFailure + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowFailure + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowFailure + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthFailure + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupFailure + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthFailure + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthFailure = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowFailure = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupFailure = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/interchainqueries/keeper/process_block_results.go b/x/interchainqueries/keeper/process_block_results.go index f00e55b7e..0692cb829 100644 --- a/x/interchainqueries/keeper/process_block_results.go +++ b/x/interchainqueries/keeper/process_block_results.go @@ -61,7 +61,7 @@ type Verifier struct{} // VerifyHeaders verify that headers are valid tendermint headers, checks them on validity by trying call ibcClient.UpdateClient(header) // to update light client's consensus state and checks that they are sequential (tl;dr header.Height + 1 == nextHeader.Height) -func (v Verifier) VerifyHeaders(ctx sdk.Context, clientKeeper clientkeeper.Keeper, clientID string, header exported.ClientMessage, nextHeader exported.ClientMessage) error { +func (v Verifier) VerifyHeaders(ctx sdk.Context, clientKeeper clientkeeper.Keeper, clientID string, header, nextHeader exported.ClientMessage) error { // this IBC handler updates the consensus state and the state root from a provided header. // But more importantly in the current situation, it checks that header is valid. // Honestly we need only to verify headers, but since the check functions are private, and we don't want to duplicate the code, diff --git a/x/interchaintxs/keeper/ibc_handlers.go b/x/interchaintxs/keeper/ibc_handlers.go index 8b851dd69..d7420809f 100644 --- a/x/interchaintxs/keeper/ibc_handlers.go +++ b/x/interchaintxs/keeper/ibc_handlers.go @@ -27,6 +27,7 @@ func (k *Keeper) outOfGasRecovery( senderAddress sdk.AccAddress, packet channeltypes.Packet, failureAckType string, + ack *channeltypes.Acknowledgement, ) { if r := recover(); r != nil { _, ok := r.(sdk.ErrorOutOfGas) @@ -35,7 +36,7 @@ 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) + k.contractManagerKeeper.AddContractFailure(ctx, &packet, senderAddress.String(), failureAckType, ack) } } @@ -96,21 +97,20 @@ func (k *Keeper) HandleAcknowledgement(ctx sdk.Context, packet channeltypes.Pack } cacheCtx, writeFn, newGasMeter := k.createCachedContext(ctx) - defer k.outOfGasRecovery(ctx, newGasMeter, icaOwner.GetContract(), packet, "ack") + defer k.outOfGasRecovery(ctx, newGasMeter, icaOwner.GetContract(), packet, contractmanagertypes.Ack, &ack) k.feeKeeper.DistributeAcknowledgementFee(ctx, relayer, feetypes.NewPacketID(packet.SourcePort, packet.SourceChannel, packet.Sequence)) // Actually we have only one kind of error returned from acknowledgement // maybe later we'll retrieve actual errors from events - errorText := ack.GetError() - if errorText != "" { - _, err = k.contractManagerKeeper.SudoError(cacheCtx, icaOwner.GetContract(), packet, errorText) + if ack.GetError() != "" { + _, err = k.contractManagerKeeper.SudoError(cacheCtx, icaOwner.GetContract(), packet, ack.GetError()) } else { _, err = k.contractManagerKeeper.SudoResponse(cacheCtx, icaOwner.GetContract(), packet, ack.GetResult()) } if err != nil { - k.contractManagerKeeper.AddContractFailure(ctx, packet.SourceChannel, icaOwner.GetContract().String(), packet.GetSequence(), "ack") + k.contractManagerKeeper.AddContractFailure(ctx, &packet, icaOwner.GetContract().String(), contractmanagertypes.Ack, &ack) k.Logger(ctx).Debug("HandleAcknowledgement: failed to Sudo contract on packet acknowledgement", "error", err) } else { ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) @@ -136,13 +136,13 @@ func (k *Keeper) HandleTimeout(ctx sdk.Context, packet channeltypes.Packet, rela } cacheCtx, writeFn, newGasMeter := k.createCachedContext(ctx) - defer k.outOfGasRecovery(ctx, newGasMeter, icaOwner.GetContract(), packet, "timeout") + defer k.outOfGasRecovery(ctx, newGasMeter, icaOwner.GetContract(), packet, contractmanagertypes.Timeout, nil) k.feeKeeper.DistributeTimeoutFee(ctx, relayer, feetypes.NewPacketID(packet.SourcePort, packet.SourceChannel, packet.Sequence)) _, err = k.contractManagerKeeper.SudoTimeout(cacheCtx, icaOwner.GetContract(), packet) if err != nil { - k.contractManagerKeeper.AddContractFailure(ctx, packet.SourceChannel, icaOwner.GetContract().String(), packet.GetSequence(), "timeout") + k.contractManagerKeeper.AddContractFailure(ctx, &packet, icaOwner.GetContract().String(), contractmanagertypes.Timeout, nil) k.Logger(ctx).Error("HandleTimeout: failed to Sudo contract on packet timeout", "error", err) } else { ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) diff --git a/x/interchaintxs/keeper/ibc_handlers_test.go b/x/interchaintxs/keeper/ibc_handlers_test.go index b02a7b6fb..d92adf5ab 100644 --- a/x/interchaintxs/keeper/ibc_handlers_test.go +++ b/x/interchaintxs/keeper/ibc_handlers_test.go @@ -71,7 +71,7 @@ func TestHandleAcknowledgement(t *testing.T) { store := cachedCtx.KVStore(storeKey) store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) // consumes 2990 }).Return(nil, fmt.Errorf("SudoResponse error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "ack") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Ack, &resACK) feeKeeper.EXPECT().DistributeAcknowledgementFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) err = icak.HandleAcknowledgement(ctx, p, resAckData, relayerAddress) require.NoError(t, err) @@ -84,7 +84,7 @@ func TestHandleAcknowledgement(t *testing.T) { store := cachedCtx.KVStore(storeKey) store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) }).Return(nil, fmt.Errorf("SudoError error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "ack") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Ack, &errACK) feeKeeper.EXPECT().DistributeAcknowledgementFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) err = icak.HandleAcknowledgement(ctx, p, errAckData, relayerAddress) require.NoError(t, err) @@ -109,7 +109,7 @@ func TestHandleAcknowledgement(t *testing.T) { store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) cachedCtx.GasMeter().ConsumeGas(cachedCtx.GasMeter().Limit()+1, "out of gas test") }).Return(nil, fmt.Errorf("SudoError error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "ack") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Ack, &errACK) feeKeeper.EXPECT().DistributeAcknowledgementFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) err = icak.HandleAcknowledgement(ctx, p, errAckData, relayerAddress) require.NoError(t, err) @@ -144,7 +144,7 @@ func TestHandleAcknowledgement(t *testing.T) { cachedCtx.GasMeter().ConsumeGas(1, "Sudo response consumption") }).Return(nil, nil) feeKeeper.EXPECT().DistributeAcknowledgementFee(lowGasCtx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) - cmKeeper.EXPECT().AddContractFailure(lowGasCtx, "channel-0", contractAddress.String(), p.GetSequence(), "ack").Do(func(ctx sdk.Context, channelId, address string, ackID uint64, ackType string) { + cmKeeper.EXPECT().AddContractFailure(lowGasCtx, &p, contractAddress.String(), types.Ack, &resACK).Do(func(ctx sdk.Context, packet channeltypes.Packet, address, ackType string, ack channeltypes.Acknowledgement) { ctx.GasMeter().ConsumeGas(keeper.GasReserve, "out of gas") }) require.Panics(t, func() { icak.HandleAcknowledgement(lowGasCtx, p, resAckData, relayerAddress) }) //nolint:errcheck // this is a panic test @@ -194,7 +194,7 @@ func TestHandleTimeout(t *testing.T) { store := cachedCtx.KVStore(storeKey) store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) }).Return(nil, fmt.Errorf("SudoTimeout error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "timeout") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Timeout, nil) feeKeeper.EXPECT().DistributeTimeoutFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) err = icak.HandleTimeout(ctx, p, relayerAddress) require.NoError(t, err) @@ -207,7 +207,7 @@ func TestHandleTimeout(t *testing.T) { store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) cachedCtx.GasMeter().ConsumeGas(cachedCtx.GasMeter().Limit()+1, "out of gas test") }).Return(nil, fmt.Errorf("SudoTimeout error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "timeout") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Timeout, nil) feeKeeper.EXPECT().DistributeTimeoutFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) err = icak.HandleTimeout(ctx, p, relayerAddress) require.NoError(t, err) diff --git a/x/interchaintxs/types/expected_keepers.go b/x/interchaintxs/types/expected_keepers.go index 7097b0ed4..10261381e 100644 --- a/x/interchaintxs/types/expected_keepers.go +++ b/x/interchaintxs/types/expected_keepers.go @@ -26,7 +26,7 @@ type BankKeeper interface { type ContractManagerKeeper interface { HasContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) bool - AddContractFailure(ctx sdk.Context, channelID, address string, ackID uint64, ackType string) + AddContractFailure(ctx sdk.Context, packet *channeltypes.Packet, address, ackType string, ack *channeltypes.Acknowledgement) SudoResponse(ctx sdk.Context, senderAddress sdk.AccAddress, request channeltypes.Packet, msg []byte) ([]byte, error) SudoError(ctx sdk.Context, senderAddress sdk.AccAddress, request channeltypes.Packet, details string) ([]byte, error) SudoTimeout(ctx sdk.Context, senderAddress sdk.AccAddress, request channeltypes.Packet) ([]byte, error) diff --git a/x/tokenfactory/types/errors.go b/x/tokenfactory/types/errors.go index ef46d16ca..1c51fec43 100644 --- a/x/tokenfactory/types/errors.go +++ b/x/tokenfactory/types/errors.go @@ -1,7 +1,5 @@ package types -// DONTCOVER - import ( fmt "fmt" diff --git a/x/transfer/ibc_handlers.go b/x/transfer/ibc_handlers.go index fe6db47d5..221e20624 100644 --- a/x/transfer/ibc_handlers.go +++ b/x/transfer/ibc_handlers.go @@ -3,6 +3,8 @@ package transfer import ( "strings" + contractmanagertypes "github.com/neutron-org/neutron/x/contractmanager/types" + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -26,6 +28,7 @@ func (im IBCModule) outOfGasRecovery( packet channeltypes.Packet, data transfertypes.FungibleTokenPacketData, failureType string, + ack *channeltypes.Acknowledgement, ) { if r := recover(); r != nil { _, ok := r.(sdk.ErrorOutOfGas) @@ -34,7 +37,7 @@ func (im IBCModule) outOfGasRecovery( } im.keeper.Logger(ctx).Debug("Out of gas", "Gas meter", gasMeter.String(), "Packet data", data) - im.ContractManagerKeeper.AddContractFailure(ctx, packet.SourceChannel, senderAddress.String(), packet.GetSequence(), failureType) + im.ContractManagerKeeper.AddContractFailure(ctx, &packet, senderAddress.String(), failureType, ack) // FIXME: add distribution call } } @@ -71,8 +74,8 @@ func (im *IBCModule) createCachedContext(ctx sdk.Context) (sdk.Context, func(), } gasMeter = sdk.NewGasMeter(newLimit) + im.keeper.Logger(ctx).Debug("New Gas limit", "gasLimit", newLimit) } - cacheCtx = cacheCtx.WithGasMeter(gasMeter) return cacheCtx, writeFn, gasMeter @@ -95,7 +98,7 @@ func (im IBCModule) HandleAcknowledgement(ctx sdk.Context, packet channeltypes.P } cacheCtx, writeFn, newGasMeter := im.createCachedContext(ctx) - defer im.outOfGasRecovery(ctx, newGasMeter, senderAddress, packet, data, "ack") + defer im.outOfGasRecovery(ctx, newGasMeter, senderAddress, packet, data, contractmanagertypes.Ack, &ack) if ack.Success() { _, err = im.ContractManagerKeeper.SudoResponse(cacheCtx, senderAddress, packet, ack.GetResult()) @@ -107,7 +110,7 @@ func (im IBCModule) HandleAcknowledgement(ctx sdk.Context, packet channeltypes.P } if err != nil { - im.ContractManagerKeeper.AddContractFailure(ctx, packet.SourceChannel, senderAddress.String(), packet.GetSequence(), "ack") + im.ContractManagerKeeper.AddContractFailure(ctx, &packet, senderAddress.String(), contractmanagertypes.Ack, &ack) im.keeper.Logger(ctx).Debug("failed to Sudo contract on packet acknowledgement", err) } else { ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) @@ -140,11 +143,11 @@ func (im IBCModule) HandleTimeout(ctx sdk.Context, packet channeltypes.Packet, r } cacheCtx, writeFn, newGasMeter := im.createCachedContext(ctx) - defer im.outOfGasRecovery(ctx, newGasMeter, senderAddress, packet, data, "timeout") + defer im.outOfGasRecovery(ctx, newGasMeter, senderAddress, packet, data, contractmanagertypes.Timeout, nil) _, err = im.ContractManagerKeeper.SudoTimeout(cacheCtx, senderAddress, packet) if err != nil { - im.ContractManagerKeeper.AddContractFailure(ctx, packet.SourceChannel, senderAddress.String(), packet.GetSequence(), "timeout") + im.ContractManagerKeeper.AddContractFailure(ctx, &packet, senderAddress.String(), contractmanagertypes.Timeout, nil) im.keeper.Logger(ctx).Debug("failed to Sudo contract on packet timeout", err) } else { ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) diff --git a/x/transfer/ibc_handlers_test.go b/x/transfer/ibc_handlers_test.go index 024d17989..7e4ff2a5e 100644 --- a/x/transfer/ibc_handlers_test.go +++ b/x/transfer/ibc_handlers_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + "github.com/neutron-org/neutron/x/contractmanager/types" + sdk "github.com/cosmos/cosmos-sdk/types" transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -100,7 +102,7 @@ func TestHandleAcknowledgement(t *testing.T) { store := cachedCtx.KVStore(storeKey) store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) // consumes 2990 }).Return(nil, fmt.Errorf("SudoResponse error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "ack") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Ack, &resACK) cmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(false) err = txModule.HandleAcknowledgement(ctx, p, resAckData, relayerAddress) require.NoError(t, err) @@ -113,7 +115,7 @@ func TestHandleAcknowledgement(t *testing.T) { store := cachedCtx.KVStore(storeKey) store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) // consumes 2990 }).Return(nil, fmt.Errorf("SudoResponse error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "ack") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Ack, &resACK) cmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(true) feeKeeper.EXPECT().DistributeAcknowledgementFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) err = txModule.HandleAcknowledgement(ctx, p, resAckData, relayerAddress) @@ -127,7 +129,7 @@ func TestHandleAcknowledgement(t *testing.T) { store := cachedCtx.KVStore(storeKey) store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) // consumes 2990 }).Return(nil, fmt.Errorf("SudoError error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "ack") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Ack, &errACK) cmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(false) // feeKeeper.EXPECT().DistributeAcknowledgementFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) err = txModule.HandleAcknowledgement(ctx, p, errAckData, relayerAddress) @@ -141,7 +143,7 @@ func TestHandleAcknowledgement(t *testing.T) { store := cachedCtx.KVStore(storeKey) store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) // consumes 2990 }).Return(nil, fmt.Errorf("SudoError error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "ack") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Ack, &errACK) cmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(true) feeKeeper.EXPECT().DistributeAcknowledgementFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) err = txModule.HandleAcknowledgement(ctx, p, errAckData, relayerAddress) @@ -179,7 +181,7 @@ func TestHandleAcknowledgement(t *testing.T) { store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) cachedCtx.GasMeter().ConsumeGas(cachedCtx.GasMeter().Limit()+1, "out of gas test") }).Return(nil, fmt.Errorf("SudoError error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "ack") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Ack, &errACK) // FIXME: fix distribution during outofgas // cmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(false) err = txModule.HandleAcknowledgement(ctx, p, errAckData, relayerAddress) @@ -193,7 +195,7 @@ func TestHandleAcknowledgement(t *testing.T) { store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) cachedCtx.GasMeter().ConsumeGas(cachedCtx.GasMeter().Limit()+1, "out of gas test") }).Return(nil, fmt.Errorf("SudoError error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "ack") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Ack, &errACK) // FIXME: fix distribution during outofgas // cmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(true) // feeKeeper.EXPECT().DistributeAcknowledgementFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) @@ -248,7 +250,7 @@ func TestHandleAcknowledgement(t *testing.T) { cachedCtx.GasMeter().ConsumeGas(1, "Sudo response consumption") }).Return(nil, nil) // feeKeeper.EXPECT().DistributeAcknowledgementFee(lowGasCtx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) - cmKeeper.EXPECT().AddContractFailure(lowGasCtx, "channel-0", contractAddress.String(), p.GetSequence(), "ack").Do(func(ctx sdk.Context, channelId, address string, ackID uint64, ackType string) { + cmKeeper.EXPECT().AddContractFailure(lowGasCtx, &p, contractAddress.String(), types.Ack, &resACK).Do(func(ctx sdk.Context, packet channeltypes.Packet, address, ackType string, ack channeltypes.Acknowledgement) { ctx.GasMeter().ConsumeGas(keeper.GasReserve, "out of gas") }) require.Panics(t, func() { txModule.HandleAcknowledgement(lowGasCtx, p, resAckData, relayerAddress) }) //nolint:errcheck // this is a test @@ -342,7 +344,7 @@ func TestHandleTimeout(t *testing.T) { store := cachedCtx.KVStore(storeKey) store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) }).Return(nil, fmt.Errorf("SudoTimeout error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "timeout") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Timeout, nil) cmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(false) err = txModule.HandleTimeout(ctx, p, relayerAddress) require.NoError(t, err) @@ -354,7 +356,7 @@ func TestHandleTimeout(t *testing.T) { store := cachedCtx.KVStore(storeKey) store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) }).Return(nil, fmt.Errorf("SudoTimeout error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "timeout") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Timeout, nil) cmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(true) feeKeeper.EXPECT().DistributeTimeoutFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) err = txModule.HandleTimeout(ctx, p, relayerAddress) @@ -368,7 +370,7 @@ func TestHandleTimeout(t *testing.T) { store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) cachedCtx.GasMeter().ConsumeGas(cachedCtx.GasMeter().Limit()+1, "out of gas test") }).Return(nil, fmt.Errorf("SudoTimeout error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "timeout") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Timeout, nil) // cmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(false) err = txModule.HandleTimeout(ctx, p, relayerAddress) require.NoError(t, err) @@ -381,7 +383,7 @@ func TestHandleTimeout(t *testing.T) { store.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) cachedCtx.GasMeter().ConsumeGas(cachedCtx.GasMeter().Limit()+1, "out of gas test") }).Return(nil, fmt.Errorf("SudoTimeout error")) - cmKeeper.EXPECT().AddContractFailure(ctx, "channel-0", contractAddress.String(), p.GetSequence(), "timeout") + cmKeeper.EXPECT().AddContractFailure(ctx, &p, contractAddress.String(), types.Timeout, nil) // FIXME: make DistributeTimeoutFee during out of gas // cmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(true) // feeKeeper.EXPECT().DistributeTimeoutFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) diff --git a/x/transfer/types/expected_keepers.go b/x/transfer/types/expected_keepers.go index 3dd233a34..d2051ec76 100644 --- a/x/transfer/types/expected_keepers.go +++ b/x/transfer/types/expected_keepers.go @@ -11,7 +11,7 @@ import ( // ContractManagerKeeper defines the expected interface needed to add ack information about sudo failure. type ContractManagerKeeper interface { HasContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) bool - AddContractFailure(ctx sdk.Context, channelID, address string, ackID uint64, ackType string) + AddContractFailure(ctx sdk.Context, packet *channeltypes.Packet, address, ackType string, ack *channeltypes.Acknowledgement) SudoResponse(ctx sdk.Context, senderAddress sdk.AccAddress, request channeltypes.Packet, msg []byte) ([]byte, error) SudoError(ctx sdk.Context, senderAddress sdk.AccAddress, request channeltypes.Packet, details string) ([]byte, error) SudoTimeout(ctx sdk.Context, senderAddress sdk.AccAddress, request channeltypes.Packet) ([]byte, error)