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

MaxEncodedLen macro is not accurate for compact fields, and skipped fields and variants #302

Open
gui1117 opened this issue Nov 23, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@gui1117
Copy link
Contributor

gui1117 commented Nov 23, 2021

AFAICT MaxEncodedLen doesn't read the attributes #[codec(skip)] and #[codec(encode_as..)] and #[codec(compact)].

Thus it can result in an inaccurate len.

For instance the type:

#[derive(MaxEncodedLen, Encode)]
struct Foo(#[codec(compact)] u8);

will have max encoded len of 1 but can actually encode in 2 bytes.

@gui1117 gui1117 added the bug Something isn't working label Nov 23, 2021
@ggwpez ggwpez mentioned this issue Jan 12, 2023
27 tasks
@ggwpez
Copy link
Member

ggwpez commented Jan 12, 2023

Still an issue. This fails to compile:

#[derive(MaxEncodedLen, TypeInfo, Encode, Decode)]
enum Error {
    Wrong(#[codec(skip)] &'static str),
}

no function or associated item named "max_encoded_len" found for reference "&'static str" in the current scope.
Same when using a named inner.

@bkchr
Copy link
Member

bkchr commented Jan 18, 2023

At least codec(skip) is already supported, but just not released. This changes it: #401

@Dmitry-Borodin
Copy link

This issue is part of paritytech/polkadot-sdk#323 in a list. And looks like it's fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants