-
Notifications
You must be signed in to change notification settings - Fork 254
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
Handling skipped type params in subxt-codegen
#1247
Comments
cc @tadeohepperle since I believe his work will soon handle this |
Ah interesting! I don't know the code in that area well enough to propose a solution, but just some thoughts and workaround ideas:
Which leads me to a couple of workaround ideas:
TypeSubstitute::custom(
"sp_runtime::generic::header::Header<T>",
"::sp_runtime::generic::Header<T, ::some_type_that::MakesSense>",
),
TypeSubstitute::custom(
"sp_runtime::generic::header::Header<T>",
"::path::to::MyCustomHeader<T>",
), where you have something like: struct MyCustomHeader<T>(::sp_runtime::generic::Header<T, ::some_type_that::MakesSense>); This adds the flexibility of being able to derive whatever you need to etc on the custom type, and allows complete control over the generic alignment (some of which you can do using (1) now anyway). And yup finally as Alex says, we have plans to move some of the core codegen stuff outside of |
Thank you for the answear and the suggestions ! You're right. I don't think the Hash type could be generated. But I don't think we can use custom types either. We don't want to hardcode the value of Then I guess the only option would be to remove the |
If it was removed, a custom Ultimately, the issue is that we can't transfer logic through the metadata; only information about the name/shape of the types. So if you need custom logic (eg about the In subxt itself for instance, we have a |
Makes sense
We have some similar configs, but it would have been nice to get these types directly from the metadata. I'm thinking if we can use them. Anyway, makes sense. Resolving this since it's not a subxt issue. |
Thought about it some more. Just as an example one of our use cases is the following. Relayers listen for finality proofs on some source chains and then sends these proofs + the finalized header to target chains using the
So the relayers will send to Rococo through
Before the
The generated runtime call was accepting the original Wococo/Millau header, which was ideal for us:
We could just take the header from the source chain and pass it to the target. Right now for this scenario,
while the metadata specifies separate types:
I think this is a bug. I hope I didn't do something wrong while using
Because then, having 2 generic params, we could actually create a custom adapter structure let's say And maybe it could also help fix the bug. |
Thanks for your reply!
I suspect you're right; lemme check! The codegen stuff "deduplicates" concrete types that have generic params, but since one of the generic params is hidden in this I'm not sure whether the solution would be to introduce another generic param or to just avoid the two different types from being squashed into one header type (the former would def be nicer, but I'm not sure offhand how easy it would be to add extra generics in this way). We'll look into it and see what we can do :) |
We basically iterate over all of the types and assume that two types with the same path are actually just the same type (and assume that therefore it must be that the generics that are different) here I think: subxt/codegen/src/types/mod.rs Line 101 in 6332196
We already have to dedupe duplicate pallets being used, which can lead to types with the same path, and we do that using this Line 47 in 6332196
I suspect the most reliable way to solve this bug is to extend that call to more reliably deduplicate types that have the same path but are different internally in any area that isn't explained by generic params. Maybe an approach like:
I think this should ensure that we never have dupe types based on paths in a more robust way than what we do currently. This isn't as nice as adding a generic param to cater for the difference, and perhaps as a step 2, we can look at how feasible it is to add that; it would be nicer, but it would also be more complex, and could complement the above logic rather than replace it. |
I implemented a better deduplication, in the way James described above, in |
Background context
The bridges team uses
subxt-codegen
in order to generate runtime types from metadata. We then use these types in order to submit bridge-related extrinsics to the chains.Here is the code.
We substitute the types that are extrinsic arguments with the original types, instead of the ones generated by
subxt-codegen
. We encoutered an error recently with one of these types (sp_runtime::generic::header::Header
). It has 2 type parameters (pub struct Header<Number: Copy + Into<U256> + TryFrom<U256>, Hash: HashT>
), but recently a #[scale_info(skip_type_params(Hash))] has been added to the original structure. Sosubxt-codegen
skips theHash
, leading to generated code that goes like:But, since we substitute it with the original type which has 2 type params, we get compilation errors:
Request
I was wondering if it would make sense to keep the original definition of the structure (including the skipped type params) in such cases, for compatibility with type substitutions, even if the skipped typed params wouldn't actually be used if the type is not substituted.
I would be happy to help with the implementation if you don't have time.
The text was updated successfully, but these errors were encountered: