Skip to content

Commit

Permalink
chore: further renaming of packetdata to payload (#7485)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolas De Giorgis authored Oct 21, 2024
1 parent a29f2c8 commit 6078dda
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 115 deletions.
10 changes: 5 additions & 5 deletions modules/core/04-channel/v2/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (k *Keeper) Acknowledgement(ctx context.Context, msg *channeltypesv2.MsgAck
recvResults[r.AppName] = r.RecvPacketResult
}

for _, pd := range msg.Packet.Data {
for _, pd := range msg.Packet.Payloads {
cbs := k.Router.Route(pd.SourcePort)
err := cbs.OnAcknowledgementPacket(ctx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, pd, recvResults[pd.DestinationPort].Acknowledgement, relayer)
if err != nil {
Expand Down Expand Up @@ -116,7 +116,7 @@ func (k *Keeper) RecvPacket(ctx context.Context, msg *channeltypesv2.MsgRecvPack
AcknowledgementResults: []channeltypesv2.AcknowledgementResult{},
}

for _, pd := range msg.Packet.Data {
for _, pd := range msg.Packet.Payloads {
// Cache context so that we may discard state changes from callback if the acknowledgement is unsuccessful.
cacheCtx, writeFn = sdkCtx.CacheContext()
cb := k.Router.Route(pd.DestinationPort)
Expand All @@ -136,13 +136,13 @@ func (k *Keeper) RecvPacket(ctx context.Context, msg *channeltypesv2.MsgRecvPack
})
}

// note this should never happen as the packet data would have had to be empty.
// note this should never happen as the payload would have had to be empty.
if len(ack.AcknowledgementResults) == 0 {
sdkCtx.Logger().Error("receive packet failed", "source-channel", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "invalid acknowledgement results"))
return &channeltypesv2.MsgRecvPacketResponse{Result: channeltypesv1.FAILURE}, errorsmod.Wrapf(err, "receive packet failed source-channel %s invalid acknowledgement results", msg.Packet.SourceChannel)
}

// NOTE: TBD how we will handle async acknowledgements with more than one packet data.
// NOTE: TBD how we will handle async acknowledgements with more than one payload.
isAsync := slices.ContainsFunc(ack.AcknowledgementResults, func(ackResult channeltypesv2.AcknowledgementResult) bool {
return ackResult.RecvPacketResult.Status == channeltypesv2.PacketStatus_Async
})
Expand Down Expand Up @@ -190,7 +190,7 @@ func (k *Keeper) Timeout(ctx context.Context, timeout *channeltypesv2.MsgTimeout
return nil, errorsmod.Wrap(err, "timeout packet verification failed")
}

for _, pd := range timeout.Packet.Data {
for _, pd := range timeout.Packet.Payloads {
cbs := k.Router.Route(pd.SourcePort)
err := cbs.OnTimeoutPacket(ctx, timeout.Packet.SourceChannel, timeout.Packet.DestinationChannel, pd, signer)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions modules/core/04-channel/v2/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (k *Keeper) sendPacket(
// Lookup channel associated with our source channel to retrieve the destination channel
channel, ok := k.GetChannel(ctx, sourceChannel)
if !ok {
// TODO: figure out how aliasing will work when more than one packet data is sent.
// TODO: figure out how aliasing will work when more than one payload is sent.
channel, ok = k.convertV1Channel(ctx, payloads[0].SourcePort, sourceChannel)
if !ok {
return 0, "", errorsmod.Wrap(types.ErrChannelNotFound, sourceChannel)
Expand Down Expand Up @@ -107,8 +107,8 @@ func (k *Keeper) recvPacket(
// packet sender is our channel's counterparty channel id.
channel, ok := k.GetChannel(ctx, packet.DestinationChannel)
if !ok {
// TODO: figure out how aliasing will work when more than one packet data is sent.
channel, ok = k.convertV1Channel(ctx, packet.Data[0].DestinationPort, packet.DestinationChannel)
// TODO: figure out how aliasing will work when more than one payload is sent.
channel, ok = k.convertV1Channel(ctx, packet.Payloads[0].DestinationPort, packet.DestinationChannel)
if !ok {
return errorsmod.Wrap(types.ErrChannelNotFound, packet.DestinationChannel)
}
Expand Down Expand Up @@ -197,8 +197,8 @@ func (k Keeper) WriteAcknowledgement(

// TODO: Validate Acknowledgment more thoroughly here after Issue #7472: https://github.com/cosmos/ibc-go/issues/7472

if len(ack.AcknowledgementResults) != len(packet.Data) {
return errorsmod.Wrapf(types.ErrInvalidAcknowledgement, "length of acknowledgement results %d does not match length of packet data %d", len(ack.AcknowledgementResults), len(packet.Data))
if len(ack.AcknowledgementResults) != len(packet.Payloads) {
return errorsmod.Wrapf(types.ErrInvalidAcknowledgement, "length of acknowledgement results %d does not match length of payload %d", len(ack.AcknowledgementResults), len(packet.Payloads))
}

// set the acknowledgement so that it can be verified on the other side
Expand Down Expand Up @@ -288,8 +288,8 @@ func (k *Keeper) timeoutPacket(
// that the packet was indeed sent by our counterparty.
channel, ok := k.GetChannel(ctx, packet.SourceChannel)
if !ok {
// TODO: figure out how aliasing will work when more than one packet data is sent.
channel, ok = k.convertV1Channel(ctx, packet.Data[0].SourcePort, packet.SourceChannel)
// TODO: figure out how aliasing will work when more than one payload is sent.
channel, ok = k.convertV1Channel(ctx, packet.Payloads[0].SourcePort, packet.SourceChannel)
if !ok {
return errorsmod.Wrap(types.ErrChannelNotFound, packet.DestinationChannel)
}
Expand Down
46 changes: 23 additions & 23 deletions modules/core/04-channel/v2/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (suite *KeeperTestSuite) TestSendPacket() {
"success with later packet",
func() {
// send the same packet earlier so next packet send should be sequence 2
_, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel, packet.TimeoutTimestamp, packet.Data)
_, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel, packet.TimeoutTimestamp, packet.Payloads)
suite.Require().NoError(err)
expSequence = 2
},
Expand All @@ -54,7 +54,7 @@ func (suite *KeeperTestSuite) TestSendPacket() {
"packet failed basic validation",
func() {
// invalid data
packet.Data = nil
packet.Payloads = nil
},
channeltypes.ErrInvalidPacket,
},
Expand Down Expand Up @@ -97,20 +97,20 @@ func (suite *KeeperTestSuite) TestSendPacket() {
path = ibctesting.NewPath(suite.chainA, suite.chainB)
path.SetupV2()

packetData := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)
payload := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)

timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Add(time.Hour).Unix())

// create standard packet that can be malleated
packet = types.NewPacket(1, path.EndpointA.ChannelID, path.EndpointB.ChannelID,
timeoutTimestamp, packetData)
timeoutTimestamp, payload)
expSequence = 1

// malleate the test case
tc.malleate()

// send packet
seq, destChannel, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel, packet.TimeoutTimestamp, packet.Data)
seq, destChannel, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel, packet.TimeoutTimestamp, packet.Payloads)

expPass := tc.expError == nil
if expPass {
Expand Down Expand Up @@ -204,12 +204,12 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
path = ibctesting.NewPath(suite.chainA, suite.chainB)
path.SetupV2()

packetData := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)
payload := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)

timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Add(time.Hour).Unix())

// send packet
packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, packetData)
packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, payload)
suite.Require().NoError(err)

tc.malleate()
Expand Down Expand Up @@ -298,13 +298,13 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() {
path := ibctesting.NewPath(suite.chainA, suite.chainB)
path.SetupV2()

packetData := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)
payload := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)

timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Add(time.Hour).Unix())

// create standard packet that can be malleated
packet = types.NewPacket(1, path.EndpointA.ChannelID, path.EndpointB.ChannelID,
timeoutTimestamp, packetData)
timeoutTimestamp, payload)

// create standard ack that can be malleated
ack = types.Acknowledgement{
Expand Down Expand Up @@ -390,8 +390,8 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
{
"failure: packet commitment bytes differ",
func() {
// change packet data after send to acknowledge different packet
packet.Data[0].Value = []byte("different value")
// change payload after send to acknowledge different packet
packet.Payloads[0].Value = []byte("different value")
},
channeltypes.ErrInvalidPacket,
},
Expand All @@ -414,12 +414,12 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {

freezeClient = false

packetData := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)
payload := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)

timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Add(time.Hour).Unix())

// send packet
packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, packetData)
packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, payload)
suite.Require().NoError(err)

err = path.EndpointB.MsgRecvPacket(packet)
Expand Down Expand Up @@ -467,7 +467,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
func() {
// send packet
_, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel,
packet.TimeoutTimestamp, packet.Data)
packet.TimeoutTimestamp, packet.Payloads)
suite.Require().NoError(err, "send packet failed")
},
nil,
Expand All @@ -477,7 +477,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
func() {
// send packet
_, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel,
packet.TimeoutTimestamp, packet.Data)
packet.TimeoutTimestamp, packet.Payloads)
suite.Require().NoError(err, "send packet failed")

packet.SourceChannel = ibctesting.InvalidID
Expand All @@ -489,7 +489,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
func() {
// send packet
_, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel,
packet.TimeoutTimestamp, packet.Data)
packet.TimeoutTimestamp, packet.Payloads)
suite.Require().NoError(err, "send packet failed")

packet.DestinationChannel = unusedChannel
Expand All @@ -503,7 +503,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {

// send packet
_, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel,
packet.TimeoutTimestamp, packet.Data)
packet.TimeoutTimestamp, packet.Payloads)
suite.Require().NoError(err, "send packet failed")
},
channeltypes.ErrTimeoutNotReached,
Expand All @@ -517,11 +517,11 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
"failure: packet does not match commitment",
func() {
_, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel,
packet.TimeoutTimestamp, packet.Data)
packet.TimeoutTimestamp, packet.Payloads)
suite.Require().NoError(err, "send packet failed")

