From c197db2ab98f408844f85264441d6311968cda9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 7 Oct 2021 11:02:15 +0200 Subject: [PATCH] remove computeVirtualTxHash --- .../27-interchain-accounts/keeper/relay.go | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/modules/apps/27-interchain-accounts/keeper/relay.go b/modules/apps/27-interchain-accounts/keeper/relay.go index 964bfb5cd20..18e6d552eff 100644 --- a/modules/apps/27-interchain-accounts/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/keeper/relay.go @@ -1,11 +1,8 @@ package keeper import ( - "encoding/binary" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/tendermint/tendermint/crypto/tmhash" "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types" clienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types" @@ -15,16 +12,16 @@ import ( // TODO: implement middleware functionality, this will allow us to use capabilities to // manage helper module access to owner addresses they do not have capabilities for -func (k Keeper) TrySendTx(ctx sdk.Context, portID string, data interface{}, memo string) ([]byte, error) { +func (k Keeper) TrySendTx(ctx sdk.Context, portID string, data interface{}, memo string) (uint64, error) { // Check for the active channel activeChannelId, found := k.GetActiveChannel(ctx, portID) if !found { - return nil, types.ErrActiveChannelNotFound + return 0, types.ErrActiveChannelNotFound } sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, portID, activeChannelId) if !found { - return []byte{}, sdkerrors.Wrap(channeltypes.ErrChannelNotFound, activeChannelId) + return 0, sdkerrors.Wrap(channeltypes.ErrChannelNotFound, activeChannelId) } destinationPort := sourceChannelEnd.GetCounterparty().GetPortID() @@ -41,9 +38,9 @@ func (k Keeper) createOutgoingPacket( destinationChannel string, data interface{}, memo string, -) ([]byte, error) { +) (uint64, error) { if data == nil { - return []byte{}, types.ErrInvalidOutgoingData + return 0, types.ErrInvalidOutgoingData } var ( @@ -55,22 +52,22 @@ func (k Keeper) createOutgoingPacket( case []sdk.Msg: txBytes, err = k.SerializeCosmosTx(k.cdc, data) default: - return nil, sdkerrors.Wrapf(types.ErrInvalidOutgoingData, "message type %T is not supported", data) + return 0, sdkerrors.Wrapf(types.ErrInvalidOutgoingData, "message type %T is not supported", data) } if err != nil { - return nil, sdkerrors.Wrap(err, "serialization of transaction data failed") + return 0, sdkerrors.Wrap(err, "serialization of transaction data failed") } channelCap, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(sourcePort, sourceChannel)) if !ok { - return []byte{}, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + return 0, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") } // get the next sequence sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel) if !found { - return []byte{}, channeltypes.ErrSequenceSendNotFound + return 0, channeltypes.ErrSequenceSendNotFound } packetData := types.InterchainAccountPacketData{ @@ -94,7 +91,11 @@ func (k Keeper) createOutgoingPacket( timeoutTimestamp, ) - return k.ComputeVirtualTxHash(packetData.Data, packet.Sequence), k.channelKeeper.SendPacket(ctx, channelCap, packet) + if err := k.channelKeeper.SendPacket(ctx, channelCap, packet); err != nil { + return 0, err + } + + return packet.Sequence, nil } // DeserializeCosmosTx unmarshals and unpacks a slice of transaction bytes @@ -188,13 +189,6 @@ func (k Keeper) executeMsg(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { return handler(ctx, msg) } -// Compute the virtual tx hash that is used only internally. -func (k Keeper) ComputeVirtualTxHash(txBytes []byte, seq uint64) []byte { - bz := make([]byte, 8) - binary.LittleEndian.PutUint64(bz, seq) - return tmhash.SumTruncated(append(txBytes, bz...)) -} - func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) error { var data types.InterchainAccountPacketData @@ -224,12 +218,12 @@ func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Pac switch ack.Response.(type) { case *channeltypes.Acknowledgement_Error: if k.hook != nil { - k.hook.OnTxFailed(ctx, packet.SourcePort, packet.SourceChannel, k.ComputeVirtualTxHash(data.Data, packet.Sequence), data.Data) + k.hook.OnTxFailed(ctx, packet.SourcePort, packet.SourceChannel, packet.Data, data.Data) } return nil case *channeltypes.Acknowledgement_Result: if k.hook != nil { - k.hook.OnTxSucceeded(ctx, packet.SourcePort, packet.SourceChannel, k.ComputeVirtualTxHash(data.Data, packet.Sequence), data.Data) + k.hook.OnTxSucceeded(ctx, packet.SourcePort, packet.SourceChannel, packet.Data, data.Data) } return nil default: @@ -241,7 +235,7 @@ func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Pac func (k Keeper) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, data types.InterchainAccountPacketData) error { if k.hook != nil { - k.hook.OnTxFailed(ctx, packet.SourcePort, packet.SourceChannel, k.ComputeVirtualTxHash(data.Data, packet.Sequence), data.Data) + k.hook.OnTxFailed(ctx, packet.SourcePort, packet.SourceChannel, packet.Data, data.Data) } return nil