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

Model ChannelId as newtype u64 and improve validation #2071

Merged
merged 11 commits into from
Apr 8, 2022

Conversation

hu55a1n1
Copy link
Member

@hu55a1n1 hu55a1n1 commented Apr 6, 2022

Closes: cosmos/ibc-rs#50


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

Reviewer checklist:

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

@hu55a1n1 hu55a1n1 mentioned this pull request Apr 6, 2022
7 tasks
@romac
Copy link
Member

romac commented Apr 7, 2022

Any idea why this test only fails in this branch (because of #2075) and was not caught before?

https://github.com/informalsystems/ibc-rs/blob/1a6b41ad4ec5e2f2183bcdc74e4be99a4713f414/relayer/src/config/filter.rs#L450-L453

@hu55a1n1
Copy link
Member Author

hu55a1n1 commented Apr 7, 2022

Any idea why this test only fails in this branch (because of #2075) and was not caught before?

@romac and I figured out that this was because the original test used the ['ft-transfer', 'network-1'] combination in tests which didn't hit this bug because the ChannelIds didn't match. We only hit the bug once this PR disallowed ChannelIds that didn't have the channel- prefix and we modified the test to ['ft-transfer', 'channel-1'].

@hu55a1n1 hu55a1n1 marked this pull request as ready for review April 7, 2022 11:33
@@ -256,7 +256,7 @@ impl From<Attributes> for Vec<Tag> {
if let Some(channel_id) = a.channel_id {
let channel_id = Tag {
key: CHANNEL_ID_ATTRIBUTE_KEY.parse().unwrap(),
value: channel_id.as_str().parse().unwrap(),
Copy link
Contributor

Choose a reason for hiding this comment

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

.to_string().parse() looks like an unnecessary string conversion roundtrip. But an ABCI tag value is a UTF-8 string super-encoded as base64 for an inexplicable reason. Go figure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, it seems unnecessary. But I don't think there's any other public constructor for Tag::Value. 🤔 So not sure how to fix this. IIUC, the tag value was originally designed to be opaque bytes and later it was decided that (event) indexing was required and we're now left with this base64 encoded string.

Copy link
Member

Choose a reason for hiding this comment

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

Nothing to fix here, maybe just add a comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just noticed that we already have this comment above -> https://github.com/informalsystems/ibc-rs/pull/2071/files/91c4c04dd191753eeac90159d2912262dfee17e0#diff-5d54d6bafcc46a42f95443d7c324b7c79563ad1f089618a686a8eb0d54e8beb0L237-L242

/// # Note
/// The parsing of `Key`s and `Value`s never fails, because the
/// `FromStr` instance of `tendermint::abci::tag::{Key, Value}`
/// is infallible, even if it is not represented in the error type.
/// Once tendermint-rs improves the API of the `Key` and `Value` types,
/// we will be able to remove the `.parse().unwrap()` calls.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, nothing to fix there, it's just an observation (maybe we should have an etiquette about this 😊)

@@ -22,7 +22,7 @@ pub(crate) fn process(
// Unwrap the old channel end (if any) and validate it against the message.
let (mut new_channel_end, channel_id) = match &msg.previous_channel_id {
Copy link
Contributor

@mzabaluev mzabaluev Apr 7, 2022

Choose a reason for hiding this comment

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

Now that ChannelId is Copy, would it be nicer to match it by value and avoid the dereferencing cruft in match arms?

Copy link
Member

@romac romac Apr 7, 2022

Choose a reason for hiding this comment

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

Good point. Also, we are passing ChannelId by reference (eg. &ChannelId in fn parameters) in a bunch of places where it would be more idiomatic to pass it by value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we always want to pass ChannelId by value? Halfway through this and the diff is huge, wondering if it's worth it ->

$ git diff --shortstat
 49 files changed, 220 insertions(+), 220 deletions(-)

Copy link
Member

Choose a reason for hiding this comment

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

It's more idiomatic but perhaps not worth it indeed. Let's file it in the backlog :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added this as an entry to this meta issue https://github.com/informalsystems/ibc-rs/issues/1696

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.

Only allow channel-ids of the form channel-{N}
3 participants