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

Issue with bounds #691

Closed
gui1117 opened this issue Jan 30, 2025 · 5 comments · Fixed by #693
Closed

Issue with bounds #691

gui1117 opened this issue Jan 30, 2025 · 5 comments · Fixed by #693
Assignees

Comments

@gui1117
Copy link
Contributor

gui1117 commented Jan 30, 2025

compiling polkadot-sdk with the latest version fails with:

error[E0277]: the trait bound `parity_scale_codec::Compact<Balance>: MaxEncodedLen` is not satisfied
   --> substrate/primitives/staking/src/lib.rs:451:2
    |
451 |     MaxEncodedLen,
    |     ^^^^^^^^^^^^^ the trait `MaxEncodedLen` is not implemented for `parity_scale_codec::Compact<Balance>`

@gui1117
Copy link
Contributor Author

gui1117 commented Jan 30, 2025

So the PR 508 make use of compact type for max encoded len,
Then PR 512 also improve on the code.
Then PR 616 adds some bound for compact type.
Then the revert of 508 and 512 doesn't actually completely revert, and still make use of the compact type for max encoded len.

So now staking doesn't compile because Compact<Balance>: MaxEncodedLen is not bound.

solution:

  • revert 508 completly (my preference)
diff --git a/derive/src/max_encoded_len.rs b/derive/src/max_encoded_len.rs
index 8a592e1..d773096 100644
--- a/derive/src/max_encoded_len.rs
+++ b/derive/src/max_encoded_len.rs
@@ -85,14 +85,8 @@ fn fields_length_expr(fields: &Fields, crate_path: &syn::Path) -> proc_macro2::T
        // caused the issue.
        let expansion = fields_iter.map(|field| {
                let ty = &field.ty;
-               if utils::is_compact(field) {
-                       quote_spanned! {
-                               ty.span() => .saturating_add(<#crate_path::Compact::<#ty> as #crate_path::MaxEncodedLen>::max_encoded_len())
-                       }
-               } else {
-                       quote_spanned! {
-                               ty.span() => .saturating_add(<#ty as #crate_path::MaxEncodedLen>::max_encoded_len())
-                       }
+               quote_spanned! {
+                       ty.span() => .saturating_add(<#ty as #crate_path::MaxEncodedLen>::max_encoded_len())
                }
        });
        quote! {
  • try to do some fix, but they might introduce some breaking change:
diff --git a/derive/src/max_encoded_len.rs b/derive/src/max_encoded_len.rs
index 8a592e1..f09f6c8 100644
--- a/derive/src/max_encoded_len.rs
+++ b/derive/src/max_encoded_len.rs
@@ -44,7 +44,7 @@ pub fn derive_max_encoded_len(input: proc_macro::TokenStream) -> proc_macro::Tok
                None,
                has_dumb_trait_bound(&input.attrs),
                &crate_path,
-               false,
+               true,
        ) {
                return e.to_compile_error().into();
        }
@@ -87,7 +87,9 @@ fn fields_length_expr(fields: &Fields, crate_path: &syn::Path) -> proc_macro2::T
                let ty = &field.ty;
                if utils::is_compact(field) {
                        quote_spanned! {
-                               ty.span() => .saturating_add(<#crate_path::Compact::<#ty> as #crate_path::MaxEncodedLen>::max_encoded_len())
+                               ty.span() => .saturating_add(
+                                       <<#ty as #crate_path::HasCompact>::Type as #crate_path::MaxEncodedLen>::max_encoded_len()
+                               )
                        }
                } else {
                        quote_spanned! {

@gui1117
Copy link
Contributor Author

gui1117 commented Jan 30, 2025

I don't have much time to work on it for now, I can start again tomorrow.

@serban300
Copy link
Contributor

@gui1117 I can take it

@serban300 serban300 self-assigned this Jan 30, 2025
@serban300
Copy link
Contributor

Now I see that there are multiple issues left even after fixing this one:

error[E0080]: evaluation of constant value failed
  --> substrate/client/network/src/protocol/message.rs:79:40
   |
79 |     #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
   |                                           ^^^^^^ the evaluated program panicked at 'Found variants that have duplicate indexes. Both `Consensus` and `RemoteCallResponse` have the index `6`. Use different indexes for each variant.', substrate/client/network/src/protocol/message.rs:79:43
   |
   = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `::core::panic` (in Nightly builds, run with -Z macro-backtrace for more info)

Seems related to #653

error[E0277]: the trait bound `types::CollectionSetting: parity_scale_codec::Encode` is not satisfied
   --> substrate/frame/nfts/src/types.rs:259:10
    |
259 | pub enum CollectionSetting {
    |          ^^^^^^^^^^^^^^^^^ the trait `WrapperTypeEncode` is not implemented for `types::CollectionSetting`, which is required by `types::CollectionSetting: parity_scale_codec::Encode`
    |
    = help: the following other types implement trait `WrapperTypeEncode`:
              &T
              &mut T
              Arc<T>
              Cow<'_, T>
              Rc<T>
              bytes::bytes::Bytes
              parity_scale_codec::Ref<'_, T, U>
              sp_core::Bytes
            and 3 others
    = note: required for `types::CollectionSetting` to implement `parity_scale_codec::Encode`
note: required by a bound in `parity_scale_codec::MaxEncodedLen`
   --> /media/serban/data/workplace/sources/parity-scale-codec/src/max_encoded_len.rs:37:26
    |
37  | pub trait MaxEncodedLen: Encode {
    |                          ^^^^^^ required by this bound in `MaxEncodedLen`

error[E0277]: the trait bound `types::ItemSetting: parity_scale_codec::Encode` is not satisfied
   --> substrate/frame/nfts/src/types.rs:396:10
    |
396 | pub enum ItemSetting {
    |          ^^^^^^^^^^^ the trait `WrapperTypeEncode` is not implemented for `types::ItemSetting`, which is required by `types::ItemSetting: parity_scale_codec::Encode`
    |
    = help: the following other types implement trait `WrapperTypeEncode`:
              &T
              &mut T
              Arc<T>
              Cow<'_, T>
              Rc<T>
              bytes::bytes::Bytes
              parity_scale_codec::Ref<'_, T, U>
              sp_core::Bytes
            and 3 others
    = note: required for `types::ItemSetting` to implement `parity_scale_codec::Encode`
note: required by a bound in `parity_scale_codec::MaxEncodedLen`

Maybe there are others as well

Will tackle them one by one

@serban300
Copy link
Contributor

Opened #693 for fixing this specific issue

Also opened a separate issues for the things mentiond above:

paritytech/polkadot-sdk#7400
#692

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 a pull request may close this issue.

2 participants