Skip to content

Commit

Permalink
Delete counterparty upgrade in deleteUpgradeInfo. Move function to ke…
Browse files Browse the repository at this point in the history
…eper. (#4294)
  • Loading branch information
DimitrisJim authored Aug 8, 2023
1 parent 1daa1d8 commit 5721b4d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
7 changes: 7 additions & 0 deletions modules/core/04-channel/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,13 @@ func (k Keeper) deleteCounterpartyUpgrade(ctx sdk.Context, portID, channelID str
store.Delete(host.ChannelCounterpartyUpgradeKey(portID, channelID))
}

// 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)
k.deleteCounterpartyUpgrade(ctx, portID, channelID)
}

// common functionality for IteratePacketCommitment and IteratePacketAcknowledgement
func (Keeper) iterateHashes(ctx sdk.Context, iterator db.Iterator, cb func(portID, channelID string, sequence uint64, hash []byte) bool) {
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })
Expand Down
6 changes: 0 additions & 6 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,9 +902,3 @@ 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)
}
9 changes: 9 additions & 0 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,9 +928,14 @@ func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel() {
upgrade, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().Equal(types.Upgrade{}, upgrade)
suite.Require().False(found)

lastPacketSequence, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyLastPacketSequence(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().Equal(uint64(0), lastPacketSequence)
suite.Require().False(found)

counterpartyUpgrade, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().Equal(types.Upgrade{}, counterpartyUpgrade)
suite.Require().False(found)
}

func (suite *KeeperTestSuite) TestChanUpgradeCancel() {
Expand Down Expand Up @@ -1088,6 +1093,10 @@ func (suite *KeeperTestSuite) TestWriteUpgradeCancelChannel() {
lastPacketSequence, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyLastPacketSequence(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().Equal(uint64(0), lastPacketSequence)
suite.Require().False(found)

counterpartyUpgrade, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().Equal(types.Upgrade{}, counterpartyUpgrade)
suite.Require().False(found)
}

func (suite *KeeperTestSuite) TestChanUpgradeTimeout() {
Expand Down

0 comments on commit 5721b4d

Please sign in to comment.