Skip to content

Commit 7e02a96

Browse files
Rename Id Fields to Channel for Packet V2 (#7428)
* change id fields to channel * Apply suggestions from code review Co-authored-by: Damian Nolan <damiannolan@gmail.com> --------- Co-authored-by: Damian Nolan <damiannolan@gmail.com>
1 parent b509c50 commit 7e02a96

File tree

8 files changed

+162
-162
lines changed

8 files changed

+162
-162
lines changed

modules/core/04-channel/v2/keeper/msg_server.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ var _ channeltypesv2.MsgServer = &Keeper{}
1616
// SendPacket implements the PacketMsgServer SendPacket method.
1717
func (k *Keeper) SendPacket(ctx context.Context, msg *channeltypesv2.MsgSendPacket) (*channeltypesv2.MsgSendPacketResponse, error) {
1818
sdkCtx := sdk.UnwrapSDKContext(ctx)
19-
sequence, err := k.sendPacket(ctx, msg.SourceId, msg.TimeoutTimestamp, msg.PacketData)
19+
sequence, err := k.sendPacket(ctx, msg.SourceChannel, msg.TimeoutTimestamp, msg.PacketData)
2020
if err != nil {
21-
sdkCtx.Logger().Error("send packet failed", "source-id", msg.SourceId, "error", errorsmod.Wrap(err, "send packet failed"))
22-
return nil, errorsmod.Wrapf(err, "send packet failed for source id: %s", msg.SourceId)
21+
sdkCtx.Logger().Error("send packet failed", "source-id", msg.SourceChannel, "error", errorsmod.Wrap(err, "send packet failed"))
22+
return nil, errorsmod.Wrapf(err, "send packet failed for source id: %s", msg.SourceChannel)
2323
}
2424

2525
signer, err := sdk.AccAddressFromBech32(msg.Signer)
@@ -34,7 +34,7 @@ func (k *Keeper) SendPacket(ctx context.Context, msg *channeltypesv2.MsgSendPack
3434
// https://github.com/cosmos/ibc-go/issues/7384
3535
// for _, pd := range msg.PacketData {
3636
// cbs := k.PortKeeper.AppRouter.Route(pd.SourcePort)
37-
// err := cbs.OnSendPacket(ctx, msg.SourceId, sequence, msg.TimeoutTimestamp, pd, signer)
37+
// err := cbs.OnSendPacket(ctx, msg.SourceChannel, sequence, msg.TimeoutTimestamp, pd, signer)
3838
// if err != nil {
3939
// return nil, err
4040
// }
@@ -52,8 +52,8 @@ func (k *Keeper) RecvPacket(ctx context.Context, msg *channeltypesv2.MsgRecvPack
5252
sdkCtx := sdk.UnwrapSDKContext(ctx)
5353
err := k.recvPacket(ctx, msg.Packet, msg.ProofCommitment, msg.ProofHeight)
5454
if err != nil {
55-
sdkCtx.Logger().Error("receive packet failed", "source-id", msg.Packet.SourceId, "dest-id", msg.Packet.DestinationId, "error", errorsmod.Wrap(err, "send packet failed"))
56-
return nil, errorsmod.Wrapf(err, "receive packet failed for source id: %s and destination id: %s", msg.Packet.SourceId, msg.Packet.DestinationId)
55+
sdkCtx.Logger().Error("receive packet failed", "source-id", msg.Packet.SourceChannel, "dest-id", msg.Packet.DestinationChannel, "error", errorsmod.Wrap(err, "send packet failed"))
56+
return nil, errorsmod.Wrapf(err, "receive packet failed for source id: %s and destination id: %s", msg.Packet.SourceChannel, msg.Packet.DestinationChannel)
5757
}
5858

5959
signer, err := sdk.AccAddressFromBech32(msg.Signer)
@@ -81,8 +81,8 @@ func (k *Keeper) RecvPacket(ctx context.Context, msg *channeltypesv2.MsgRecvPack
8181
func (k *Keeper) Timeout(ctx context.Context, timeout *channeltypesv2.MsgTimeout) (*channeltypesv2.MsgTimeoutResponse, error) {
8282
sdkCtx := sdk.UnwrapSDKContext(ctx)
8383
if err := k.timeoutPacket(ctx, timeout.Packet, timeout.ProofUnreceived, timeout.ProofHeight); err != nil {
84-
sdkCtx.Logger().Error("Timeout packet failed", "source-id", timeout.Packet.SourceId, "destination-id", timeout.Packet.DestinationId, "error", errorsmod.Wrap(err, "timeout packet failed"))
85-
return nil, errorsmod.Wrapf(err, "send packet failed for source id: %s and destination id: %s", timeout.Packet.SourceId, timeout.Packet.DestinationId)
84+
sdkCtx.Logger().Error("Timeout packet failed", "source-id", timeout.Packet.SourceChannel, "destination-id", timeout.Packet.DestinationChannel, "error", errorsmod.Wrap(err, "timeout packet failed"))
85+
return nil, errorsmod.Wrapf(err, "send packet failed for source id: %s and destination id: %s", timeout.Packet.SourceChannel, timeout.Packet.DestinationChannel)
8686
}
8787

8888
signer, err := sdk.AccAddressFromBech32(timeout.Signer)
@@ -97,7 +97,7 @@ func (k *Keeper) Timeout(ctx context.Context, timeout *channeltypesv2.MsgTimeout
9797
// https://github.com/cosmos/ibc-go/issues/7384
9898
// for _, pd := range timeout.Packet.Data {
9999
// cbs := k.PortKeeper.AppRouter.Route(pd.SourcePort)
100-
// err := cbs.OnTimeoutPacket(timeout.Packet.SourceId, timeout.Packet.TimeoutTimestamp, signer)
100+
// err := cbs.OnTimeoutPacket(timeout.Packet.SourceChannel, timeout.Packet.TimeoutTimestamp, signer)
101101
// if err != nil {
102102
// return err, err
103103
// }

modules/core/04-channel/v2/keeper/relay.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (k *Keeper) sendPacket(
9191
k.SetNextSequenceSend(ctx, sourceID, sequence+1)
9292
k.SetPacketCommitment(ctx, sourceID, packet.GetSequence(), commitment)
9393

94-
k.Logger(ctx).Info("packet sent", "sequence", strconv.FormatUint(packet.Sequence, 10), "dest_id", packet.DestinationId, "src_id", packet.SourceId)
94+
k.Logger(ctx).Info("packet sent", "sequence", strconv.FormatUint(packet.Sequence, 10), "dest_channel_id", packet.DestinationChannel, "src_channel_id", packet.SourceChannel)
9595

9696
EmitSendPacketEvents(ctx, packet)
9797

@@ -114,15 +114,15 @@ func (k Keeper) recvPacket(
114114
) error {
115115
// Lookup counterparty associated with our channel and ensure
116116
// that the packet was indeed sent by our counterparty.
117-
counterparty, ok := k.GetCounterparty(ctx, packet.DestinationId)
117+
counterparty, ok := k.GetCounterparty(ctx, packet.DestinationChannel)
118118
if !ok {
119119
// TODO: figure out how aliasing will work when more than one packet data is sent.
120-
counterparty, ok = k.getV1Counterparty(ctx, packet.Data[0].DestinationPort, packet.DestinationId)
120+
counterparty, ok = k.getV1Counterparty(ctx, packet.Data[0].DestinationPort, packet.DestinationChannel)
121121
if !ok {
122-
return errorsmod.Wrap(types.ErrCounterpartyNotFound, packet.DestinationId)
122+
return errorsmod.Wrap(types.ErrCounterpartyNotFound, packet.DestinationChannel)
123123
}
124124
}
125-
if counterparty.ClientId != packet.SourceId {
125+
if counterparty.ClientId != packet.SourceChannel {
126126
return channeltypes.ErrInvalidChannelIdentifier
127127
}
128128

@@ -137,7 +137,7 @@ func (k Keeper) recvPacket(
137137
// REPLAY PROTECTION: Packet receipts will indicate that a packet has already been received
138138
// on unordered channels. Packet receipts must not be pruned, unless it has been marked stale
139139
// by the increase of the recvStartSequence.
140-
_, found := k.GetPacketReceipt(ctx, packet.DestinationId, packet.Sequence)
140+
_, found := k.GetPacketReceipt(ctx, packet.DestinationChannel, packet.Sequence)
141141
if found {
142142
EmitRecvPacketEvents(ctx, packet)
143143
// This error indicates that the packet has already been relayed. Core IBC will
@@ -146,27 +146,27 @@ func (k Keeper) recvPacket(
146146
return channeltypes.ErrNoOpMsg
147147
}
148148

149-
path := hostv2.PacketCommitmentKey(packet.SourceId, packet.Sequence)
149+
path := hostv2.PacketCommitmentKey(packet.SourceChannel, packet.Sequence)
150150
merklePath := types.BuildMerklePath(counterparty.MerklePathPrefix, path)
151151

152152
commitment := channeltypesv2.CommitPacket(packet)
153153

154154
if err := k.ClientKeeper.VerifyMembership(
155155
ctx,
156-
packet.DestinationId,
156+
packet.DestinationChannel,
157157
proofHeight,
158158
0, 0,
159159
proof,
160160
merklePath,
161161
commitment,
162162
); err != nil {
163-
return errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", packet.DestinationId)
163+
return errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", packet.DestinationChannel)
164164
}
165165

166166
// Set Packet Receipt to prevent timeout from occurring on counterparty
167-
k.SetPacketReceipt(ctx, packet.DestinationId, packet.Sequence)
167+
k.SetPacketReceipt(ctx, packet.DestinationChannel, packet.Sequence)
168168

169-
k.Logger(ctx).Info("packet received", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_id", packet.SourceId, "dst_id", packet.DestinationId)
169+
k.Logger(ctx).Info("packet received", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_id", packet.SourceChannel, "dst_id", packet.DestinationChannel)
170170

171171
EmitRecvPacketEvents(ctx, packet)
172172

@@ -188,17 +188,17 @@ func (k Keeper) timeoutPacket(
188188
) error {
189189
// Lookup counterparty associated with our channel and ensure
190190
// that the packet was indeed sent by our counterparty.
191-
counterparty, ok := k.GetCounterparty(ctx, packet.SourceId)
191+
counterparty, ok := k.GetCounterparty(ctx, packet.SourceChannel)
192192
if !ok {
193193
// TODO: figure out how aliasing will work when more than one packet data is sent.
194-
counterparty, ok = k.getV1Counterparty(ctx, packet.Data[0].SourcePort, packet.SourceId)
194+
counterparty, ok = k.getV1Counterparty(ctx, packet.Data[0].SourcePort, packet.SourceChannel)
195195
if !ok {
196-
return errorsmod.Wrap(types.ErrCounterpartyNotFound, packet.DestinationId)
196+
return errorsmod.Wrap(types.ErrCounterpartyNotFound, packet.DestinationChannel)
197197
}
198198
}
199199

200200
// check that timeout height or timeout timestamp has passed on the other end
201-
proofTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, packet.SourceId, proofHeight)
201+
proofTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, packet.SourceChannel, proofHeight)
202202
if err != nil {
203203
return err
204204
}
@@ -209,7 +209,7 @@ func (k Keeper) timeoutPacket(
209209
}
210210

211211
// check that the commitment has not been cleared and that it matches the packet sent by relayer
212-
commitment, ok := k.GetPacketCommitment(ctx, packet.SourceId, packet.Sequence)
212+
commitment, ok := k.GetPacketCommitment(ctx, packet.SourceChannel, packet.Sequence)
213213

214214
if !ok {
215215
EmitTimeoutPacketEvents(ctx, packet)
@@ -227,24 +227,24 @@ func (k Keeper) timeoutPacket(
227227
}
228228

229229
// verify packet receipt absence
230-
path := hostv2.PacketReceiptKey(packet.SourceId, packet.Sequence)
230+
path := hostv2.PacketReceiptKey(packet.SourceChannel, packet.Sequence)
231231
merklePath := types.BuildMerklePath(counterparty.MerklePathPrefix, path)
232232

233233
if err := k.ClientKeeper.VerifyNonMembership(
234234
ctx,
235-
packet.SourceId,
235+
packet.SourceChannel,
236236
proofHeight,
237237
0, 0,
238238
proof,
239239
merklePath,
240240
); err != nil {
241-
return errorsmod.Wrapf(err, "failed packet receipt absence verification for client (%s)", packet.SourceId)
241+
return errorsmod.Wrapf(err, "failed packet receipt absence verification for client (%s)", packet.SourceChannel)
242242
}
243243

244244
// delete packet commitment to prevent replay
245-
k.DeletePacketCommitment(ctx, packet.SourceId, packet.Sequence)
245+
k.DeletePacketCommitment(ctx, packet.SourceChannel, packet.Sequence)
246246

247-
k.Logger(ctx).Info("packet timed out", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_id", packet.SourceId, "dst_id", packet.DestinationId)
247+
k.Logger(ctx).Info("packet timed out", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_channel_id", packet.SourceChannel, "dst_channel_id", packet.DestinationChannel)
248248

249249
EmitTimeoutPacketEvents(ctx, packet)
250250

0 commit comments

Comments
 (0)