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

Allow for optimistic channel handshake #2919

Merged
merged 9 commits into from
Jan 19, 2023
Merged

Conversation

ancazamfir
Copy link
Collaborator

@ancazamfir ancazamfir commented Dec 5, 2022

Closes: #2910

Description

Assuming channel mode is enabled in the hermes configuration.

For the case where a channel is initialized with a connection that is not opened, the approach in this PR is:

  • if connection mode is not enabled do not run optimistic channel handshake. This is the same as current behavior.
  • if both connection and channel modes are enabled the channel handshake will be triggered and the retry mechanism waits for connection to be established.

The main changes relative to the current implementation:

  1. supervisor spawns channel workers on channel events when:
    • current: channel mode is enabled and connection is opened
    • proposal: channel mode is enabled and either connection is opened or connection mode is enabled
  2. if both connection and channel modes are enabled, supervisor scans in-progress connection and starts channel workers if channels have been optimistically initialized for those connections
  3. channel worker retry strategy is changed to be based on the max block time of the two chains and allow connection handshake to finalize over 10 blocks. This is the same strategy used during the CLI triggered handshake (i.e. hermes create channel ...)

Test Case for 1 that occurs during this sequence (hermes start creates workers from events):

hermes create client --host-chain ibc-0 --reference-chain ibc-1
hermes create client --host-chain ibc-1 --reference-chain ibc-0
hermes start
hermes tx conn-init --dst-chain ibc-0 --src-chain ibc-1 --dst-client 07-tendermint-0 --src-client 07-tendermint-0
hermes tx chan-open-init --dst-chain ibc-0 --src-chain ibc-1 --dst-connection connection-0 --dst-port transfer --src-port transfer

Test Case for 2 that occurs during this sequence (hermes start creates workers from scanned state):

hermes create client --host-chain ibc-0 --reference-chain ibc-1
hermes create client --host-chain ibc-1 --reference-chain ibc-0
hermes tx conn-init --dst-chain ibc-0 --src-chain ibc-1 --dst-client 07-tendermint-0 --src-client 07-tendermint-0
hermes tx chan-open-init --dst-chain ibc-0 --src-chain ibc-1 --dst-connection connection-0 --dst-port transfer --src-port transfer
hermes start

Tests:

  • Manual tests for Case 1 and Case 2
    • with connection and channel mode enabled: channel is opened
    • with connection mode disabled, channel mode enabled: channel stays in init state
  • Integration test for Case 2 with connection and channel mode enabled: channel is eventually opened

Notes: CI fails due to #3006


PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests: integration (for Hermes) or unit/mock tests (for modules).
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).
  • Tagged one reviewer who will be the one responsible for shepherding this PR.

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

@ancazamfir ancazamfir marked this pull request as ready for review January 5, 2023 22:07
@romac
Copy link
Member

romac commented Jan 6, 2023

What's the best way to test this?

@ancazamfir
Copy link
Collaborator Author

What's the best way to test this?

Sorry I should have mentioned. I start two chains, create clients, connection and channel in INIT state then start the relayer. The config has connection and channel mode enabled. Here are the commands:

hermes create client --host-chain ibc-0 --reference-chain ibc-1
hermes create client --host-chain ibc-1 --reference-chain ibc-0
hermes tx conn-init --dst-chain ibc-0 --src-chain ibc-1 --dst-client 07-tendermint-0 --src-client 07-tendermint-0
hermes tx chan-open-init --dst-chain ibc-0 --src-chain ibc-1 --dst-connection connection-0 --dst-port transfer --src-port transfer
hermes start

Let hermes run for a bit then check the channel and connection states and make sure they are opened.
We should write some integration tests for this.

@romac
Copy link
Member

romac commented Jan 9, 2023

We should write some integration tests for this.

@ancazamfir I am happy to take care of this if you want?

@ancazamfir
Copy link
Collaborator Author

We should write some integration tests for this.

@ancazamfir I am happy to take care of this if you want?

That would be great! I just committed something I had locally if you want to take it from there, or just discard and rewrite.

@ancazamfir
Copy link
Collaborator Author

I just found that in the case hermes is started before the chan-open-init step things won't work. I think restoring channel from event also needs some changes.
Will move back to draft until I figure it out.

@ancazamfir ancazamfir marked this pull request as draft January 10, 2023 05:07
@ancazamfir ancazamfir marked this pull request as ready for review January 17, 2023 13:16
Copy link
Member

@romac romac left a comment

Choose a reason for hiding this comment

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

Fantastic!

@romac romac merged commit 65beac1 into master Jan 19, 2023
@romac romac deleted the anca/2910_opt_ch_handshake branch January 19, 2023 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for optimistic channel handshake initiation from the state machine
2 participants