Skip to content

Commit

Permalink
chore: rename PacketData to Payload (#7483)
Browse files Browse the repository at this point in the history
* chore: rename PacketData to Payload

* Update modules/core/04-channel/v2/types/msgs.go

Co-authored-by: Cian Hatton <[email protected]>

* Update proto/ibc/core/channel/v2/tx.proto

Co-authored-by: Cian Hatton <[email protected]>

* Update modules/core/04-channel/v2/keeper/packet.go

Co-authored-by: Cian Hatton <[email protected]>

* Update modules/core/04-channel/v2/keeper/msg_server_test.go

Co-authored-by: Cian Hatton <[email protected]>

* Update modules/core/04-channel/v2/keeper/export_test.go

Co-authored-by: Cian Hatton <[email protected]>

* fixes after renaming - PR feedback

---------

Co-authored-by: Cian Hatton <[email protected]>
  • Loading branch information
Nikolas De Giorgis and chatton authored Oct 21, 2024
1 parent e77a0f4 commit aeb9980
Show file tree
Hide file tree
Showing 20 changed files with 273 additions and 493 deletions.
4 changes: 2 additions & 2 deletions modules/core/04-channel/v2/keeper/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ func (k *Keeper) SendPacketTest(
ctx context.Context,
sourceChannel string,
timeoutTimestamp uint64,
data []channeltypesv2.PacketData,
payloads []channeltypesv2.Payload,
) (uint64, string, error) {
return k.sendPacket(
ctx,
sourceChannel,
timeoutTimestamp,
data,
payloads,
)
}

Expand Down
4 changes: 2 additions & 2 deletions modules/core/04-channel/v2/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var _ channeltypesv2.MsgServer = &Keeper{}
// SendPacket implements the PacketMsgServer SendPacket method.
func (k *Keeper) SendPacket(ctx context.Context, msg *channeltypesv2.MsgSendPacket) (*channeltypesv2.MsgSendPacketResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
sequence, destChannel, err := k.sendPacket(ctx, msg.SourceChannel, msg.TimeoutTimestamp, msg.PacketData)
sequence, destChannel, err := k.sendPacket(ctx, msg.SourceChannel, msg.TimeoutTimestamp, msg.Payloads)
if err != nil {
sdkCtx.Logger().Error("send packet failed", "source-channel", msg.SourceChannel, "error", errorsmod.Wrap(err, "send packet failed"))
return nil, errorsmod.Wrapf(err, "send packet failed for source id: %s", msg.SourceChannel)
Expand All @@ -32,7 +32,7 @@ func (k *Keeper) SendPacket(ctx context.Context, msg *channeltypesv2.MsgSendPack
return nil, errorsmod.Wrap(err, "invalid address for msg Signer")
}

for _, pd := range msg.PacketData {
for _, pd := range msg.Payloads {
cbs := k.Router.Route(pd.SourcePort)
err := cbs.OnSendPacket(ctx, msg.SourceChannel, destChannel, sequence, pd, signer)
if err != nil {
Expand Down
30 changes: 15 additions & 15 deletions modules/core/04-channel/v2/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (suite *KeeperTestSuite) TestMsgSendPacket() {
path *ibctesting.Path
expectedPacket channeltypesv2.Packet
timeoutTimestamp uint64
packetData channeltypesv2.PacketData
payload channeltypesv2.Payload
)

testCases := []struct {
Expand Down Expand Up @@ -53,7 +53,7 @@ func (suite *KeeperTestSuite) TestMsgSendPacket() {
{
name: "failure: application callback error",
malleate: func() {
path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnSendPacket = func(ctx context.Context, sourceID string, destinationID string, sequence uint64, data channeltypesv2.PacketData, signer sdk.AccAddress) error {
path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnSendPacket = func(ctx context.Context, sourceID string, destinationID string, sequence uint64, data channeltypesv2.Payload, signer sdk.AccAddress) error {
return mock.MockApplicationCallbackError
}
},
Expand All @@ -69,7 +69,7 @@ func (suite *KeeperTestSuite) TestMsgSendPacket() {
{
name: "failure: route to non existing app",
malleate: func() {
packetData.SourcePort = "foo"
payload.SourcePort = "foo"
},
expError: fmt.Errorf("no route for foo"),
},
Expand All @@ -85,13 +85,13 @@ func (suite *KeeperTestSuite) TestMsgSendPacket() {
path.SetupV2()

timeoutTimestamp = suite.chainA.GetTimeoutTimestamp()
packetData = mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB)
payload = mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)

expectedPacket = channeltypesv2.NewPacket(1, path.EndpointA.ChannelID, path.EndpointB.ChannelID, timeoutTimestamp, packetData)
expectedPacket = channeltypesv2.NewPacket(1, path.EndpointA.ChannelID, path.EndpointB.ChannelID, timeoutTimestamp, payload)

tc.malleate()

packet, err := path.EndpointA.MsgSendPacket(timeoutTimestamp, packetData)
packet, err := path.EndpointA.MsgSendPacket(timeoutTimestamp, payload)

expPass := tc.expError == nil
if expPass {
Expand Down Expand Up @@ -146,7 +146,7 @@ func (suite *KeeperTestSuite) TestMsgRecvPacket() {
// a failed ack should be returned by the application.
expectedAck.AcknowledgementResults[0].RecvPacketResult = failedRecvResult

path.EndpointB.Chain.GetSimApp().MockModuleV2B.IBCApp.OnRecvPacket = func(ctx context.Context, sourceChannel string, destinationChannel string, data channeltypesv2.PacketData, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult {
path.EndpointB.Chain.GetSimApp().MockModuleV2B.IBCApp.OnRecvPacket = func(ctx context.Context, sourceChannel string, destinationChannel string, data channeltypesv2.Payload, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult {
return failedRecvResult
}
},
Expand All @@ -162,7 +162,7 @@ func (suite *KeeperTestSuite) TestMsgRecvPacket() {
// an async ack should be returned by the application.
expectedAck.AcknowledgementResults[0].RecvPacketResult = asyncResult

path.EndpointB.Chain.GetSimApp().MockModuleV2B.IBCApp.OnRecvPacket = func(ctx context.Context, sourceChannel string, destinationChannel string, data channeltypesv2.PacketData, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult {
path.EndpointB.Chain.GetSimApp().MockModuleV2B.IBCApp.OnRecvPacket = func(ctx context.Context, sourceChannel string, destinationChannel string, data channeltypesv2.Payload, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult {
return asyncResult
}
},
Expand Down Expand Up @@ -204,7 +204,7 @@ func (suite *KeeperTestSuite) TestMsgRecvPacket() {
timeoutTimestamp := suite.chainA.GetTimeoutTimestamp()

var err error
packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB))
packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB))
suite.Require().NoError(err)

// default expected ack is a single successful recv result for moduleB.
Expand Down Expand Up @@ -349,15 +349,15 @@ func (suite *KeeperTestSuite) TestMsgAcknowledgement() {

// Modify the callback to return an error.
// This way, we can verify that the callback is not executed in a No-op case.
path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnAcknowledgementPacket = func(context.Context, string, string, channeltypesv2.PacketData, []byte, sdk.AccAddress) error {
path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnAcknowledgementPacket = func(context.Context, string, string, channeltypesv2.Payload, []byte, sdk.AccAddress) error {
return mock.MockApplicationCallbackError
}
},
},
{
name: "failure: callback fails",
malleate: func() {
path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnAcknowledgementPacket = func(context.Context, string, string, channeltypesv2.PacketData, []byte, sdk.AccAddress) error {
path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnAcknowledgementPacket = func(context.Context, string, string, channeltypesv2.Payload, []byte, sdk.AccAddress) error {
return mock.MockApplicationCallbackError
}
},
Expand Down Expand Up @@ -397,7 +397,7 @@ func (suite *KeeperTestSuite) TestMsgAcknowledgement() {

var err error
// Send packet from A to B
packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB))
packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB))
suite.Require().NoError(err)

err = path.EndpointB.MsgRecvPacket(packet)
Expand Down Expand Up @@ -450,7 +450,7 @@ func (suite *KeeperTestSuite) TestMsgTimeout() {

// Modify the callback to return a different error.
// This way, we can verify that the callback is not executed in a No-op case.
path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnTimeoutPacket = func(context.Context, string, string, channeltypesv2.PacketData, sdk.AccAddress) error {
path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnTimeoutPacket = func(context.Context, string, string, channeltypesv2.Payload, sdk.AccAddress) error {
return mock.MockApplicationCallbackError
}
},
Expand All @@ -459,7 +459,7 @@ func (suite *KeeperTestSuite) TestMsgTimeout() {
{
name: "failure: callback fails",
malleate: func() {
path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnTimeoutPacket = func(context.Context, string, string, channeltypesv2.PacketData, sdk.AccAddress) error {
path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnTimeoutPacket = func(context.Context, string, string, channeltypesv2.Payload, sdk.AccAddress) error {
return mock.MockApplicationCallbackError
}
},
Expand Down Expand Up @@ -498,7 +498,7 @@ func (suite *KeeperTestSuite) TestMsgTimeout() {

// Send packet from A to B
timeoutTimestamp := uint64(suite.chainA.GetContext().BlockTime().Unix())
mockData := mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB)
mockData := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)

var err error
packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, mockData)
Expand Down
6 changes: 3 additions & 3 deletions modules/core/04-channel/v2/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func (k *Keeper) sendPacket(
ctx context.Context,
sourceChannel string,
timeoutTimestamp uint64,
data []types.PacketData,
payloads []types.Payload,
) (uint64, string, error) {
// 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.
channel, ok = k.convertV1Channel(ctx, data[0].SourcePort, sourceChannel)
channel, ok = k.convertV1Channel(ctx, payloads[0].SourcePort, sourceChannel)
if !ok {
return 0, "", errorsmod.Wrap(types.ErrChannelNotFound, sourceChannel)
}
Expand All @@ -47,7 +47,7 @@ func (k *Keeper) sendPacket(
}

// construct packet from given fields and channel state
packet := types.NewPacket(sequence, sourceChannel, destChannel, timeoutTimestamp, data...)
packet := types.NewPacket(sequence, sourceChannel, destChannel, timeoutTimestamp, payloads...)

if err := packet.ValidateBasic(); err != nil {
return 0, "", errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "constructed packet failed basic validation: %v", err)
Expand Down
14 changes: 7 additions & 7 deletions modules/core/04-channel/v2/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (suite *KeeperTestSuite) TestSendPacket() {
path = ibctesting.NewPath(suite.chainA, suite.chainB)
path.SetupV2()

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

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

Expand Down Expand Up @@ -204,7 +204,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
path = ibctesting.NewPath(suite.chainA, suite.chainB)
path.SetupV2()

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

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

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

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

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

Expand Down Expand Up @@ -391,7 +391,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
"failure: packet commitment bytes differ",
func() {
// change packet data after send to acknowledge different packet
packet.Data[0].Payload.Value = []byte("different value")
packet.Data[0].Value = []byte("different value")
},
channeltypes.ErrInvalidPacket,
},
Expand All @@ -414,7 +414,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {

freezeClient = false

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

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

Expand Down Expand Up @@ -521,7 +521,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
suite.Require().NoError(err, "send packet failed")

// try to timeout packet with different data
packet.Data[0].Payload.Value = []byte("different value")
packet.Data[0].Value = []byte("different value")
},
channeltypes.ErrInvalidPacket,
},
Expand Down Expand Up @@ -564,7 +564,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
path.SetupV2()

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

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

Expand Down
12 changes: 6 additions & 6 deletions modules/core/04-channel/v2/types/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ func CommitPacket(packet Packet) []byte {
buf = append(buf, destIDHash[:]...)

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

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

// hashPacketData returns the hash of the packet data.
func hashPacketData(data PacketData) []byte {
// hashPayload returns the hash of the packet data.
func hashPayload(data Payload) []byte {
var buf []byte
sourceHash := sha256.Sum256([]byte(data.SourcePort))
buf = append(buf, sourceHash[:]...)
destHash := sha256.Sum256([]byte(data.DestinationPort))
buf = append(buf, destHash[:]...)
payloadValueHash := sha256.Sum256(data.Payload.Value)
payloadValueHash := sha256.Sum256(data.Value)
buf = append(buf, payloadValueHash[:]...)
payloadEncodingHash := sha256.Sum256([]byte(data.Payload.Encoding))
payloadEncodingHash := sha256.Sum256([]byte(data.Encoding))
buf = append(buf, payloadEncodingHash[:]...)
payloadVersionHash := sha256.Sum256([]byte(data.Payload.Version))
payloadVersionHash := sha256.Sum256([]byte(data.Version))
buf = append(buf, payloadVersionHash[:]...)
hash := sha256.Sum256(buf)
return hash[:]
Expand Down
1 change: 0 additions & 1 deletion modules/core/04-channel/v2/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ var (
ErrInvalidPacket = errorsmod.Register(SubModuleName, 4, "invalid packet")
ErrInvalidPayload = errorsmod.Register(SubModuleName, 5, "invalid payload")
ErrSequenceSendNotFound = errorsmod.Register(SubModuleName, 6, "sequence send not found")
ErrInvalidPacketData = errorsmod.Register(SubModuleName, 7, "invalid packet data")
ErrInvalidAcknowledgement = errorsmod.Register(SubModuleName, 8, "invalid acknowledgement")
)
10 changes: 5 additions & 5 deletions modules/core/04-channel/v2/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ func (msg *MsgCreateChannel) ValidateBasic() error {
}

// NewMsgSendPacket creates a new MsgSendPacket instance.
func NewMsgSendPacket(sourceChannel string, timeoutTimestamp uint64, signer string, packetData ...PacketData) *MsgSendPacket {
func NewMsgSendPacket(sourceChannel string, timeoutTimestamp uint64, signer string, payloads ...Payload) *MsgSendPacket {
return &MsgSendPacket{
SourceChannel: sourceChannel,
TimeoutTimestamp: timeoutTimestamp,
PacketData: packetData,
Payloads: payloads,
Signer: signer,
}
}
Expand All @@ -105,11 +105,11 @@ func (msg *MsgSendPacket) ValidateBasic() error {
return errorsmod.Wrap(channeltypesv1.ErrInvalidTimeout, "timeout must not be 0")
}

if len(msg.PacketData) != 1 {
return errorsmod.Wrapf(ErrInvalidPacketData, "packet data must be of length 1, got %d instead", len(msg.PacketData))
if len(msg.Payloads) != 1 {
return errorsmod.Wrapf(ErrInvalidPayload, "payloads must be of length 1, got %d instead", len(msg.Payloads))
}

for _, pd := range msg.PacketData {
for _, pd := range msg.Payloads {
if err := pd.ValidateBasic(); err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions modules/core/04-channel/v2/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,16 @@ func (s *TypesTestSuite) TestMsgSendPacketValidateBasic() {
expError: channeltypesv1.ErrInvalidTimeout,
},
{
name: "failure: invalid length for packetdata",
name: "failure: invalid length for payload",
malleate: func() {
msg.PacketData = []types.PacketData{}
msg.Payloads = []types.Payload{}
},
expError: types.ErrInvalidPacketData,
expError: types.ErrInvalidPayload,
},
{
name: "failure: invalid packetdata",
malleate: func() {
msg.PacketData[0].DestinationPort = ""
msg.Payloads[0].DestinationPort = ""
},
expError: host.ErrInvalidID,
},
Expand All @@ -200,7 +200,7 @@ func (s *TypesTestSuite) TestMsgSendPacketValidateBasic() {
msg = types.NewMsgSendPacket(
ibctesting.FirstChannelID, s.chainA.GetTimeoutTimestamp(),
s.chainA.SenderAccount.GetAddress().String(),
types.PacketData{SourcePort: ibctesting.MockPort, DestinationPort: ibctesting.MockPort, Payload: types.NewPayload("ics20-1", "json", ibctesting.MockPacketData)},
types.Payload{SourcePort: ibctesting.MockPort, DestinationPort: ibctesting.MockPort, Version: "ics20-1", Encoding: "json", Value: ibctesting.MockPacketData},
)

tc.malleate()
Expand Down Expand Up @@ -230,7 +230,7 @@ func (s *TypesTestSuite) TestMsgRecvPacketValidateBasic() {
{
name: "failure: invalid packet",
malleate: func() {
msg.Packet.Data = []types.PacketData{}
msg.Packet.Data = []types.Payload{}
},
expError: types.ErrInvalidPacket,
},
Expand All @@ -251,7 +251,7 @@ func (s *TypesTestSuite) TestMsgRecvPacketValidateBasic() {
}
for _, tc := range testCases {
s.Run(tc.name, func() {
packet := types.NewPacket(1, ibctesting.FirstChannelID, ibctesting.SecondChannelID, s.chainA.GetTimeoutTimestamp(), mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB))
packet := types.NewPacket(1, ibctesting.FirstChannelID, ibctesting.SecondChannelID, s.chainA.GetTimeoutTimestamp(), mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB))

msg = types.NewMsgRecvPacket(packet, testProof, s.chainA.GetTimeoutHeight(), s.chainA.SenderAccount.GetAddress().String())

Expand Down Expand Up @@ -306,7 +306,7 @@ func (s *TypesTestSuite) TestMsgAcknowledge_ValidateBasic() {
for _, tc := range testCases {
s.Run(tc.name, func() {
msg = types.NewMsgAcknowledgement(
types.NewPacket(1, ibctesting.FirstChannelID, ibctesting.SecondChannelID, s.chainA.GetTimeoutTimestamp(), mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB)),
types.NewPacket(1, ibctesting.FirstChannelID, ibctesting.SecondChannelID, s.chainA.GetTimeoutTimestamp(), mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)),
types.Acknowledgement{},
testProof,
clienttypes.ZeroHeight(),
Expand Down Expand Up @@ -363,7 +363,7 @@ func (s *TypesTestSuite) TestMsgTimeoutValidateBasic() {
for _, tc := range testCases {
s.Run(tc.name, func() {
msg = types.NewMsgTimeout(
types.NewPacket(1, ibctesting.FirstChannelID, ibctesting.SecondChannelID, s.chainA.GetTimeoutTimestamp(), mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB)),
types.NewPacket(1, ibctesting.FirstChannelID, ibctesting.SecondChannelID, s.chainA.GetTimeoutTimestamp(), mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)),
testProof,
clienttypes.ZeroHeight(),
s.chainA.SenderAccount.GetAddress().String(),
Expand Down
Loading

0 comments on commit aeb9980

Please sign in to comment.