Skip to content

Commit

Permalink
helper function to clear state stored during an upgrade (#4147)
Browse files Browse the repository at this point in the history
  • Loading branch information
crodriguezvega authored Jul 24, 2023
1 parent ace3acd commit 4072cbd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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)
}

0 comments on commit 4072cbd

Please sign in to comment.