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

Use array-bytes for array/bytes/hex operations #695

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

AurevoirXavier
Copy link

@AurevoirXavier AurevoirXavier commented Nov 23, 2022

@AurevoirXavier AurevoirXavier requested a review from a team as a code owner November 23, 2022 15:50
}
Ok(result)
fn from_str(input: &str) -> $crate::core_::result::Result<$name, $crate::array_bytes::Error> {
$crate::array_bytes::hex_n_into::<Self, { Self::len_bytes() }>(input)
Copy link
Author

@AurevoirXavier AurevoirXavier Nov 23, 2022

Choose a reason for hiding this comment

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

As you can see, it has some really friendly APIs.

And it will handle the "0x" prefix and errors.

Copy link

@acatangiu acatangiu left a comment

Choose a reason for hiding this comment

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

Looks ok to me, but it is incomplete (good to merge once it passes CI)

@ordian ordian added the breaking-change Breaking change label Nov 24, 2022
@AurevoirXavier
Copy link
Author

Looks ok to me, but it is incomplete (good to merge once it passes CI)

Fixed. And it looks like there are some new errors in your CI script.

@AurevoirXavier AurevoirXavier marked this pull request as draft November 25, 2022 06:14
@AurevoirXavier
Copy link
Author

AurevoirXavier commented Nov 26, 2022

And I made some algorithm optimization these days.

Check the benchmark results here.
https://github.com/hack-ink/array-bytes#benchmark-results

Not only it has blockchain-developer-friendly API.

I think it's also 1.2x ~ 4x faster than the hex crate.

@AurevoirXavier AurevoirXavier marked this pull request as ready for review November 26, 2022 09:34
@AurevoirXavier
Copy link
Author

AurevoirXavier commented Dec 6, 2022

Hi! Any plan for this?

@acatangiu
Copy link

Can you resolve the merge conflict?
@ordian wanna also take a look?

Copy link
Member

@ordian ordian left a comment

Choose a reason for hiding this comment

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

I've taken a look before and remained unconvinced.

One of the benefits advertized:

And it's completely no-std.

We could also use rustc-hex without it's std feature and call it completely no-std this way.

By switfly looking at https://github.com/hack-ink/array-bytes/blob/main/src/lib.rs I see a few problems:

  1. It's using unidiomatic function naming: https://rust-lang.github.io/api-guidelines/naming.html
  2. Unwraps and safe unchecked methods.
  3. It's not audited.

So what's the benefit, really?

Comment on lines -169 to +172
Some(&self.inner)
// Some(&self.inner)
// TODO: <https://github.com/rust-lang/project-error-handling/issues/3>
None
Copy link
Member

Choose a reason for hiding this comment

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

^^^

@AurevoirXavier
Copy link
Author

AurevoirXavier commented Dec 6, 2022

I've taken a look before and remained unconvinced.

One of the benefits advertized:

And it's completely no-std.

We could also use rustc-hex without it's std feature and call it completely no-std this way.

By switfly looking at https://github.com/hack-ink/array-bytes/blob/main/src/lib.rs I see a few problems:

  1. It's using unidiomatic function naming: https://rust-lang.github.io/api-guidelines/naming.html
  2. Unwraps and safe unchecked methods.
  3. It's not audited.

So what's the benefit, really?

  1. IMHO, the API is much easier to understand: x2y.
  2. It did provide some unchecked functions, but to use it, it's totally up to you. Maybe you are writing some off-chain tools or unit tests, then you might want to get rid of the Result.
  3. True. But I'd love to push this.
    1. It has fuzzy tests.
    2. It was used by Substrate.
  4. It's faster than rust-hex.
  5. It handles the 0x prefix.
  6. And it provides some *_into functions which are pretty convenient/handy for Substrate/blockchain development.
  7. Also, some serde support.

For me, I want to bring these to other blockchain developers.

It's really an honor and a good example to be a part of the parity-common (one of the most frequently used blockchain library).

Would you consider this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants