Skip to content

Commit

Permalink
imp!: removed 'ConsensusHost' interface (backport #6937) (#7057)
Browse files Browse the repository at this point in the history
* imp!: removed 'ConsensusHost' interface (#6937)

* imp(02-client,03-connection)!: remove `ValidateSelfClient` (#6853)

* imp: removed ValidateSelfClient

* docs: updated a godoc

* imp: deleted consensus host from core

* imp(08-wasm): removed consensus host

* imp: fix linter

* imp: fixed linter

* imp: fixed simapp

* imp: updated docs

* imp: removed more code

* revert

* imp: removed unneeded proto fields

* imp: lint

* lint

* imp: auto generated code

* imp: removed conflicts

* imp: removed more code

* fix: tests

* feat: all tests passing

* fix: added the reserved proto fields back with deprecation notice

* style: linted

* imp: regenerated proto

* imp: review item

* revert: conn name change

* docs: added changelog

* add godoc string of QueryConnectionHandshakeProof

* add migration docs for ibc-go

* Update CHANGELOG.md

* update changelog

* imp(proto): added deprecation notice to field

* imp: ran 'make proto-all'

* imp: removed unused keeper

* Update CHANGELOG.md

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* Update docs/docs/05-migrations/13-v8-to-v9.md

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* Update docs/docs/05-migrations/13-v8-to-v9.md

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
(cherry picked from commit 2028e9a)

# Conflicts:
#	CHANGELOG.md
#	docs/docs/01-ibc/02-integration.md
#	docs/docs/05-migrations/13-v8-to-v9.md
#	modules/core/02-client/keeper/keeper.go
#	modules/core/keeper/keeper.go
#	modules/light-clients/08-wasm/CHANGELOG.md

* fix merge conflicts, changelog, delete docs, keeper fns

---------

Co-authored-by: srdtrk <59252793+srdtrk@users.noreply.github.com>
Co-authored-by: Colin Axnér <25233464+colin-axner@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 7, 2024
1 parent 98d1edc commit ff78dea
Show file tree
Hide file tree
Showing 30 changed files with 219 additions and 1,643 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (core/types) [\#6794](https://github.com/cosmos/ibc-go/pull/6794) The composite interface `QueryServer` has been removed from package `core/types`. Please use the granular `QueryServer` interfaces provided by each core submodule.
* (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/03-connection, core/02-client) [\#6937](https://github.com/cosmos/ibc-go/pull/6937) Remove 'ConsensusHost' interface, also removing self client and consensus state validation in the connection handshake.
* (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
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/callbacks/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func NewSimApp(
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// NOTE: The mock ContractKeeper is only created for testing.
Expand Down
28 changes: 1 addition & 27 deletions modules/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
router *types.Router
consensusHost types.ConsensusHost
legacySubspace types.ParamSubspace
upgradeKeeper types.UpgradeKeeper
}

// NewKeeper creates a new NewKeeper instance
func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace types.ParamSubspace, consensusHost types.ConsensusHost, uk types.UpgradeKeeper) *Keeper {
func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace types.ParamSubspace, uk types.UpgradeKeeper) *Keeper {
router := types.NewRouter()
localhostModule := localhost.NewLightClientModule(cdc, key)
router.AddRoute(exported.Localhost, localhostModule)
Expand All @@ -42,7 +41,6 @@ func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace ty
storeKey: key,
cdc: cdc,
router: router,
consensusHost: consensusHost,
legacySubspace: legacySubspace,
upgradeKeeper: uk,
}
Expand Down Expand Up @@ -90,15 +88,6 @@ func (k *Keeper) Route(ctx sdk.Context, clientID string) (exported.LightClientMo
return clientModule, nil
}

// SetConsensusHost sets a custom ConsensusHost for self client state and consensus state validation.
func (k *Keeper) SetConsensusHost(consensusHost types.ConsensusHost) {
if consensusHost == nil {
panic(fmt.Errorf("cannot set a nil self consensus host"))
}

k.consensusHost = consensusHost
}

// GenerateClientIdentifier returns the next client identifier.
func (k *Keeper) GenerateClientIdentifier(ctx sdk.Context, clientType string) string {
nextClientSeq := k.GetNextClientSequence(ctx)
Expand Down Expand Up @@ -315,21 +304,6 @@ func (k *Keeper) GetLatestClientConsensusState(ctx sdk.Context, clientID string)
return k.GetClientConsensusState(ctx, clientID, clientModule.LatestHeight(ctx, clientID))
}

// GetSelfConsensusState introspects the (self) past historical info at a given height
// and returns the expected consensus state at that height.
// For now, can only retrieve self consensus states for the current revision
func (k *Keeper) GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) {
return k.consensusHost.GetSelfConsensusState(ctx, height)
}

// ValidateSelfClient validates the client parameters for a client of the running chain.
// This function is only used to validate the client state the counterparty stores for this chain.
// NOTE: If the client type is not of type Tendermint then delegate to a custom client validator function.
// This allows support for non-Tendermint clients, for example 08-wasm clients.
func (k *Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error {
return k.consensusHost.ValidateSelfClient(ctx, clientState)
}

// VerifyMembership retrieves the light client module for the clientID and verifies the proof of the existence of a key-value pair at a specified height.
func (k *Keeper) VerifyMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error {
clientModule, err := k.Route(ctx, clientID)
Expand Down
7 changes: 0 additions & 7 deletions modules/core/02-client/types/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
errorsmod "cosmossdk.io/errors"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"

host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
Expand All @@ -22,12 +21,6 @@ var (
_ codectypes.UnpackInterfacesMessage = (*ConsensusStateWithHeight)(nil)
)

// ConsensusHost defines an interface used to validate an IBC ClientState and ConsensusState against the host chain's underlying consensus parameters.
type ConsensusHost interface {
GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error)
ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error
}

// NewIdentifiedClientState creates a new IdentifiedClientState instance
func NewIdentifiedClientState(clientID string, clientState exported.ClientState) IdentifiedClientState {
msg, ok := clientState.(proto.Message)
Expand Down
8 changes: 0 additions & 8 deletions modules/core/02-client/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@ package types

import (
"context"
"time"

upgradetypes "cosmossdk.io/x/upgrade/types"

sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// StakingKeeper expected staking keeper
type StakingKeeper interface {
GetHistoricalInfo(ctx context.Context, height int64) (stakingtypes.HistoricalInfo, error)
UnbondingTime(ctx context.Context) (time.Duration, error)
}

// UpgradeKeeper expected upgrade keeper
type UpgradeKeeper interface {
GetUpgradePlan(ctx context.Context) (plan upgradetypes.Plan, err error)
Expand Down
15 changes: 6 additions & 9 deletions modules/core/03-connection/keeper/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ func (suite *KeeperTestSuite) TestMsgConnectionOpenTryEvents() {

suite.Require().NoError(path.EndpointB.UpdateClient())

counterpartyClient, clientProof, consensusProof, consensusHeight, initProof, proofHeight := path.EndpointB.QueryConnectionHandshakeProof()
initProof, proofHeight := path.EndpointB.QueryConnectionHandshakeProof()

msg := types.NewMsgConnectionOpenTry(
path.EndpointB.ClientID, path.EndpointB.Counterparty.ConnectionID, path.EndpointB.Counterparty.ClientID,
counterpartyClient, path.EndpointB.Counterparty.Chain.GetPrefix(), []*types.Version{ibctesting.ConnectionVersion}, path.EndpointB.ConnectionConfig.DelayPeriod,
initProof, clientProof, consensusProof,
proofHeight, consensusHeight,
path.EndpointB.Counterparty.Chain.GetPrefix(), []*types.Version{ibctesting.ConnectionVersion},
path.EndpointB.ConnectionConfig.DelayPeriod, initProof, proofHeight,
path.EndpointB.Chain.SenderAccount.GetAddress().String(),
)

Expand Down Expand Up @@ -88,13 +87,11 @@ func (suite *KeeperTestSuite) TestMsgConnectionOpenAckEvents() {

suite.Require().NoError(path.EndpointA.UpdateClient())

counterpartyClient, clientProof, consensusProof, consensusHeight, tryProof, proofHeight := path.EndpointA.QueryConnectionHandshakeProof()
tryProof, proofHeight := path.EndpointA.QueryConnectionHandshakeProof()

msg := types.NewMsgConnectionOpenAck(
path.EndpointA.ConnectionID, path.EndpointA.Counterparty.ConnectionID, counterpartyClient,
tryProof, clientProof, consensusProof,
proofHeight, consensusHeight,
ibctesting.ConnectionVersion,
path.EndpointA.ConnectionID, path.EndpointA.Counterparty.ConnectionID,
tryProof, proofHeight, ibctesting.ConnectionVersion,
path.EndpointA.Chain.SenderAccount.GetAddress().String(),
)

Expand Down
74 changes: 0 additions & 74 deletions modules/core/03-connection/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types"
ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
)

Expand Down Expand Up @@ -67,37 +66,13 @@ func (k *Keeper) ConnOpenTry(
counterparty types.Counterparty, // counterpartyConnectionIdentifier, counterpartyPrefix and counterpartyClientIdentifier
delayPeriod uint64,
clientID string, // clientID of chainA
clientState exported.ClientState, // clientState that chainA has for chainB
counterpartyVersions []*types.Version, // supported versions of chain A
initProof []byte, // proof that chainA stored connectionEnd in state (on ConnOpenInit)
clientProof []byte, // proof that chainA stored a light client of chainB
consensusProof []byte, // proof that chainA stored chainB's consensus state at consensus height
proofHeight exported.Height, // height at which relayer constructs proof of A storing connectionEnd in state
consensusHeight exported.Height, // latest height of chain B which chain A has stored in its chain B client
) (string, error) {
// generate a new connection
connectionID := k.GenerateConnectionIdentifier(ctx)

// check that the consensus height the counterparty chain is using to store a representation
// of this chain's consensus state is at a height in the past
selfHeight := clienttypes.GetSelfHeight(ctx)
if consensusHeight.GTE(selfHeight) {
return "", errorsmod.Wrapf(
ibcerrors.ErrInvalidHeight,
"consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight,
)
}

// validate client parameters of a chainB client stored on chainA
if err := k.clientKeeper.ValidateSelfClient(ctx, clientState); err != nil {
return "", err
}

expectedConsensusState, err := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight)
if err != nil {
return "", errorsmod.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String())
}

// expectedConnection defines Chain A's ConnectionEnd
// NOTE: chain A's counterparty is chain B (i.e where this code is executed)
// NOTE: chainA and chainB must have the same delay period
Expand All @@ -124,18 +99,6 @@ func (k *Keeper) ConnOpenTry(
return "", err
}

// Check that ChainA stored the clientState provided in the msg
if err := k.VerifyClientState(ctx, connection, proofHeight, clientProof, clientState); err != nil {
return "", err
}

// Check that ChainA stored the correct ConsensusState of chainB at the given consensusHeight
if err := k.VerifyClientConsensusState(
ctx, connection, proofHeight, consensusHeight, consensusProof, expectedConsensusState,
); err != nil {
return "", err
}

// store connection in chainB state
if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil {
return "", errorsmod.Wrapf(err, "failed to add connection with ID %s to client with ID %s", connectionID, clientID)
Expand All @@ -158,25 +121,11 @@ func (k *Keeper) ConnOpenTry(
func (k *Keeper) ConnOpenAck(
ctx sdk.Context,
connectionID string,
clientState exported.ClientState, // client state for chainA on chainB
version *types.Version, // version that ChainB chose in ConnOpenTry
counterpartyConnectionID string,
tryProof []byte, // proof that connectionEnd was added to ChainB state in ConnOpenTry
clientProof []byte, // proof of client state on chainB for chainA
consensusProof []byte, // proof that chainB has stored ConsensusState of chainA on its client
proofHeight exported.Height, // height that relayer constructed proofTry
consensusHeight exported.Height, // latest height of chainA that chainB has stored on its chainA client
) error {
// check that the consensus height the counterparty chain is using to store a representation
// of this chain's consensus state is at a height in the past
selfHeight := clienttypes.GetSelfHeight(ctx)
if consensusHeight.GTE(selfHeight) {
return errorsmod.Wrapf(
ibcerrors.ErrInvalidHeight,
"consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight,
)
}

// Retrieve connection
connection, found := k.GetConnection(ctx, connectionID)
if !found {
Expand All @@ -199,17 +148,6 @@ func (k *Keeper) ConnOpenAck(
)
}

// validate client parameters of a chainA client stored on chainB
if err := k.clientKeeper.ValidateSelfClient(ctx, clientState); err != nil {
return err
}

// Retrieve chainA's consensus state at consensusheight
expectedConsensusState, err := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight)
if err != nil {
return errorsmod.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String())
}

prefix := k.GetCommitmentPrefix()
expectedCounterparty := types.NewCounterparty(connection.ClientId, connectionID, commitmenttypes.NewMerklePrefix(prefix.Bytes()))
expectedConnection := types.NewConnectionEnd(types.TRYOPEN, connection.Counterparty.ClientId, expectedCounterparty, []*types.Version{version}, connection.DelayPeriod)
Expand All @@ -222,18 +160,6 @@ func (k *Keeper) ConnOpenAck(
return err
}

// Check that ChainB stored the clientState provided in the msg
if err := k.VerifyClientState(ctx, connection, proofHeight, clientProof, clientState); err != nil {
return err
}

// Ensure that ChainB has stored the correct ConsensusState for chainA at the consensusHeight
if err := k.VerifyClientConsensusState(
ctx, connection, proofHeight, consensusHeight, consensusProof, expectedConsensusState,
); err != nil {
return err
}

k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", types.INIT, "new-state", types.OPEN)

defer telemetry.IncrCounter(1, "ibc", "connection", "open-ack")
Expand Down
Loading

0 comments on commit ff78dea

Please sign in to comment.