Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: document channel id requirements for packet commitment keys #7633

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading