Skip to content

Commit

Permalink
chore: document packet commitment keys + move prefixes to 24-host
Browse files Browse the repository at this point in the history
  • Loading branch information
gjermundgaraba committed Dec 7, 2024
1 parent cf82eba commit 02fbd30
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
5 changes: 3 additions & 2 deletions modules/core/04-channel/v2/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2"
)

var _ types.QueryServer = (*queryServer)(nil)
Expand Down Expand Up @@ -138,7 +139,7 @@ func (q *queryServer) PacketCommitments(ctx context.Context, req *types.QueryPac
}

var commitments []*types.PacketState
store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), types.PacketCommitmentPrefixKey(req.ChannelId))
store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), hostv2.PacketCommitmentPrefixKey(req.ChannelId))

pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error {
keySplit := strings.Split(string(key), "/")
Expand Down Expand Up @@ -205,7 +206,7 @@ func (q *queryServer) PacketAcknowledgements(ctx context.Context, req *types.Que
}

var acks []*types.PacketState
store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), types.PacketAcknowledgementPrefixKey(req.ChannelId))
store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), hostv2.PacketAcknowledgementPrefixKey(req.ChannelId))

// if a list of packet sequences is provided then query for each specific ack and return a list <= len(req.PacketCommitmentSequences)
// otherwise, maintain previous behaviour and perform paginated query
Expand Down
10 changes: 0 additions & 10 deletions modules/core/04-channel/v2/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,3 @@ const (
// the creator key is not a part of the ics-24 host specification
CreatorKey = "creator"
)

// PacketCommitmentPrefixKey returns the store key prefix under which packet commitments for a particular channel are stored.
func PacketCommitmentPrefixKey(channelID string) []byte {
return append([]byte(channelID), byte(1))
}

// PacketAcknowledgementPrefixKey returns the store key prefix under which packet acknowledgements for a particular channel are stored.
func PacketAcknowledgementPrefixKey(channelID string) []byte {
return append([]byte(channelID), byte(3))
}
27 changes: 24 additions & 3 deletions modules/core/24-host/v2/packet_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,40 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// PacketCommitmentPrefixKey returns the store key prefix under which packet commitments for a particular channel are stored.
// channelID must be a generated identifier, not provided externally so key collisions are not possible.
func PacketCommitmentPrefixKey(channelID string) []byte {
return append([]byte(channelID), byte(1))
}

// PacketCommitmentKey returns the store key of under which a packet commitment is stored.
// channelID must be a generated identifier, not provided externally so key collisions are not possible.
func PacketCommitmentKey(channelID string, sequence uint64) []byte {
return append(append([]byte(channelID), byte(1)), sdk.Uint64ToBigEndian(sequence)...)
return append(PacketCommitmentPrefixKey((channelID)), sdk.Uint64ToBigEndian(sequence)...)
}

// PacketReceiptPrefixKey returns the store key prefix under which packet receipts for a particular channel are stored.
// channelID must be a generated identifier, not provided externally so key collisions are not possible.
func PacketReceiptPrefixKey(channelID string) []byte {
return append([]byte(channelID), byte(2))
}

// PacketReceiptKey returns the store key of under which a packet receipt is stored.
// channelID must be a generated identifier, not provided externally so key collisions are not possible.
func PacketReceiptKey(channelID string, sequence uint64) []byte {
return append(append([]byte(channelID), byte(2)), sdk.Uint64ToBigEndian(sequence)...)
return append(PacketReceiptPrefixKey(channelID), sdk.Uint64ToBigEndian(sequence)...)
}

// PacketAcknowledgementPrefixKey returns the store key prefix under which packet acknowledgements for a particular channel are stored.
// channelID must be a generated identifier, not provided externally so key collisions are not possible.
func PacketAcknowledgementPrefixKey(channelID string) []byte {
return append([]byte(channelID), byte(3))
}

// PacketAcknowledgementKey returns the store key of under which a packet acknowledgement is stored.
// channelID must be a generated identifier, not provided externally so key collisions are not possible.
func PacketAcknowledgementKey(channelID string, sequence uint64) []byte {
return append(append([]byte(channelID), byte(3)), sdk.Uint64ToBigEndian(sequence)...)
return append(PacketAcknowledgementPrefixKey(channelID), sdk.Uint64ToBigEndian(sequence)...)
}

// NextSequenceSendKey returns the store key for the next sequence send of a given channelID.
Expand Down

0 comments on commit 02fbd30

Please sign in to comment.