Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp: reduce channel lookup in timeout flow #7149

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/core/04-channel/keeper/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ func (k *Keeper) SetRecvStartSequence(ctx sdk.Context, portID, channelID string,
}

// TimeoutExecuted is a wrapper around timeoutExecuted to allow the function to be directly called in tests.
func (k *Keeper) TimeoutExecuted(ctx sdk.Context, capability *capabilitytypes.Capability, packet types.Packet) error {
return k.timeoutExecuted(ctx, capability, packet)
func (k *Keeper) TimeoutExecuted(ctx sdk.Context, channel types.Channel, capability *capabilitytypes.Capability, packet types.Packet) error {
return k.timeoutExecuted(ctx, channel, capability, packet)
}
10 changes: 3 additions & 7 deletions modules/core/04-channel/keeper/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (k *Keeper) TimeoutPacket(
return "", err
}

if err = k.timeoutExecuted(ctx, chanCap, packet); err != nil {
if err = k.timeoutExecuted(ctx, channel, chanCap, packet); err != nil {
return "", err
}

Expand All @@ -136,14 +136,10 @@ func (k *Keeper) TimeoutPacket(
// CONTRACT: this function must be called in the IBC handler
func (k *Keeper) timeoutExecuted(
ctx sdk.Context,
channel types.Channel,
chanCap *capabilitytypes.Capability,
packet types.Packet,
) error {
channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel())
if !found {
return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel())
}

capName := host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel())
if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) {
return errorsmod.Wrapf(
Expand Down Expand Up @@ -302,7 +298,7 @@ func (k *Keeper) TimeoutOnClose(
return "", err
}

if err = k.timeoutExecuted(ctx, chanCap, packet); err != nil {
if err = k.timeoutExecuted(ctx, channel, chanCap, packet); err != nil {
return "", err
}

Expand Down
18 changes: 1 addition & 17 deletions modules/core/04-channel/keeper/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,22 +283,6 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() {
},
nil,
},
{
"channel not found",
func() {
// use wrong channel naming
path.Setup()
packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
},
func(packetCommitment []byte, err error) {
suite.Require().Error(err)
suite.Require().ErrorIs(err, types.ErrChannelNotFound)

// packet never sent.
suite.Require().Nil(packetCommitment)
},
nil,
},
{
"incorrect capability ORDERED",
func() {
Expand Down Expand Up @@ -528,7 +512,7 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() {

tc.malleate()

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

tc.expResult(pc, err)
Expand Down
Loading