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

Conversation

sampocs
Copy link
Collaborator

@sampocs sampocs commented Apr 13, 2024

Context

There are a couple issues with how the connection ID is handled that prevents the re-registering of a host zone after it's been unregistered. This is primarily relevant for testnet, but also indicates a flaw in the current logic.

Namely the issues are:

  • The function GetConnectionIdFromICAPort returns the first connection ID that matches the port ID - but there can be more than one connection with a given port ID
  • The connection ID for the Delegation and SetWithdrawalAddress ICA's is pulled from the above function instead of from the connection ID on the host zone
  • The OnChanOpenAck callback uses the above erroneous function which prevents registering ICAs on a new connection (since it will always match to the old expired connection)

Brief Changelog

  • Removed GetConnectionIdFromICAPort
  • Used ConnnectionId from host zone in Delegation and SetWithdrawalAddress ICAs
  • Used GetConnectionFromChannel in place of the removed function in the OnChanOpenAck callback

@sampocs sampocs force-pushed the sam/connection-id-reference branch from c919a4a to 0180e14 Compare April 13, 2024 01:15
@sampocs sampocs changed the title Sam/connection id reference remove GetConnectionIdFromICAPort, use connection ID from host zone Apr 13, 2024
@riley-stride
Copy link
Contributor

Nice to get rid of those blocks of unnecessary code!

Do we need changes to ICAs that are submitted via submittxs to ICAs that are not the delegate acct? E.g. the ICA to the withdrawal acct that sweep rewards (submitted in FeeBalanceCallback)

As long as we address that question and integration test this I'm signed off

@sampocs
Copy link
Collaborator Author

sampocs commented Apr 14, 2024

Do we need changes to ICAs that are submitted via submittxs to ICAs that are not the delegate acct? E.g. the ICA to the withdrawal acct that sweep rewards (submitted in FeeBalanceCallback)

@riley-stride sorry can you say more on this question / point to a specific example?

I think all other references just grab the connection ID from the host zone (e.g. fee balance callback)

@riley-stride
Copy link
Contributor

Do we need changes to ICAs that are submitted via submittxs to ICAs that are not the delegate acct? E.g. the ICA to the withdrawal acct that sweep rewards (submitted in FeeBalanceCallback)

@riley-stride sorry can you say more on this question / point to a specific example?

I think all other references just grab the connection ID from the host zone (e.g. fee balance callback)

Resolved in Slack with
"There’s only one connection ID per host zone - and each ICA channel belongs to that same connection. So the delegation and withdrawal ICA accounts/channels, share the same connection".

I'm signed off.

@asalzmann
Copy link
Contributor

asalzmann commented Apr 15, 2024

I thought each ICA had its own connection?

If there's just one connection per host zone, this makes sense.

[EDIT]
In RegisterHostZone, we pass in the zone's connection id when registering new ICAs, so it looks like the connection id is shared across accounts

@sampocs
Copy link
Collaborator Author

sampocs commented Apr 15, 2024

Each ICA has it's own channel - and all channels are on the same connection.

example

Copy link
Contributor

@asalzmann asalzmann left a comment

Choose a reason for hiding this comment

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

The function GetConnectionIdFromICAPort returns the first connection ID that matches the port ID - but there can be more than one connection with a given port ID

What's the scenario where there are two connections associated with an ICA port ID? Is it due to migrating the connection on an active host zone?

Copy link
Contributor

@shellvish shellvish left a comment

Choose a reason for hiding this comment

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

This looks great to me! This is a great catch, it's quite an edge case.

I'm surprised we use the port_id->connection_id lookup when the connection_id is so readily available, but on-board with changing it now.

x/stakeibc/keeper/delegation.go Show resolved Hide resolved
@sampocs
Copy link
Collaborator Author

sampocs commented Apr 15, 2024

What's the scenario where there are two connections associated with an ICA port ID? Is it due to migrating the connection on an active host zone?

Yeah the use case would be if a light client expired for a host and we had to update the connection. Hope to god we never have to worry about this on mainnet, but it already happened on testnet with dydx unfortunately :(

@sampocs sampocs merged commit e31df3a into main Apr 15, 2024
10 checks passed
Copy link
Contributor

@ethan-stride ethan-stride left a comment

Choose a reason for hiding this comment

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

LGTM
Much simplified, these Mocks are going to help testing in the future because in unit tests I often had to do the exact type of reverse lookups you now have built in.

@@ -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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants