Skip to content

Instantly share code, notes, and snippets.

@ascjones
Last active July 22, 2022 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ascjones/0d81a4c44e84cacd9f714cd34a6de823 to your computer and use it in GitHub Desktop.
Save ascjones/0d81a4c44e84cacd9f714cd34a6de823 to your computer and use it in GitHub Desktop.
Migration guide for Substrate Metadata V14

Substrate Runtime Builders

When updating to use the latest Substrate with V14 metadata, your runtime will fail to compile.

The following steps are required to make your pallets/runtime compatible. The compiler will guide you...

  • Remove any #[pallet::metadata(..)] attributes from the pallet Event definition.
  • Add scale-info dependency to pallet and runtime crates:
    • scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
    • std = [ "scale-info/std" ]
  • Derive scale_info::TypeInfo for any types which derive Decode, Encode.
    • If the type is in a separate crate to the pallet, add the scale-info dependency as above.
  • Update any pallet Call variant constructors to use named structs (previously unnamed tuple structs).
  • Update the metadata runtime API call:
impl sp_api::Metadata<Block> for Runtime {
    fn metadata() -> OpaqueMetadata {
        OpaqueMetadata::new(Runtime::metadata().into())
    }
}

See the cumulus and polkadot PRs (linked below) for examples of the above conversion.

Resources

@nazar-pc
Copy link

Shouldn't scale-info version be 1.0?

@ascjones
Copy link
Author

Indeed it should be, Updated.

@wischli
Copy link

wischli commented Oct 18, 2021

I would like to add that you should add #[scale_info(skip_type_params(T))] for structs which lazily use the pallet's Config as generic such as pub struct Example<T: Config> - if this statement is correct. This would have saved me quite some time when debugging our upgrade to 0.9.11 😅

@NukeManDan
Copy link

We should surface this here: substrate-developer-hub/substrate-docs#385

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment