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

feat: derive AsRef for CommitmentProofBytes #1008

Merged
merged 4 commits into from
Dec 18, 2023
Merged

Conversation

mina86
Copy link
Contributor

@mina86 mina86 commented Dec 14, 2023

Derive AsRef for CommitmentProofBytes so it’s possible to access its
underlying bytes without having to own it.

The type can be converted into Vec but that requires ownership. If
all one has is a reference to the proof bytes (as in verify_membership
method for example), there’s no way to access underlying bytes without
cloning it first.

With derive_more::AsRef added, one can now use as_ref method to borrow
the underlying bytes slice.

While at it. Replace explicit From implementation by derive_more::Into
and get rid of unnecessary clone inside of conversion into MerkleProof.


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).

Derive AsRef for CommitmentProofBytes so it’s possible to access its
underlying bytes without having to own it.

The type can be converted into Vec but that requires ownership.  If all
one has is a reference to the proof bytes (as in verify_membership
method for example), there’s no way to access underlying bytes without
cloning it first.

With derive_more::AsRef added, one can now use as_ref method to borrow
the underlying byets slice.

Whilo at it.  Replace explicit From implementation by derive_more::Into
and get rid of unnecessary clone inside of conversion into MerkleProof.
Copy link

codecov bot commented Dec 14, 2023

Codecov Report

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

Comparison is base (bc7866f) 70.69% compared to head (0052973) 70.69%.
Report is 1 commits behind head on main.

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

Files Patch % Lines
ibc-core/ics23-commitment/types/src/commitment.rs 16.66% 5 Missing ⚠️
ibc-clients/ics07-tendermint/src/client_state.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1008      +/-   ##
==========================================
- Coverage   70.69%   70.69%   -0.01%     
==========================================
  Files         178      178              
  Lines       17870    17868       -2     
==========================================
- Hits        12634    12631       -3     
- Misses       5236     5237       +1     

☔ 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 @mina86 for this improvement. 👌🏻

@Farhad-Shabani Farhad-Shabani added this to the v0.49.0 milestone Dec 18, 2023
@Farhad-Shabani Farhad-Shabani merged commit a6b225e into cosmos:main Dec 18, 2023
11 checks passed
@mina86 mina86 deleted the b branch December 18, 2023 19:41
Farhad-Shabani added a commit that referenced this pull request Sep 9, 2024
* feat: derive AsRef for CommitmentProofBytes

Derive AsRef for CommitmentProofBytes so it’s possible to access its
underlying bytes without having to own it.

The type can be converted into Vec but that requires ownership.  If all
one has is a reference to the proof bytes (as in verify_membership
method for example), there’s no way to access underlying bytes without
cloning it first.

With derive_more::AsRef added, one can now use as_ref method to borrow
the underlying byets slice.

Whilo at it.  Replace explicit From implementation by derive_more::Into
and get rid of unnecessary clone inside of conversion into MerkleProof.

* log

* nit: remove now redundant clones

* chore: remove redundant conversion to MerkleProof from owned CommitmentProofBytes

---------

Co-authored-by: Farhad Shabani <[email protected]>
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.

2 participants