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 <cwgoes@pluranimity.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
colin axnér 2020-10-19 11:59:31 +02:00 committed by GitHub
parent 6fa73998bd
commit 0f8fdf60df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 28 deletions

View File

@ -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))

View File

@ -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]

View File

@ -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)

View File

@ -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", ""},
}

View File

@ -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 {

View File

@ -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 |