Skip to content

Commit

Permalink
chore: added AcknowledgementV2 and WriteAsyncV2 functions
Browse files Browse the repository at this point in the history
  • Loading branch information
chatton committed Sep 18, 2024
1 parent 877fd5b commit 833cbcd
Show file tree
Hide file tree
Showing 15 changed files with 257 additions and 92 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
github.com/spf13/cast v1.7.0
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094
google.golang.org/grpc v1.66.2
google.golang.org/protobuf v1.34.2
Expand Down Expand Up @@ -179,7 +180,6 @@ require (
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.8.0 // indirect
Expand Down
1 change: 0 additions & 1 deletion modules/apps/callbacks/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ require (
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.2.0 // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.1 // indirect
github.com/cosmos/ics23/go v0.11.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/creachadair/atomicfile v0.3.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions modules/apps/callbacks/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,6 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fr
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
github.com/cosmos/iavl v1.2.0 h1:kVxTmjTh4k0Dh1VNL046v6BXqKziqMDzxo93oh3kOfM=
github.com/cosmos/iavl v1.2.0/go.mod h1:HidWWLVAtODJqFD6Hbne2Y0q3SdxByJepHUOeoH4LiI=
github.com/cosmos/ibc-go/modules/capability v1.0.1 h1:ibwhrpJ3SftEEZRxCRkH0fQZ9svjthrX2+oXdZvzgGI=
github.com/cosmos/ibc-go/modules/capability v1.0.1/go.mod h1:rquyOV262nGJplkumH+/LeYs04P3eV8oB7ZM4Ygqk4E=
github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU=
github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0=
github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM=
Expand Down
144 changes: 73 additions & 71 deletions modules/core/04-channel/v2/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 53 additions & 3 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import (
"context"
"errors"
"fmt"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"


"golang.org/x/exp/slices"

errorsmod "cosmossdk.io/errors"
channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"

sdk "github.com/cosmos/cosmos-sdk/types"

clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/keeper"
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors"
"github.com/cosmos/ibc-go/v9/modules/core/internal/telemetry"
"github.com/cosmos/ibc-go/v9/modules/core/legacy"
Expand Down Expand Up @@ -1177,7 +1179,55 @@ func (k *Keeper) TimeoutV2(ctx context.Context, msg *channeltypesv2.MsgTimeout)
}

func (k *Keeper) AcknowledgementV2(ctx context.Context, msg *channeltypesv2.MsgAcknowledgement) (*channeltypesv2.MsgAcknowledgementResponse, error) {
return nil, nil
sdkCtx := sdk.UnwrapSDKContext(ctx)

relayer, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
sdkCtx.Logger().Error("acknowledgement failed", "error", errorsmod.Wrap(err, "Invalid address for msg Signer"))
return nil, errorsmod.Wrap(err, "Invalid address for msg Signer")
}

// Perform TAO verification
//
// If the acknowledgement was already received, perform a no-op
// Use a cached context to prevent accidental state changes
cacheCtx, writeFn := sdkCtx.CacheContext()
err = k.PacketServerKeeper.AcknowledgePacketV2(cacheCtx, msg.Packet, msg.MultiAcknowledgement, msg.ProofAcked, msg.ProofHeight)

switch err {
case nil:
writeFn()
case channeltypes.ErrNoOpMsg:
// no-ops do not need event emission as they will be ignored
sdkCtx.Logger().Debug("no-op on redundant relay", "source-id", msg.Packet.SourceId)
return &channeltypesv2.MsgAcknowledgementResponse{Result: channeltypes.NOOP}, nil
default:
sdkCtx.Logger().Error("acknowledgement failed", "source-id", msg.Packet.SourceId, "error", errorsmod.Wrap(err, "acknowledge packet verification failed"))
return nil, errorsmod.Wrap(err, "acknowledge packet verification failed")
}

// construct mapping of app name to recvPacketResult
// TODO: helper fn to do this.
recvResults := make(map[string]channeltypes.RecvPacketResult)
for _, r := range msg.MultiAcknowledgement.AcknowledgementResults {
recvResults[r.AppName] = r.RecvPacketResult
}

// Perform application logic callback
for _, pd := range msg.Packet.Data {
cb := k.PortKeeper.AppRouter.Route(pd.SourcePort)
err = cb.OnAcknowledgementPacketV2(ctx, msg.Packet, pd.Payload, recvResults[pd.DestinationPort], relayer)
if err != nil {
sdkCtx.Logger().Error("acknowledgement failed", "src_id", msg.Packet.SourceId, "src_port", pd.SourcePort, "dst_port", pd.DestinationPort, "error", errorsmod.Wrap(err, "acknowledge packet callback failed"))
return nil, errorsmod.Wrap(err, "acknowledge packet callback failed")
}
}

// defer telemetry.ReportAcknowledgePacket(msg.PacketV2)

sdkCtx.Logger().Info("acknowledgement succeeded", "src_id", msg.Packet.SourceId, "result", channeltypes.SUCCESS.String())

return &channeltypesv2.MsgAcknowledgementResponse{Result: channeltypes.SUCCESS}, nil
}

// convertToErrorEvents converts all events to error events by appending the
Expand Down
1 change: 1 addition & 0 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"

upgradetypes "cosmossdk.io/x/upgrade/types"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down
Loading

0 comments on commit 833cbcd

Please sign in to comment.