Skip to content

Commit 4d99a06

Browse files
chore: remove orderedmap (#8555)
Co-authored-by: Tamjid Ahmed <[email protected]>
1 parent 16eb140 commit 4d99a06

File tree

22 files changed

+804
-215
lines changed

22 files changed

+804
-215
lines changed

e2e/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ require (
2222
github.com/cosmos/ibc-go/v10 v10.3.0
2323
github.com/cosmos/interchaintest/v10 v10.0.0
2424
github.com/docker/docker v28.0.0+incompatible
25-
github.com/iancoleman/orderedmap v0.3.0
2625
github.com/moby/moby v27.5.1+incompatible
2726
github.com/pelletier/go-toml v1.9.5
2827
github.com/stretchr/testify v1.10.0

e2e/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,8 +1266,6 @@ github.com/huandu/skiplist v1.2.1/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXM
12661266
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
12671267
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
12681268
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
1269-
github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
1270-
github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE=
12711269
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
12721270
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
12731271
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=

e2e/tests/packet_forward_middleware/forward_timeout_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package pfm
44

55
import (
66
"context"
7-
"encoding/json"
87
"testing"
98
"time"
109

@@ -64,21 +63,21 @@ func (s *PFMTimeoutTestSuite) TestTimeoutOnForward() {
6463
// Send packet from a -> b -> c that should timeout between b -> c
6564
retries := uint8(0)
6665

67-
bToCMetadata := &pfmtypes.PacketMetadata{
68-
Forward: &pfmtypes.ForwardMetadata{
66+
bToCMetadata := pfmtypes.PacketMetadata{
67+
Forward: pfmtypes.ForwardMetadata{
6968
Receiver: userC.FormattedAddress(),
7069
Channel: chanBC.ChannelID,
7170
Port: chanBC.PortID,
7271
Retries: &retries,
73-
Timeout: pfmtypes.Duration(time.Second * 10), // Short timeout
72+
Timeout: time.Second * 10, // Short timeout
7473
},
7574
}
7675

77-
memo, err := json.Marshal(bToCMetadata)
76+
memo, err := bToCMetadata.ToMemo()
7877
s.Require().NoError(err)
7978

8079
opts := ibc.TransferOptions{
81-
Memo: string(memo),
80+
Memo: memo,
8281
}
8382

8483
transferAmount := math.NewInt(100_000)
@@ -169,19 +168,19 @@ func (s *PFMTimeoutTestSuite) TestTimeoutOnForward() {
169168
err = relayer.StartRelayer(ctx, s.GetRelayerExecReporter())
170169
s.Require().NoError(err)
171170

172-
bToCMetadata = &pfmtypes.PacketMetadata{
173-
Forward: &pfmtypes.ForwardMetadata{
171+
bToCMetadata = pfmtypes.PacketMetadata{
172+
Forward: pfmtypes.ForwardMetadata{
174173
Receiver: userC.FormattedAddress(),
175174
Channel: chanBC.ChannelID,
176175
Port: chanBC.PortID,
177176
},
178177
}
179178

180-
memo, err = json.Marshal(bToCMetadata)
179+
memo, err = bToCMetadata.ToMemo()
181180
s.Require().NoError(err)
182181

183182
opts = ibc.TransferOptions{
184-
Memo: string(memo),
183+
Memo: memo,
185184
}
186185

187186
aHeightBeforeTransfer, err := chainA.Height(ctx)

e2e/tests/packet_forward_middleware/packet_forward_test.go

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ package pfm
44

55
import (
66
"context"
7-
"encoding/json"
87
"testing"
98

109
"github.com/cosmos/interchaintest/v10/ibc"
11-
"github.com/iancoleman/orderedmap"
1210
testifysuite "github.com/stretchr/testify/suite"
1311

1412
"github.com/cosmos/ibc-go/e2e/testsuite"
@@ -77,30 +75,27 @@ func (s *PFMTestSuite) TestForwardPacket() {
7775
// From A -> B will be handled by transfer msg.
7876
// From B -> C will be handled by firstHopMetadata.
7977
// From C -> D will be handled by secondHopMetadata.
80-
secondHopMetadata := &pfmtypes.PacketMetadata{
81-
Forward: &pfmtypes.ForwardMetadata{
78+
secondHopMetadata := pfmtypes.PacketMetadata{
79+
Forward: pfmtypes.ForwardMetadata{
8280
Receiver: userD.FormattedAddress(),
8381
Channel: chanCD.ChannelID,
8482
Port: chanCD.PortID,
8583
},
8684
}
87-
nextBz, err := json.Marshal(secondHopMetadata)
88-
s.Require().NoError(err)
89-
next := pfmtypes.NewJSONObject(false, nextBz, *orderedmap.New())
9085

91-
firstHopMetadata := &pfmtypes.PacketMetadata{
92-
Forward: &pfmtypes.ForwardMetadata{
86+
firstHopMetadata := pfmtypes.PacketMetadata{
87+
Forward: pfmtypes.ForwardMetadata{
9388
Receiver: userC.FormattedAddress(),
9489
Channel: chanBC.ChannelID,
9590
Port: chanBC.PortID,
96-
Next: next,
91+
Next: &secondHopMetadata,
9792
},
9893
}
9994

100-
memo, err := json.Marshal(firstHopMetadata)
95+
memo, err := firstHopMetadata.ToMemo()
10196
s.Require().NoError(err)
10297

103-
txResp := s.Transfer(ctx, chainA, userA, chanAB.PortID, chanAB.ChannelID, testvalues.DefaultTransferAmount(denomA), userA.FormattedAddress(), userB.FormattedAddress(), s.GetTimeoutHeight(ctx, chainA), 0, string(memo))
98+
txResp := s.Transfer(ctx, chainA, userA, chanAB.PortID, chanAB.ChannelID, testvalues.DefaultTransferAmount(denomA), userA.FormattedAddress(), userB.FormattedAddress(), s.GetTimeoutHeight(ctx, chainA), 0, memo)
10499
s.AssertTxSuccess(txResp)
105100

106101
s.FlushPackets(ctx, relayer, []ibc.Chain{chainA, chainB, chainC, chainD})
@@ -133,30 +128,27 @@ func (s *PFMTestSuite) TestForwardPacket() {
133128
})
134129

135130
t.Run("Packet forwarded [D -> C -> B -> A]", func(_ *testing.T) {
136-
secondHopMetadata := &pfmtypes.PacketMetadata{
137-
Forward: &pfmtypes.ForwardMetadata{
131+
secondHopMetadata := pfmtypes.PacketMetadata{
132+
Forward: pfmtypes.ForwardMetadata{
138133
Receiver: userA.FormattedAddress(),
139134
Channel: chanAB.Counterparty.ChannelID,
140135
Port: chanAB.Counterparty.PortID,
141136
},
142137
}
143-
nextBz, err := json.Marshal(secondHopMetadata)
144-
s.Require().NoError(err)
145-
next := pfmtypes.NewJSONObject(false, nextBz, *orderedmap.New())
146138

147-
firstHopMetadata := &pfmtypes.PacketMetadata{
148-
Forward: &pfmtypes.ForwardMetadata{
139+
firstHopMetadata := pfmtypes.PacketMetadata{
140+
Forward: pfmtypes.ForwardMetadata{
149141
Receiver: userB.FormattedAddress(),
150142
Channel: chanBC.Counterparty.ChannelID,
151143
Port: chanBC.Counterparty.PortID,
152-
Next: next,
144+
Next: &secondHopMetadata,
153145
},
154146
}
155147

156-
memo, err := json.Marshal(firstHopMetadata)
148+
memo, err := firstHopMetadata.ToMemo()
157149
s.Require().NoError(err)
158150

159-
txResp := s.Transfer(ctx, chainD, userD, chanCD.Counterparty.PortID, chanCD.Counterparty.ChannelID, testvalues.DefaultTransferAmount(ibcTokenD.IBCDenom()), userD.FormattedAddress(), userC.FormattedAddress(), s.GetTimeoutHeight(ctx, chainD), 0, string(memo))
151+
txResp := s.Transfer(ctx, chainD, userD, chanCD.Counterparty.PortID, chanCD.Counterparty.ChannelID, testvalues.DefaultTransferAmount(ibcTokenD.IBCDenom()), userD.FormattedAddress(), userC.FormattedAddress(), s.GetTimeoutHeight(ctx, chainD), 0, memo)
160152
s.AssertTxSuccess(txResp)
161153

162154
// Flush the packet all the way back to Chain A and then the acknowledgement back to Chain D
@@ -186,31 +178,27 @@ func (s *PFMTestSuite) TestForwardPacket() {
186178
})
187179

188180
t.Run("Error while forwarding: Refund ok [A -> B -> C ->X D]", func(_ *testing.T) {
189-
secondHopMetadata := &pfmtypes.PacketMetadata{
190-
Forward: &pfmtypes.ForwardMetadata{
181+
secondHopMetadata := pfmtypes.PacketMetadata{
182+
Forward: pfmtypes.ForwardMetadata{
191183
Receiver: "GurbageAddress",
192184
Channel: chanCD.ChannelID,
193185
Port: chanCD.PortID,
194186
},
195187
}
196-
nextBz, err := json.Marshal(secondHopMetadata)
197-
s.Require().NoError(err)
198-
199-
next := pfmtypes.NewJSONObject(false, nextBz, *orderedmap.New())
200188

201-
firstHopMetadata := &pfmtypes.PacketMetadata{
202-
Forward: &pfmtypes.ForwardMetadata{
189+
firstHopMetadata := pfmtypes.PacketMetadata{
190+
Forward: pfmtypes.ForwardMetadata{
203191
Receiver: userC.FormattedAddress(),
204192
Channel: chanBC.ChannelID,
205193
Port: chanBC.PortID,
206-
Next: next,
194+
Next: &secondHopMetadata,
207195
},
208196
}
209197

210-
memo, err := json.Marshal(firstHopMetadata)
198+
memo, err := firstHopMetadata.ToMemo()
211199
s.Require().NoError(err)
212200

213-
txResp := s.Transfer(ctx, chainA, userA, chanAB.PortID, chanAB.ChannelID, testvalues.DefaultTransferAmount(ibcTokenD.IBCDenom()), userA.FormattedAddress(), userB.FormattedAddress(), s.GetTimeoutHeight(ctx, chainA), 0, string(memo))
201+
txResp := s.Transfer(ctx, chainA, userA, chanAB.PortID, chanAB.ChannelID, testvalues.DefaultTransferAmount(ibcTokenD.IBCDenom()), userA.FormattedAddress(), userB.FormattedAddress(), s.GetTimeoutHeight(ctx, chainA), 0, memo)
214202
s.AssertTxFailure(txResp, transfertypes.ErrDenomNotFound)
215203

216204
// Flush the packet all the way back to Chain D and then the acknowledgement back to Chain A
@@ -283,18 +271,18 @@ func (s *PFMTestSuite) TestForwardPacket() {
283271
balanceBInt, err := s.GetChainBNativeBalance(ctx, userB)
284272
s.Require().NoError(err)
285273

286-
firstHopMetadata := &pfmtypes.PacketMetadata{
287-
Forward: &pfmtypes.ForwardMetadata{
274+
firstHopMetadata := pfmtypes.PacketMetadata{
275+
Forward: pfmtypes.ForwardMetadata{
288276
Receiver: userA.FormattedAddress(),
289277
Channel: chanAB.Counterparty.ChannelID,
290278
Port: chanAB.Counterparty.PortID,
291279
},
292280
}
293281

294-
memo, err := json.Marshal(firstHopMetadata)
282+
memo, err := firstHopMetadata.ToMemo()
295283
s.Require().NoError(err)
296284

297-
txResp := s.Transfer(ctx, chainA, userA, chanAB.PortID, chanAB.ChannelID, testvalues.DefaultTransferAmount(denomA), userA.FormattedAddress(), userB.FormattedAddress(), s.GetTimeoutHeight(ctx, chainA), 0, string(memo))
285+
txResp := s.Transfer(ctx, chainA, userA, chanAB.PortID, chanAB.ChannelID, testvalues.DefaultTransferAmount(denomA), userA.FormattedAddress(), userB.FormattedAddress(), s.GetTimeoutHeight(ctx, chainA), 0, memo)
298286
s.AssertTxSuccess(txResp)
299287

300288
s.FlushPackets(ctx, relayer, []ibc.Chain{chainA, chainB})

e2e/tests/packet_forward_middleware/pfm_upgrade_test.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ package pfm
44

55
import (
66
"context"
7-
"encoding/json"
87
"strings"
98
"testing"
109
"time"
1110

1211
"github.com/cosmos/interchaintest/v10/chain/cosmos"
1312
"github.com/cosmos/interchaintest/v10/ibc"
1413
test "github.com/cosmos/interchaintest/v10/testutil"
15-
"github.com/iancoleman/orderedmap"
1614

1715
"github.com/cosmos/ibc-go/e2e/testsuite"
1816
"github.com/cosmos/ibc-go/e2e/testsuite/query"
@@ -125,34 +123,31 @@ func (s *PFMUpgradeTestSuite) TestV8ToV10ChainUpgrade_PacketForward() {
125123

126124
// Send the IBC denom that chain A received from the previous step
127125
t.Run("Send from A -> B -> C ->X D", func(_ *testing.T) {
128-
secondHopMetadata := &pfmtypes.PacketMetadata{
129-
Forward: &pfmtypes.ForwardMetadata{
126+
secondHopMetadata := pfmtypes.PacketMetadata{
127+
Forward: pfmtypes.ForwardMetadata{
130128
Receiver: "cosmos1wgz9ntx6e5vu4npeabcde88d7kfsymag62p6y2",
131129
Channel: chanCD.ChannelID,
132130
Port: chanCD.PortID,
133131
},
134132
}
135-
nextBz, err := json.Marshal(secondHopMetadata)
136-
s.Require().NoError(err)
137-
next := pfmtypes.NewJSONObject(false, nextBz, *orderedmap.New())
138133

139-
firstHopMetadata := &pfmtypes.PacketMetadata{
140-
Forward: &pfmtypes.ForwardMetadata{
134+
firstHopMetadata := pfmtypes.PacketMetadata{
135+
Forward: pfmtypes.ForwardMetadata{
141136
Receiver: userC.FormattedAddress(),
142137
Channel: chanBC.ChannelID,
143138
Port: chanBC.PortID,
144-
Next: next,
139+
Next: &secondHopMetadata,
145140
},
146141
}
147142

148-
memo, err := json.Marshal(firstHopMetadata)
143+
memo, err := firstHopMetadata.ToMemo()
149144
s.Require().NoError(err)
150145

151146
bHeight, err := chainB.Height(ctx)
152147
s.Require().NoError(err)
153148

154149
ibcDenomOnA := ibcTokenA.IBCDenom()
155-
txResp := s.Transfer(ctx, chainA, userA, chanAB.PortID, chanAB.ChannelID, testvalues.DefaultTransferAmount(ibcDenomOnA), userA.FormattedAddress(), userB.FormattedAddress(), s.GetTimeoutHeight(ctx, chainA), 0, string(memo))
150+
txResp := s.Transfer(ctx, chainA, userA, chanAB.PortID, chanAB.ChannelID, testvalues.DefaultTransferAmount(ibcDenomOnA), userA.FormattedAddress(), userB.FormattedAddress(), s.GetTimeoutHeight(ctx, chainA), 0, memo)
156151
s.AssertTxSuccess(txResp)
157152

158153
packet, err := ibctesting.ParseV1PacketFromEvents(txResp.Events)

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ require (
2323
github.com/golang/protobuf v1.5.4
2424
github.com/grpc-ecosystem/grpc-gateway v1.16.0
2525
github.com/hashicorp/go-metrics v0.5.4
26-
github.com/iancoleman/orderedmap v0.3.0
2726
github.com/spf13/cast v1.9.2
2827
github.com/spf13/cobra v1.9.1
2928
github.com/stretchr/testify v1.10.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,8 +1186,6 @@ github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0Jr
11861186
github.com/huandu/skiplist v1.2.1 h1:dTi93MgjwErA/8idWTzIw4Y1kZsMWx35fmI2c8Rij7w=
11871187
github.com/huandu/skiplist v1.2.1/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w=
11881188
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
1189-
github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
1190-
github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE=
11911189
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
11921190
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
11931191
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=

modules/apps/packet-forward-middleware/ibc_middleware.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package packetforward
22

33
import (
4-
"encoding/json"
54
"errors"
65
"fmt"
76
"time"
@@ -165,22 +164,18 @@ func (im IBCMiddleware) OnRecvPacket(ctx sdk.Context, channelVersion string, pac
165164
"memo", data.Memo,
166165
)
167166

168-
d := make(map[string]any)
169-
err = json.Unmarshal([]byte(data.Memo), &d)
170-
logger.Debug("packetForwardMiddleware json", "memo", data.Memo)
171-
if err != nil || d["forward"] == nil {
167+
packetMetadata, isPFM, err := types.GetPacketMetadataFromPacketdata(data)
168+
if err != nil && !isPFM {
172169
// not a packet that should be forwarded
173170
logger.Debug("packetForwardMiddleware OnRecvPacket forward metadata does not exist")
174171
return im.app.OnRecvPacket(ctx, channelVersion, packet, relayer)
175172
}
176-
m := &types.PacketMetadata{}
177-
err = json.Unmarshal([]byte(data.Memo), m)
178-
if err != nil {
173+
if err != nil && isPFM {
179174
logger.Error("packetForwardMiddleware OnRecvPacket error parsing forward metadata", "error", err)
180175
return newErrorAcknowledgement(fmt.Errorf("error parsing forward metadata: %w", err))
181176
}
182177

183-
metadata := m.Forward
178+
metadata := packetMetadata.Forward
184179

185180
goCtx := ctx.Context()
186181
nonrefundable := getBoolFromAny(goCtx.Value(types.NonrefundableKey{}))
@@ -214,7 +209,7 @@ func (im IBCMiddleware) OnRecvPacket(ctx sdk.Context, channelVersion string, pac
214209

215210
token := sdk.NewCoin(denomOnThisChain, amountInt)
216211

217-
timeout := time.Duration(metadata.Timeout)
212+
timeout := metadata.Timeout
218213

219214
if timeout.Nanoseconds() <= 0 {
220215
timeout = im.forwardTimeout

0 commit comments

Comments
 (0)