Skip to content

Commit

Permalink
fix: return bool in GetPruningSequenceStart (#5488) (#5511)
Browse files Browse the repository at this point in the history
(cherry picked from commit 20312be)

Co-authored-by: Carlos Rodriguez <[email protected]>
  • Loading branch information
mergify[bot] and Carlos Rodriguez authored Jan 4, 2024
1 parent ef48e59 commit 3aa49ff
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
11 changes: 5 additions & 6 deletions modules/core/04-channel/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,14 +649,14 @@ func (k Keeper) SetPruningSequenceStart(ctx sdk.Context, portID, channelID strin
}

// GetPruningSequenceStart gets a channel's pruning sequence start from the store.
func (k Keeper) GetPruningSequenceStart(ctx sdk.Context, portID, channelID string) uint64 {
func (k Keeper) GetPruningSequenceStart(ctx sdk.Context, portID, channelID string) (uint64, bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(host.PruningSequenceStartKey(portID, channelID))
if len(bz) == 0 {
return 0
return 0, false
}

return sdk.BigEndianToUint64(bz)
return sdk.BigEndianToUint64(bz), true
}

// HasPruningSequenceStart returns true if the pruning sequence start is set for the specified channel.
Expand All @@ -671,11 +671,10 @@ func (k Keeper) HasPruningSequenceStart(ctx sdk.Context, portID, channelID strin
// Pruning sequence start keeps track of the packet ack/receipt that can be pruned next. When it reaches pruningSequenceEnd,
// pruning is complete.
func (k Keeper) PruneAcknowledgements(ctx sdk.Context, portID, channelID string, limit uint64) (uint64, uint64, error) {
if !k.HasPruningSequenceStart(ctx, portID, channelID) {
pruningSequenceStart, found := k.GetPruningSequenceStart(ctx, portID, channelID)
if !found {
return 0, 0, errorsmod.Wrapf(types.ErrPruningSequenceStartNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}

pruningSequenceStart := k.GetPruningSequenceStart(ctx, portID, channelID)
pruningSequenceEnd, found := k.GetPruningSequenceEnd(ctx, portID, channelID)
if !found {
return 0, 0, errorsmod.Wrapf(types.ErrPruningSequenceEndNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
Expand Down
6 changes: 4 additions & 2 deletions modules/core/04-channel/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,8 @@ func (suite *KeeperTestSuite) TestPruneAcknowledgements() {
receipts := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetAllPacketReceipts(suite.chainA.GetContext())
suite.Require().Len(receipts, int(expReceiptsLen))

start := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetPruningSequenceStart(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
start, found := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetPruningSequenceStart(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(start, expPruningSequenceStart)
}
)
Expand All @@ -577,7 +578,8 @@ func (suite *KeeperTestSuite) TestPruneAcknowledgements() {
func() {},
func(pruned, left uint64) {
// Assert that PruneSequenceStart and PruneSequenceEnd are both set to 1.
start := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetPruningSequenceStart(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
start, found := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetPruningSequenceStart(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(found)
end, found := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetPruningSequenceEnd(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(found)

Expand Down
8 changes: 4 additions & 4 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1515,8 +1515,8 @@ func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel_Ordering() {
suite.Require().Equal(uint64(1), seq)

// Assert that pruning sequence start has been initialized (set to 1)
suite.Require().True(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.HasPruningSequenceStart(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID))
pruningSeq := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetPruningSequenceStart(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
pruningSeq, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetPruningSequenceStart(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(uint64(1), pruningSeq)

// Assert that pruning sequence end has been set correctly
Expand Down Expand Up @@ -1575,8 +1575,8 @@ func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel_Ordering() {
suite.Require().Equal(uint64(2), seq)

// Assert that pruning sequence start has been initialized (set to 1)
suite.Require().True(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.HasPruningSequenceStart(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID))
pruningSeq := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetPruningSequenceStart(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
pruningSeq, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetPruningSequenceStart(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(uint64(1), pruningSeq)

// Assert that pruning sequence end has been set correctly
Expand Down

0 comments on commit 3aa49ff

Please sign in to comment.