From 989e0b1dc96155abbddd2a6c90b5fa7ee39a2b32 Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Wed, 20 Dec 2023 14:24:44 +0200 Subject: [PATCH] Rename keys. --- modules/core/04-channel/keeper/keeper.go | 30 ++++++------- modules/core/04-channel/keeper/upgrade.go | 8 ++-- .../core/04-channel/keeper/upgrade_test.go | 28 ++++++------- modules/core/24-host/packet_keys.go | 42 +++++++++---------- 4 files changed, 54 insertions(+), 54 deletions(-) diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index 9fd9bd14e33..63847fd175d 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -611,17 +611,17 @@ func (k Keeper) HasInflightPackets(ctx sdk.Context, portID, channelID string) bo return iterator.Valid() } -// SetCounterpartyNextSequenceSend sets the counterparty next send sequence to the store. -func (k Keeper) SetCounterpartyNextSequenceSend(ctx sdk.Context, portID, channelID string, sequence uint64) { +// SetPruningSequenceEnd sets the channel's pruning sequence end to the store. +func (k Keeper) SetPruningSequenceEnd(ctx sdk.Context, portID, channelID string, sequence uint64) { store := ctx.KVStore(k.storeKey) bz := sdk.Uint64ToBigEndian(sequence) - store.Set(host.CounterpartyNextSequenceSendKey(portID, channelID), bz) + store.Set(host.PruningSequenceEndKey(portID, channelID), bz) } -// GetCounterpartyNextSequenceSend gets the counterparty next send sequence from the store. -func (k Keeper) GetCounterpartyNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) { +// GetPruningSequenceEnd gets a channel's pruning sequence end from the store. +func (k Keeper) GetPruningSequenceEnd(ctx sdk.Context, portID, channelID string) (uint64, bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(host.CounterpartyNextSequenceSendKey(portID, channelID)) + bz := store.Get(host.PruningSequenceEndKey(portID, channelID)) if len(bz) == 0 { return 0, false } @@ -629,17 +629,17 @@ func (k Keeper) GetCounterpartyNextSequenceSend(ctx sdk.Context, portID, channel return sdk.BigEndianToUint64(bz), true } -// SetPruningSequence sets a channel's pruning sequence to the store. -func (k Keeper) SetPruningSequence(ctx sdk.Context, portID, channelID string, sequence uint64) { +// SetPruningSequenceStart sets a channel's pruning sequence start to the store. +func (k Keeper) SetPruningSequenceStart(ctx sdk.Context, portID, channelID string, sequence uint64) { store := ctx.KVStore(k.storeKey) bz := sdk.Uint64ToBigEndian(sequence) - store.Set(host.PruningSequenceKey(portID, channelID), bz) + store.Set(host.PruningSequenceStartKey(portID, channelID), bz) } -// GetPruningSequence gets a channel's pruning sequence from the store. -func (k Keeper) GetPruningSequence(ctx sdk.Context, portID, channelID string) uint64 { +// GetPruningSequenceStart gets a channel's pruning sequence start from the store. +func (k Keeper) GetPruningSequenceStart(ctx sdk.Context, portID, channelID string) uint64 { store := ctx.KVStore(k.storeKey) - bz := store.Get(host.PruningSequenceKey(portID, channelID)) + bz := store.Get(host.PruningSequenceStartKey(portID, channelID)) if len(bz) == 0 { return 0 } @@ -647,10 +647,10 @@ func (k Keeper) GetPruningSequence(ctx sdk.Context, portID, channelID string) ui return sdk.BigEndianToUint64(bz) } -// HasPruningSequence returns true if the pruning sequence is set for the specified channel. -func (k Keeper) HasPruningSequence(ctx sdk.Context, portID, channelID string) bool { +// HasPruningSequenceStart returns true if the pruning sequence start is set for the specified channel. +func (k Keeper) HasPruningSequenceStart(ctx sdk.Context, portID, channelID string) bool { store := ctx.KVStore(k.storeKey) - return store.Has(host.PruningSequenceKey(portID, channelID)) + return store.Has(host.PruningSequenceStartKey(portID, channelID)) } // PruneAcknowledgements prunes packet acknowledgements from the store that have a sequence number less than or equal to the pruning sequence. diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index 0489081521c..5f451955606 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -582,14 +582,14 @@ func (k Keeper) WriteUpgradeOpenChannel(ctx sdk.Context, portID, channelID strin k.SetNextSequenceAck(ctx, portID, channelID, upgrade.NextSequenceSend) } - // set the counterparty next sequence send in order to have upper bound to prune to - k.SetCounterpartyNextSequenceSend(ctx, portID, channelID, counterpartyUpgrade.NextSequenceSend) + // set the counterparty next sequence send as pruning sequence end in order to have upper bound to prune to + k.SetPruningSequenceEnd(ctx, portID, channelID, counterpartyUpgrade.NextSequenceSend) // First upgrade for this channel will set the pruning sequence to 1, the starting sequence for pruning. // Subsequent upgrades will not modify the pruning sequence thereby allowing pruning to continue from the last // pruned sequence. - if !k.HasPruningSequence(ctx, portID, channelID) { - k.SetPruningSequence(ctx, portID, channelID, 1) + if !k.HasPruningSequenceStart(ctx, portID, channelID) { + k.SetPruningSequenceStart(ctx, portID, channelID, 1) } // Switch channel fields to upgrade fields and set channel state to OPEN diff --git a/modules/core/04-channel/keeper/upgrade_test.go b/modules/core/04-channel/keeper/upgrade_test.go index 4faf97e73f6..db01c0a728e 100644 --- a/modules/core/04-channel/keeper/upgrade_test.go +++ b/modules/core/04-channel/keeper/upgrade_test.go @@ -1488,11 +1488,11 @@ func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel_Ordering() { suite.Require().True(found) suite.Require().Equal(uint64(2), seq) - // Assert that pruning sequence has not been initialized. - suite.Require().False(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.HasPruningSequence(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + // Assert that pruning sequence start has not been initialized. + suite.Require().False(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.HasPruningSequenceStart(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) - // Assert that CounterpartyNextSequenceSend has been set correctly - counterpartyNextSequenceSend, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyNextSequenceSend(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + // Assert that pruning sequence end has been set correctly + counterpartyNextSequenceSend, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetPruningSequenceEnd(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) suite.Require().False(found) suite.Require().Equal(uint64(0), counterpartyNextSequenceSend) }, @@ -1514,13 +1514,13 @@ func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel_Ordering() { suite.Require().True(found) suite.Require().Equal(uint64(1), seq) - // Assert that pruning sequence has been initialized (set to 1) - suite.Require().True(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.HasPruningSequence(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) - pruningSeq := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetPruningSequence(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + // 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) suite.Require().Equal(uint64(1), pruningSeq) - // Assert that CounterpartyNextSequenceSend has been set correctly - counterpartySequenceSend, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyNextSequenceSend(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + // Assert that pruning sequence end has been set correctly + counterpartySequenceSend, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetPruningSequenceEnd(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) suite.Require().True(found) suite.Require().Equal(uint64(2), counterpartySequenceSend) }, @@ -1548,10 +1548,10 @@ func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel_Ordering() { suite.Require().Equal(uint64(1), seq) // Assert that pruning sequence has not been initialized. - suite.Require().False(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.HasPruningSequence(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + suite.Require().False(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.HasPruningSequenceStart(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) // Assert that CounterpartyNextSequenceSend has been set correctly - counterpartyNextSequenceSend, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyNextSequenceSend(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + counterpartyNextSequenceSend, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetPruningSequenceEnd(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) suite.Require().False(found) suite.Require().Equal(uint64(0), counterpartyNextSequenceSend) }, @@ -1575,12 +1575,12 @@ func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel_Ordering() { suite.Require().Equal(uint64(2), seq) // Assert that pruning sequence has been initialized (set to 1) - suite.Require().True(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.HasPruningSequence(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) - pruningSeq := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetPruningSequence(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + 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) suite.Require().Equal(uint64(1), pruningSeq) // Assert that CounterpartyNextSequenceSend has been set correctly - counterpartySequenceSend, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyNextSequenceSend(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + counterpartySequenceSend, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetPruningSequenceEnd(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) suite.Require().True(found) suite.Require().Equal(uint64(2), counterpartySequenceSend) }, diff --git a/modules/core/24-host/packet_keys.go b/modules/core/24-host/packet_keys.go index 9656a3cba65..75730e57d73 100644 --- a/modules/core/24-host/packet_keys.go +++ b/modules/core/24-host/packet_keys.go @@ -3,15 +3,15 @@ package host import "fmt" const ( - KeySequencePrefix = "sequences" - KeyNextSeqSendPrefix = "nextSequenceSend" - KeyNextSeqRecvPrefix = "nextSequenceRecv" - KeyNextSeqAckPrefix = "nextSequenceAck" - KeyPacketCommitmentPrefix = "commitments" - KeyPacketAckPrefix = "acks" - KeyPacketReceiptPrefix = "receipts" - KeyPruningSequence = "pruningSequence" - KeyCounterpartyNextSeqSend = "counterpartyNextSequenceSend" + KeySequencePrefix = "sequences" + KeyNextSeqSendPrefix = "nextSequenceSend" + KeyNextSeqRecvPrefix = "nextSequenceRecv" + KeyNextSeqAckPrefix = "nextSequenceAck" + KeyPacketCommitmentPrefix = "commitments" + KeyPacketAckPrefix = "acks" + KeyPacketReceiptPrefix = "receipts" + KeyPruningSequenceStart = "pruningSequenceStart" + KeyPruningSequenceEnd = "pruningSequenceEnd" ) // ICS04 @@ -93,24 +93,24 @@ func PacketReceiptKey(portID, channelID string, sequence uint64) []byte { return []byte(PacketReceiptPath(portID, channelID, sequence)) } -// PruningSequencePath defines the path under which the pruning sequence is stored -func PruningSequencePath(portID, channelID string) string { - return fmt.Sprintf("%s/%s", KeyPruningSequence, channelPath(portID, channelID)) +// PruningSequenceStartPath defines the path under which the pruning sequence starting value is stored +func PruningSequenceStartPath(portID, channelID string) string { + return fmt.Sprintf("%s/%s", KeyPruningSequenceStart, channelPath(portID, channelID)) } -// PruningSequenceKey returns the store key for the pruning sequence of a particular channel -func PruningSequenceKey(portID, channelID string) []byte { - return []byte(PruningSequencePath(portID, channelID)) +// PruningSequenceStartKey returns the store key for the pruning sequence start of a particular channel +func PruningSequenceStartKey(portID, channelID string) []byte { + return []byte(PruningSequenceStartPath(portID, channelID)) } -// CounterpartyNextSequenceSendPath defines the path under which the next send sequence counter of the counterparty chain is stored -func CounterpartyNextSequenceSendPath(portID, channelID string) string { - return fmt.Sprintf("%s/%s", KeyCounterpartyNextSeqSend, channelPath(portID, channelID)) +// PruningSequenceEndPath defines the path under which the pruning sequence end is stored +func PruningSequenceEndPath(portID, channelID string) string { + return fmt.Sprintf("%s/%s", KeyPruningSequenceEnd, channelPath(portID, channelID)) } -// CounterpartyNextSequenceSendKey returns the store key for the next send sequence counter of the counterparty chain -func CounterpartyNextSequenceSendKey(portID, channelID string) []byte { - return []byte(CounterpartyNextSequenceSendPath(portID, channelID)) +// PruningSequenceEndKey returns the store key for the pruning sequence end of a particular channel +func PruningSequenceEndKey(portID, channelID string) []byte { + return []byte(PruningSequenceEndPath(portID, channelID)) } func sequencePath(sequence uint64) string {