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

Signer parsing from context #1393

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sug0
Copy link
Contributor

@sug0 sug0 commented Jan 17, 2025

Based on #1392

Diff: https://github.com/heliaxdev/cosmos-ibc-rs/compare/heliaxdev:cosmos-ibc-rs:tiago/optional-ack-rebased..heliaxdev:cosmos-ibc-rs:tiago/signer-parsing-from-ctx

Description

This PR replaces the TryFrom<Signer> bound on AccountId with new context methods, with the aim of contextually parsing Signer instances.

(Some context: #1392 (comment))


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

@sug0 sug0 mentioned this pull request Jan 17, 2025
7 tasks
Copy link

codecov bot commented Jan 17, 2025

Codecov Report

Attention: Patch coverage is 65.07937% with 44 lines in your changes missing coverage. Please review.

Project coverage is 67.06%. Comparing base (36944b8) to head (12ffb4b).

Files with missing lines Patch % Lines
...-core/ics04-channel/src/handler/acknowledgement.rs 70.37% 24 Missing ⚠️
...-apps/ics20-transfer/src/handler/on_recv_packet.rs 0.00% 8 Missing ⚠️
ibc-apps/ics20-transfer/src/handler/mod.rs 0.00% 6 Missing ⚠️
...t/src/testapp/ibc/applications/transfer/context.rs 50.00% 3 Missing ⚠️
...rc/testapp/ibc/applications/nft_transfer/module.rs 0.00% 2 Missing ⚠️
ibc-core/ics04-channel/src/handler/recv_packet.rs 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1393      +/-   ##
==========================================
- Coverage   67.09%   67.06%   -0.04%     
==========================================
  Files         226      226              
  Lines       22425    22483      +58     
==========================================
+ Hits        15047    15079      +32     
- Misses       7378     7404      +26     

☔ 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 for splitting out this PR! Please take a look at the comments. Additionally:

Comment on lines +14 to +18
/// Attempt to convert a [`Signer`] to a native chain sender account.
fn sender_account_from_signer(&self, signer: &Signer) -> Option<Self::AccountId>;

/// Attempt to convert a [`Signer`] to a native chain receiver account.
fn receiver_account_from_signer(&self, signer: &Signer) -> Option<Self::AccountId>;
Copy link
Member

Choose a reason for hiding this comment

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

Can you update the return type to Result<Self::AccountId, HostError>? It’d keep it consistent with our other APIs. Since the account ID isn’t always derivable from the signer, and ibc-rs typically propagates errors originating from the host boundary as HostError, it makes more sense to classify it this way. This also gives hosts the flexibility to include contextual information in the error, which ibc-rs can then pass along.
(This PR seems like a good move from this perspective too.)

type AccountId;

/// Attempt to convert a [`Signer`] to a native chain sender account.
fn sender_account_from_signer(&self, signer: &Signer) -> Option<Self::AccountId>;
Copy link
Member

Choose a reason for hiding this comment

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

I suggest renaming these methods to sender_account and receiver_account. The Signer type is currently used for account-like fields everywhere in ibc-rs, but it actually need improvement later since it can be confusing. As you can see, the sender and receiver aren’t actually signers here. So, I'm suggesting to avoid breaking the API naming in the future. Even the args can be updated to sender and receiver.

.map_err(|_| TokenTransferError::FailedToParseAccount)?;
let sender = token_ctx_a
.sender_account_from_signer(&msg.packet_data.sender)
.ok_or(TokenTransferError::FailedToParseAccount)?;
Copy link
Member

@Farhad-Shabani Farhad-Shabani Jan 17, 2025

Choose a reason for hiding this comment

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

With the update requested in the other comment, this FailedToParseAccount variant can completely be removed.

@@ -0,0 +1,3 @@
- Replace the `TryFrom<Signer>` bound on `AccountId` with new context
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Replace the `TryFrom<Signer>` bound on `AccountId` with new context
- [ibc-apps] Replace the `TryFrom<Signer>` bound on `AccountId` with new context

@@ -0,0 +1,3 @@
- Replace the `TryFrom<Signer>` bound on `AccountId` with new context
Copy link
Member

Choose a reason for hiding this comment

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

Let's put this under the /unreleased/breaking-changes/ directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📥 To Do
Development

Successfully merging this pull request may close these issues.

2 participants