-
Notifications
You must be signed in to change notification settings - Fork 278
Remove codec::Encode and codec::Decode derives from generated APIs by default
#2008
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
Conversation
codec::Encode and codec::Decode from generated APIs by defaultcodec::Encode and codec::Decode derives from generated APIs by default
| if key.hasher.ends_with_key() { | ||
| let arg = &key.arg_name; | ||
| let keys = quote!(#static_storage_key::new(#arg.borrow())); | ||
| let keys = quote!(#static_storage_key::new(#arg)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use references anymore because we need the self of the key to work with EncodeAsType and DecodeAsType?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The basic reason was just because previously we would SCALE encode the key before doing anything with it, but now we want to avoid SCALE encoding and so we keep the key itself, requiring us to have ownership of the key.
It might be that we can allow the stored key to be a reference as well or something like that, because we only need it for long enough to encode it given actual metadata!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🙏
Most APIs in Subxt haven't used
codec::Encodeorcodec::Decodein a while; these traits encode and decode bytes from/to a chain based on the precise shape of our generated types and don't take into account any changes in the chain metadata. Nevertheless, our codegen spits out these derives and the associatedcodecattributes by default.One of the issues we recently hit was #2006, whereby
EncodeandDecodederives in our generated APIs were not playing nicely with compact encoded generics.One solution from that issue is to migrate our generated APIs away from using
codec::Encodeorcodec::Decodeand relying only onEncodeAsTypeandDecodeAstype, which take the chain metadata into account and handle things like encoding and decoding compact encoded values transparently. This PR takes this path.As a nice side effect, the generated code size is reduced in line count by ~10%.
Users can still derive
EncodeandDecodethemselves on types that they want these traits on, or on everything (potentially running into issues like this again which would require workarounds like in the linked issue), but all of the main Subxt interfaces no longer have any reliance on them, and so they do not need to be derviced by default.Closes #2006