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

remove GetConnectionIdFromICAPort, use connection ID from host zone #1179

Merged
merged 5 commits into from
Apr 15, 2024
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
4 changes: 3 additions & 1 deletion app/apptesting/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,11 @@ func (s *AppTestHelper) MockICAChannel(connectionId, channelId, owner, address s
// Create an open channel with the ICA port
portId, _ := icatypes.NewControllerPortID(owner)
channel := channeltypes.Channel{
State: channeltypes.OPEN,
State: channeltypes.OPEN,
ConnectionHops: []string{connectionId},
}
s.App.IBCKeeper.ChannelKeeper.SetChannel(s.Ctx, portId, channelId, channel)
s.App.IBCKeeper.ConnectionKeeper.SetConnection(s.Ctx, connectionId, connectiontypes.ConnectionEnd{})

// Then set the address and make the channel active
s.App.ICAControllerKeeper.SetInterchainAccountAddress(s.Ctx, connectionId, portId, address)
Expand Down
18 changes: 2 additions & 16 deletions x/stakeibc/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,12 @@ import (
"github.com/cosmos/gogoproto/proto"
"github.com/spf13/cast"

icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"

"github.com/Stride-Labs/stride/v21/utils"
recordstypes "github.com/Stride-Labs/stride/v21/x/records/types"
"github.com/Stride-Labs/stride/v21/x/stakeibc/types"
)

func (k Keeper) DelegateOnHost(ctx sdk.Context, hostZone types.HostZone, amt sdk.Coin, depositRecord recordstypes.DepositRecord) error {
// TODO: Remove this block and use connection-id from host zone
sampocs marked this conversation as resolved.
Show resolved Hide resolved
// the relevant ICA is the delegate account
owner := types.FormatHostZoneICAOwner(hostZone.ChainId, types.ICAAccountType_DELEGATION)
portID, err := icatypes.NewControllerPortID(owner)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "%s has no associated portId", owner)
}
connectionId, found := k.GetConnectionIdFromICAPortId(ctx, portID)
if !found {
return errorsmod.Wrapf(types.ErrICAAccountNotFound, "unable to find ICA connection Id for port %s", portID)
}

// Fetch the relevant ICA
if hostZone.DelegationIcaAddress == "" {
return errorsmod.Wrapf(types.ErrICAAccountNotFound, "no delegation account found for %s", hostZone.ChainId)
Expand Down Expand Up @@ -79,9 +65,9 @@ func (k Keeper) DelegateOnHost(ctx sdk.Context, hostZone types.HostZone, amt sdk
}

// Send the transaction through SubmitTx
_, err = k.SubmitTxsStrideEpoch(ctx, connectionId, msgs, types.ICAAccountType_DELEGATION, ICACallbackID_Delegate, marshalledCallbackArgs)
_, err = k.SubmitTxsStrideEpoch(ctx, hostZone.ConnectionId, msgs, types.ICAAccountType_DELEGATION, ICACallbackID_Delegate, marshalledCallbackArgs)
if err != nil {
return errorsmod.Wrapf(err, "Failed to SubmitTxs for connectionId %s on %s. Messages: %s", connectionId, hostZone.ChainId, msgs)
return errorsmod.Wrapf(err, "Failed to SubmitTxs for connectionId %s on %s. Messages: %s", hostZone.ConnectionId, hostZone.ChainId, msgs)
}
k.Logger(ctx).Info(utils.LogWithHostZone(hostZone.ChainId, "ICA MsgDelegates Successfully Sent"))

Expand Down
9 changes: 4 additions & 5 deletions x/stakeibc/keeper/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ import (
)

func (k Keeper) OnChanOpenAck(ctx sdk.Context, portID, channelID string) error {
// Lookup the ICA address and chainId from the port and connection
controllerConnectionId, found := k.GetConnectionIdFromICAPortId(ctx, portID)
if !found {
k.Logger(ctx).Info(fmt.Sprintf("portId %s has no associated ICA account", portID))
return nil
// Lookup connection ID, counterparty chain ID, and ICA address from the channel ID
controllerConnectionId, _, err := k.IBCKeeper.ChannelKeeper.GetChannelConnection(ctx, portID, channelID)
sampocs marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
address, found := k.ICAControllerKeeper.GetInterchainAccountAddress(ctx, controllerConnectionId, portID)
if !found {
Expand Down
7 changes: 3 additions & 4 deletions x/stakeibc/keeper/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ func (s *KeeperTestSuite) TestOnChanOpenAck() {
tradeOwner := types.FormatTradeRouteICAOwner(tradeChainId, RewardDenom, HostDenom, types.ICAAccountType_CONVERTER_TRADE)
tradePortId, _ := icatypes.NewControllerPortID(tradeOwner)

// Mock out an ICA address for each
s.App.ICAControllerKeeper.SetInterchainAccountAddress(s.Ctx, delegationConnectionId, delegationPortId, delegationAddress)
s.App.ICAControllerKeeper.SetInterchainAccountAddress(s.Ctx, tradeConnectionId, tradePortId, tradeAddress)
// Mock out the relevant clients, channels, and ICA addresses so the callback can map back to the relevant info
s.MockICAChannel(delegationConnectionId, delegationChannelId, delegationOwner, delegationAddress)
s.MockICAChannel(tradeConnectionId, tradeChannelId, tradeOwner, tradeAddress)

// Mock out a client and connection for each channel so the callback can map back from portId to chainId
s.MockClientAndConnection(delegationChainId, delegationClientId, delegationConnectionId)
s.MockClientAndConnection(tradeChainId, tradeClientId, tradeConnectionId)

Expand Down
16 changes: 2 additions & 14 deletions x/stakeibc/keeper/interchainaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ const (
)

func (k Keeper) SetWithdrawalAddressOnHost(ctx sdk.Context, hostZone types.HostZone) error {
// TODO: Remove this block and use connection-id from host zone
// The relevant ICA is the delegate account
owner := types.FormatHostZoneICAOwner(hostZone.ChainId, types.ICAAccountType_DELEGATION)
portID, err := icatypes.NewControllerPortID(owner)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "%s has no associated portId", owner)
}
connectionId, found := k.GetConnectionIdFromICAPortId(ctx, portID)
if !found {
return errorsmod.Wrapf(types.ErrICAAccountNotFound, "unable to find ICA connection Id for port %s", portID)
}

// Fetch the relevant ICA
if hostZone.DelegationIcaAddress == "" {
k.Logger(ctx).Error(fmt.Sprintf("Zone %s is missing a delegation address!", hostZone.ChainId))
Expand All @@ -56,9 +44,9 @@ func (k Keeper) SetWithdrawalAddressOnHost(ctx sdk.Context, hostZone types.HostZ
WithdrawAddress: hostZone.WithdrawalIcaAddress,
},
}
_, err = k.SubmitTxsStrideEpoch(ctx, connectionId, msgs, types.ICAAccountType_DELEGATION, "", nil)
_, err := k.SubmitTxsStrideEpoch(ctx, hostZone.ConnectionId, msgs, types.ICAAccountType_DELEGATION, "", nil)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to SubmitTxs for %s, %s, %s", connectionId, hostZone.ChainId, msgs)
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to SubmitTxs for %s, %s, %s", hostZone.ConnectionId, hostZone.ChainId, msgs)
}

return nil
Expand Down
11 changes: 0 additions & 11 deletions x/stakeibc/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,6 @@ func (k Keeper) GetAuthority() string {
return k.authority
}

// Searches all interchain accounts and finds the connection ID that corresponds with a given port ID
func (k Keeper) GetConnectionIdFromICAPortId(ctx sdk.Context, portId string) (connectionId string, found bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For ICA controllers I see how the port is unique but what about for transfer channels where the port is always 'transfer'
How was this reverse lookup function working before?

icas := k.ICAControllerKeeper.GetAllInterchainAccounts(ctx)
for _, ica := range icas {
if ica.PortId == portId {
return ica.ConnectionId, true
}
}
return "", false
}

func (k Keeper) GetICATimeoutNanos(ctx sdk.Context, epochType string) (uint64, error) {
epochTracker, found := k.GetEpochTracker(ctx, epochType)
if !found {
Expand Down
8 changes: 4 additions & 4 deletions x/stakeibc/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1994,15 +1994,15 @@ func (s *KeeperTestSuite) SetupTestCreateTradeRoute() (msg types.MsgCreateTradeR
minSwapAmount := sdkmath.NewInt(100)
maxSwapAmount := sdkmath.NewInt(1_000)

// Mock out connections for the reward an trade chain so that an ICA registration can be submitted
s.MockClientAndConnection(rewardChainId, "07-tendermint-0", rewardConnectionId)
s.MockClientAndConnection(tradeChainId, "07-tendermint-1", tradeConnectionId)

// Register an exisiting ICA account for the unwind ICA to test that
// existing accounts are re-used
owner := types.FormatTradeRouteICAOwner(rewardChainId, RewardDenom, HostDenom, types.ICAAccountType_CONVERTER_UNWIND)
s.MockICAChannel(rewardConnectionId, "channel-0", owner, unwindAddress)

// Mock out connections for the reward an trade chain so that an ICA registration can be submitted
s.MockClientAndConnection(rewardChainId, "07-tendermint-0", rewardConnectionId)
s.MockClientAndConnection(tradeChainId, "07-tendermint-1", tradeConnectionId)

// Create a host zone with an exisiting withdrawal address
hostZone := types.HostZone{
ChainId: HostChainId,
Expand Down
Loading