From 53ecc9465c82d64769e5d0b3148960c5799d90e5 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 11 Feb 2022 17:54:05 +0100 Subject: [PATCH 1/6] fix: for async WriteAck store source address for query later --- modules/apps/29-fee/ibc_module.go | 2 +- modules/apps/29-fee/keeper/relay.go | 9 ++++++++- modules/apps/29-fee/keeper/relay_test.go | 9 ++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/apps/29-fee/ibc_module.go b/modules/apps/29-fee/ibc_module.go index cb5eb71b6d3..738c8a81a68 100644 --- a/modules/apps/29-fee/ibc_module.go +++ b/modules/apps/29-fee/ibc_module.go @@ -200,7 +200,7 @@ func (im IBCModule) OnRecvPacket( // incase of async aknowledgement (ack == nil) store the ForwardRelayer address for use later if ack == nil && found { - im.keeper.SetForwardRelayerAddress(ctx, channeltypes.NewPacketId(packet.GetSourceChannel(), packet.GetSourcePort(), packet.GetSequence()), forwardRelayer) + im.keeper.SetForwardRelayerAddress(ctx, channeltypes.NewPacketId(packet.GetSourceChannel(), packet.GetSourcePort(), packet.GetSequence()), relayer.String()) } return types.NewIncentivizedAcknowledgement(forwardRelayer, ack.Acknowledgement()) diff --git a/modules/apps/29-fee/keeper/relay.go b/modules/apps/29-fee/keeper/relay.go index 628ad40a61f..c8b389b90e1 100644 --- a/modules/apps/29-fee/keeper/relay.go +++ b/modules/apps/29-fee/keeper/relay.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" @@ -19,11 +20,17 @@ func (k Keeper) SendPacket(ctx sdk.Context, chanCap *capabilitytypes.Capability, func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement []byte) error { // retrieve the forward relayer that was stored in `onRecvPacket` packetId := channeltypes.NewPacketId(packet.GetSourceChannel(), packet.GetSourcePort(), packet.GetSequence()) + + // relayer address returned here is the relayer, _ := k.GetForwardRelayerAddress(ctx, packetId) + forwardRelayer, found := k.GetCounterpartyAddress(ctx, relayer) + if !found { + return sdkerrors.Wrapf(types.ErrCounterpartyAddressEmpty, "counterparty address not found for address: %s", forwardRelayer) + } k.DeleteForwardRelayerAddress(ctx, packetId) - ack := types.NewIncentivizedAcknowledgement(relayer, acknowledgement) + ack := types.NewIncentivizedAcknowledgement(forwardRelayer, acknowledgement) // ics4Wrapper may be core IBC or higher-level middleware return k.ics4Wrapper.WriteAcknowledgement(ctx, chanCap, packet, ack) diff --git a/modules/apps/29-fee/keeper/relay_test.go b/modules/apps/29-fee/keeper/relay_test.go index 79410552b05..0e8114c957b 100644 --- a/modules/apps/29-fee/keeper/relay_test.go +++ b/modules/apps/29-fee/keeper/relay_test.go @@ -13,15 +13,18 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgementAsync() { }{ { "success", - func() {}, + func() { + suite.chainB.GetSimApp().IBCFeeKeeper.SetForwardRelayerAddress(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1), suite.chainA.SenderAccount.GetAddress().String()) + suite.chainB.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainB.GetContext(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String()) + }, true, }, { - "forward relayer address is successfully deleted", + "counterparty address not set", func() { suite.chainB.GetSimApp().IBCFeeKeeper.SetForwardRelayerAddress(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1), suite.chainA.SenderAccount.GetAddress().String()) }, - true, + false, }, } From c43ff9dfaf01bebd182e95c3c73d582460a6bde3 Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 15 Feb 2022 17:15:54 +0100 Subject: [PATCH 2/6] ics29:fix: update genesis type (#913) * fix: adding ForwardRelayerAddresses to genesis * fix: trimspace on string check * nit: err + trimspace error case --- modules/apps/29-fee/types/genesis.go | 22 +++++++++--- modules/apps/29-fee/types/genesis_test.go | 42 ++++++++++++++++++----- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/modules/apps/29-fee/types/genesis.go b/modules/apps/29-fee/types/genesis.go index c0a84516291..78d230792bf 100644 --- a/modules/apps/29-fee/types/genesis.go +++ b/modules/apps/29-fee/types/genesis.go @@ -1,6 +1,8 @@ package types import ( + "strings" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -8,11 +10,12 @@ import ( ) // NewGenesisState creates a 29-fee GenesisState instance. -func NewGenesisState(identifiedFees []IdentifiedPacketFee, feeEnabledChannels []*FeeEnabledChannel, registeredRelayers []*RegisteredRelayerAddress) *GenesisState { +func NewGenesisState(identifiedFees []IdentifiedPacketFee, feeEnabledChannels []*FeeEnabledChannel, registeredRelayers []*RegisteredRelayerAddress, forwardRelayers []*ForwardRelayerAddress) *GenesisState { return &GenesisState{ IdentifiedFees: identifiedFees, FeeEnabledChannels: feeEnabledChannels, RegisteredRelayers: registeredRelayers, + ForwardRelayers: forwardRelayers, } } @@ -22,6 +25,7 @@ func DefaultGenesisState() *GenesisState { IdentifiedFees: []IdentifiedPacketFee{}, FeeEnabledChannels: []*FeeEnabledChannel{}, RegisteredRelayers: []*RegisteredRelayerAddress{}, + ForwardRelayers: []*ForwardRelayerAddress{}, } } @@ -48,15 +52,25 @@ func (gs GenesisState) Validate() error { // Validate RegisteredRelayers for _, rel := range gs.RegisteredRelayers { - _, err := sdk.AccAddressFromBech32(rel.Address) - if err != nil { + if _, err := sdk.AccAddressFromBech32(rel.Address); err != nil { return sdkerrors.Wrap(err, "failed to convert source relayer address into sdk.AccAddress") } - if rel.CounterpartyAddress == "" { + if strings.TrimSpace(rel.CounterpartyAddress) == "" { return ErrCounterpartyAddressEmpty } } + // Validate ForwardRelayers + for _, rel := range gs.ForwardRelayers { + if _, err := sdk.AccAddressFromBech32(rel.Address); err != nil { + return sdkerrors.Wrap(err, "failed to convert forward relayer address into sdk.AccAddress") + } + + if err := rel.PacketId.Validate(); err != nil { + return err + } + } + return nil } diff --git a/modules/apps/29-fee/types/genesis_test.go b/modules/apps/29-fee/types/genesis_test.go index c41fd8f7469..eeb894f8859 100644 --- a/modules/apps/29-fee/types/genesis_test.go +++ b/modules/apps/29-fee/types/genesis_test.go @@ -23,14 +23,16 @@ var ( func TestValidateGenesis(t *testing.T) { var ( - packetId channeltypes.PacketId - fee types.Fee - refundAcc string - sender string - counterparty string - portID string - channelID string - seq uint64 + packetId channeltypes.PacketId + fee types.Fee + refundAcc string + sender string + forwardAddr string + counterparty string + portID string + channelID string + packetChannelID string + seq uint64 ) testCases := []struct { @@ -118,7 +120,21 @@ func TestValidateGenesis(t *testing.T) { { "invalid RegisteredRelayers: invalid counterparty", func() { - counterparty = "" + counterparty = " " + }, + false, + }, + { + "invalid ForwardRelayerAddress: invalid forwardAddr", + func() { + forwardAddr = "" + }, + false, + }, + { + "invalid ForwardRelayerAddress: invalid packet", + func() { + packetChannelID = "1" }, false, }, @@ -127,6 +143,7 @@ func TestValidateGenesis(t *testing.T) { for _, tc := range testCases { portID = transfertypes.PortID channelID = ibctesting.FirstChannelID + packetChannelID = ibctesting.FirstChannelID seq = uint64(1) // build PacketId & Fee @@ -146,6 +163,7 @@ func TestValidateGenesis(t *testing.T) { // relayer addresses sender = addr1 counterparty = addr2 + forwardAddr = addr2 tc.malleate() @@ -170,6 +188,12 @@ func TestValidateGenesis(t *testing.T) { CounterpartyAddress: counterparty, }, }, + ForwardRelayers: []*types.ForwardRelayerAddress{ + { + Address: forwardAddr, + PacketId: channeltypes.NewPacketId(packetChannelID, portID, 1), + }, + }, } err := genState.Validate() From 88cf2be0fd0d960d448fcaf37ae70bd4e39ee810 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 21 Feb 2022 16:45:21 +0100 Subject: [PATCH 3/6] refactor: updating WriteAck + keeper fn name --- modules/apps/29-fee/ibc_module.go | 2 +- modules/apps/29-fee/keeper/genesis.go | 2 +- modules/apps/29-fee/keeper/genesis_test.go | 2 +- modules/apps/29-fee/keeper/keeper.go | 8 +-- modules/apps/29-fee/keeper/relay.go | 10 +-- modules/apps/29-fee/keeper/relay_test.go | 10 ++- modules/apps/29-fee/types/errors.go | 1 + modules/apps/29-fee/types/tx.pb.go | 75 +++++++++++----------- proto/ibc/applications/fee/v1/tx.proto | 1 - 9 files changed, 55 insertions(+), 56 deletions(-) diff --git a/modules/apps/29-fee/ibc_module.go b/modules/apps/29-fee/ibc_module.go index 738c8a81a68..352371b0f9e 100644 --- a/modules/apps/29-fee/ibc_module.go +++ b/modules/apps/29-fee/ibc_module.go @@ -200,7 +200,7 @@ func (im IBCModule) OnRecvPacket( // incase of async aknowledgement (ack == nil) store the ForwardRelayer address for use later if ack == nil && found { - im.keeper.SetForwardRelayerAddress(ctx, channeltypes.NewPacketId(packet.GetSourceChannel(), packet.GetSourcePort(), packet.GetSequence()), relayer.String()) + im.keeper.SetRelayerAddressForAsyncAck(ctx, channeltypes.NewPacketId(packet.GetSourceChannel(), packet.GetSourcePort(), packet.GetSequence()), relayer.String()) } return types.NewIncentivizedAcknowledgement(forwardRelayer, ack.Acknowledgement()) diff --git a/modules/apps/29-fee/keeper/genesis.go b/modules/apps/29-fee/keeper/genesis.go index 51879dbe14f..f4e3c09faba 100644 --- a/modules/apps/29-fee/keeper/genesis.go +++ b/modules/apps/29-fee/keeper/genesis.go @@ -17,7 +17,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { } for _, forwardAddr := range state.ForwardRelayers { - k.SetForwardRelayerAddress(ctx, forwardAddr.PacketId, forwardAddr.Address) + k.SetRelayerAddressForAsyncAck(ctx, forwardAddr.PacketId, forwardAddr.Address) } for _, enabledChan := range state.FeeEnabledChannels { diff --git a/modules/apps/29-fee/keeper/genesis_test.go b/modules/apps/29-fee/keeper/genesis_test.go index 568335daed1..34bfb30f252 100644 --- a/modules/apps/29-fee/keeper/genesis_test.go +++ b/modules/apps/29-fee/keeper/genesis_test.go @@ -95,7 +95,7 @@ func (suite *KeeperTestSuite) TestExportGenesis() { suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainA.GetContext(), sender, counterparty) // set forward relayer address - suite.chainA.GetSimApp().IBCFeeKeeper.SetForwardRelayerAddress(suite.chainA.GetContext(), packetId, sender) + suite.chainA.GetSimApp().IBCFeeKeeper.SetRelayerAddressForAsyncAck(suite.chainA.GetContext(), packetId, sender) // export genesis genesisState := suite.chainA.GetSimApp().IBCFeeKeeper.ExportGenesis(suite.chainA.GetContext()) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 441aaf57a2c..7e41a0682e8 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -174,14 +174,14 @@ func (k Keeper) GetAllRelayerAddresses(ctx sdk.Context) []*types.RegisteredRelay return registeredAddrArr } -// SetForwardRelayerAddress sets the forward relayer address during OnRecvPacket in case of async acknowledgement -func (k Keeper) SetForwardRelayerAddress(ctx sdk.Context, packetId channeltypes.PacketId, address string) { +// SetRelayerAddressForAsyncAck sets the forward relayer address during OnRecvPacket in case of async acknowledgement +func (k Keeper) SetRelayerAddressForAsyncAck(ctx sdk.Context, packetId channeltypes.PacketId, address string) { store := ctx.KVStore(k.storeKey) store.Set(types.KeyForwardRelayerAddress(packetId), []byte(address)) } -// GetForwardRelayerAddress gets forward relayer address for a particular packet -func (k Keeper) GetForwardRelayerAddress(ctx sdk.Context, packetId channeltypes.PacketId) (string, bool) { +// GetRelayerAddressForAsyncAck gets forward relayer address for a particular packet +func (k Keeper) GetRelayerAddressForAsyncAck(ctx sdk.Context, packetId channeltypes.PacketId) (string, bool) { store := ctx.KVStore(k.storeKey) key := types.KeyForwardRelayerAddress(packetId) if !store.Has(key) { diff --git a/modules/apps/29-fee/keeper/relay.go b/modules/apps/29-fee/keeper/relay.go index c8b389b90e1..ee0e7b23da9 100644 --- a/modules/apps/29-fee/keeper/relay.go +++ b/modules/apps/29-fee/keeper/relay.go @@ -21,13 +21,15 @@ func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.C // retrieve the forward relayer that was stored in `onRecvPacket` packetId := channeltypes.NewPacketId(packet.GetSourceChannel(), packet.GetSourcePort(), packet.GetSequence()) - // relayer address returned here is the - relayer, _ := k.GetForwardRelayerAddress(ctx, packetId) - forwardRelayer, found := k.GetCounterpartyAddress(ctx, relayer) + relayer, found := k.GetRelayerAddressForAsyncAck(ctx, packetId) if !found { - return sdkerrors.Wrapf(types.ErrCounterpartyAddressEmpty, "counterparty address not found for address: %s", forwardRelayer) + return sdkerrors.Wrapf(types.ErrRelayerNotFoundForAsyncAck, "No relayer address stored for async acknowledgement for packet with portID: %s, channelID: %s, sequence: %d", packetId.PortId, packetId.ChannelId, packetId.Sequence) } + // it is possible that a relayer has not registered a counterparty address. + // if there is no registered counterparty address then write acknowledgement with empty relayer address and refund recv_fee. + forwardRelayer, _ := k.GetCounterpartyAddress(ctx, relayer) + k.DeleteForwardRelayerAddress(ctx, packetId) ack := types.NewIncentivizedAcknowledgement(forwardRelayer, acknowledgement) diff --git a/modules/apps/29-fee/keeper/relay_test.go b/modules/apps/29-fee/keeper/relay_test.go index 0e8114c957b..1ff511c79c0 100644 --- a/modules/apps/29-fee/keeper/relay_test.go +++ b/modules/apps/29-fee/keeper/relay_test.go @@ -14,16 +14,14 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgementAsync() { { "success", func() { - suite.chainB.GetSimApp().IBCFeeKeeper.SetForwardRelayerAddress(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1), suite.chainA.SenderAccount.GetAddress().String()) + suite.chainB.GetSimApp().IBCFeeKeeper.SetRelayerAddressForAsyncAck(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1), suite.chainA.SenderAccount.GetAddress().String()) suite.chainB.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainB.GetContext(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String()) }, true, }, { - "counterparty address not set", - func() { - suite.chainB.GetSimApp().IBCFeeKeeper.SetForwardRelayerAddress(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1), suite.chainA.SenderAccount.GetAddress().String()) - }, + "relayer address not set for async WriteAcknowledgement", + func() {}, false, }, } @@ -59,7 +57,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgementAsync() { if tc.expPass { suite.Require().NoError(err) - _, found := suite.chainB.GetSimApp().IBCFeeKeeper.GetForwardRelayerAddress(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1)) + _, found := suite.chainB.GetSimApp().IBCFeeKeeper.GetRelayerAddressForAsyncAck(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1)) suite.Require().False(found) } else { suite.Require().Error(err) diff --git a/modules/apps/29-fee/types/errors.go b/modules/apps/29-fee/types/errors.go index 55ce843e92c..75fdd436c91 100644 --- a/modules/apps/29-fee/types/errors.go +++ b/modules/apps/29-fee/types/errors.go @@ -14,4 +14,5 @@ var ( ErrCounterpartyAddressEmpty = sdkerrors.Register(ModuleName, 7, "counterparty address must not be empty") ErrForwardRelayerAddressNotFound = sdkerrors.Register(ModuleName, 8, "forward relayer address not found") ErrFeeNotEnabled = sdkerrors.Register(ModuleName, 9, "fee module is not enabled for this channel. If this error occurs after channel setup, fee module may not be enabled") + ErrRelayerNotFoundForAsyncAck = sdkerrors.Register(ModuleName, 10, "relayer address must be stored for async WriteAcknowledgement") ) diff --git a/modules/apps/29-fee/types/tx.pb.go b/modules/apps/29-fee/types/tx.pb.go index 46f20f29783..624c6d8279a 100644 --- a/modules/apps/29-fee/types/tx.pb.go +++ b/modules/apps/29-fee/types/tx.pb.go @@ -6,7 +6,6 @@ package types import ( context "context" fmt "fmt" - _ "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" @@ -281,44 +280,44 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/tx.proto", fileDescriptor_05c93128649f1b96) } var fileDescriptor_05c93128649f1b96 = []byte{ - // 587 bytes of a gzipped FileDescriptorProto + // 577 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4f, 0x4f, 0xdb, 0x4c, - 0x10, 0xc6, 0x6d, 0xc2, 0xcb, 0x0b, 0x5b, 0x54, 0x84, 0x81, 0x12, 0x4c, 0x64, 0x53, 0xab, 0xaa, - 0x72, 0x68, 0xec, 0x12, 0x8a, 0xaa, 0x72, 0x41, 0x04, 0x09, 0x35, 0x87, 0xa8, 0x91, 0x8f, 0xbd, - 0x44, 0xce, 0x7a, 0x62, 0xb6, 0x4d, 0xbc, 0xd6, 0xee, 0x26, 0xaa, 0xbf, 0x00, 0xea, 0x91, 0x5b, - 0x7b, 0xe4, 0xda, 0x6f, 0xc2, 0x91, 0x63, 0x4f, 0x51, 0x95, 0x5c, 0x7a, 0xce, 0x27, 0xa8, 0x6c, - 0x27, 0xc1, 0x21, 0x7f, 0x44, 0x7b, 0xdb, 0xdd, 0xf9, 0xcd, 0xb3, 0x33, 0xcf, 0xae, 0x06, 0x1d, - 0x90, 0x3a, 0xb6, 0x9c, 0x20, 0x68, 0x12, 0xec, 0x08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45, 0x4f, 0x39, 0x6d, 0x33, 0x0c, 0xb5, 0x80, 0x32, 0x51, 0x23, 0xee, 0xb0, 0x97, 0xbd, 0x41, - 0x57, 0xdf, 0x49, 0x7a, 0x99, 0x8c, 0x1b, 0xf6, 0x7a, 0x72, 0x50, 0xa5, 0x4c, 0x94, 0x5d, 0xe5, - 0x3d, 0xda, 0x1c, 0x02, 0x43, 0x9f, 0x23, 0x8d, 0x4c, 0xac, 0x91, 0x1b, 0x74, 0xf5, 0xec, 0x84, - 0xc6, 0x3d, 0x62, 0xd8, 0x1b, 0xc9, 0xd9, 0x79, 0x72, 0x54, 0x76, 0x95, 0x67, 0x68, 0x85, 0x13, - 0xcf, 0x07, 0x96, 0x5d, 0x8e, 0x5d, 0x1f, 0xee, 0x14, 0x15, 0xad, 0x32, 0x68, 0x3a, 0x21, 0x30, - 0x9e, 0xfd, 0xef, 0x20, 0x93, 0x5f, 0xb3, 0xc7, 0xfb, 0x94, 0x79, 0x7b, 0x68, 0xf7, 0x81, 0x23, - 0x63, 0xb7, 0x7e, 0xc8, 0x68, 0xfb, 0x41, 0xec, 0x8c, 0x87, 0x3e, 0x56, 0xae, 0x64, 0xb4, 0x43, - 0x5c, 0xf0, 0x05, 0x69, 0x10, 0x70, 0x6b, 0x41, 0x1c, 0xad, 0xdd, 0xbb, 0xf8, 0x6a, 0xae, 0x8b, - 0xe5, 0x71, 0xd6, 0x58, 0xb2, 0xf4, 0x22, 0x72, 0x75, 0xd0, 0xd5, 0x73, 0x49, 0xcb, 0x33, 0x85, - 0x0d, 0x7b, 0x8b, 0x4c, 0xa7, 0xa6, 0xda, 0xd0, 0x50, 0x6e, 0x56, 0xa9, 0xa3, 0x5e, 0x8a, 0x57, - 0x19, 0x94, 0xa9, 0x70, 0x4f, 0xf9, 0x26, 0xa3, 0xfd, 0x45, 0x7f, 0xf8, 0xed, 0xdc, 0xd2, 0x17, - 0x7f, 0x31, 0xf5, 0xf4, 0x1f, 0x13, 0x47, 0x15, 0x2a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0x33, 0xfc, 0x76, 0x61, 0xe9, 0xcb, 0x47, 0x4c, 0x3d, 0xfd, 0xc7, 0xc0, 0x51, 0x85, 0xca, 0x27, + 0xb4, 0x39, 0x35, 0x97, 0xf9, 0x65, 0x82, 0x93, 0xa4, 0xfa, 0xfa, 0xb1, 0xe4, 0x38, 0x57, 0x88, + 0xb6, 0x67, 0xff, 0x6a, 0xe1, 0xb1, 0x32, 0x31, 0xae, 0x1e, 0xff, 0x15, 0x3e, 0x4a, 0x5d, 0xfa, + 0x70, 0xdb, 0xd3, 0xe4, 0xbb, 0x9e, 0x26, 0xff, 0xea, 0x69, 0xf2, 0x75, 0x5f, 0x93, 0xee, 0xfa, + 0x9a, 0xf4, 0xb3, 0xaf, 0x49, 0x1f, 0x8f, 0x3d, 0x22, 0x2e, 0xdb, 0x75, 0x13, 0xd3, 0x96, 0x85, + 0x29, 0x6f, 0x51, 0x6e, 0x91, 0x3a, 0x2e, 0x78, 0xd4, 0xea, 0x1c, 0x59, 0x2d, 0xea, 0xb6, 0x9b, + 0xc0, 0xa3, 0x25, 0xc5, 0xad, 0xe2, 0xbb, 0x42, 0xb4, 0x9f, 0x44, 0x18, 0x00, 0xaf, 0xaf, 0xc5, + 0xfb, 0xe9, 0xe8, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x81, 0xea, 0x8a, 0x9a, 0x15, 0x05, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/proto/ibc/applications/fee/v1/tx.proto b/proto/ibc/applications/fee/v1/tx.proto index 4540c28967e..900764f9343 100644 --- a/proto/ibc/applications/fee/v1/tx.proto +++ b/proto/ibc/applications/fee/v1/tx.proto @@ -6,7 +6,6 @@ option go_package = "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"; import "gogoproto/gogo.proto"; import "ibc/applications/fee/v1/fee.proto"; -import "ibc/core/channel/v1/channel.proto"; // Msg defines the ibc/fee Msg service. service Msg { From 88eac60eb62f93e6bfa45d0e01ab47115826e492 Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 22 Feb 2022 10:23:44 +0100 Subject: [PATCH 4/6] Update modules/apps/29-fee/keeper/relay.go Co-authored-by: Damian Nolan --- modules/apps/29-fee/keeper/relay.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/29-fee/keeper/relay.go b/modules/apps/29-fee/keeper/relay.go index ee0e7b23da9..e6dc51880d5 100644 --- a/modules/apps/29-fee/keeper/relay.go +++ b/modules/apps/29-fee/keeper/relay.go @@ -23,7 +23,7 @@ func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.C relayer, found := k.GetRelayerAddressForAsyncAck(ctx, packetId) if !found { - return sdkerrors.Wrapf(types.ErrRelayerNotFoundForAsyncAck, "No relayer address stored for async acknowledgement for packet with portID: %s, channelID: %s, sequence: %d", packetId.PortId, packetId.ChannelId, packetId.Sequence) + return sdkerrors.Wrapf(types.ErrRelayerNotFoundForAsyncAck, "no relayer address stored for async acknowledgement for packet with portID: %s, channelID: %s, sequence: %d", packetId.PortId, packetId.ChannelId, packetId.Sequence) } // it is possible that a relayer has not registered a counterparty address. From 9afb86dfae0ddf4e43146b737ec5adf38ea76471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 21 Feb 2022 17:19:26 +0100 Subject: [PATCH 5/6] chore: remove legacy testing functions (#954) --- modules/apps/29-fee/fee_test.go | 40 ----------------------- modules/apps/29-fee/ibc_module_test.go | 14 ++++---- modules/apps/29-fee/keeper/keeper_test.go | 23 ------------- 3 files changed, 7 insertions(+), 70 deletions(-) diff --git a/modules/apps/29-fee/fee_test.go b/modules/apps/29-fee/fee_test.go index 88037046a69..12d7e70a147 100644 --- a/modules/apps/29-fee/fee_test.go +++ b/modules/apps/29-fee/fee_test.go @@ -3,11 +3,9 @@ package fee_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/suite" "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" - transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" @@ -25,27 +23,11 @@ type FeeTestSuite struct { path *ibctesting.Path } -// TODO: remove and rename 'SetupMockTest' to 'SetupTest' func (suite *FeeTestSuite) SetupTest() { suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) - path := ibctesting.NewPath(suite.chainA, suite.chainB) - feeTransferVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: transfertypes.Version})) - path.EndpointA.ChannelConfig.Version = feeTransferVersion - path.EndpointB.ChannelConfig.Version = feeTransferVersion - path.EndpointA.ChannelConfig.PortID = transfertypes.PortID - path.EndpointB.ChannelConfig.PortID = transfertypes.PortID - suite.path = path -} - -// TODO: rename to 'SetupTest' when the above function is removed -func (suite *FeeTestSuite) SetupMockTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) - path := ibctesting.NewPath(suite.chainA, suite.chainB) mockFeeVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: ibcmock.Version})) path.EndpointA.ChannelConfig.Version = mockFeeVersion @@ -59,28 +41,6 @@ func TestIBCFeeTestSuite(t *testing.T) { suite.Run(t, new(FeeTestSuite)) } -// TODO: remove -func (suite *FeeTestSuite) CreateICS20Packet(coin sdk.Coin) channeltypes.Packet { - - fungibleTokenPacket := transfertypes.NewFungibleTokenPacketData( - coin.Denom, - sdk.NewInt(100).String(), - suite.chainA.SenderAccount.GetAddress().String(), - suite.chainB.SenderAccount.GetAddress().String(), - ) - - return channeltypes.NewPacket( - fungibleTokenPacket.GetBytes(), - suite.chainA.SenderAccount.GetSequence(), - suite.path.EndpointA.ChannelConfig.PortID, - suite.path.EndpointA.ChannelID, - suite.path.EndpointB.ChannelConfig.PortID, - suite.path.EndpointB.ChannelID, - clienttypes.NewHeight(0, 100), - 0, - ) -} - func (suite *FeeTestSuite) CreateMockPacket() channeltypes.Packet { return channeltypes.NewPacket( ibcmock.MockPacketData, diff --git a/modules/apps/29-fee/ibc_module_test.go b/modules/apps/29-fee/ibc_module_test.go index b556f057d7e..2a9bf532767 100644 --- a/modules/apps/29-fee/ibc_module_test.go +++ b/modules/apps/29-fee/ibc_module_test.go @@ -59,7 +59,7 @@ func (suite *FeeTestSuite) TestOnChanOpenInit() { suite.Run(tc.name, func() { // reset suite - suite.SetupMockTest() + suite.SetupTest() suite.coordinator.SetupConnections(suite.path) // setup mock callback @@ -150,7 +150,7 @@ func (suite *FeeTestSuite) TestOnChanOpenTry() { suite.Run(tc.name, func() { // reset suite - suite.SetupMockTest() + suite.SetupTest() suite.coordinator.SetupConnections(suite.path) suite.path.EndpointB.ChanOpenInit() @@ -255,7 +255,7 @@ func (suite *FeeTestSuite) TestOnChanOpenAck() { for _, tc := range testCases { tc := tc suite.Run(tc.name, func() { - suite.SetupMockTest() + suite.SetupTest() suite.coordinator.SetupConnections(suite.path) // setup mock callback @@ -337,7 +337,7 @@ func (suite *FeeTestSuite) TestOnChanCloseInit() { for _, tc := range testCases { tc := tc suite.Run(tc.name, func() { - suite.SetupMockTest() + suite.SetupTest() suite.coordinator.Setup(suite.path) // setup channel origBal := suite.chainA.GetSimApp().BankKeeper.GetAllBalances(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress()) @@ -415,7 +415,7 @@ func (suite *FeeTestSuite) TestOnChanCloseConfirm() { for _, tc := range testCases { tc := tc suite.Run(tc.name, func() { - suite.SetupMockTest() + suite.SetupTest() suite.coordinator.Setup(suite.path) // setup channel origBal := suite.chainA.GetSimApp().BankKeeper.GetAllBalances(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress()) @@ -481,7 +481,7 @@ func (suite *FeeTestSuite) TestOnRecvPacket() { for _, tc := range testCases { tc := tc suite.Run(tc.name, func() { - suite.SetupMockTest() + suite.SetupTest() suite.coordinator.Setup(suite.path) // set up a different channel to make sure that the test will error if the destination channel of the packet is not fee enabled @@ -724,7 +724,7 @@ func (suite *FeeTestSuite) TestOnTimeoutPacket() { for _, tc := range testCases { tc := tc suite.Run(tc.name, func() { - suite.SetupMockTest() + suite.SetupTest() suite.coordinator.Setup(suite.path) packet := suite.CreateMockPacket() diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index be49deef63b..3fbfa96406d 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" - transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" ibcmock "github.com/cosmos/ibc-go/v3/testing/mock" @@ -34,31 +33,11 @@ type KeeperTestSuite struct { queryClient types.QueryClient } -// TODO: remove and rename 'SetupMockTest' to 'SetupTest' func (suite *KeeperTestSuite) SetupTest() { suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) - path := ibctesting.NewPath(suite.chainA, suite.chainB) - feeTransferVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: transfertypes.Version})) - path.EndpointA.ChannelConfig.Version = feeTransferVersion - path.EndpointB.ChannelConfig.Version = feeTransferVersion - path.EndpointA.ChannelConfig.PortID = transfertypes.PortID - path.EndpointB.ChannelConfig.PortID = transfertypes.PortID - suite.path = path - - queryHelper := baseapp.NewQueryServerTestHelper(suite.chainA.GetContext(), suite.chainA.GetSimApp().InterfaceRegistry()) - types.RegisterQueryServer(queryHelper, suite.chainA.GetSimApp().IBCFeeKeeper) - suite.queryClient = types.NewQueryClient(queryHelper) -} - -// TODO: rename to 'SetupTest' when the above function is removed -func (suite *KeeperTestSuite) SetupMockTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) - path := ibctesting.NewPath(suite.chainA, suite.chainB) mockFeeVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: ibcmock.Version})) path.EndpointA.ChannelConfig.Version = mockFeeVersion @@ -77,7 +56,6 @@ func TestKeeperTestSuite(t *testing.T) { } func (suite *KeeperTestSuite) TestFeeInEscrow() { - suite.SetupMockTest() suite.coordinator.Setup(suite.path) fee := types.Fee{RecvFee: defaultReceiveFee, AckFee: defaultAckFee, TimeoutFee: defaultTimeoutFee} @@ -119,7 +97,6 @@ func (suite *KeeperTestSuite) TestDisableAllChannels() { } func (suite *KeeperTestSuite) TestGetAllIdentifiedPacketFees() { - suite.SetupMockTest() suite.coordinator.Setup(suite.path) // escrow a fee From 64d67428c66ac4cc79ba1e1e1c3e7c28e88b9db9 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 21 Feb 2022 18:00:36 +0100 Subject: [PATCH 6/6] fix:ics29: WriteAck update + adding success bool to IncentivizedAck (#952) * fix: updating WriteAck & adding Success boolean to IncentivizedAcknowledgement * feat: adding check of is fee enabled * nit: change successful to underlying_application_success * test: adding seperate test for fee disabled write async * Update modules/apps/29-fee/ibc_module_test.go Co-authored-by: Aditya * test: adding check to compare hash of acks * fix: var name Co-authored-by: Aditya --- docs/ibc/proto-docs.md | 1 + modules/apps/29-fee/ibc_module.go | 2 +- modules/apps/29-fee/ibc_module_test.go | 35 ++++++---- modules/apps/29-fee/keeper/relay.go | 9 ++- modules/apps/29-fee/keeper/relay_test.go | 30 ++++++++- modules/apps/29-fee/types/ack.go | 5 +- modules/apps/29-fee/types/ack.pb.go | 81 ++++++++++++++++++------ proto/ibc/applications/fee/v1/ack.proto | 1 + 8 files changed, 128 insertions(+), 36 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 84127283e32..0eeff647971 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -341,6 +341,7 @@ It contains the raw acknowledgement bytes, as well as the forward relayer addres | ----- | ---- | ----- | ----------- | | `result` | [bytes](#bytes) | | | | `forward_relayer_address` | [string](#string) | | | +| `underlying_app_success` | [bool](#bool) | | | diff --git a/modules/apps/29-fee/ibc_module.go b/modules/apps/29-fee/ibc_module.go index ed212876563..5f24e78442f 100644 --- a/modules/apps/29-fee/ibc_module.go +++ b/modules/apps/29-fee/ibc_module.go @@ -205,7 +205,7 @@ func (im IBCModule) OnRecvPacket( // if forwardRelayer is not found we refund recv_fee forwardRelayer, _ := im.keeper.GetCounterpartyAddress(ctx, relayer.String()) - return types.NewIncentivizedAcknowledgement(forwardRelayer, ack.Acknowledgement()) + return types.NewIncentivizedAcknowledgement(forwardRelayer, ack.Acknowledgement(), ack.Success()) } // OnAcknowledgementPacket implements the IBCModule interface diff --git a/modules/apps/29-fee/ibc_module_test.go b/modules/apps/29-fee/ibc_module_test.go index 2a9bf532767..ff992a61f1d 100644 --- a/modules/apps/29-fee/ibc_module_test.go +++ b/modules/apps/29-fee/ibc_module_test.go @@ -10,6 +10,7 @@ import ( transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v3/modules/core/24-host" + "github.com/cosmos/ibc-go/v3/modules/core/exported" ibctesting "github.com/cosmos/ibc-go/v3/testing" ibcmock "github.com/cosmos/ibc-go/v3/testing/mock" ) @@ -461,11 +462,18 @@ func (suite *FeeTestSuite) TestOnRecvPacket() { true, }, { - "source relayer is empty string", + "async write acknowledgement: ack is nil", func() { - suite.chainB.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainB.GetContext(), suite.chainA.SenderAccount.GetAddress().String(), "") + // setup mock callback + suite.chainB.GetSimApp().FeeMockModule.IBCApp.OnRecvPacket = func( + ctx sdk.Context, + packet channeltypes.Packet, + relayer sdk.AccAddress, + ) exported.Acknowledgement { + return nil + } }, - false, + true, true, }, { @@ -476,6 +484,14 @@ func (suite *FeeTestSuite) TestOnRecvPacket() { true, false, }, + { + "forward address is not found", + func() { + suite.chainB.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainB.GetContext(), suite.chainA.SenderAccount.GetAddress().String(), "") + }, + false, + true, + }, } for _, tc := range testCases { @@ -509,19 +525,16 @@ func (suite *FeeTestSuite) TestOnRecvPacket() { case !tc.feeEnabled: suite.Require().Equal(ibcmock.MockAcknowledgement, result) - case tc.forwardRelayer: - ack := types.IncentivizedAcknowledgement{ - Result: ibcmock.MockAcknowledgement.Acknowledgement(), - ForwardRelayerAddress: suite.chainB.SenderAccount.GetAddress().String(), - } - suite.Require().Equal(ack, result) + case tc.forwardRelayer && result == nil: + suite.Require().Equal(nil, result) case !tc.forwardRelayer: - ack := types.IncentivizedAcknowledgement{ + expectedAck := types.IncentivizedAcknowledgement{ Result: ibcmock.MockAcknowledgement.Acknowledgement(), ForwardRelayerAddress: "", + UnderlyingAppSuccess: true, } - suite.Require().Equal(ack, result) + suite.Require().Equal(expectedAck, result) } }) } diff --git a/modules/apps/29-fee/keeper/relay.go b/modules/apps/29-fee/keeper/relay.go index e6dc51880d5..80eceaaf391 100644 --- a/modules/apps/29-fee/keeper/relay.go +++ b/modules/apps/29-fee/keeper/relay.go @@ -17,7 +17,12 @@ func (k Keeper) SendPacket(ctx sdk.Context, chanCap *capabilitytypes.Capability, // WriteAcknowledgement wraps IBC ChannelKeeper's WriteAcknowledgement function // ICS29 WriteAcknowledgement is used for asynchronous acknowledgements -func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement []byte) error { +func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error { + if !k.IsFeeEnabled(ctx, packet.GetDestPort(), packet.GetDestChannel()) { + // ics4Wrapper may be core IBC or higher-level middleware + return k.ics4Wrapper.WriteAcknowledgement(ctx, chanCap, packet, acknowledgement) + } + // retrieve the forward relayer that was stored in `onRecvPacket` packetId := channeltypes.NewPacketId(packet.GetSourceChannel(), packet.GetSourcePort(), packet.GetSequence()) @@ -32,7 +37,7 @@ func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.C k.DeleteForwardRelayerAddress(ctx, packetId) - ack := types.NewIncentivizedAcknowledgement(forwardRelayer, acknowledgement) + ack := types.NewIncentivizedAcknowledgement(forwardRelayer, acknowledgement.Acknowledgement(), acknowledgement.Success()) // ics4Wrapper may be core IBC or higher-level middleware return k.ics4Wrapper.WriteAcknowledgement(ctx, chanCap, packet, ack) diff --git a/modules/apps/29-fee/keeper/relay_test.go b/modules/apps/29-fee/keeper/relay_test.go index 1ff511c79c0..a1e6c22aa07 100644 --- a/modules/apps/29-fee/keeper/relay_test.go +++ b/modules/apps/29-fee/keeper/relay_test.go @@ -47,7 +47,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgementAsync() { timeoutTimestamp, ) - ack := []byte("ack") + ack := channeltypes.NewResultAcknowledgement([]byte("success")) chanCap := suite.chainB.GetChannelCapability(suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID) // malleate test case @@ -65,3 +65,31 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgementAsync() { }) } } + +func (suite *KeeperTestSuite) TestWriteAcknowledgementAsyncFeeDisabled() { + // open incentivized channel + suite.coordinator.Setup(suite.path) + suite.chainB.GetSimApp().IBCFeeKeeper.DeleteFeeEnabled(suite.chainB.GetContext(), suite.path.EndpointB.ChannelConfig.PortID, "channel-0") + + // build packet + timeoutTimestamp := ^uint64(0) + packet := channeltypes.NewPacket( + []byte("packetData"), + 1, + suite.path.EndpointA.ChannelConfig.PortID, + suite.path.EndpointA.ChannelID, + suite.path.EndpointB.ChannelConfig.PortID, + suite.path.EndpointB.ChannelID, + clienttypes.ZeroHeight(), + timeoutTimestamp, + ) + + ack := channeltypes.NewResultAcknowledgement([]byte("success")) + chanCap := suite.chainB.GetChannelCapability(suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID) + + err := suite.chainB.GetSimApp().IBCFeeKeeper.WriteAcknowledgement(suite.chainB.GetContext(), chanCap, packet, ack) + suite.Require().NoError(err) + + packetAck, _ := suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(suite.chainB.GetContext(), packet.DestinationPort, packet.DestinationChannel, 1) + suite.Require().Equal(packetAck, channeltypes.CommitAcknowledgement(ack.Acknowledgement())) +} diff --git a/modules/apps/29-fee/types/ack.go b/modules/apps/29-fee/types/ack.go index f54214d8432..229d8e4cc3f 100644 --- a/modules/apps/29-fee/types/ack.go +++ b/modules/apps/29-fee/types/ack.go @@ -5,10 +5,11 @@ import ( ) // NewIncentivizedAcknowledgement creates a new instance of IncentivizedAcknowledgement -func NewIncentivizedAcknowledgement(relayer string, ack []byte) IncentivizedAcknowledgement { +func NewIncentivizedAcknowledgement(relayer string, ack []byte, success bool) IncentivizedAcknowledgement { return IncentivizedAcknowledgement{ Result: ack, ForwardRelayerAddress: relayer, + UnderlyingAppSuccess: success, } } @@ -16,7 +17,7 @@ func NewIncentivizedAcknowledgement(relayer string, ack []byte) IncentivizedAckn // considered successful if the forward relayer address is empty. Otherwise it is // considered a failed acknowledgement. func (ack IncentivizedAcknowledgement) Success() bool { - return ack.ForwardRelayerAddress != "" + return ack.UnderlyingAppSuccess } // Acknowledgement implements the Acknowledgement interface. It returns the diff --git a/modules/apps/29-fee/types/ack.pb.go b/modules/apps/29-fee/types/ack.pb.go index 796fa3cd139..dfcc0e1041c 100644 --- a/modules/apps/29-fee/types/ack.pb.go +++ b/modules/apps/29-fee/types/ack.pb.go @@ -28,6 +28,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type IncentivizedAcknowledgement struct { Result []byte `protobuf:"bytes,1,opt,name=result,proto3" json:"result,omitempty"` ForwardRelayerAddress string `protobuf:"bytes,2,opt,name=forward_relayer_address,json=forwardRelayerAddress,proto3" json:"forward_relayer_address,omitempty" yaml:"forward_relayer_address"` + UnderlyingAppSuccess bool `protobuf:"varint,3,opt,name=underlying_app_success,json=underlyingAppSuccess,proto3" json:"underlying_app_success,omitempty" yaml:"underlying_app_successl"` } func (m *IncentivizedAcknowledgement) Reset() { *m = IncentivizedAcknowledgement{} } @@ -77,6 +78,13 @@ func (m *IncentivizedAcknowledgement) GetForwardRelayerAddress() string { return "" } +func (m *IncentivizedAcknowledgement) GetUnderlyingAppSuccess() bool { + if m != nil { + return m.UnderlyingAppSuccess + } + return false +} + func init() { proto.RegisterType((*IncentivizedAcknowledgement)(nil), "ibc.applications.fee.v1.IncentivizedAcknowledgement") } @@ -84,25 +92,27 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/ack.proto", fileDescriptor_ab2834946fb65ea4) } var fileDescriptor_ab2834946fb65ea4 = []byte{ - // 274 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0xd0, 0xb1, 0x4e, 0xc3, 0x30, - 0x10, 0x06, 0xe0, 0x9a, 0xa1, 0x12, 0x11, 0x53, 0x04, 0xb4, 0x02, 0x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1, 0xe4, 0xad, 0xa5, 0x83, 0x7d, 0x4b, 0x07, 0x9f, 0x2d, 0x1d, 0xac, 0xef, 0x53, 0xe5, 0x5e, - 0xca, 0x38, 0x14, 0x98, 0x31, 0x81, 0x36, 0x43, 0xcb, 0x54, 0x2c, 0x66, 0x29, 0xb2, 0x6a, 0xc1, - 0x32, 0x94, 0xa5, 0x06, 0xdb, 0xf5, 0x63, 0xd9, 0xdd, 0xc3, 0xac, 0xab, 0xc6, 0xd5, 0x05, 0xd8, - 0x78, 0x78, 0xf8, 0x75, 0xf1, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x50, 0xc6, 0xd5, 0xaa, 0x3f, 0x01, - 0x00, 0x00, + // 315 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xb1, 0x4e, 0xf3, 0x30, + 0x14, 0x85, 0xeb, 0xff, 0x97, 0x2a, 0x88, 0x98, 0xa2, 0xd2, 0x56, 0x20, 0x85, 0x92, 0xa9, 0x4b, + 0x63, 0x95, 0x8a, 0x01, 0xb6, 0x76, 0x63, 0x42, 0x0a, 0x0b, 0xea, 0x12, 0x39, 0xf6, 0x6d, 0xb0, + 0xea, 0xd8, 0x96, 0xed, 0xa4, 0x0a, 0x4f, 0xc1, 0x63, 0x31, 0x76, 0x64, 0x42, 0xa8, 0x1d, 0xd9, + 0x78, 0x02, 0x94, 0xa6, 0x12, 0x1d, 0x60, 0xbb, 0xf7, 0x9c, 0x4f, 0x67, 0xf8, 0xbc, 0x4b, 0x9e, + 0x52, 0x4c, 0xb4, 0x16, 0x9c, 0x12, 0xc7, 0x95, 0xb4, 0x78, 0x01, 0x80, 0xcb, 0x31, 0x26, 0x74, + 0x19, 0x69, 0xa3, 0x9c, 0xf2, 0x7b, 0x3c, 0xa5, 0xd1, 0x21, 0x12, 0x2d, 0x00, 0xa2, 0x72, 0x7c, + 0xd6, 0xc9, 0x54, 0x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d, 0xc5, 0xc9, 0x77, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x2e, 0x38, 0x5f, 0x80, 0x99, 0x01, 0x00, 0x00, } func (m *IncentivizedAcknowledgement) Marshal() (dAtA []byte, err error) { @@ -125,6 +135,16 @@ func (m *IncentivizedAcknowledgement) MarshalToSizedBuffer(dAtA []byte) (int, er _ = i var l int _ = l + if m.UnderlyingAppSuccess { + i-- + if m.UnderlyingAppSuccess { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x18 + } if len(m.ForwardRelayerAddress) > 0 { i -= len(m.ForwardRelayerAddress) copy(dAtA[i:], m.ForwardRelayerAddress) @@ -167,6 +187,9 @@ func (m *IncentivizedAcknowledgement) Size() (n int) { if l > 0 { n += 1 + l + sovAck(uint64(l)) } + if m.UnderlyingAppSuccess { + n += 2 + } return n } @@ -271,6 +294,26 @@ func (m *IncentivizedAcknowledgement) Unmarshal(dAtA []byte) error { } m.ForwardRelayerAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UnderlyingAppSuccess", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAck + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.UnderlyingAppSuccess = bool(v != 0) default: iNdEx = preIndex skippy, err := skipAck(dAtA[iNdEx:]) diff --git a/proto/ibc/applications/fee/v1/ack.proto b/proto/ibc/applications/fee/v1/ack.proto index b978454892d..1a0c5e3f404 100644 --- a/proto/ibc/applications/fee/v1/ack.proto +++ b/proto/ibc/applications/fee/v1/ack.proto @@ -11,4 +11,5 @@ import "gogoproto/gogo.proto"; message IncentivizedAcknowledgement { bytes result = 1; string forward_relayer_address = 2 [(gogoproto.moretags) = "yaml:\"forward_relayer_address\""]; + bool underlying_app_success = 3 [(gogoproto.moretags) = "yaml:\"underlying_app_successl\""]; }