Skip to content

Commit

Permalink
Remove ClientType func and update consensus state path (#7573)
Browse files Browse the repository at this point in the history
* update paths and remove unused func

* fix bug

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Christopher Goes <cwgoes@pluranimity.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
4 people committed Oct 19, 2020
1 parent 6fa7399 commit 0f8fdf6
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 28 deletions.
3 changes: 2 additions & 1 deletion x/ibc/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"fmt"
"strings"

"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/<clientID>/consensusState/<height>"
if len(keySplit) != 4 || keySplit[2] != "consensusState" {
// consensus key is in the format "clients/<clientID>/consensusStates/<height>"
if len(keySplit) != 4 || keySplit[2] != string(host.KeyConsensusStatesPrefix) {
continue
}
clientID := keySplit[1]
Expand Down
3 changes: 0 additions & 3 deletions x/ibc/core/02-client/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions x/ibc/core/02-client/simulation/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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),
Expand All @@ -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", ""},
}
Expand Down
18 changes: 4 additions & 14 deletions x/ibc/core/24-host/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,28 +65,17 @@ 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
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 {
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/core/spec/02_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down

0 comments on commit 0f8fdf6

Please sign in to comment.