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

Move MaxEncodedLen from Substrate #268

Merged
merged 16 commits into from
Jun 23, 2021
Merged

Move MaxEncodedLen from Substrate #268

merged 16 commits into from
Jun 23, 2021

Conversation

coriolinus
Copy link
Contributor

After further discussion, it turns out that we want the MaxEncodedLen trait and derive macro in this crate after all instead of in Substrate. This PR forms part 1 of a three-step process:

  • Add MaxEncodedLen to parity-scale-codec
  • Drop a new release of parity-scale-codec
  • Update Substrate:
    • upgrade parity-scale-codec dependency
    • update all references from frame_support::MaxEncodedLen to codec::MaxEncodedLen
    • remove frame_support::traits::MaxEncodedLen and frame_support_procedural::MaxEncodedLen

Part of paritytech/substrate#8719.

@coriolinus coriolinus self-assigned this May 10, 2021
@coriolinus coriolinus added the enhancement New feature or request label May 10, 2021
@shawntabrizi
Copy link
Member

are we ready to move it?

I wanted to actually have it live in substrate a bit longer while we migrate pallets to use MaxEncodedLen.

Then if everything looks good, we can move it to SCALE. Otherwise, we may have to sync and bump substrate multiple times with SCALE to make it work.

@coriolinus
Copy link
Contributor Author

I think we're ready, on the basis that the trait itself hasn't changed pretty much since we wrote the tracking issue, and I don't anticipate it changing much in the future. Still, if you like, we can put this on hold for a while.

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

As @shawntabrizi said, we should wait until benchmarks etc are done in Substrate. Then we can move this. Otherwise we may need to release a new major version to break the trait definition.

src/lib.rs Outdated Show resolved Hide resolved
tests/max_encoded_len.rs Outdated Show resolved Hide resolved
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
@Xanewok
Copy link
Contributor

Xanewok commented Jun 21, 2021

we should wait until benchmarks etc are done in Substrate.

Is this done and/or is this blocked on anything else?

We're looking at major releases in paritytech/substrate#9140 anyway but it'd be good if we can make it without releasing an additional crate if this will be moved into parity-scale-codec anyway.

@Xanewok
Copy link
Contributor

Xanewok commented Jun 21, 2021

I took the liberty to resolve the conflict via web UI, I hope you don't mind.

@coriolinus
Copy link
Contributor Author

coriolinus commented Jun 21, 2021 via email

@Xanewok
Copy link
Contributor

Xanewok commented Jun 21, 2021

Is this a whitespace/line ending issue? I'm re-running the test suite on Linux locally and it seems to pass but CI is grumpy for whatever reason.

test tests/max_encoded_len_ui/union.rs ... mismatch

EXPECTED:
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
error: Union types are not supported
 --> $DIR/union.rs:4:1
  |
4 | union Union {
  | ^^^^^

error: Union types are not supported.
 --> $DIR/union.rs:4:1
  |
4 | union Union {
  | ^^^^^
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈

ACTUAL OUTPUT:
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
error: Union types are not supported.
 --> $DIR/union.rs:4:1
  |
4 | union Union {
  | ^^^^^

error: Union types are not supported
 --> $DIR/union.rs:4:1
  |
4 | union Union {
  | ^^^^^
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈

@coriolinus
Copy link
Contributor Author

Huh, weird. I'm not sure. I'm increasingly of the opinion that the macro ui tests are just flaky and should not be required in order to merge.

@Xanewok
Copy link
Contributor

Xanewok commented Jun 21, 2021

Oh, I just noticed the dot reordering... that's annoying. Updated to latest stable locally and reproduced it, ran with TRYBUILD=overwrite and locally it's looking good for now.

tests/max_encoded_len.rs Outdated Show resolved Hide resolved
tests/max_encoded_len_ui.rs Outdated Show resolved Hide resolved
src/max_encoded_len.rs Outdated Show resolved Hide resolved
@bkchr
Copy link
Member

bkchr commented Jun 21, 2021

Still misses the version bumps

This is a pre-release rather than a full release in order to help shape
the new `MaxEncodedLen` trait used in Substrate in case some more
involved changes are found out to be required.
The API did not change since its introduction until now so chances are
slim but it's good to leave some leeway.
@Xanewok
Copy link
Contributor

Xanewok commented Jun 21, 2021

Wanted to do a version bump in a separate PR I can do that here as well if you want me to.

I'd be inclined to publish that as a pre-release in order to progress with the release and prune max-encoded-len from the Substrate tree and once the dust settles, we can go ahead with the full release. WDYT? I'd be happy to merge, tag and publish this if you think that's a sound idea.

@bkchr
Copy link
Member

bkchr commented Jun 21, 2021

Yeah fine

@coriolinus
Copy link
Contributor Author

Great! I'll ensure that this has all the updates from Substrate, then merge.

Note: doesn't include the MaxEncodedLen impl for H160, H256, H512.
A substrate companion will be necessary to re-add those.
@coriolinus
Copy link
Contributor Author

Brought in the changes from the substrate version in 9f24e9d.

Note: the substrate implementation added H160, H256, H512 to the impl_primitives list. Those are substrate types, so didn't depend on Substrate to retain that implementation. Instead, the Substrate companion which switches dependencies to this crate will also need to re-implement those derives.

@coriolinus
Copy link
Contributor Author

@ordian yes, that's the substrate companion.

src/lib.rs Outdated Show resolved Hide resolved
derive/src/max_encoded_len.rs Show resolved Hide resolved
derive/src/max_encoded_len.rs Outdated Show resolved Hide resolved
derive/src/max_encoded_len.rs Outdated Show resolved Hide resolved
@coriolinus
Copy link
Contributor Author

@bkchr 395dbaa rewrites the code which fetches the max_encoded_len crate entirely. It moves the code which gets the crate into utils.rs, so that in principle Encode, Decode could easily use it as well, though I haven't actually implemented it for either of those derive macros. I believe it to satisfy all of your comments above.

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Ty. Much simpler and way more easier to read,

derive/src/utils.rs Outdated Show resolved Hide resolved
derive/src/utils.rs Outdated Show resolved Hide resolved
derive/src/utils.rs Outdated Show resolved Hide resolved
derive/src/utils.rs Outdated Show resolved Hide resolved
coriolinus and others added 4 commits June 23, 2021 10:47
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
@Xanewok
Copy link
Contributor

Xanewok commented Jun 23, 2021

Released appropriate v2.2.0-rc.1 versions that contain this change and tagged the latest master. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants