-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Import runtime Call / Storage metadata without import the whole runtime #8158
Comments
I'll post more details here. We'd like to implement helpers in #[pallet::call]
impl<T: Config> Pallet<T> {
//TODO: weight
#[pallet::weight(10)]
#[transactional]
pub fn hrmp_init_open_channel(
origin: OriginFor<T>,
recipient: ParaId,
proposed_max_capacity: u32,
proposed_max_message_size: u32,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
let call = rococo_runtime::Call::Hrmp(HrmpCall::hrmp_init_open_channel(
recipient,
proposed_max_capacity,
proposed_max_message_size,
)).encode();
let msg = Xcm::Transact {
origin_type: OriginKind::Native,
call,
};
T::XcmSender::send_xcm(Parent.into(), msg).map_err(|_|
Error::<T>::SendXcmFailed)?;
Ok(().into())
}
} After integrated this pallet into Mandala parachain runtime, build fails with error:
It seems rococo runtime would be included into our runtime. Even if this error was fixable, the build wasm would be too large. We're currently doing the encoding via PolkadotJS (I wrote a guide), though it doesn't return the exact encoded call and needs workaround. I guess this issue could be fixed in the similar way how PolkadotJS do it with metadata. |
We are currently working on producing rich type metadata using However this won't be available in the short term, but what you could do in the meantime is to manually construct a #[derive(Encode, Decode)]
pub enum Call {
#[codec(index = "10")] // the index should match the position of the module in `construct_runtime!`
Hrmp(HrmpCall),
}
#[derive(Encode, Decode)]
pub enum HrmpCall {
#[codec(index = "1")] // the index should match the position of the dispatchable in the target pallet
hrmp_init_open_channel(u32, u32, u32),
} This obviously would become cumbersome the more calls and pallets you use, but I think it should allow you to make progress while waiting for the new metadata format. |
We were also discussing generating such standalone (no dependencies) enum as part of runtime compilation. Perhaps with frame-v2 macros this would be easy enough to implement? CC @thiolliere ? |
My thinking is that the metadata should contain enough information to generate SCALE compatible runtime types in any language, e.g. like in this (out of date) prototype for generating Rust types. |
Yes, that would be awesome! I was thinking of a temporary solution before we add |
@ascjones what are the main blockers to not have the type info available in the short term? I saw the frame-metadata crate already has the V13 version of the metadata that includes the type registry and was happy it could land soon to use in a project that would rely on it. I thought it would only be matter of updating the macros to include the |
I think the scale-info is the only solution I see. Call enum has field with types defined outside of the |
On the
There is that and adding various bounds to traits, and also producing the new metadata format which I have a prototype of in https://github.com/paritytech/substrate/compare/aj-metadata-vnext. However that is dependent on converting all the pallets to the new It would be possible of course to produce the new style metadata with the old macros too, but I don't currently plan to do so. |
The question is how much do we want to cover - obviously If full |
I'll spend some time this afternoon thinking and experimenting to determine if an interim solution is workable.
|
|
polkadot-fellows/xcm-format#22 will address the module index issue. |
Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions. |
In order to use XCM::Transact, we need to know how to encode the call on destination chain. The best way should be just import the
Call
enum from runtime. But we cannot do it because last time we tried, it tries to import the whole Rococo runtime into our parachain runtime, which obviously wouldn't work.We should have some way to allow others to import some generated types from runtime, without import the whole thing.
Not exactly sure how it can be implemented though, all the generic makes thing harder. One potential solution is reconstruct the enum from metadata using polkadot.js.
The text was updated successfully, but these errors were encountered: