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 1 commit
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: 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
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
Loading