From 0f8fdf60dfee893a7c5edfa444293b62e2ada7d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 19 Oct 2020 11:59:31 +0200 Subject: [PATCH] Remove ClientType func and update consensus state path (#7573) * update paths and remove unused func * fix bug Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Christopher Goes Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- x/ibc/core/02-client/keeper/grpc_query.go | 3 ++- x/ibc/core/02-client/keeper/keeper.go | 4 ++-- x/ibc/core/02-client/simulation/decoder.go | 3 --- .../core/02-client/simulation/decoder_test.go | 6 ------ x/ibc/core/24-host/keys.go | 18 ++++-------------- x/ibc/core/spec/02_state.md | 4 ++-- 6 files changed, 10 insertions(+), 28 deletions(-) diff --git a/x/ibc/core/02-client/keeper/grpc_query.go b/x/ibc/core/02-client/keeper/grpc_query.go index ba9429264ee0..eeb3c10b8f5b 100644 --- a/x/ibc/core/02-client/keeper/grpc_query.go +++ b/x/ibc/core/02-client/keeper/grpc_query.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" "strings" "google.golang.org/grpc/codes" @@ -151,7 +152,7 @@ func (q Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusStat ctx := sdk.UnwrapSDKContext(c) consensusStates := []types.ConsensusStateWithHeight{} - store := prefix.NewStore(ctx.KVStore(q.storeKey), host.FullKeyClientPath(req.ClientId, []byte("consensusState/"))) + store := prefix.NewStore(ctx.KVStore(q.storeKey), host.FullKeyClientPath(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatesPrefix)))) pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { height, err := types.ParseHeight(string(key)) diff --git a/x/ibc/core/02-client/keeper/keeper.go b/x/ibc/core/02-client/keeper/keeper.go index 2b03b7622d50..68220db8af59 100644 --- a/x/ibc/core/02-client/keeper/keeper.go +++ b/x/ibc/core/02-client/keeper/keeper.go @@ -90,8 +90,8 @@ func (k Keeper) IterateConsensusStates(ctx sdk.Context, cb func(clientID string, defer iterator.Close() for ; iterator.Valid(); iterator.Next() { keySplit := strings.Split(string(iterator.Key()), "/") - // consensus key is in the format "clients//consensusState/" - if len(keySplit) != 4 || keySplit[2] != "consensusState" { + // consensus key is in the format "clients//consensusStates/" + if len(keySplit) != 4 || keySplit[2] != string(host.KeyConsensusStatesPrefix) { continue } clientID := keySplit[1] diff --git a/x/ibc/core/02-client/simulation/decoder.go b/x/ibc/core/02-client/simulation/decoder.go index c5c1f72fe94d..a5cff11d42c5 100644 --- a/x/ibc/core/02-client/simulation/decoder.go +++ b/x/ibc/core/02-client/simulation/decoder.go @@ -27,9 +27,6 @@ func NewDecodeStore(cdc ClientUnmarshaler, kvA, kvB kv.Pair) (string, bool) { clientStateB := cdc.MustUnmarshalClientState(kvB.Value) return fmt.Sprintf("ClientState A: %v\nClientState B: %v", clientStateA, clientStateB), true - case bytes.HasPrefix(kvA.Key, host.KeyClientStorePrefix) && bytes.HasSuffix(kvA.Key, host.KeyClientType()): - return fmt.Sprintf("Client type A: %s\nClient type B: %s", string(kvA.Value), string(kvB.Value)), true - case bytes.HasPrefix(kvA.Key, host.KeyClientStorePrefix) && bytes.Contains(kvA.Key, []byte("consensusState")): consensusStateA := cdc.MustUnmarshalConsensusState(kvA.Value) consensusStateB := cdc.MustUnmarshalConsensusState(kvB.Value) diff --git a/x/ibc/core/02-client/simulation/decoder_test.go b/x/ibc/core/02-client/simulation/decoder_test.go index e3b80549f430..6ee442eabfce 100644 --- a/x/ibc/core/02-client/simulation/decoder_test.go +++ b/x/ibc/core/02-client/simulation/decoder_test.go @@ -13,7 +13,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" host "github.com/cosmos/cosmos-sdk/x/ibc/core/24-host" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types" - ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing" ) func TestDecodeStore(t *testing.T) { @@ -36,10 +35,6 @@ func TestDecodeStore(t *testing.T) { Key: host.FullKeyClientPath(clientID, host.KeyClientState()), Value: app.IBCKeeper.ClientKeeper.MustMarshalClientState(clientState), }, - { - Key: host.FullKeyClientPath(clientID, host.KeyClientType()), - Value: []byte(ibctesting.Tendermint), - }, { Key: host.FullKeyClientPath(clientID, host.KeyConsensusState(height)), Value: app.IBCKeeper.ClientKeeper.MustMarshalConsensusState(consState), @@ -55,7 +50,6 @@ func TestDecodeStore(t *testing.T) { expectedLog string }{ {"ClientState", fmt.Sprintf("ClientState A: %v\nClientState B: %v", clientState, clientState)}, - {"client type", fmt.Sprintf("Client type A: %s\nClient type B: %s", ibctesting.Tendermint, ibctesting.Tendermint)}, {"ConsensusState", fmt.Sprintf("ConsensusState A: %v\nConsensusState B: %v", consState, consState)}, {"other", ""}, } diff --git a/x/ibc/core/24-host/keys.go b/x/ibc/core/24-host/keys.go index d266d2516162..50249552c0ec 100644 --- a/x/ibc/core/24-host/keys.go +++ b/x/ibc/core/24-host/keys.go @@ -22,8 +22,9 @@ const ( // KVStore key prefixes for IBC var ( - KeyClientStorePrefix = []byte("clients") - KeyConnectionPrefix = []byte("connections") + KeyClientStorePrefix = []byte("clients") + KeyConsensusStatesPrefix = []byte("consensusStates") + KeyConnectionPrefix = []byte("connections") ) // KVStore key prefixes for IBC @@ -64,16 +65,10 @@ func ClientStatePath() string { return "clientState" } -// ClientTypePath takes an Identifier and returns Path under which to store the -// type of a particular client. -func ClientTypePath() string { - return "clientType" -} - // ConsensusStatePath takes an Identifier and returns a Path under which to // store the consensus state of a client. func ConsensusStatePath(height exported.Height) string { - return fmt.Sprintf("consensusState/%s", height) + return fmt.Sprintf("%s/%s", KeyConsensusStatesPrefix, height) } // KeyClientState returns the store key for a particular client state @@ -81,11 +76,6 @@ func KeyClientState() []byte { return []byte(ClientStatePath()) } -// KeyClientType returns the store key for type of a particular client -func KeyClientType() []byte { - return []byte(ClientTypePath()) -} - // KeyConsensusState returns the store key for the consensus state of a particular // client func KeyConsensusState(height exported.Height) []byte { diff --git a/x/ibc/core/spec/02_state.md b/x/ibc/core/spec/02_state.md index 4f4b5a1a393d..a5381a735c82 100644 --- a/x/ibc/core/spec/02_state.md +++ b/x/ibc/core/spec/02_state.md @@ -9,8 +9,8 @@ a prefix to the path to be able to aggregate the values for querying purposes. | Prefix | Path | Value type | |--------|------------------------------------------------------------------------|----------------| -| "0/" | "clients/{identifier}" | ClientState | -| "0/" | "clients/{identifier}/consensusState/{height}" | ConsensusState | +| "0/" | "clients/{identifier}/clientState" | ClientState | +| "0/" | "clients/{identifier}/consensusStates/{height}" | ConsensusState | | "0/" | "clients/{identifier}/type" | ClientType | | "0/" | "connections/{identifier}" | ConnectionEnd | | "0/" | "ports/{identifier}" | CapabilityKey |