Skip to content

Commit

Permalink
Move channel back to counterparty (#7842)
Browse files Browse the repository at this point in the history
* add back client registerCounterparty

* change channel to id in packet

* fix tests

* split messaging key to prefix and clientId

* change eureka packet handlers to no longer rely on channel

* naming suggestions

* fix test file

* start to fix tests

* fix v2/keeper tests

* fix tests

* DELETE channel from v2

* rm commented code

* move nextSeqSend to a better place

* remove resolveV2Identifiers for now

* lint

* lint

* review suggestions

* Update cli.go
  • Loading branch information
AdityaSripal authored Jan 17, 2025
1 parent 20a54f2 commit b3184b4
Show file tree
Hide file tree
Showing 57 changed files with 2,434 additions and 6,405 deletions.
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
},
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),
},
}
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) {
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) {
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 {
return CounterpartyInfo{
MerklePrefix: merklePrefix,
ClientId: clientID,
}
}
Loading

0 comments on commit b3184b4

Please sign in to comment.