diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index 9c30c8f252c..1a5cf96d7a5 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -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. @@ -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) diff --git a/modules/core/04-channel/keeper/keeper_test.go b/modules/core/04-channel/keeper/keeper_test.go index 93711a93065..588d1002de1 100644 --- a/modules/core/04-channel/keeper/keeper_test.go +++ b/modules/core/04-channel/keeper/keeper_test.go @@ -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) } ) @@ -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) diff --git a/modules/core/04-channel/keeper/upgrade_test.go b/modules/core/04-channel/keeper/upgrade_test.go index 5400a99e5ac..268980c8846 100644 --- a/modules/core/04-channel/keeper/upgrade_test.go +++ b/modules/core/04-channel/keeper/upgrade_test.go @@ -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 @@ -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