-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Metadata with complete type information #1328
Conversation
It looks like @xlc signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
Nice and ty. That was something I was thinking to do as well. Good that you started it :) |
I can remove the Your idea will make breaking changes more explicit but still not solving my original issue, that update runtime module should have minimal changes to js sdk. Let's say I want to make a runtime upgrade that introduce a new type, how to make it non-breaking change regards to existing js clients? This will happen pretty frequently when there is one team working on building a runtime module and upgrading runtime frequently. With existing Substrate and polkadot.js architecture, it is hard to quickly iterate things because someone needs to make sure polkadot.js api have the new type information, all client apps are updated to use latest api, and then an upgrade can happen. But this to me feels like defects the whole purpose or upgradeable runtime, that upgrades should be non-breaking and clients should be able to self-discovery the available features. This may be solvable on polkadot.js side (unable to parse module information for a particular module something shouldn't break everything), or parity-codec side (somehow to make codec breaking changes harder to make, or at least detect upfront they are incompatible), but I think some changes are needed on Substrate side. |
First, you would just have a map:
For adding a new type, you would just need to add |
64da76c
to
cdce193
Compare
@bkchr I have updated it to use enum (u8) to encode primitive types instead of string. Not sure what is the best way to make unrecognized primitive type become a compile-time error instead of runtime error, maybe need to rewrite Please let me know if you think this is the correct direction to go and the best way to structure the repos. This substrate-metadata module to me can be either part of parity-codec, or a separate lib depends on parity-codec. And some method name is a bit awkward ( I want to keep working on this but I don't want to send too much time on it and then found out it towards to a dead end. |
Looks pretty cool overall (though it'll need to work with the |
b6864bc
to
e19bc18
Compare
e19bc18
to
1446c3b
Compare
a9a5376
to
3638935
Compare
Needs help Some methods I tried:
I tried duplicate the implementation of I tried replace I am also thinking move the metadata code into parity-codec, which should simplify some implementation details. Do you guys think is this something part of parity-codec? I am stuck and need help to continue. |
Metadata just uses parity-codec and does not belongs to parity-codec. |
Latest metadata with options 1 |
…to metadata-reflection-poc
aa9808f
to
49fa7e8
Compare
49fa7e8
to
88275c0
Compare
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.
Nits, but I am not too familiar with this code.
@@ -0,0 +1,206 @@ | |||
use quote::{quote, quote_spanned}; |
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.
I have no experience writing procedural macros. @rphmeier can you help review this?
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.
I don't have much experience with proc-macros or this code in particular either.
@@ -186,12 +188,14 @@ impl<Address, Index, Call, Signature> fmt::Debug for UncheckedMortalCompactExtri | |||
} | |||
} | |||
|
|||
#[cfg(test)] |
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.
is this intentional?
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.
no. probably a merge error
No automatically generated type metadata anymore? |
We still plan to do it but unlikely within next two weeks. |
Just a note here, the closing is not because we don't want the feature, but because the PR had gotten stale enough that it's easier to re-open fresh when ready than trying to resolve all merge conflicts, we regularly close stale issues and PRs because of uncertainty around status, so again, not an indication of desire to have it or not. |
Great! |
This fixes #917, which is one of the biggest pain point to me when working with Substrate (and polkadot.js), that any type information needs to be implemented twice and incompatible type information simply cause polkadot.js crashes without much helpful clues (other than it is mostly likely a codec error).
This introduce
type_registry
toRuntimeMetadata
which contains all the type informations i.e. the metadata itself stores the information about how to decode the storage types.Ideally, this will remove the needs to manually maintain type information in polkadot.js (currently implemented at https://github.com/polkadot-js/api/tree/master/packages/types/src). Those JS classes can be generated at runtime by parsing the metadata. TS files can be generated ahead-of-time if needed. This will also make implement (and support) other languages SDK much easily.
Some code copied from parity-codec.
Fixes #917
Enable the proper fix for polkadot-js/api#416
Could be the foundation work for polkadot-js/api#429
This is the debug print of the resulting metadata:
https://gist.github.com/xlc/19d010e55f84bf6d43afafdc5e5b5df6#file-metadata-L5525