-
Notifications
You must be signed in to change notification settings - Fork 87
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(ics20): PrefixedDenom
parsing
#1178
Conversation
I added the client validation logic. But now, the question remains - what happens in the following cases: ibc-rs/ibc-apps/ics20-transfer/types/src/denom.rs Lines 396 to 405 in dfac6b5
Note the following are valid cases in this PR: ibc-rs/ibc-apps/ics20-transfer/types/src/denom.rs Lines 427 to 438 in dfac6b5
Update: looks like ibc-go accepts them. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1178 +/- ##
==========================================
- Coverage 64.40% 64.34% -0.06%
==========================================
Files 229 229
Lines 22109 22005 -104
==========================================
- Hits 14240 14160 -80
+ Misses 7869 7845 -24 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good for the most part. Would be great if we could add a docstring of the PrefixedDenom::from_str
implementation. Feel free to use my suggested description or write a different one.
.changelog/unreleased/bug-fixes/1177-fix-prefixed-denom-parsing.md
Outdated
Show resolved
Hide resolved
@@ -294,18 +301,34 @@ impl FromStr for PrefixedDenom { | |||
type Err = TokenTransferError; | |||
|
|||
fn from_str(s: &str) -> Result<Self, Self::Err> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful to add a description of the logic of this from_str
implementation, as it's a little bit convoluted. Here's a suggestion:
/// Initializes a `PrefixedDenom` from a string that adheres to the format
/// `{port-id-1/channel-id-1}/{port-id-2/channel-id-2}/.../{port-id-n/channel-id-n}/base-denom`.
/// A `PrefixedDenom` exhibits between 1..n number of `{port-id/channel-id}` pairs.
/// The set of these pairs makes up the `TracePath`.
///
/// This `from_str` implementation peeks the first two segments split on the `/`
/// delimiter and attempts to convert the first segment into a `PortId` and the
/// second segment into a `ChannelId`. This continues in a loop until a
/// `{port-id/channel-id}` pair cannot be created from the top two segments.
/// The remaining parts of the string are then considered the `BaseDenom`.
///
/// For example, given the following denom trace:
/// "transfer/channel-75/factory/stars16da2uus9zrsy83h23ur42v3lglg5rmyrpqnju4/dust",
/// the first two `/`-delimited segments are `"transfer"` and `"channel-75"`. The
/// first is a valid `PortId` and the second is a valid `ChannelId`, so that becomes
/// the first `{port-id/channel-id}` pair that gets added as part of the `TracePath`
/// of the `PrefixedDenom`. The next two segments are `"factory"`, which is not a
/// valid `PortId`, and `"stars16da2uus9zrsy83h23ur42v3lglg5rmyrpqnju4"`, which is
/// not a valid `ChannelId`. The loop breaks at this point, resulting in a
/// `TracePath` of `"transfer/channel-75"` and a `BaseDenom` of
/// `"factory/stars16da2uus9zrsy83h23ur42v3lglg5rmyrpqnju4/dust"`.
Feel free to edit the above to make the description more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Sean. The above description helps a lot. Great.
The next two segments are
"factory"
, which is not a validPortId
Just a small note: "factory" is a valid PortId
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rnbguy for getting into the details! The tests are fantastic.
I have a few suggestions and nitpicks, but overall, everything looks great.
Co-authored-by: Sean Chen <[email protected]> Co-authored-by: Farhad Shabani <[email protected]> Signed-off-by: Rano | Ranadeep <[email protected]>
I'm fine either way. If we want to include the ics-721 changes in this PR, then go ahead 👍 |
Co-authored-by: Sean Chen <[email protected]> Signed-off-by: Rano | Ranadeep <[email protected]>
8a3996f
to
736d4a1
Compare
hey @seanchen1991, in recent commits, I added I also updated the algorithm subtly - to handle another incorrect parsing (7408994). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to merge 👍
Farhad is on leave and the fix is on 53fad12 .
* add failing test * add TracePath::new * imp PrefixedDenom parsing * add validate_named_u64_index * validate_named_u64_index in channel and connection validation * add tests for validate_named_u64_index * update PrefixDenom parsing tests * update accepted cases in ibc-go * update accepted cases * add test cases from ibc-go * use valid connection id * failing doc tests * use existing constants * changelog entry * refactor tests * apply suggestions from code review Co-authored-by: Sean Chen <[email protected]> Co-authored-by: Farhad Shabani <[email protected]> Signed-off-by: Rano | Ranadeep <[email protected]> * add comment for PrefixedDenom::from_str * rm TracePath::new * collect the same tests * test parsed PrefixedDenom string repr * test trace order * more tests * update tests * rm redundant error variant * refactor tests * update doc string * add comment on virtual split_twice * update doc str * add TracePrefix::strip and TracePath::trim * add whitespace cases * refactor tests * spelling * parse over from_str * nit * apply suggestions from code review Co-authored-by: Sean Chen <[email protected]> Signed-off-by: Rano | Ranadeep <[email protected]> * add failing test * fix TracePath::from_str * fix parsing * fix test * add ibc-app-transfer-types dep * rm reusable code * update impls * update tests * accepted class ids * refactor tests * update changelog entry * opt trace prefix and path parsing * add new tests * Update changelog entry * fix trace-prefix index order --------- Signed-off-by: Rano | Ranadeep <[email protected]> Co-authored-by: Sean Chen <[email protected]> Co-authored-by: Farhad Shabani <[email protected]>
Closes: #1177
Description
PR author checklist:
unclog
.docs/
).Reviewer checklist:
Files changed
in the GitHub PR explorer.