Skip to content

Commit

Permalink
revert transfer test
Browse files Browse the repository at this point in the history
  • Loading branch information
bznein committed Sep 19, 2024
1 parent a004929 commit 63a82c7
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 184 deletions.
4 changes: 3 additions & 1 deletion modules/apps/transfer/ibc_module_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ func (im *IBCModuleV2) OnSendPacketV2(
// fail the unmarshaling above, where if ics20version == types.V1 we first unmarshal
// into a V1 packet and then convert.

if data.Sender != signer.String() {
if data.Sender != string(signer) {
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "invalid signer address: expected %s, got %s", data.Sender, signer)
}

return im.keeper.OnSendPacket(ctx, sourceID, data, signer)

// TODO: port
}

// OnRecvPacketV2 implements the IBCModuleV2 interface. A successful acknowledgement
Expand Down
5 changes: 5 additions & 0 deletions modules/apps/transfer/keeper/relay_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ func (k Keeper) OnSendPacket(
packetData types.FungibleTokenPacketDataV2,
sender sdk.AccAddress,
) error {
//_, ok := k.packetServerKeeper.GetCounterparty(ctx, sourceID)

Check failure on line 179 in modules/apps/transfer/keeper/relay_v2.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 179 in modules/apps/transfer/keeper/relay_v2.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
//if !ok {

Check failure on line 180 in modules/apps/transfer/keeper/relay_v2.go

View workflow job for this annotation

GitHub Actions / lint

comment-spacings: no space between comment delimiter and comment text (revive)

Check failure on line 180 in modules/apps/transfer/keeper/relay_v2.go

View workflow job for this annotation

GitHub Actions / lint

comment-spacings: no space between comment delimiter and comment text (revive)
// return errorsmod.Wrap(packetservertypes.ErrCounterpartyNotFound, sourceID)
//}

Check failure on line 182 in modules/apps/transfer/keeper/relay_v2.go

View workflow job for this annotation

GitHub Actions / lint

comment-spacings: no space between comment delimiter and comment text (revive)

Check failure on line 182 in modules/apps/transfer/keeper/relay_v2.go

View workflow job for this annotation

GitHub Actions / lint

comment-spacings: no space between comment delimiter and comment text (revive)

var coins sdk.Coins
for _, token := range packetData.Tokens {
transferAmount, ok := sdkmath.NewIntFromString(token.Amount)
Expand Down
146 changes: 0 additions & 146 deletions modules/apps/transfer/transfer_v2_test.go

This file was deleted.

1 change: 0 additions & 1 deletion modules/core/04-channel/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,5 @@ func (k *Keeper) GetV2Counterparty(ctx context.Context, portID, channelID string
ClientId: connection.ClientId,
MerklePathPrefix: merklePathPrefix,
}

return counterparty, true
}
9 changes: 1 addition & 8 deletions modules/core/keeper/msg_server_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ func (k *Keeper) SendPacketV2(ctx context.Context, msg *channeltypesv2.MsgSendPa

for _, pd := range msg.PacketData {
cbs := k.PortKeeper.AppRouter.Route(pd.SourcePort)

// TODO: is it safe to assume an sdk.AccAddress?
signer, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
}

err = cbs.OnSendPacketV2(ctx, msg.SourceId, sequence, msg.TimeoutTimestamp, pd.Payload, signer)
err := cbs.OnSendPacketV2(ctx, msg.SourceId, sequence, msg.TimeoutTimestamp, pd.Payload, sdk.AccAddress(msg.Signer))
if err != nil {
return nil, err
}
Expand Down
8 changes: 1 addition & 7 deletions modules/core/packet-server/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,7 @@ func (k *Keeper) GetCounterpartyV2(ctx context.Context, portID, channelID, clien
store := k.ChannelStore(ctx, clientID)
bz := store.Get([]byte(types.CounterpartyKey))
if len(bz) == 0 {
cp, ok := k.ChannelKeeper.GetV2Counterparty(ctx, portID, clientID)
if !ok {
return types.Counterparty{}, false
}
k.SetCounterparty(ctx, channelID, cp)
//k.SetCounterparty(ctx, clientID, cp)
return cp, true
return k.ChannelKeeper.GetV2Counterparty(ctx, portID, channelID)
}

var counterparty types.Counterparty
Expand Down
38 changes: 17 additions & 21 deletions modules/core/packet-server/keeper/relay_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (k Keeper) SendPacketV2(
}

// construct packet from given fields and channel state
packet := channeltypesv2.NewPacketV2(sequence, sourceID, "channel-1", timeoutTimestamp, data...)
packet := channeltypesv2.NewPacketV2(sequence, sourceID, counterparty.ClientId, timeoutTimestamp, data...)

if err := packet.ValidateBasic(); err != nil {
return 0, errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "constructed packet failed basic validation: %v", err)
Expand Down Expand Up @@ -82,13 +82,13 @@ func (k Keeper) RecvPacketV2(
) error {
// Lookup counterparty associated with our channel and ensure
// that the packet was indeed sent by our counterparty.
counterparty, ok := k.GetCounterpartyV2(ctx, packet.Data[0].DestinationPort, "channel-1", packet.DestinationId)
counterparty, ok := k.GetCounterparty(ctx, packet.DestinationId)
if !ok {
return errorsmod.Wrap(types.ErrCounterpartyNotFound, packet.DestinationId)
}
//if counterparty.ClientId != packet.SourceId {
// return channeltypes.ErrInvalidChannelIdentifier
//}
if counterparty.ClientId != packet.SourceId {
return channeltypes.ErrInvalidChannelIdentifier
}

sdkCtx := sdk.UnwrapSDKContext(ctx)
// check if packet timed out by comparing it with the latest height of the chain
Expand All @@ -101,8 +101,7 @@ func (k Keeper) RecvPacketV2(
// REPLAY PROTECTION: Packet receipts will indicate that a packet has already been received
// on unordered channels. Packet receipts must not be pruned, unless it has been marked stale
// by the increase of the recvStartSequence.
//_, found := k.ChannelKeeper.GetPacketReceipt(ctx, host.SentinelV2PortID, packet.DestinationId, packet.Sequence)
_, found := k.ChannelKeeper.GetPacketReceipt(ctx, packet.Data[0].DestinationPort, packet.DestinationId, packet.Sequence)
_, found := k.ChannelKeeper.GetPacketReceipt(ctx, host.SentinelV2PortID, packet.DestinationId, packet.Sequence)
if found {
// TODO: figure out events
// channelkeeper.EmitRecvPacketEventV2(ctx, packet, sentinelChannel(packet.DestinationChannel))
Expand All @@ -112,22 +111,21 @@ func (k Keeper) RecvPacketV2(
return channeltypes.ErrNoOpMsg
}

path := host.PacketCommitmentKey(host.SentinelV2PortID, counterparty.ClientId, packet.Sequence)
//path := host.PacketCommitmentKey(packet.Data[0].SourcePort, packet.SourceId, packet.Sequence)
path := host.PacketCommitmentKey(host.SentinelV2PortID, packet.SourceId, packet.Sequence)
merklePath := types.BuildMerklePath(counterparty.MerklePathPrefix, path)

commitment := channeltypes.CommitPacketV2(packet)

if err := k.ClientKeeper.VerifyMembership(
ctx,
counterparty.ClientId,
packet.DestinationId,
proofHeight,
0, 0,
proof,
merklePath,
commitment,
); err != nil {
return errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", counterparty.ClientId)
return errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", packet.DestinationId)
}

// Set Packet Receipt to prevent timeout from occurring on counterparty
Expand All @@ -152,16 +150,14 @@ func (k Keeper) WriteAcknowledgementV2(
// TODO: this should probably error out if any of the acks are async.
// Lookup counterparty associated with our channel and ensure
// that the packet was indeed sent by our counterparty.
//counterparty, ok := k.GetCounterparty(ctx, packet.DestinationId)
//if !ok {
// return errorsmod.Wrap(types.ErrCounterpartyNotFound, packet.DestinationId)
//}

// TODO: how can we make this work if packet.SourceID is a channelID and counterparty has been stored
// under the key of a channelID?
//if counterparty.ClientId != packet.SourceId {
// return channeltypes.ErrInvalidChannelIdentifier
//}
counterparty, ok := k.GetCounterparty(ctx, packet.DestinationId)
if !ok {
return errorsmod.Wrap(types.ErrCounterpartyNotFound, packet.DestinationId)
}

if counterparty.ClientId != packet.SourceId {
return channeltypes.ErrInvalidChannelIdentifier
}

// NOTE: IBC app modules might have written the acknowledgement synchronously on
// the OnRecvPacket callback so we need to check if the acknowledgement is already
Expand Down

0 comments on commit 63a82c7

Please sign in to comment.