// try to timeout packet with different data
packet.Data[0].Value = []byte("different value")
packet.Payloads[0].Value = []byte("different value")
},
channeltypes.ErrInvalidPacket,
},
Expand All @@ -530,7 +530,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
func() {
// send packet
_, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel,
packet.TimeoutTimestamp, packet.Data)
packet.TimeoutTimestamp, packet.Payloads)
suite.Require().NoError(err, "send packet failed")

freezeClient = true
Expand All @@ -542,7 +542,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
func() {
// send packet
_, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel,
packet.TimeoutTimestamp, packet.Data)
packet.TimeoutTimestamp, packet.Payloads)
suite.Require().NoError(err, "send packet failed")

// set packet receipt to mock a valid past receive
Expand All @@ -564,13 +564,13 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
path.SetupV2()

// create default packet with a timed out timestamp
packetData := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)
payload := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)

timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Unix())

// test cases may mutate timeout values
packet = types.NewPacket(1, path.EndpointA.ChannelID, path.EndpointB.ChannelID,
timeoutTimestamp, packetData)
timeoutTimestamp, payload)

tc.malleate()

Expand Down
8 changes: 4 additions & 4 deletions modules/core/04-channel/v2/types/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// CommitPacket returns the V2 packet commitment bytes. The commitment consists of:
// sha256_hash(timeout) + sha256_hash(destinationChannel) + sha256_hash(packetData) from a given packet.
// sha256_hash(timeout) + sha256_hash(destinationChannel) + sha256_hash(payload) from a given packet.
// This results in a fixed length preimage.
// NOTE: A fixed length preimage is ESSENTIAL to prevent relayers from being able
// to malleate the packet fields and create a commitment hash that matches the original packet.
Expand All @@ -17,15 +17,15 @@ func CommitPacket(packet Packet) []byte {
destIDHash := sha256.Sum256([]byte(packet.DestinationChannel))
buf = append(buf, destIDHash[:]...)

for _, data := range packet.Data {
buf = append(buf, hashPayload(data)...)
for _, payload := range packet.Payloads {
buf = append(buf, hashPayload(payload)...)
}

hash := sha256.Sum256(buf)
return hash[:]
}

// hashPayload returns the hash of the packet data.
// hashPayload returns the hash of the payload.
func hashPayload(data Payload) []byte {
var buf []byte
sourceHash := sha256.Sum256([]byte(data.SourcePort))
Expand Down
4 changes: 2 additions & 2 deletions modules/core/04-channel/v2/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (s *TypesTestSuite) TestMsgSendPacketValidateBasic() {
expError: types.ErrInvalidPayload,
},
{
name: "failure: invalid packetdata",
name: "failure: invalid payload",
malleate: func() {
msg.Payloads[0].DestinationPort = ""
},
Expand Down Expand Up @@ -230,7 +230,7 @@ func (s *TypesTestSuite) TestMsgRecvPacketValidateBasic() {
{
name: "failure: invalid packet",
malleate: func() {
msg.Packet.Data = []types.Payload{}
msg.Packet.Payloads = []types.Payload{}
},
expError: types.ErrInvalidPacket,
},
Expand Down
14 changes: 7 additions & 7 deletions modules/core/04-channel/v2/types/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
)

// NewPacket constructs a new packet.
func NewPacket(sequence uint64, sourceChannel, destinationChannel string, timeoutTimestamp uint64, data ...Payload) Packet {
func NewPacket(sequence uint64, sourceChannel, destinationChannel string, timeoutTimestamp uint64, payloads ...Payload) Packet {
return Packet{
Sequence: sequence,
SourceChannel: sourceChannel,
DestinationChannel: destinationChannel,
TimeoutTimestamp: timeoutTimestamp,
Data: data,
Payloads: payloads,
}
}

// NewPayload constructs a new PacketData
// NewPayload constructs a new Payload
func NewPayload(sourcePort, destPort, version, encoding string, value []byte) Payload {
return Payload{
SourcePort: sourcePort,
Expand All @@ -32,13 +32,13 @@ func NewPayload(sourcePort, destPort, version, encoding string, value []byte) Pa

// ValidateBasic validates that a Packet satisfies the basic requirements.
func (p Packet) ValidateBasic() error {
if len(p.Data) == 0 {
return errorsmod.Wrap(ErrInvalidPacket, "packet data must not be empty")
if len(p.Payloads) == 0 {
return errorsmod.Wrap(ErrInvalidPacket, "payloads must not be empty")
}

for _, pd := range p.Data {
for _, pd := range p.Payloads {
if err := pd.ValidateBasic(); err != nil {
return errorsmod.Wrap(err, "invalid Packet Data")
return errorsmod.Wrap(err, "invalid Payload")
}
}

Expand Down
Loading

0 comments on commit 6078dda

Please sign in to comment.