From 4072cbd0ffa4937989f9e7ce26045b8e9f97709c Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 24 Jul 2023 14:57:11 +0200 Subject: [PATCH] helper function to clear state stored during an upgrade (#4147) --- modules/core/04-channel/keeper/upgrade.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index f7ebeb000cb..0f6dc79f780 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -445,8 +445,7 @@ func (k Keeper) WriteUpgradeOpenChannel(ctx sdk.Context, portID, channelID strin k.SetChannel(ctx, portID, channelID, channel) // delete state associated with upgrade which is no longer required. - k.deleteUpgrade(ctx, portID, channelID) - k.deleteCounterpartyLastPacketSequence(ctx, portID, channelID) + k.deleteUpgradeInfo(ctx, portID, channelID) k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", previousState.String(), "new-state", types.OPEN.String()) emitChannelUpgradeOpenEvent(ctx, portID, channelID, channel) @@ -881,8 +880,7 @@ func (k Keeper) restoreChannel(ctx sdk.Context, portID, channelID string, upgrad k.SetChannel(ctx, portID, channelID, currentChannel) // delete state associated with upgrade which is no longer required. - k.deleteUpgrade(ctx, portID, channelID) - k.deleteCounterpartyLastPacketSequence(ctx, portID, channelID) + k.deleteUpgradeInfo(ctx, portID, channelID) } // writeErrorReceipt will write an error receipt from the provided UpgradeError. @@ -896,3 +894,9 @@ func (k Keeper) writeErrorReceipt(ctx sdk.Context, portID, channelID string, upg emitErrorReceiptEvent(ctx, portID, channelID, channel, upgrade, upgradeError) return nil } + +// deleteUpgradeInfo deletes all auxiliary upgrade information. +func (k Keeper) deleteUpgradeInfo(ctx sdk.Context, portID, channelID string) { + k.deleteUpgrade(ctx, portID, channelID) + k.deleteCounterpartyLastPacketSequence(ctx, portID, channelID) +}