Skip to content

Commit

Permalink
Rename keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Dec 20, 2023
1 parent ff2b170 commit 989e0b1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 54 deletions.
30 changes: 15 additions & 15 deletions modules/core/04-channel/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,46 +611,46 @@ 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
}

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
}

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.
Expand Down
8 changes: 4 additions & 4 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand All @@ -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)
},
Expand Down Expand Up @@ -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)
},
Expand All @@ -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)
},
Expand Down
42 changes: 21 additions & 21 deletions modules/core/24-host/packet_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 989e0b1

Please sign in to comment.