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

fix: support chain identifiers without {chain_name}-{revision_number} pattern #941

Merged
merged 42 commits into from
Nov 6, 2023

Conversation

rnbguy
Copy link
Collaborator

@rnbguy rnbguy commented Nov 1, 2023

Closes: #940
Closes: #943

Description

ibc-go allows a hardcoded revision number for a chain-id without revision number.

Currently, ibc-rs requires all chain-ids to have a revision number. This PR allows ChainId struct to accept chain ID strings without revision numbers.

This PR also adds an optimized implementation for validate_length_prefix.


PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests.
  • 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).

@rnbguy rnbguy requested a review from Farhad-Shabani November 1, 2023 14:57
Copy link

codecov bot commented Nov 1, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (553bc79) 67.65% compared to head (091f291) 67.84%.
Report is 2 commits behind head on main.

❗ Current head 091f291 differs from pull request most recent head 5782666. Consider uploading reports for the commit 5782666 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #941      +/-   ##
==========================================
+ Coverage   67.65%   67.84%   +0.18%     
==========================================
  Files         130      130              
  Lines       16415    16431      +16     
==========================================
+ Hits        11106    11147      +41     
+ Misses       5309     5284      -25     
Files Coverage Δ
...s/ibc/src/clients/ics07_tendermint/client_state.rs 74.31% <100.00%> (ø)
...ibc/src/core/ics02_client/handler/update_client.rs 96.33% <ø> (ø)
...src/core/ics03_connection/handler/conn_open_ack.rs 94.56% <100.00%> (ø)
...src/core/ics03_connection/handler/conn_open_try.rs 91.26% <100.00%> (ø)
crates/ibc/src/mock/context.rs 72.81% <100.00%> (ø)
crates/ibc/src/mock/ics18_relayer/context.rs 65.00% <ø> (ø)
crates/ibc/src/core/ics24_host/identifier.rs 68.10% <98.30%> (+1.86%) ⬆️
...tes/ibc/src/core/ics24_host/identifier/validate.rs 96.66% <50.00%> (-3.34%) ⬇️

... and 8 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Farhad-Shabani Farhad-Shabani left a comment

Choose a reason for hiding this comment

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

Thanks @rnbguy for taking care of this 🙏🏻
Since the ChainId's data structure has changed here and other changes are related, let's go over that first:

crates/ibc/src/core/ics24_host/identifier.rs Outdated Show resolved Hide resolved
@rnbguy rnbguy changed the title fix: use optional revision number in ChainId fix: handle ChainIds without revision numbers Nov 2, 2023
crates/ibc/src/core/ics24_host/identifier.rs Outdated Show resolved Hide resolved
crates/ibc/src/core/ics24_host/identifier.rs Outdated Show resolved Hide resolved
crates/ibc/src/core/ics24_host/identifier.rs Outdated Show resolved Hide resolved
crates/ibc/src/core/ics24_host/identifier.rs Outdated Show resolved Hide resolved
crates/ibc/src/core/ics24_host/identifier.rs Show resolved Hide resolved
@rnbguy rnbguy self-assigned this Nov 3, 2023
Copy link

codecov bot commented Nov 3, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (553bc79) 67.65% compared to head (94ede00) 67.89%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #941      +/-   ##
==========================================
+ Coverage   67.65%   67.89%   +0.23%     
==========================================
  Files         130      130              
  Lines       16415    16449      +34     
==========================================
+ Hits        11106    11168      +62     
+ Misses       5309     5281      -28     
Files Coverage Δ
...s/ibc/src/clients/ics07_tendermint/client_state.rs 74.31% <100.00%> (ø)
...ibc/src/core/ics02_client/handler/update_client.rs 96.33% <ø> (ø)
...src/core/ics03_connection/handler/conn_open_ack.rs 94.56% <100.00%> (ø)
...src/core/ics03_connection/handler/conn_open_try.rs 91.26% <100.00%> (ø)
crates/ibc/src/core/ics24_host/identifier.rs 68.93% <100.00%> (+2.70%) ⬆️
crates/ibc/src/mock/context.rs 72.81% <100.00%> (ø)
crates/ibc/src/mock/ics18_relayer/context.rs 65.00% <ø> (ø)
...tes/ibc/src/core/ics24_host/identifier/validate.rs 99.04% <96.29%> (-0.96%) ⬇️

... and 8 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rnbguy rnbguy force-pushed the rano/fix/chain-id-rev-number branch from fcf02fd to a19ac45 Compare November 3, 2023 19:42
Copy link
Member

@Farhad-Shabani Farhad-Shabani left a comment

Choose a reason for hiding this comment

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

Thanks @rnbguy for digging into this issue! Great job!
Just a few nits, then we are good to go!

@rnbguy rnbguy changed the title fix: handle ChainIds without revision numbers fix: support chain identifiers without {chain_name}-{revision_number} pattern Nov 3, 2023
rnbguy and others added 2 commits November 3, 2023 18:08
Co-authored-by: Farhad Shabani <Farhad.Shabani@gmail.com>
Signed-off-by: Rano | Ranadeep <ranadip.bswas@gmail.com>
rnbguy and others added 4 commits November 6, 2023 13:34
Co-authored-by: Farhad Shabani <Farhad.Shabani@gmail.com>
Signed-off-by: Rano | Ranadeep <ranadip.bswas@gmail.com>
Copy link
Member

@Farhad-Shabani Farhad-Shabani left a comment

Choose a reason for hiding this comment

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

🎉

@Farhad-Shabani Farhad-Shabani merged commit 1ec4b8c into main Nov 6, 2023
13 checks passed
@Farhad-Shabani Farhad-Shabani deleted the rano/fix/chain-id-rev-number branch November 6, 2023 18:47
Farhad-Shabani added a commit that referenced this pull request Sep 9, 2024
…}` pattern (#941)

* optional revision number for chain id

* add additional methods

* update tests

* add changelog entry

* new test for codecov

* revert optional u64

* rename method

* update tests

* visualize actual testcases

* revert method rename

* update changelog entry

* refactor ChainId::new

* rm ChainId::has_revision_number method

* refactor ChainId::set_revision_number to ChainId::increment_revision_number

* rm old set unset revision_number test

* add tests for ChainId::increment_revision_number

* add length validation tests

* refactor source code for ChainId::new

* fix doc test

* fix chain identifier length validation

* update tests

* fix typo

* reword changelog entry

* reword doc string

* fix ChainId::validate_length

* add ChainId::validate_length in tests

* replace ID with identifier

* use validate_prefix_length over validate_identifier_length

* optimize validate_prefix_length

* rename changelog entry

* fix incorrect doc comment

Co-authored-by: Farhad Shabani <Farhad.Shabani@gmail.com>
Signed-off-by: Rano | Ranadeep <ranadip.bswas@gmail.com>

* use u64::checked_add

* update doc comment

* update doc tests

* simplify validate_prefix_length

* tests for validate_prefix_length

* fix tests

* add changelog entry

* import test_log::test

* fix rstest test attribute

* cargo fmt

* fix typo

Co-authored-by: Farhad Shabani <Farhad.Shabani@gmail.com>
Signed-off-by: Rano | Ranadeep <ranadip.bswas@gmail.com>

---------

Signed-off-by: Rano | Ranadeep <ranadip.bswas@gmail.com>
Co-authored-by: Farhad Shabani <Farhad.Shabani@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

validate_prefix_length can avoid creating new Strings ChainId parsing fails if revision number is absent
2 participants