parity-common icon indicating copy to clipboard operation
parity-common copied to clipboard

Use `array-bytes` for array/bytes/hex operations

Open aurexav opened this issue 2 years ago • 5 comments

Reasons: https://github.com/paritytech/substrate/issues/12111 Substrate PR: https://github.com/paritytech/substrate/pull/12190

aurexav avatar Nov 23 '22 15:11 aurexav

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.

aurexav avatar Nov 24 '22 13:11 aurexav

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.

aurexav avatar Nov 26 '22 09:11 aurexav

Hi! Any plan for this?

aurexav avatar Dec 06 '22 07:12 aurexav

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

acatangiu avatar Dec 06 '22 09:12 acatangiu

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?

aurexav avatar Dec 06 '22 13:12 aurexav