Metadata V15: Expose types for the overarching Call, Event, Error enums (#14143)

* frame-metadata: Point to unreleased branch

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame: Generalize outer enum generation for events and errors

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame: Remove individual generation of outer enum events

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* primitives/traits: Add marker trait for outer runtime enums

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame: Derive Clone, PartialEq, Eq for RuntimeEvents only

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/pallet: Include `#[pallet::error]` enum into pallet parts

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata-ir: Include call, event, error types

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/metadata: Include outer enum types in V15 metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/tests: Ensure `RuntimeError` includes `#[pallet::error]` parts

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Document the reserved name for `RuntimeError`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame: Use self-generated `RuntimeEvent` for `GetRuntimeOuterEnumTypes`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/ui: Fix UI tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Remove unused system path

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/ui: Unexpected field and reintroduce frame_system::Config for RuntimeCall

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Remove `GetRuntimeOuterEnumTypes` marker trait

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Remove `;` from macro

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update frame-metadata to point to unreleased branch

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Rename error_enum_ty to module_error_enum_ty

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update module_error_ty documentation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame: Implement from_dispatch_error

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Adjust test to ModuleErrorType

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Fix clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Improve documentation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/tests: Check `from_dispatch_error` impl

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update frame-metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Remove the module_error_ty

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Apply fmt

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Revert unneeded parts

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Revert "Revert unneeded parts"

This reverts commit b94bbd16078a025775a48da1095edec1705e6a4d.

Revert "Apply fmt"

This reverts commit 9b1c3e7b4ef27d32e10b35054a99916067e0397b.

Revert "Remove the module_error_ty"

This reverts commit 98de5b24653f9f9ec6ee842b749401b18a01758a.

* Update frame-metadata to origin/master

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Add outerEnums to the metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Add tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Keep backwards compatibility for explicit pallet parts

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Rename tt_error_part to be more generic

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Increase recursion_limit to 1k

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Rename `fully_expanded` to `expanded`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Improve documentation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust UI tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update UI tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update undefined_validate_unsigned_part.stderr UI test

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust yet again

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Optimise macro expansions

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Use latest frame-metadata and rename `moduleErrorType` to `RuntimeError`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Fix comment

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Apply fmt

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update frame/support/procedural/src/construct_runtime/parse.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update frame/support/procedural/src/construct_runtime/parse.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update frame-metadata PR

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Remove `expanded` from error messages and fix typo

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Move docs to the function

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* ui: Use the intermed syntax for pallet parts

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update frame-metadata with latest release

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame: Address feedback for `from_dispatch_error`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Alexandru Vasile
2023-06-28 12:44:05 +03:00
committed by GitHub
parent 4249643df2
commit 73a368c2e4
33 changed files with 1143 additions and 337 deletions
@@ -85,6 +85,11 @@ mod test {
},
ty: meta_type::<()>(),
apis: vec![],
outer_enums: OuterEnumsIR {
call_enum_ty: meta_type::<()>(),
event_enum_ty: meta_type::<()>(),
error_enum_ty: meta_type::<()>(),
},
}
}
@@ -39,6 +39,8 @@ pub struct MetadataIR<T: Form = MetaForm> {
pub ty: T::Type,
/// Metadata of the Runtime API.
pub apis: Vec<RuntimeApiMetadataIR<T>>,
/// The outer enums types as found in the runtime.
pub outer_enums: OuterEnumsIR<T>,
}
/// Metadata of a runtime trait.
@@ -398,3 +400,40 @@ impl From<MetaType> for PalletErrorMetadataIR {
Self { ty }
}
}
/// The type of the outer enums.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct OuterEnumsIR<T: Form = MetaForm> {
/// The type of the outer `RuntimeCall` enum.
pub call_enum_ty: T::Type,
/// The type of the outer `RuntimeEvent` enum.
pub event_enum_ty: T::Type,
/// The module error type of the
/// [`DispatchError::Module`](https://docs.rs/sp-runtime/24.0.0/sp_runtime/enum.DispatchError.html#variant.Module) variant.
///
/// The `Module` variant will be 5 scale encoded bytes which are normally decoded into
/// an `{ index: u8, error: [u8; 4] }` struct. This type ID points to an enum type which
/// instead interprets the first `index` byte as a pallet variant, and the remaining `error`
/// bytes as the appropriate `pallet::Error` type. It is an equally valid way to decode the
/// error bytes, and can be more informative.
///
/// # Note
///
/// - This type cannot be used directly to decode `sp_runtime::DispatchError` from the chain.
/// It provides just the information needed to decode `sp_runtime::DispatchError::Module`.
/// - Decoding the 5 error bytes into this type will not always lead to all of the bytes being
/// consumed; many error types do not require all of the bytes to represent them fully.
pub error_enum_ty: T::Type,
}
impl IntoPortable for OuterEnumsIR {
type Output = OuterEnumsIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
OuterEnumsIR {
call_enum_ty: registry.register_type(&self.call_enum_ty),
event_enum_ty: registry.register_type(&self.event_enum_ty),
error_enum_ty: registry.register_type(&self.error_enum_ty),
}
}
}
+25 -91
View File
@@ -17,20 +17,17 @@
//! Convert the IR to V15 metadata.
use crate::OuterEnumsIR;
use super::types::{
ExtrinsicMetadataIR, MetadataIR, PalletCallMetadataIR, PalletConstantMetadataIR,
PalletErrorMetadataIR, PalletEventMetadataIR, PalletMetadataIR, PalletStorageMetadataIR,
RuntimeApiMetadataIR, RuntimeApiMethodMetadataIR, RuntimeApiMethodParamMetadataIR,
SignedExtensionMetadataIR, StorageEntryMetadataIR, StorageEntryModifierIR, StorageEntryTypeIR,
StorageHasherIR,
ExtrinsicMetadataIR, MetadataIR, PalletMetadataIR, RuntimeApiMetadataIR,
RuntimeApiMethodMetadataIR, RuntimeApiMethodParamMetadataIR, SignedExtensionMetadataIR,
};
use frame_metadata::v15::{
ExtrinsicMetadata, PalletCallMetadata, PalletConstantMetadata, PalletErrorMetadata,
PalletEventMetadata, PalletMetadata, PalletStorageMetadata, RuntimeApiMetadata,
CustomMetadata, ExtrinsicMetadata, OuterEnums, PalletMetadata, RuntimeApiMetadata,
RuntimeApiMethodMetadata, RuntimeApiMethodParamMetadata, RuntimeMetadataV15,
SignedExtensionMetadata, StorageEntryMetadata, StorageEntryModifier, StorageEntryType,
StorageHasher,
SignedExtensionMetadata,
};
impl From<MetadataIR> for RuntimeMetadataV15 {
@@ -40,6 +37,10 @@ impl From<MetadataIR> for RuntimeMetadataV15 {
ir.extrinsic.into(),
ir.ty,
ir.apis.into_iter().map(Into::into).collect(),
ir.outer_enums.into(),
// Substrate does not collect yet the custom metadata fields.
// This allows us to extend the V15 easily.
CustomMetadata { map: Default::default() },
)
}
}
@@ -86,87 +87,6 @@ impl From<PalletMetadataIR> for PalletMetadata {
}
}
impl From<StorageEntryModifierIR> for StorageEntryModifier {
fn from(ir: StorageEntryModifierIR) -> Self {
match ir {
StorageEntryModifierIR::Optional => StorageEntryModifier::Optional,
StorageEntryModifierIR::Default => StorageEntryModifier::Default,
}
}
}
impl From<StorageHasherIR> for StorageHasher {
fn from(ir: StorageHasherIR) -> Self {
match ir {
StorageHasherIR::Blake2_128 => StorageHasher::Blake2_128,
StorageHasherIR::Blake2_256 => StorageHasher::Blake2_256,
StorageHasherIR::Blake2_128Concat => StorageHasher::Blake2_128Concat,
StorageHasherIR::Twox128 => StorageHasher::Twox128,
StorageHasherIR::Twox256 => StorageHasher::Twox256,
StorageHasherIR::Twox64Concat => StorageHasher::Twox64Concat,
StorageHasherIR::Identity => StorageHasher::Identity,
}
}
}
impl From<StorageEntryTypeIR> for StorageEntryType {
fn from(ir: StorageEntryTypeIR) -> Self {
match ir {
StorageEntryTypeIR::Plain(ty) => StorageEntryType::Plain(ty),
StorageEntryTypeIR::Map { hashers, key, value } => StorageEntryType::Map {
hashers: hashers.into_iter().map(Into::into).collect(),
key,
value,
},
}
}
}
impl From<StorageEntryMetadataIR> for StorageEntryMetadata {
fn from(ir: StorageEntryMetadataIR) -> Self {
StorageEntryMetadata {
name: ir.name,
modifier: ir.modifier.into(),
ty: ir.ty.into(),
default: ir.default,
docs: ir.docs,
}
}
}
impl From<PalletStorageMetadataIR> for PalletStorageMetadata {
fn from(ir: PalletStorageMetadataIR) -> Self {
PalletStorageMetadata {
prefix: ir.prefix,
entries: ir.entries.into_iter().map(Into::into).collect(),
}
}
}
impl From<PalletCallMetadataIR> for PalletCallMetadata {
fn from(ir: PalletCallMetadataIR) -> Self {
PalletCallMetadata { ty: ir.ty }
}
}
impl From<PalletEventMetadataIR> for PalletEventMetadata {
fn from(ir: PalletEventMetadataIR) -> Self {
PalletEventMetadata { ty: ir.ty }
}
}
impl From<PalletConstantMetadataIR> for PalletConstantMetadata {
fn from(ir: PalletConstantMetadataIR) -> Self {
PalletConstantMetadata { name: ir.name, ty: ir.ty, value: ir.value, docs: ir.docs }
}
}
impl From<PalletErrorMetadataIR> for PalletErrorMetadata {
fn from(ir: PalletErrorMetadataIR) -> Self {
PalletErrorMetadata { ty: ir.ty }
}
}
impl From<SignedExtensionMetadataIR> for SignedExtensionMetadata {
fn from(ir: SignedExtensionMetadataIR) -> Self {
SignedExtensionMetadata {
@@ -180,9 +100,23 @@ impl From<SignedExtensionMetadataIR> for SignedExtensionMetadata {
impl From<ExtrinsicMetadataIR> for ExtrinsicMetadata {
fn from(ir: ExtrinsicMetadataIR) -> Self {
ExtrinsicMetadata {
ty: ir.ty,
version: ir.version,
signed_extensions: ir.signed_extensions.into_iter().map(Into::into).collect(),
// Note: These fields are populated by complementary PR: https://github.com/paritytech/substrate/pull/14123.
address_ty: ir.ty,
call_ty: ir.ty,
signature_ty: ir.ty,
extra_ty: ir.ty,
}
}
}
impl From<OuterEnumsIR> for OuterEnums {
fn from(ir: OuterEnumsIR) -> Self {
OuterEnums {
call_enum_ty: ir.call_enum_ty,
event_enum_ty: ir.event_enum_ty,
error_enum_ty: ir.error_enum_ty,
}
}
}