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 5 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
8 changes: 4 additions & 4 deletions modules/apps/transfer/v2/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,15 @@ func (suite *KeeperTestSuite) TestMsgRecvPacketTransfer() {
"failure: invalid destination channel on received packet",
func() {},
func() {
packet.DestinationChannel = ibctesting.InvalidID
packet.DestinationId = ibctesting.InvalidID
},
channeltypesv2.ErrChannelNotFound,
},
{
"failure: counter party channel does not match source channel",
func() {},
func() {
packet.SourceChannel = ibctesting.InvalidID
packet.SourceId = ibctesting.InvalidID
},
channeltypes.ErrInvalidChannelIdentifier,
},
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.DestinationId, 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.DestinationId),
},
}

Expand Down
39 changes: 39 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,45 @@ 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())
}

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))
}

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
8 changes: 8 additions & 0 deletions modules/core/02-client/types/counterparty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package types

func NewCounterpartyInfo(merklePrefix [][]byte, clientId string) CounterpartyInfo {

Check failure on line 3 in modules/core/02-client/types/counterparty.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: func parameter clientId should be clientID (revive)

Check failure on line 3 in modules/core/02-client/types/counterparty.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: func parameter clientId should be clientID (revive)
return CounterpartyInfo{
MerklePrefix: merklePrefix,
ClientId: clientId,
}
}
Loading
Loading