Skip to content
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

Deprecation info support in RuntimeMetadataIR #4851

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

pkhry
Copy link

@pkhry pkhry commented Jun 20, 2024

Description:

Adds DeprecationStatus enum to sp_metadata_ir.
Adds deprecation_info field to
- RuntimeApiMetadataIR
- RuntimeApiMethodMetadataIR
- StorageEntryMetadataIR
- PalletConstantMetadataIR

There's also some test updates to make sure that deprecation attributes are getting propagated to the relevant structs.

see: #4098, Solution: A

TODO(to be done in separate MR):

Add a Btree<T::Type, DeprecationStatus> to PalletMetadataIR to store deprecation info on Pallet events and errors and have the ability to query deprecation info by T::Type.
updated MetadataIr would like like this:

/// The intermediate representation for a pallet metadata.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct PalletMetadataIR<T: Form = MetaForm> {
	/// Pallet name.
	pub name: T::String,
	/// Pallet storage metadata.
	pub storage: Option<PalletStorageMetadataIR<T>>,
        ...
	/// Deprecation info
	pub deprecation_info: DeprecationStatus<T>,
}

Note that it's not really possible to put deprecation metadata on Events and Errors themselves as they are required to have From<MetaType> impls.

PS:

i used cargo +nightly fmt --all and cargo +nightly-2024-04-10 fmt --all and still getting line changes due to formatting, what's the correct incantation?

@@ -58,7 +58,6 @@ pub fn expand_runtime_metadata(
#attr
}
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Unrelated change

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it

@@ -97,26 +97,29 @@ impl Parse for RuntimeDeclaration {
let pallets_token = pallets.token;

match convert_pallets(pallets.content.inner.into_iter().collect())? {
PalletsConversion::Implicit(pallets) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes of this file look unrelated. I think you'll need to configure the rustfmt to comply with substrate

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't notice that it was relying on nightly settings, corrected

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weirdly enough even using the settings from rustfmt config it still changes some of the formatting, are some files formatted by hand?

Comment on lines 409 to 410
// assert_eq!(
// get_deprecation(&[simple_path]).unwrap(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dq: Should we uncomment thsese?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

let simple_path: Attribute = parse_quote!(#[deprecated = #FIRST]);
let meta_list: Attribute = parse_quote!(#[deprecated(note = #FIRST)]);
let meta_list_with_since: Attribute =
parse_quote!(#[deprecated(note = #FIRST, since = #SECOND)]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be interesting to see how this behaves with extra parameters

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will just ignore them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we can turn that into a compile error? And specify inside the message the forms we support?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a compiler error already, that's one of the reason why i decided to use rust's deprecated. But the parsing now doesnt fail if attribute is malformed(not sure how useful it is tho)

@@ -441,6 +441,7 @@ fn expected_metadata() -> PalletStorageMetadataIR {
ty: StorageEntryTypeIR::Plain(scale_info::meta_type::<u32>()),
default: vec![0, 0, 0, 0],
docs: vec![],
deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a few tests similar to these (with/without note=.. since=..):

  • check deprecation info for storage entries
  • check deprecation info for runtime APIs for individual methods and for the trait itself
  • check deprecation info for constants

This way we'll also have a good example and see the API in action from the user's perspective

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added more testcases for StorageEntryMetadataIr and constants metadata

}

Ok(().into())
}
}

#[pallet::storage]
#[deprecated]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test here! Bikeshedding on the attribute naming; how would pallet::depreacated sound like? Would it bring more clarity to the user that this is related entirely to the metadata collection?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, but that would introduce the need to use two separate deprecation attributes, one for metadata and one for rustc deprecation warnings. Or that's totally ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would make it a bit clear that the deprecation tag is collected into the metadata. Then, the pallet::deprecated could insert under the hood the deprecated attribute to the type, and propagate DeprecationInfo to the metadata. Up to you in the end, I have no strong pref here :D

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about sp-api-proc-macro stuff? should it also be pallet::deprecated there or for example api::deprecated?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can go with the default deprecation tag for now, I would focus on the metadata collection first, we can come back and change it later if needed

@lexnv
Copy link
Contributor

lexnv commented Jun 26, 2024

Nice work here @pkhry! Certainly off to a good start! 👍

Left a few thoughts after the initial review, mainly:

  • would be good to keep the changes related to this PR only (ie adjust the rustfmt)
  • a few more tests to illustrate how this feels in practice for the user experience (also to validate the approach for all deprecation included calls / storage etc)
  • would be interesting also to include a negative test that fails to compile because pallet::deprecated includes unsupported fields (ie fields that are not empty; "note" or "since")
  • make the CI happy (to double check the tests for now, everything should pass since changes are made in isolation)

From the CI step: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6513912:

error: unused import: `proc_macro::TokenStream`
  --> substrate/frame/support/procedural/src/pallet/parse/config.rs:20:5
   |
20 | use proc_macro::TokenStream;
   |     ^^^^^^^^^^^^^^^^^^^^^^^

After that we can have a look at exposing deprecation info for events / errors (maybe in a separate PR), your initial approach of using a BTreeMap sounds good offhand, but I would consolidate this first. Let me know if you have any questions here 🙏

@lexnv lexnv assigned lexnv and unassigned lexnv Jun 27, 2024
@lexnv lexnv added R0-silent Changes should not be mentioned in any release notes I5-enhancement An additional feature request. D1-medium Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase. labels Jun 27, 2024
@pkhry pkhry force-pushed the pkhry/deprecation_attr_frame_support branch from f0008e0 to c8d2285 Compare June 27, 2024 23:06
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: cargo-clippy
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6581715

@pkhry pkhry requested a review from lexnv June 28, 2024 00:01
@pkhry pkhry marked this pull request as ready for review June 28, 2024 00:01
@pkhry pkhry requested a review from a team as a code owner June 28, 2024 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D1-medium Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase. I5-enhancement An additional feature request. R0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants