Skip to content

Commit 0743c09

Browse files
authored
refactor: reduce channel lookup for timeout flow (#7149)
1 parent 2a07e6e commit 0743c09

File tree

3 files changed

+6
-26
lines changed

3 files changed

+6
-26
lines changed

modules/core/04-channel/keeper/export_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ func (k *Keeper) SetRecvStartSequence(ctx sdk.Context, portID, channelID string,
3737
}
3838

3939
// TimeoutExecuted is a wrapper around timeoutExecuted to allow the function to be directly called in tests.
40-
func (k *Keeper) TimeoutExecuted(ctx sdk.Context, capability *capabilitytypes.Capability, packet types.Packet) error {
41-
return k.timeoutExecuted(ctx, capability, packet)
40+
func (k *Keeper) TimeoutExecuted(ctx sdk.Context, channel types.Channel, capability *capabilitytypes.Capability, packet types.Packet) error {
41+
return k.timeoutExecuted(ctx, channel, capability, packet)
4242
}

modules/core/04-channel/keeper/timeout.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (k *Keeper) TimeoutPacket(
120120
return "", err
121121
}
122122

123-
if err = k.timeoutExecuted(ctx, chanCap, packet); err != nil {
123+
if err = k.timeoutExecuted(ctx, channel, chanCap, packet); err != nil {
124124
return "", err
125125
}
126126

@@ -136,14 +136,10 @@ func (k *Keeper) TimeoutPacket(
136136
// CONTRACT: this function must be called in the IBC handler
137137
func (k *Keeper) timeoutExecuted(
138138
ctx sdk.Context,
139+
channel types.Channel,
139140
chanCap *capabilitytypes.Capability,
140141
packet types.Packet,
141142
) error {
142-
channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel())
143-
if !found {
144-
return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel())
145-
}
146-
147143
capName := host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel())
148144
if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) {
149145
return errorsmod.Wrapf(
@@ -302,7 +298,7 @@ func (k *Keeper) TimeoutOnClose(
302298
return "", err
303299
}
304300

305-
if err = k.timeoutExecuted(ctx, chanCap, packet); err != nil {
301+
if err = k.timeoutExecuted(ctx, channel, chanCap, packet); err != nil {
306302
return "", err
307303
}
308304

modules/core/04-channel/keeper/timeout_test.go

+1-17
Original file line numberDiff line numberDiff line change
@@ -283,22 +283,6 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() {
283283
},
284284
nil,
285285
},
286-
{
287-
"channel not found",
288-
func() {
289-
// use wrong channel naming
290-
path.Setup()
291-
packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
292-
},
293-
func(packetCommitment []byte, err error) {
294-
suite.Require().Error(err)
295-
suite.Require().ErrorIs(err, types.ErrChannelNotFound)
296-
297-
// packet never sent.
298-
suite.Require().Nil(packetCommitment)
299-
},
300-
nil,
301-
},
302286
{
303287
"incorrect capability ORDERED",
304288
func() {
@@ -528,7 +512,7 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() {
528512

529513
tc.malleate()
530514

531-
err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.TimeoutExecuted(ctx, chanCap, packet)
515+
err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.TimeoutExecuted(ctx, path.EndpointA.GetChannel(), chanCap, packet)
532516
pc := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
533517

534518
tc.expResult(pc, err)

0 commit comments

Comments
 (0)