From f4eba717194056d2b6c45d0d04893774eebf389b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 1 Aug 2024 23:51:18 +0200 Subject: [PATCH] refactor!: remove 24-host path function in favour of sybling key functions (#7016) * refactor: remove all Path functions from 24-host in favour of Key functions * docs: migration + changelog * Update docs/docs/05-migrations/13-v8-to-v9.md * lint --- CHANGELOG.md | 1 + docs/docs/05-migrations/13-v8-to-v9.md | 5 ++ modules/core/04-channel/keeper/grpc_query.go | 4 +- modules/core/04-channel/keeper/keeper.go | 4 +- modules/core/24-host/channel_keys.go | 33 +++++++-- modules/core/24-host/channel_paths.go | 46 ------------- modules/core/24-host/client_keys.go | 18 +++-- modules/core/24-host/client_paths.go | 49 ------------- modules/core/24-host/connection_keys.go | 11 ++- modules/core/24-host/connection_paths.go | 18 ----- modules/core/24-host/packet_keys.go | 47 ++++++++++--- modules/core/24-host/packet_paths.go | 72 -------------------- modules/core/24-host/parse_test.go | 6 +- 13 files changed, 104 insertions(+), 210 deletions(-) delete mode 100644 modules/core/24-host/channel_paths.go delete mode 100644 modules/core/24-host/client_paths.go delete mode 100644 modules/core/24-host/connection_paths.go delete mode 100644 modules/core/24-host/packet_paths.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dc1dec2208..a876b3a9fe9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (light-clients/06-solomachine) [\#6888](https://github.com/cosmos/ibc-go/pull/6888) Remove `TypeClientMisbehaviour` constant and the `Type` method on `Misbehaviour`. * (light-clients/06-solomachine, light-clients/07-tendermint) [\#6891](https://github.com/cosmos/ibc-go/pull/6891) The `VerifyMembership` and `VerifyNonMembership` functions of solomachine's `ClientState` have been made private. The `VerifyMembership`, `VerifyNonMembership`, `GetTimestampAtHeight`, `Status` and `Initialize` functions of tendermint's `ClientState` have been made private. * (core/04-channel) [\#6902](https://github.com/cosmos/ibc-go/pull/6902) Add channel version to core application callbacks. +* (core/24-host) [\#6882](https://github.com/cosmos/ibc-go/issues/6882) All functions ending in `Path` have been removed from 24-host in favour of their sybling functions ending in `Key`. ### State Machine Breaking diff --git a/docs/docs/05-migrations/13-v8-to-v9.md b/docs/docs/05-migrations/13-v8-to-v9.md index e06b79e3b44..1a4e2f26820 100644 --- a/docs/docs/05-migrations/13-v8-to-v9.md +++ b/docs/docs/05-migrations/13-v8-to-v9.md @@ -20,6 +20,7 @@ There are four sections based on the four potential user groups of this document - [04-channel](#04-channel) - [05-port](#05-port) - [23-commitment](#23-commitment) + - [24-host](#24-host) - [IBC Apps](#ibc-apps) - [ICS20 - Transfer](#ics20---transfer) - [ICS20 v2](#ics20-v2) @@ -195,6 +196,10 @@ type PacketDataUnmarshaler interface { - The [`MerklePath` type](https://github.com/cosmos/ibc-go/blob/release/v9.0.x/modules/core/23-commitment/types/commitment.pb.go#L113-L119) has been deprecated and a new [`commitment.v2.MerklePath` type](https://github.com/cosmos/ibc-go/blob/release/v9.0.x/modules/core/23-commitment/types/v2/commitment.pb.go#L25-L30) has been introduced in [#6644](https://github.com/cosmos/ibc-go/pull/6644). The new `commitment.v2.MerklePath` contains `repeated bytes` in favour of `repeated string`. This allows users to prove values stored under keys which contain non-utf8 encoded symbols. As a result, changes have been made to the 02-client `Query` service and 08-wasm contract API messages for JSON blobs. See [02-client](#02-client) and [08-wasm](#08-wasm), respectively. - The `commitment.v1.MerklePath` type has been removed and a new `commitment.v2.MerklePath` type has been introduced in [#6644](https://github.com/cosmos/ibc-go/pull/6644). The new `commitment.v2.MerklePath` contains `repeated bytes` in favour of `repeated string`. This allows users to prove values stored under keys which contain non-utf8 encoded symbols. As a result, changes have been made to the 02-client `Query` service and 08-wasm contract API messages for JSON blobs. See [02-client](#02-client) and [08-wasm](#08-wasm), respectively. +### 24-host + +All functions ending with `Path` naming have been removed in favour of their sybling function which ends in `Key`. + ## IBC Apps ### ICS20 - Transfer diff --git a/modules/core/04-channel/keeper/grpc_query.go b/modules/core/04-channel/keeper/grpc_query.go index ffc70ef655c..3d03f8f9088 100644 --- a/modules/core/04-channel/keeper/grpc_query.go +++ b/modules/core/04-channel/keeper/grpc_query.go @@ -266,7 +266,7 @@ func (q *queryServer) PacketCommitments(c context.Context, req *types.QueryPacke ) } var commitments []*types.PacketState - store := prefix.NewStore(ctx.KVStore(q.storeKey), []byte(host.PacketCommitmentPrefixPath(req.PortId, req.ChannelId))) + store := prefix.NewStore(ctx.KVStore(q.storeKey), host.PacketCommitmentPrefixKey(req.PortId, req.ChannelId)) pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { keySplit := strings.Split(string(key), "/") @@ -370,7 +370,7 @@ func (q *queryServer) PacketAcknowledgements(c context.Context, req *types.Query ) } var acks []*types.PacketState - store := prefix.NewStore(ctx.KVStore(q.storeKey), []byte(host.PacketAcknowledgementPrefixPath(req.PortId, req.ChannelId))) + store := prefix.NewStore(ctx.KVStore(q.storeKey), host.PacketAcknowledgementPrefixKey(req.PortId, 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 diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index a362715230e..33f9e6d2856 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -332,7 +332,7 @@ func (k *Keeper) GetAllPacketCommitments(ctx sdk.Context) (commitments []types.P // true, the iterator will close and stop. func (k *Keeper) IteratePacketCommitmentAtChannel(ctx sdk.Context, portID, channelID string, cb func(_, _ string, sequence uint64, hash []byte) bool) { store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte(host.PacketCommitmentPrefixPath(portID, channelID))) + iterator := storetypes.KVStorePrefixIterator(store, host.PacketCommitmentPrefixKey(portID, channelID)) k.iterateHashes(ctx, iterator, cb) } @@ -629,7 +629,7 @@ func (Keeper) iterateHashes(ctx sdk.Context, iterator db.Iterator, cb func(portI // HasInflightPackets returns true if there are packet commitments stored at the specified // port and channel, and false otherwise. func (k *Keeper) HasInflightPackets(ctx sdk.Context, portID, channelID string) bool { - iterator := storetypes.KVStorePrefixIterator(ctx.KVStore(k.storeKey), []byte(host.PacketCommitmentPrefixPath(portID, channelID))) + iterator := storetypes.KVStorePrefixIterator(ctx.KVStore(k.storeKey), host.PacketCommitmentPrefixKey(portID, channelID)) defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) return iterator.Valid() diff --git a/modules/core/24-host/channel_keys.go b/modules/core/24-host/channel_keys.go index f4eb589993f..a6d3cee060c 100644 --- a/modules/core/24-host/channel_keys.go +++ b/modules/core/24-host/channel_keys.go @@ -1,21 +1,46 @@ package host +import "fmt" + +const ( + KeyChannelEndPrefix = "channelEnds" + KeyChannelPrefix = "channels" + KeyChannelUpgradePrefix = "channelUpgrades" + KeyUpgradePrefix = "upgrades" + KeyUpgradeErrorPrefix = "upgradeError" + KeyCounterpartyUpgrade = "counterpartyUpgrade" + KeyChannelCapabilityPrefix = "capabilities" +) + +// ICS04 +// The following paths are the keys to the store as defined in https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#store-paths + // ChannelKey returns the store key for a particular channel func ChannelKey(portID, channelID string) []byte { - return []byte(ChannelPath(portID, channelID)) + return []byte(fmt.Sprintf("%s/%s", KeyChannelEndPrefix, channelPath(portID, channelID))) +} + +// ChannelCapabilityPath defines the path under which capability keys associated +// with a channel are stored +func ChannelCapabilityPath(portID, channelID string) string { + return fmt.Sprintf("%s/%s", KeyChannelCapabilityPrefix, channelPath(portID, channelID)) } // ChannelUpgradeErrorKey returns the store key for a particular channelEnd used to stor the ErrorReceipt in the case that a chain does not accept the proposed upgrade func ChannelUpgradeErrorKey(portID, channelID string) []byte { - return []byte(ChannelUpgradeErrorPath(portID, channelID)) + return []byte(fmt.Sprintf("%s/%s/%s", KeyChannelUpgradePrefix, KeyUpgradeErrorPrefix, channelPath(portID, channelID))) } // ChannelUpgradeKey returns the store key for a particular channel upgrade attempt func ChannelUpgradeKey(portID, channelID string) []byte { - return []byte(ChannelUpgradePath(portID, channelID)) + return []byte(fmt.Sprintf("%s/%s/%s", KeyChannelUpgradePrefix, KeyUpgradePrefix, channelPath(portID, channelID))) } // ChannelCounterpartyUpgradeKey returns the store key for the upgrade used on the counterparty channel. func ChannelCounterpartyUpgradeKey(portID, channelID string) []byte { - return []byte(ChannelCounterpartyUpgradePath(portID, channelID)) + return []byte(fmt.Sprintf("%s/%s/%s", KeyChannelUpgradePrefix, KeyCounterpartyUpgrade, channelPath(portID, channelID))) +} + +func channelPath(portID, channelID string) string { + return fmt.Sprintf("%s/%s/%s/%s", KeyPortPrefix, portID, KeyChannelPrefix, channelID) } diff --git a/modules/core/24-host/channel_paths.go b/modules/core/24-host/channel_paths.go deleted file mode 100644 index a4a7ba6461a..00000000000 --- a/modules/core/24-host/channel_paths.go +++ /dev/null @@ -1,46 +0,0 @@ -package host - -import "fmt" - -const ( - KeyChannelEndPrefix = "channelEnds" - KeyChannelPrefix = "channels" - KeyChannelUpgradePrefix = "channelUpgrades" - KeyUpgradePrefix = "upgrades" - KeyUpgradeErrorPrefix = "upgradeError" - KeyCounterpartyUpgrade = "counterpartyUpgrade" - KeyChannelCapabilityPrefix = "capabilities" -) - -// ICS04 -// The following paths are the keys to the store as defined in https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#store-paths - -// ChannelPath defines the path under which channels are stored -func ChannelPath(portID, channelID string) string { - return fmt.Sprintf("%s/%s", KeyChannelEndPrefix, channelPath(portID, channelID)) -} - -// ChannelCapabilityPath defines the path under which capability keys associated -// with a channel are stored -func ChannelCapabilityPath(portID, channelID string) string { - return fmt.Sprintf("%s/%s", KeyChannelCapabilityPrefix, channelPath(portID, channelID)) -} - -// ChannelUpgradeErrorPath defines the path under which the ErrorReceipt is stored in the case that a chain does not accept the proposed upgrade -func ChannelUpgradeErrorPath(portID, channelID string) string { - return fmt.Sprintf("%s/%s/%s", KeyChannelUpgradePrefix, KeyUpgradeErrorPrefix, channelPath(portID, channelID)) -} - -// ChannelUpgradePath defines the path which stores the information related to an upgrade attempt -func ChannelUpgradePath(portID, channelID string) string { - return fmt.Sprintf("%s/%s/%s", KeyChannelUpgradePrefix, KeyUpgradePrefix, channelPath(portID, channelID)) -} - -// ChannelCounterpartyUpgradePath defines the path under which the upgrade used on the counterparty channel is stored. -func ChannelCounterpartyUpgradePath(portID, channelID string) string { - return fmt.Sprintf("%s/%s/%s", KeyChannelUpgradePrefix, KeyCounterpartyUpgrade, channelPath(portID, channelID)) -} - -func channelPath(portID, channelID string) string { - return fmt.Sprintf("%s/%s/%s/%s", KeyPortPrefix, portID, KeyChannelPrefix, channelID) -} diff --git a/modules/core/24-host/client_keys.go b/modules/core/24-host/client_keys.go index d2bc3260bd1..ad80cbae63a 100644 --- a/modules/core/24-host/client_keys.go +++ b/modules/core/24-host/client_keys.go @@ -1,20 +1,30 @@ package host import ( + "fmt" + "github.com/cosmos/ibc-go/v9/modules/core/exported" ) +// KeyClientStorePrefix defines the KVStore key prefix for IBC clients +var KeyClientStorePrefix = []byte("clients") + +const ( + KeyClientState = "clientState" + KeyConsensusStatePrefix = "consensusStates" +) + // FullClientKey returns the full path of specific client path in the format: // "clients/{clientID}/{path}" as a byte array. func FullClientKey(clientID string, path []byte) []byte { - return []byte(FullClientPath(clientID, string(path))) + return []byte(fmt.Sprintf("%s/%s/%s", KeyClientStorePrefix, clientID, path)) } // PrefixedClientStoreKey returns a key which can be used for prefixed // key store iteration. The prefix may be a clientType, clientID, or any // valid key prefix which may be concatenated with the client store constant. func PrefixedClientStoreKey(prefix []byte) []byte { - return []byte(PrefixedClientStorePath(prefix)) + return []byte(fmt.Sprintf("%s/%s", KeyClientStorePrefix, prefix)) } // FullClientStateKey takes a client identifier and returns a Key under which to store a @@ -32,11 +42,11 @@ func ClientStateKey() []byte { // FullConsensusStateKey returns the store key for the consensus state of a particular // client. func FullConsensusStateKey(clientID string, height exported.Height) []byte { - return []byte(FullConsensusStatePath(clientID, height)) + return FullClientKey(clientID, ConsensusStateKey(height)) } // ConsensusStateKey returns the store key for a the consensus state of a particular // client stored in a client prefixed store. func ConsensusStateKey(height exported.Height) []byte { - return []byte(ConsensusStatePath(height)) + return []byte(fmt.Sprintf("%s/%s", KeyConsensusStatePrefix, height)) } diff --git a/modules/core/24-host/client_paths.go b/modules/core/24-host/client_paths.go deleted file mode 100644 index f307a866fc0..00000000000 --- a/modules/core/24-host/client_paths.go +++ /dev/null @@ -1,49 +0,0 @@ -package host - -import ( - "fmt" - - "github.com/cosmos/ibc-go/v9/modules/core/exported" -) - -// KeyClientStorePrefix defines the KVStore key prefix for IBC clients -var KeyClientStorePrefix = []byte("clients") - -const ( - KeyClientState = "clientState" - KeyConsensusStatePrefix = "consensusStates" -) - -// FullClientPath returns the full path of a specific client path in the format: -// "clients/{clientID}/{path}" as a string. -func FullClientPath(clientID string, path string) string { - return fmt.Sprintf("%s/%s/%s", KeyClientStorePrefix, clientID, path) -} - -// PrefixedClientStorePath returns a key path which can be used for prefixed -// key store iteration. The prefix may be a clientType, clientID, or any -// valid key prefix which may be concatenated with the client store constant. -func PrefixedClientStorePath(prefix []byte) string { - return fmt.Sprintf("%s/%s", KeyClientStorePrefix, prefix) -} - -// ICS02 -// The following paths are the keys to the store as defined in https://github.com/cosmos/ibc/tree/master/spec/core/ics-002-client-semantics#path-space - -// FullClientStatePath takes a client identifier and returns a Path under which to store a -// particular client state -func FullClientStatePath(clientID string) string { - return FullClientPath(clientID, KeyClientState) -} - -// FullConsensusStatePath takes a client identifier and returns a Path under which to -// store the consensus state of a client. -func FullConsensusStatePath(clientID string, height exported.Height) string { - return FullClientPath(clientID, ConsensusStatePath(height)) -} - -// ConsensusStatePath returns the suffix store key for the consensus state at a -// particular height stored in a client prefixed store. -func ConsensusStatePath(height exported.Height) string { - return fmt.Sprintf("%s/%s", KeyConsensusStatePrefix, height) -} diff --git a/modules/core/24-host/connection_keys.go b/modules/core/24-host/connection_keys.go index 2b20e74f091..bd0b1802ccd 100644 --- a/modules/core/24-host/connection_keys.go +++ b/modules/core/24-host/connection_keys.go @@ -1,11 +1,18 @@ package host +import "fmt" + +const KeyConnectionPrefix = "connections" + +// ICS03 +// The following paths are the keys to the store as defined in https://github.com/cosmos/ibc/blob/master/spec/core/ics-003-connection-semantics#store-paths + // ClientConnectionsKey returns the store key for the connections of a given client func ClientConnectionsKey(clientID string) []byte { - return []byte(ClientConnectionsPath(clientID)) + return FullClientKey(clientID, []byte(KeyConnectionPrefix)) } // ConnectionKey returns the store key for a particular connection func ConnectionKey(connectionID string) []byte { - return []byte(ConnectionPath(connectionID)) + return []byte(fmt.Sprintf("%s/%s", KeyConnectionPrefix, connectionID)) } diff --git a/modules/core/24-host/connection_paths.go b/modules/core/24-host/connection_paths.go deleted file mode 100644 index cd362e278a6..00000000000 --- a/modules/core/24-host/connection_paths.go +++ /dev/null @@ -1,18 +0,0 @@ -package host - -import "fmt" - -const KeyConnectionPrefix = "connections" - -// ICS03 -// The following paths are the keys to the store as defined in https://github.com/cosmos/ibc/blob/master/spec/core/ics-003-connection-semantics#store-paths - -// ClientConnectionsPath defines a reverse mapping from clients to a set of connections -func ClientConnectionsPath(clientID string) string { - return FullClientPath(clientID, KeyConnectionPrefix) -} - -// ConnectionPath defines the path under which connection paths are stored -func ConnectionPath(connectionID string) string { - return fmt.Sprintf("%s/%s", KeyConnectionPrefix, connectionID) -} diff --git a/modules/core/24-host/packet_keys.go b/modules/core/24-host/packet_keys.go index 2bde2a040ac..55e7f024e41 100644 --- a/modules/core/24-host/packet_keys.go +++ b/modules/core/24-host/packet_keys.go @@ -1,47 +1,78 @@ package host +import "fmt" + +const ( + KeySequencePrefix = "sequences" + KeyNextSeqSendPrefix = "nextSequenceSend" + KeyNextSeqRecvPrefix = "nextSequenceRecv" + KeyNextSeqAckPrefix = "nextSequenceAck" + KeyPacketCommitmentPrefix = "commitments" + KeyPacketAckPrefix = "acks" + KeyPacketReceiptPrefix = "receipts" + KeyPruningSequenceStart = "pruningSequenceStart" + KeyRecvStartSequence = "recvStartSequence" +) + +// ICS04 +// The following paths are the keys to the store as defined in https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#store-paths + // NextSequenceSendKey returns the store key for the send sequence of a particular // channel binded to a specific port. func NextSequenceSendKey(portID, channelID string) []byte { - return []byte(NextSequenceSendPath(portID, channelID)) + return []byte(fmt.Sprintf("%s/%s", KeyNextSeqSendPrefix, channelPath(portID, channelID))) } // NextSequenceRecvKey returns the store key for the receive sequence of a particular // channel binded to a specific port func NextSequenceRecvKey(portID, channelID string) []byte { - return []byte(NextSequenceRecvPath(portID, channelID)) + return []byte(fmt.Sprintf("%s/%s", KeyNextSeqRecvPrefix, channelPath(portID, channelID))) } // NextSequenceAckKey returns the store key for the acknowledgement sequence of // a particular channel binded to a specific port. func NextSequenceAckKey(portID, channelID string) []byte { - return []byte(NextSequenceAckPath(portID, channelID)) + return []byte(fmt.Sprintf("%s/%s", KeyNextSeqAckPrefix, channelPath(portID, channelID))) } // PacketCommitmentKey returns the store key of under which a packet commitment // is stored func PacketCommitmentKey(portID, channelID string, sequence uint64) []byte { - return []byte(PacketCommitmentPath(portID, channelID, sequence)) + return []byte(fmt.Sprintf("%s/%d", PacketCommitmentPrefixKey(portID, channelID), sequence)) +} + +// PacketCommitmentPrefixKey defines the prefix for commitments to packet data fields store path. +func PacketCommitmentPrefixKey(portID, channelID string) []byte { + return []byte(fmt.Sprintf("%s/%s/%s", KeyPacketCommitmentPrefix, channelPath(portID, channelID), KeySequencePrefix)) } // PacketAcknowledgementKey returns the store key of under which a packet // acknowledgement is stored func PacketAcknowledgementKey(portID, channelID string, sequence uint64) []byte { - return []byte(PacketAcknowledgementPath(portID, channelID, sequence)) + return []byte(fmt.Sprintf("%s/%d", PacketAcknowledgementPrefixKey(portID, channelID), sequence)) +} + +// PacketAcknowledgementPrefixKey defines the prefix for commitments to packet data fields store path. +func PacketAcknowledgementPrefixKey(portID, channelID string) []byte { + return []byte(fmt.Sprintf("%s/%s/%s", KeyPacketAckPrefix, channelPath(portID, channelID), KeySequencePrefix)) } // PacketReceiptKey returns the store key of under which a packet // receipt is stored func PacketReceiptKey(portID, channelID string, sequence uint64) []byte { - return []byte(PacketReceiptPath(portID, channelID, sequence)) + return []byte(fmt.Sprintf("%s/%s/%s", KeyPacketReceiptPrefix, channelPath(portID, channelID), sequencePath(sequence))) } // 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)) + return []byte(fmt.Sprintf("%s/%s", KeyPruningSequenceStart, channelPath(portID, channelID))) } // RecvStartSequenceKey returns the store key for the recv start sequence of a particular channel func RecvStartSequenceKey(portID, channelID string) []byte { - return []byte(RecvStartSequencePath(portID, channelID)) + return []byte(fmt.Sprintf("%s/%s", KeyRecvStartSequence, channelPath(portID, channelID))) +} + +func sequencePath(sequence uint64) string { + return fmt.Sprintf("%s/%d", KeySequencePrefix, sequence) } diff --git a/modules/core/24-host/packet_paths.go b/modules/core/24-host/packet_paths.go deleted file mode 100644 index 99b8bf2e974..00000000000 --- a/modules/core/24-host/packet_paths.go +++ /dev/null @@ -1,72 +0,0 @@ -package host - -import "fmt" - -const ( - KeySequencePrefix = "sequences" - KeyNextSeqSendPrefix = "nextSequenceSend" - KeyNextSeqRecvPrefix = "nextSequenceRecv" - KeyNextSeqAckPrefix = "nextSequenceAck" - KeyPacketCommitmentPrefix = "commitments" - KeyPacketAckPrefix = "acks" - KeyPacketReceiptPrefix = "receipts" - KeyPruningSequenceStart = "pruningSequenceStart" - KeyRecvStartSequence = "recvStartSequence" -) - -// ICS04 -// The following paths are the keys to the store as defined in https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#store-paths - -// NextSequenceSendPath defines the next send sequence counter store path -func NextSequenceSendPath(portID, channelID string) string { - return fmt.Sprintf("%s/%s", KeyNextSeqSendPrefix, channelPath(portID, channelID)) -} - -// NextSequenceRecvPath defines the next receive sequence counter store path. -func NextSequenceRecvPath(portID, channelID string) string { - return fmt.Sprintf("%s/%s", KeyNextSeqRecvPrefix, channelPath(portID, channelID)) -} - -// NextSequenceAckPath defines the next acknowledgement sequence counter store path -func NextSequenceAckPath(portID, channelID string) string { - return fmt.Sprintf("%s/%s", KeyNextSeqAckPrefix, channelPath(portID, channelID)) -} - -// PacketCommitmentPath defines the commitments to packet data fields store path -func PacketCommitmentPath(portID, channelID string, sequence uint64) string { - return fmt.Sprintf("%s/%d", PacketCommitmentPrefixPath(portID, channelID), sequence) -} - -// PacketCommitmentPrefixPath defines the prefix for commitments to packet data fields store path. -func PacketCommitmentPrefixPath(portID, channelID string) string { - return fmt.Sprintf("%s/%s/%s", KeyPacketCommitmentPrefix, channelPath(portID, channelID), KeySequencePrefix) -} - -// PacketAcknowledgementPath defines the packet acknowledgement store path -func PacketAcknowledgementPath(portID, channelID string, sequence uint64) string { - return fmt.Sprintf("%s/%d", PacketAcknowledgementPrefixPath(portID, channelID), sequence) -} - -// PacketAcknowledgementPrefixPath defines the prefix for commitments to packet data fields store path. -func PacketAcknowledgementPrefixPath(portID, channelID string) string { - return fmt.Sprintf("%s/%s/%s", KeyPacketAckPrefix, channelPath(portID, channelID), KeySequencePrefix) -} - -// PacketReceiptPath defines the packet receipt store path -func PacketReceiptPath(portID, channelID string, sequence uint64) string { - return fmt.Sprintf("%s/%s/%s", KeyPacketReceiptPrefix, channelPath(portID, channelID), sequencePath(sequence)) -} - -// 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)) -} - -// RecvStartSequencePath defines the path under which the recv start sequence is stored -func RecvStartSequencePath(portID, channelID string) string { - return fmt.Sprintf("%s/%s", KeyRecvStartSequence, channelPath(portID, channelID)) -} - -func sequencePath(sequence uint64) string { - return fmt.Sprintf("%s/%d", KeySequencePrefix, sequence) -} diff --git a/modules/core/24-host/parse_test.go b/modules/core/24-host/parse_test.go index 37789ef0b19..e7d039be2a4 100644 --- a/modules/core/24-host/parse_test.go +++ b/modules/core/24-host/parse_test.go @@ -56,13 +56,13 @@ func TestMustParseClientStatePath(t *testing.T) { path string expPass bool }{ - {"valid", host.FullClientStatePath(ibctesting.FirstClientID), true}, + {"valid", string(host.FullClientStateKey(ibctesting.FirstClientID)), true}, {"path too large", fmt.Sprintf("clients/clients/%s/clientState", ibctesting.FirstClientID), false}, {"path too small", fmt.Sprintf("clients/%s", ibctesting.FirstClientID), false}, {"path does not begin with client store", fmt.Sprintf("cli/%s/%s", ibctesting.FirstClientID, host.KeyClientState), false}, {"path does not end with client state key", fmt.Sprintf("%s/%s/consensus", string(host.KeyClientStorePrefix), ibctesting.FirstClientID), false}, - {"client ID is empty", host.FullClientStatePath(""), false}, - {"client ID is only spaces", host.FullClientStatePath(" "), false}, + {"client ID is empty", string(host.FullClientStateKey("")), false}, + {"client ID is only spaces", string(host.FullClientStateKey(" ")), false}, } for _, tc := range testCases {