Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Aliasing the v1 channels to v2 counterparty so that v1 channels can support v2 packets #7174

Draft
wants to merge 10 commits into
base: feat/ibc-eureka
Choose a base branch
from
2 changes: 2 additions & 0 deletions e2e/testsuite/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
packetservertypes "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types"
solomachine "github.com/cosmos/ibc-go/v9/modules/light-clients/06-solomachine"
ibctmtypes "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
Expand Down Expand Up @@ -69,6 +70,7 @@ func codecAndEncodingConfig() (*codec.ProtoCodec, testutil.TestEncodingConfig) {
connectiontypes.RegisterInterfaces(cfg.InterfaceRegistry)
ibctmtypes.RegisterInterfaces(cfg.InterfaceRegistry)
wasmtypes.RegisterInterfaces(cfg.InterfaceRegistry)
packetservertypes.RegisterInterfaces(cfg.InterfaceRegistry)

// all other types
upgradetypes.RegisterInterfaces(cfg.InterfaceRegistry)
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 @@ -409,7 +409,7 @@ func NewSimApp(
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.PacketServer = packetserverkeeper.NewKeeper(appCodec, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper)
app.PacketServer = packetserverkeeper.NewKeeper(appCodec, keys[ibcexported.StoreKey], app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper)

// NOTE: The mock ContractKeeper is only created for testing.
// Real applications should not use the mock ContractKeeper
Expand Down
2 changes: 1 addition & 1 deletion modules/core/02-client/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewTxCmd() *cobra.Command {
newUpgradeClientCmd(),
newSubmitRecoverClientProposalCmd(),
newScheduleIBCUpgradeProposalCmd(),
newProvideCounterpartyCmd(),
// newProvideCounterpartyCmd(),
)

return txCmd
Expand Down
68 changes: 34 additions & 34 deletions modules/core/02-client/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,40 +455,40 @@ func newScheduleIBCUpgradeProposalCmd() *cobra.Command {
}

// newProvideCounterpartyCmd defines the command to provide the counterparty to an IBC client.
func newProvideCounterpartyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "provide-counterparty [client-identifier] [counterparty-client-identifier] [counterparty-merkle-path-prefix]",
Args: cobra.ExactArgs(3),
Short: "provide the counterparty to an IBC client",
Long: `Provide the counterparty to an IBC client specified by its client ID.
The [counterparty-merkle-path-prefix] is a comma-separated list of hex-encoded strings.`,
Example: fmt.Sprintf("%s tx %s %s provide-counterparty 07-tendermint-0 07-tendermint-1 696263,657572656b61", version.AppName, exported.ModuleName, types.SubModuleName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

clientIdentifier := args[0]
counterpartyClientIdentifier := args[1]
counterpartyMerklePathPrefix, err := parseMerklePathPrefix(args[2])
if err != nil {
return err
}

counterparty := types.NewCounterparty(counterpartyClientIdentifier, counterpartyMerklePathPrefix)
msg := types.MsgProvideCounterparty{
ClientId: clientIdentifier,
Counterparty: counterparty,
Signer: clientCtx.GetFromAddress().String(),
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}
// func newProvideCounterpartyCmd() *cobra.Command {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented out this for now because in this PR MsgProvideCounterparty has changed and needs more information from the CLI to fill it all in.

// cmd := &cobra.Command{
// Use: "provide-counterparty [client-identifier] [counterparty-client-identifier] [counterparty-merkle-path-prefix]",
// Args: cobra.ExactArgs(3),
// Short: "provide the counterparty to an IBC client",
// Long: `Provide the counterparty to an IBC client specified by its client ID.
// The [counterparty-merkle-path-prefix] is a comma-separated list of hex-encoded strings.`,
// Example: fmt.Sprintf("%s tx %s %s provide-counterparty 07-tendermint-0 07-tendermint-1 696263,657572656b61", version.AppName, exported.ModuleName, types.SubModuleName),
// RunE: func(cmd *cobra.Command, args []string) error {
// clientCtx, err := client.GetClientTxContext(cmd)
// if err != nil {
// return err
// }

// clientIdentifier := args[0]
// counterpartyClientIdentifier := args[1]
// counterpartyMerklePathPrefix, err := parseMerklePathPrefix(args[2])
// if err != nil {
// return err
// }

// counterparty := types.NewCounterparty(counterpartyClientIdentifier, counterpartyMerklePathPrefix)
// msg := types.MsgProvideCounterparty{
// ClientId: clientIdentifier,
// Counterparty: counterparty,
// Signer: clientCtx.GetFromAddress().String(),
// }
// return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
// },
// }

// flags.AddTxFlagsToCmd(cmd)
// return cmd
// }

// parseMerklePathPrefix parses a comma-separated list of hex-encoded strings into a MerklePath.
func parseMerklePathPrefix(merklePathPrefixString string) (commitmenttypesv2.MerklePath, error) {
Expand Down
4 changes: 2 additions & 2 deletions modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ func (q *queryServer) Client(ctx context.Context, req *types.QueryClientRequest)
creator, _ := q.GetCreator(sdkCtx, req.ClientId)
res.Creator = creator

counterparty, _ := q.GetCounterparty(sdkCtx, req.ClientId)
res.Counterparty = counterparty
// counterparty, _ := q.GetCounterparty(sdkCtx, req.ClientId)
// res.Counterparty = counterparty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented this also out because there is a circular dependency in the pb.go file between 02-client and packet-server types.


return &res, nil
}
18 changes: 9 additions & 9 deletions modules/core/02-client/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -957,9 +957,9 @@ func (suite *KeeperTestSuite) TestQueryVerifyMembershipProof() {

func (suite *KeeperTestSuite) TestQueryClient() {
var (
req *types.QueryClientRequest
expCreator string
expCounterparty types.Counterparty
req *types.QueryClientRequest
expCreator string
// expCounterparty types.Counterparty
)

testCases := []struct {
Expand All @@ -972,7 +972,7 @@ func (suite *KeeperTestSuite) TestQueryClient() {
func() {
ctx := suite.chainA.GetContext()
suite.chainA.App.GetIBCKeeper().ClientKeeper.SetCreator(ctx, ibctesting.FirstClientID, expCreator)
suite.chainA.App.GetIBCKeeper().ClientKeeper.SetCounterparty(ctx, ibctesting.FirstClientID, expCounterparty)
// suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetCounterparty(ctx, ibctesting.FirstClientID, expCounterparty)

req = &types.QueryClientRequest{
ClientId: ibctesting.FirstClientID,
Expand All @@ -985,7 +985,7 @@ func (suite *KeeperTestSuite) TestQueryClient() {
func() {
expCreator = ""

suite.chainA.App.GetIBCKeeper().ClientKeeper.SetCounterparty(suite.chainA.GetContext(), ibctesting.FirstClientID, expCounterparty)
// suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetCounterparty(suite.chainA.GetContext(), ibctesting.FirstClientID, expCounterparty)

req = &types.QueryClientRequest{
ClientId: ibctesting.FirstClientID,
Expand All @@ -996,7 +996,7 @@ func (suite *KeeperTestSuite) TestQueryClient() {
{
"success: no counterparty",
func() {
expCounterparty = types.Counterparty{}
// expCounterparty = packetservertypes.Counterparty{}

suite.chainA.App.GetIBCKeeper().ClientKeeper.SetCreator(suite.chainA.GetContext(), ibctesting.FirstClientID, expCreator)

Expand Down Expand Up @@ -1029,8 +1029,8 @@ func (suite *KeeperTestSuite) TestQueryClient() {
suite.SetupTest() // reset

expCreator = ibctesting.TestAccAddress
merklePathPrefix := commitmenttypes.NewMerklePath([]byte("prefix"))
expCounterparty = types.Counterparty{ClientId: ibctesting.SecondClientID, MerklePathPrefix: merklePathPrefix}
// merklePathPrefix := commitmenttypes.NewMerklePath([]byte("prefix"))
// expCounterparty = types.Counterparty{ClientId: ibctesting.SecondClientID, MerklePathPrefix: merklePathPrefix}

tc.malleate()

Expand All @@ -1042,7 +1042,7 @@ func (suite *KeeperTestSuite) TestQueryClient() {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(expCreator, res.Creator)
suite.Require().Equal(expCounterparty, res.Counterparty)
// suite.Require().Equal(expCounterparty, res.Counterparty)
} else {
suite.Require().ErrorIs(err, tc.expError)
suite.Require().Nil(res)
Expand Down
19 changes: 0 additions & 19 deletions modules/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,25 +304,6 @@ func (k *Keeper) GetLatestClientConsensusState(ctx sdk.Context, clientID string)
return k.GetClientConsensusState(ctx, clientID, clientModule.LatestHeight(ctx, clientID))
}

// SetCounterparty sets the Counterparty for a given client identifier.
func (k *Keeper) SetCounterparty(ctx sdk.Context, clientID string, counterparty types.Counterparty) {
bz := k.cdc.MustMarshal(&counterparty)
k.ClientStore(ctx, clientID).Set([]byte(types.CounterpartyKey), bz)
}

// GetCounterparty gets the Counterparty for a given client identifier.
func (k *Keeper) GetCounterparty(ctx sdk.Context, clientID string) (types.Counterparty, bool) {
store := k.ClientStore(ctx, clientID)
bz := store.Get([]byte(types.CounterpartyKey))
if len(bz) == 0 {
return types.Counterparty{}, false
}

var counterparty types.Counterparty
k.cdc.MustUnmarshal(bz, &counterparty)
return counterparty, true
}

// GetCreator returns the creator of the client.
func (k *Keeper) GetCreator(ctx sdk.Context, clientID string) (string, bool) {
bz := k.ClientStore(ctx, clientID).Get([]byte(types.CreatorKey))
Expand Down
17 changes: 0 additions & 17 deletions modules/core/02-client/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,6 @@ func (suite *KeeperTestSuite) TestSetClientState() {
suite.Require().Equal(clientState, retrievedState, "Client states are not equal")
}

func (suite *KeeperTestSuite) TestSetCounterparty() {
merklePathPrefix := commitmenttypes.NewMerklePath([]byte("ibc"), []byte(""))
counterparty := types.Counterparty{
ClientId: testClientID,
MerklePathPrefix: merklePathPrefix,
}
suite.keeper.SetCounterparty(suite.ctx, testClientID, counterparty)

retrievedCounterparty, found := suite.keeper.GetCounterparty(suite.ctx, testClientID)
suite.Require().True(found, "GetCounterparty does not return counterparty")
suite.Require().Equal(counterparty, retrievedCounterparty, "Counterparty retrieved not equal")

retrievedCounterparty, found = suite.keeper.GetCounterparty(suite.ctx, "client-0")
suite.Require().False(found, "GetCounterparty unexpectedly returned a counterparty")
suite.Require().Equal(types.Counterparty{}, retrievedCounterparty, "Counterparty retrieved not empty")
}

func (suite *KeeperTestSuite) TestSetCreator() {
clientID := ibctesting.FirstClientID
expectedCreator := "test-creator"
Expand Down
22 changes: 0 additions & 22 deletions modules/core/02-client/types/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

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

commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
)
Expand Down Expand Up @@ -65,27 +64,6 @@ func (ics IdentifiedClientStates) Sort() IdentifiedClientStates {
return ics
}

// NewCounterparty creates a new Counterparty instance
func NewCounterparty(clientID string, merklePathPrefix commitmenttypes.MerklePath) Counterparty {
return Counterparty{
ClientId: clientID,
MerklePathPrefix: merklePathPrefix,
}
}

// Validate validates the Counterparty
func (c Counterparty) Validate() error {
if err := host.ClientIdentifierValidator(c.ClientId); err != nil {
return err
}

if err := c.MerklePathPrefix.ValidateAsPrefix(); err != nil {
return errorsmod.Wrap(ErrInvalidCounterparty, err.Error())
}

return nil
}

// NewConsensusStateWithHeight creates a new ConsensusStateWithHeight instance
func NewConsensusStateWithHeight(height Height, consensusState exported.ConsensusState) ConsensusStateWithHeight {
msg, ok := consensusState.(proto.Message)
Expand Down
Loading
Loading