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

Move channel back to counterparty #7842

Merged
merged 19 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions modules/apps/transfer/v2/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,20 @@ func (suite *KeeperTestSuite) TestMsgRecvPacketTransfer() {
nil,
},
{
"failure: invalid destination channel on received packet",
"failure: invalid destination client on received packet",
func() {},
func() {
packet.DestinationChannel = ibctesting.InvalidID
packet.DestinationClient = ibctesting.InvalidID
},
channeltypesv2.ErrChannelNotFound,
clienttypes.ErrCounterpartyNotFound,
},
{
"failure: counter party channel does not match source channel",
"failure: counter party client does not match source client",
func() {},
func() {
packet.SourceChannel = ibctesting.InvalidID
packet.SourceClient = ibctesting.InvalidID
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit of a nit, but I don't get why we don't just add the ID to all these names? If we're dealing with the ID, and we use that name in most other contexts, why not keep it consistent and always refer to it as SourceClientID and so on?

},
channeltypes.ErrInvalidChannelIdentifier,
clienttypes.ErrInvalidCounterparty,
},
{
"failure: receive is disabled",
Expand Down Expand Up @@ -335,15 +335,15 @@ func (suite *KeeperTestSuite) TestMsgRecvPacketTransfer() {
if expPass {
suite.Require().NoError(err)

actualAckHash := suite.chainB.GetSimApp().IBCKeeper.ChannelKeeperV2.GetPacketAcknowledgement(suite.chainB.GetContext(), packet.DestinationChannel, packet.Sequence)
actualAckHash := suite.chainB.GetSimApp().IBCKeeper.ChannelKeeperV2.GetPacketAcknowledgement(suite.chainB.GetContext(), packet.DestinationClient, packet.Sequence)
expectedHash := channeltypesv2.CommitAcknowledgement(expectedAck)

suite.Require().Equal(expectedHash, actualAckHash)

denom := transfertypes.Denom{
Base: sdk.DefaultBondDenom,
Trace: []transfertypes.Hop{
transfertypes.NewHop(sendPayload.DestinationPort, packet.DestinationChannel),
transfertypes.NewHop(sendPayload.DestinationPort, packet.DestinationClient),
},
}

Expand Down Expand Up @@ -593,7 +593,7 @@ func (suite *KeeperTestSuite) TestV2RetainsFungibility() {
denomBtoC := transfertypes.Denom{
Base: sdk.DefaultBondDenom,
Trace: []transfertypes.Hop{
transfertypes.NewHop(transfertypes.ModuleName, pathv2.EndpointB.ChannelID),
transfertypes.NewHop(transfertypes.ModuleName, pathv2.EndpointB.ClientID),
transfertypes.NewHop(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID),
Comment on lines +596 to 597
Copy link
Member Author

Choose a reason for hiding this comment

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

First hop used IBC Classic, second hop used IBC Eureka

},
}
Expand Down
41 changes: 41 additions & 0 deletions modules/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,47 @@ func (k *Keeper) SetClientState(ctx context.Context, clientID string, clientStat
store.Set(host.ClientStateKey(), types.MustMarshalClientState(k.cdc, clientState))
}

// GetClientCreator returns the creator of a client
func (k *Keeper) GetClientCreator(ctx context.Context, clientID string) sdk.AccAddress {
store := k.ClientStore(ctx, clientID)
bz := store.Get(types.CreatorKey())
if len(bz) == 0 {
return nil
}
return sdk.AccAddress(bz)
}

// SetClientCreator sets the creator of a client
func (k *Keeper) SetClientCreator(ctx context.Context, clientID string, creator sdk.AccAddress) {
store := k.ClientStore(ctx, clientID)
store.Set(types.CreatorKey(), creator.Bytes())
}

// DeleteClientCreator deletes the creator of a client
func (k *Keeper) DeleteClientCreator(ctx context.Context, clientID string) {
store := k.ClientStore(ctx, clientID)
store.Delete(types.CreatorKey())
}

// SetClientCounterparty sets counterpartyInfo for a given clientID
func (k *Keeper) SetClientCounterparty(ctx context.Context, clientID string, counterparty types.CounterpartyInfo) {
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
store := k.ClientStore(ctx, clientID)
store.Set(types.CounterpartyKey(), k.cdc.MustMarshal(&counterparty))
}

// GetClientCounterparty gets counterpartyInfo for a given clientID
func (k *Keeper) GetClientCounterparty(ctx context.Context, clientID string) (types.CounterpartyInfo, bool) {
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
store := k.ClientStore(ctx, clientID)
bz := store.Get(types.CounterpartyKey())
if len(bz) == 0 {
return types.CounterpartyInfo{}, false
}

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

// GetClientConsensusState gets the stored consensus state from a client at a given height.
func (k *Keeper) GetClientConsensusState(ctx context.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) {
store := k.ClientStore(ctx, clientID)
Expand Down
19 changes: 19 additions & 0 deletions modules/core/02-client/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,25 @@ func (suite *KeeperTestSuite) TestSetClientState() {
suite.Require().Equal(clientState, retrievedState, "Client states are not equal")
}

func (suite *KeeperTestSuite) TestSetClientCreator() {
creator := suite.chainA.SenderAccount.GetAddress()
suite.keeper.SetClientCreator(suite.ctx, testClientID, creator)
getCreator := suite.keeper.GetClientCreator(suite.ctx, testClientID)
suite.Require().Equal(creator, getCreator)
suite.keeper.DeleteClientCreator(suite.ctx, testClientID)
getCreator = suite.keeper.GetClientCreator(suite.ctx, testClientID)
suite.Require().Equal(sdk.AccAddress(nil), getCreator)
}

func (suite *KeeperTestSuite) TestSetClientCounterparty() {
counterparty := types.NewCounterpartyInfo([][]byte{[]byte("ibc"), []byte("channel-7")}, testClientID2)
suite.keeper.SetClientCounterparty(suite.ctx, testClientID, counterparty)

retrievedCounterparty, found := suite.keeper.GetClientCounterparty(suite.ctx, testClientID)
suite.Require().True(found, "GetCounterparty failed")
suite.Require().Equal(counterparty, retrievedCounterparty, "Counterparties are not equal")
}

func (suite *KeeperTestSuite) TestSetClientConsensusState() {
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, suite.consensusState)

Expand Down
1 change: 1 addition & 0 deletions modules/core/02-client/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func RegisterInterfaces(registry coreregistry.InterfaceRegistrar) {
&MsgRecoverClient{},
&MsgIBCSoftwareUpgrade{},
&MsgUpdateParams{},
&MsgRegisterCounterparty{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Expand Down
9 changes: 9 additions & 0 deletions modules/core/02-client/types/counterparty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package types

// NewCounterpartyInfo creates a new counterparty info instance from merlePrefix and clientID
func NewCounterpartyInfo(merklePrefix [][]byte, clientID string) CounterpartyInfo {
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
return CounterpartyInfo{
MerklePrefix: merklePrefix,
ClientId: clientID,
}
}
Loading
Loading