Skip to content

Commit

Permalink
Merge branch 'master' into sahith/add-community-spend
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored May 14, 2020
2 parents ef7caf7 + 48aebed commit 3d51357
Show file tree
Hide file tree
Showing 75 changed files with 1,105 additions and 1,212 deletions.
6 changes: 6 additions & 0 deletions types/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ var (
// ErrorInvalidGasAdjustment defines an error for an invalid gas adjustment
ErrorInvalidGasAdjustment = Register(RootCodespace, 25, "invalid gas adjustment")

// ErrInvalidHeight defines an error for an invalid height
ErrInvalidHeight = Register(RootCodespace, 26, "invalid height")

// ErrInvalidVersion defines a general error for an invalid version
ErrInvalidVersion = Register(RootCodespace, 27, "invalid version")

// ErrPanic is only set when we recover from a panic, so we know to
// redact potentially sensitive system info
ErrPanic = Register(UndefinedCodespace, 111222, "panic")
Expand Down
6 changes: 3 additions & 3 deletions x/ibc/02-client/client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)

// QueryAllClientStates returns all the light client states. It _does not_ return
Expand Down Expand Up @@ -44,7 +44,7 @@ func QueryClientState(
) (types.StateResponse, error) {
req := abci.RequestQuery{
Path: "store/ibc/key",
Data: prefixClientKey(clientID, ibctypes.KeyClientState()),
Data: prefixClientKey(clientID, host.KeyClientState()),
Prove: prove,
}

Expand Down Expand Up @@ -72,7 +72,7 @@ func QueryConsensusState(

req := abci.RequestQuery{
Path: "store/ibc/key",
Data: prefixClientKey(clientID, ibctypes.KeyConsensusState(height)),
Data: prefixClientKey(clientID, host.KeyConsensusState(height)),
Prove: prove,
}

Expand Down
22 changes: 11 additions & 11 deletions x/ibc/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

Expand All @@ -37,13 +37,13 @@ func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, sk types.StakingKeeper) Keepe

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", ibctypes.ModuleName, types.SubModuleName))
return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", host.ModuleName, types.SubModuleName))
}

// GetClientState gets a particular client from the store
func (k Keeper) GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool) {
store := k.ClientStore(ctx, clientID)
bz := store.Get(ibctypes.KeyClientState())
bz := store.Get(host.KeyClientState())
if bz == nil {
return nil, false
}
Expand All @@ -57,13 +57,13 @@ func (k Keeper) GetClientState(ctx sdk.Context, clientID string) (exported.Clien
func (k Keeper) SetClientState(ctx sdk.Context, clientState exported.ClientState) {
store := k.ClientStore(ctx, clientState.GetID())
bz := k.cdc.MustMarshalBinaryBare(clientState)
store.Set(ibctypes.KeyClientState(), bz)
store.Set(host.KeyClientState(), bz)
}

// GetClientType gets the consensus type for a specific client
func (k Keeper) GetClientType(ctx sdk.Context, clientID string) (exported.ClientType, bool) {
store := k.ClientStore(ctx, clientID)
bz := store.Get(ibctypes.KeyClientType())
bz := store.Get(host.KeyClientType())
if bz == nil {
return 0, false
}
Expand All @@ -74,13 +74,13 @@ func (k Keeper) GetClientType(ctx sdk.Context, clientID string) (exported.Client
// SetClientType sets the specific client consensus type to the provable store
func (k Keeper) SetClientType(ctx sdk.Context, clientID string, clientType exported.ClientType) {
store := k.ClientStore(ctx, clientID)
store.Set(ibctypes.KeyClientType(), []byte{byte(clientType)})
store.Set(host.KeyClientType(), []byte{byte(clientType)})
}

// GetClientConsensusState gets the stored consensus state from a client at a given height.
func (k Keeper) GetClientConsensusState(ctx sdk.Context, clientID string, height uint64) (exported.ConsensusState, bool) {
store := k.ClientStore(ctx, clientID)
bz := store.Get(ibctypes.KeyConsensusState(height))
bz := store.Get(host.KeyConsensusState(height))
if bz == nil {
return nil, false
}
Expand All @@ -95,15 +95,15 @@ func (k Keeper) GetClientConsensusState(ctx sdk.Context, clientID string, height
func (k Keeper) SetClientConsensusState(ctx sdk.Context, clientID string, height uint64, consensusState exported.ConsensusState) {
store := k.ClientStore(ctx, clientID)
bz := k.cdc.MustMarshalBinaryBare(consensusState)
store.Set(ibctypes.KeyConsensusState(height), bz)
store.Set(host.KeyConsensusState(height), bz)
}

// IterateConsensusStates provides an iterator over all stored consensus states.
// objects. For each State object, cb will be called. If the cb returns true,
// the iterator will close and stop.
func (k Keeper) IterateConsensusStates(ctx sdk.Context, cb func(clientID string, cs exported.ConsensusState) bool) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, ibctypes.KeyClientStorePrefix)
iterator := sdk.KVStorePrefixIterator(store, host.KeyClientStorePrefix)

defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
Expand Down Expand Up @@ -163,7 +163,7 @@ func (k Keeper) GetAllConsensusStates(ctx sdk.Context) (clientConsStates []types
// client at the given height
func (k Keeper) HasClientConsensusState(ctx sdk.Context, clientID string, height uint64) bool {
store := k.ClientStore(ctx, clientID)
return store.Has(ibctypes.KeyConsensusState(height))
return store.Has(host.KeyConsensusState(height))
}

// GetLatestClientConsensusState gets the latest ConsensusState stored for a given client
Expand Down Expand Up @@ -211,7 +211,7 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height uint64) (exported.
// the iterator will close and stop.
func (k Keeper) IterateClients(ctx sdk.Context, cb func(exported.ClientState) bool) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, ibctypes.KeyClientStorePrefix)
iterator := sdk.KVStorePrefixIterator(store, host.KeyClientStorePrefix)

defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/02-client/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
import (
"fmt"

ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)

// IBC client events
Expand All @@ -18,5 +18,5 @@ var (
EventTypeUpdateClient = "update_client"
EventTypeSubmitMisbehaviour = "client_misbehaviour"

AttributeValueCategory = fmt.Sprintf("%s_%s", ibctypes.ModuleName, SubModuleName)
AttributeValueCategory = fmt.Sprintf("%s_%s", host.ModuleName, SubModuleName)
)
6 changes: 3 additions & 3 deletions x/ibc/02-client/types/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)

// query routes supported by the IBC client Querier
Expand Down Expand Up @@ -48,7 +48,7 @@ func NewClientStateResponse(
return StateResponse{
ClientState: clientState,
Proof: commitmenttypes.MerkleProof{Proof: proof},
ProofPath: commitmenttypes.NewMerklePath(append([]string{clientID}, strings.Split(ibctypes.ClientStatePath(), "/")...)),
ProofPath: commitmenttypes.NewMerklePath(append([]string{clientID}, strings.Split(host.ClientStatePath(), "/")...)),
ProofHeight: uint64(height),
}
}
Expand All @@ -69,7 +69,7 @@ func NewConsensusStateResponse(
return ConsensusStateResponse{
ConsensusState: cs,
Proof: commitmenttypes.MerkleProof{Proof: proof},
ProofPath: commitmenttypes.NewMerklePath(append([]string{clientID}, strings.Split(ibctypes.ClientStatePath(), "/")...)),
ProofPath: commitmenttypes.NewMerklePath(append([]string{clientID}, strings.Split(host.ClientStatePath(), "/")...)),
ProofHeight: uint64(height),
}
}
5 changes: 5 additions & 0 deletions x/ibc/03-connection/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const (
QueryAllConnections = types.QueryAllConnections
QueryAllClientConnections = types.QueryAllClientConnections
QueryClientConnections = types.QueryClientConnections
UNINITIALIZED = types.UNINITIALIZED
INIT = types.INIT
TRYOPEN = types.TRYOPEN
OPEN = types.OPEN
)

var (
Expand Down Expand Up @@ -64,6 +68,7 @@ var (
type (
Keeper = keeper.Keeper
End = types.ConnectionEnd
State = types.State
Counterparty = types.Counterparty
ClientKeeper = types.ClientKeeper
MsgConnectionOpenInit = types.MsgConnectionOpenInit
Expand Down
6 changes: 3 additions & 3 deletions x/ibc/03-connection/client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)

// QueryAllConnections returns all the connections. It _does not_ return
Expand Down Expand Up @@ -45,7 +45,7 @@ func QueryConnection(
) (types.ConnectionResponse, error) {
req := abci.RequestQuery{
Path: "store/ibc/key",
Data: ibctypes.KeyConnection(connectionID),
Data: host.KeyConnection(connectionID),
Prove: prove,
}

Expand Down Expand Up @@ -94,7 +94,7 @@ func QueryClientConnections(
) (types.ClientConnectionsResponse, error) {
req := abci.RequestQuery{
Path: "store/ibc/key",
Data: ibctypes.KeyClientConnections(clientID),
Data: host.KeyClientConnections(clientID),
Prove: prove,
}

Expand Down
3 changes: 1 addition & 2 deletions x/ibc/03-connection/exported/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package exported

import (
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)

// ConnectionI describes the required methods for a connection.
type ConnectionI interface {
GetState() ibctypes.State
GetID() string
GetClientID() string
GetState() int32
GetCounterparty() CounterpartyI
GetVersions() []string
ValidateBasic() error
Expand Down
29 changes: 14 additions & 15 deletions x/ibc/03-connection/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)

// ConnOpenInit initialises a connection attempt on chain A.
Expand All @@ -28,7 +27,7 @@ func (k Keeper) ConnOpenInit(
}

// connection defines chain A's ConnectionEnd
connection := types.NewConnectionEnd(ibctypes.INIT, connectionID, clientID, counterparty, types.GetCompatibleVersions())
connection := types.NewConnectionEnd(types.INIT, connectionID, clientID, counterparty, types.GetCompatibleVersions())
k.SetConnection(ctx, connectionID, connection)

if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil {
Expand Down Expand Up @@ -57,7 +56,7 @@ func (k Keeper) ConnOpenTry(
consensusHeight uint64, // latest height of chain B which chain A has stored in its chain B client
) error {
if consensusHeight > uint64(ctx.BlockHeight()) {
return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "invalid consensus height")
return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "invalid consensus height")
}

expectedConsensusState, found := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight)
Expand All @@ -69,14 +68,14 @@ func (k Keeper) ConnOpenTry(
// NOTE: chain A's counterparty is chain B (i.e where this code is executed)
prefix := k.GetCommitmentPrefix()
expectedCounterparty := types.NewCounterparty(clientID, connectionID, commitmenttypes.NewMerklePrefix(prefix.Bytes()))
expectedConnection := types.NewConnectionEnd(ibctypes.INIT, counterparty.ConnectionID, counterparty.ClientID, expectedCounterparty, counterpartyVersions)
expectedConnection := types.NewConnectionEnd(types.INIT, counterparty.ConnectionID, counterparty.ClientID, expectedCounterparty, counterpartyVersions)

// chain B picks a version from Chain A's available versions that is compatible
// with the supported IBC versions
version := types.PickVersion(counterpartyVersions, types.GetCompatibleVersions())

// connection defines chain B's ConnectionEnd
connection := types.NewConnectionEnd(ibctypes.UNINITIALIZED, connectionID, clientID, counterparty, []string{version})
connection := types.NewConnectionEnd(types.UNINITIALIZED, connectionID, clientID, counterparty, []string{version})

// Check that ChainA committed expectedConnectionEnd to its state
if err := k.VerifyConnectionState(
Expand All @@ -97,7 +96,7 @@ func (k Keeper) ConnOpenTry(
// is chainA and connection is on INIT stage
// Check that existing connection version is on desired version of current handshake
previousConnection, found := k.GetConnection(ctx, connectionID)
if found && !(previousConnection.State == ibctypes.INIT &&
if found && !(previousConnection.State == types.INIT &&
previousConnection.Counterparty.ConnectionID == counterparty.ConnectionID &&
bytes.Equal(previousConnection.Counterparty.Prefix.Bytes(), counterparty.Prefix.Bytes()) &&
previousConnection.ClientID == clientID &&
Expand All @@ -107,7 +106,7 @@ func (k Keeper) ConnOpenTry(
}

// Set connection state to TRYOPEN and store in chainB state
connection.State = ibctypes.TRYOPEN
connection.State = types.TRYOPEN
if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil {
return sdkerrors.Wrap(err, "cannot relay connection attempt")
}
Expand All @@ -132,7 +131,7 @@ func (k Keeper) ConnOpenAck(
) error {
// Check that chainB client hasn't stored invalid height
if consensusHeight > uint64(ctx.BlockHeight()) {
return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "invalid consensus height")
return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "invalid consensus height")
}

// Retrieve connection
Expand All @@ -142,7 +141,7 @@ func (k Keeper) ConnOpenAck(
}

// Check connection on ChainA is on correct state: INIT or TRYOPEN
if connection.State != ibctypes.INIT && connection.State != ibctypes.TRYOPEN {
if connection.State != types.INIT && connection.State != types.TRYOPEN {
return sdkerrors.Wrapf(
types.ErrInvalidConnectionState,
"connection state is not INIT (got %s)", connection.State.String(),
Expand All @@ -152,7 +151,7 @@ func (k Keeper) ConnOpenAck(
// Check that ChainB's proposed version is one of chainA's accepted versions
if types.LatestVersion(connection.Versions) != version {
return sdkerrors.Wrapf(
ibctypes.ErrInvalidVersion,
sdkerrors.ErrInvalidVersion,
"connection version does't match provided one (%s ≠ %s)", types.LatestVersion(connection.Versions), version,
)
}
Expand All @@ -165,7 +164,7 @@ func (k Keeper) ConnOpenAck(

prefix := k.GetCommitmentPrefix()
expectedCounterparty := types.NewCounterparty(connection.ClientID, connectionID, commitmenttypes.NewMerklePrefix(prefix.Bytes()))
expectedConnection := types.NewConnectionEnd(ibctypes.TRYOPEN, connection.Counterparty.ConnectionID, connection.Counterparty.ClientID, expectedCounterparty, []string{version})
expectedConnection := types.NewConnectionEnd(types.TRYOPEN, connection.Counterparty.ConnectionID, connection.Counterparty.ClientID, expectedCounterparty, []string{version})

// Ensure that ChainB stored expected connectionEnd in its state during ConnOpenTry
if err := k.VerifyConnectionState(
Expand All @@ -183,7 +182,7 @@ func (k Keeper) ConnOpenAck(
}

// Update connection state to Open
connection.State = ibctypes.OPEN
connection.State = types.OPEN
connection.Versions = []string{version}
k.SetConnection(ctx, connectionID, connection)
k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: INIT -> OPEN ", connectionID))
Expand All @@ -207,7 +206,7 @@ func (k Keeper) ConnOpenConfirm(
}

// Check that connection state on ChainB is on state: TRYOPEN
if connection.State != ibctypes.TRYOPEN {
if connection.State != types.TRYOPEN {
return sdkerrors.Wrapf(
types.ErrInvalidConnectionState,
"connection state is not TRYOPEN (got %s)", connection.State.String(),
Expand All @@ -216,7 +215,7 @@ func (k Keeper) ConnOpenConfirm(

prefix := k.GetCommitmentPrefix()
expectedCounterparty := types.NewCounterparty(connection.ClientID, connectionID, commitmenttypes.NewMerklePrefix(prefix.Bytes()))
expectedConnection := types.NewConnectionEnd(ibctypes.OPEN, connection.Counterparty.ConnectionID, connection.Counterparty.ClientID, expectedCounterparty, connection.Versions)
expectedConnection := types.NewConnectionEnd(types.OPEN, connection.Counterparty.ConnectionID, connection.Counterparty.ClientID, expectedCounterparty, connection.Versions)

// Check that connection on ChainA is open
if err := k.VerifyConnectionState(
Expand All @@ -227,7 +226,7 @@ func (k Keeper) ConnOpenConfirm(
}

// Update ChainB's connection to Open
connection.State = ibctypes.OPEN
connection.State = types.OPEN
k.SetConnection(ctx, connectionID, connection)
k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: TRYOPEN -> OPEN ", connectionID))
return nil
Expand Down
Loading

0 comments on commit 3d51357

Please sign in to comment.