From d4ba24cdd95ee35f7233e6e36edb630ac530ff7f Mon Sep 17 00:00:00 2001 From: Giuseppe Re Date: Tue, 26 Nov 2024 17:26:19 +0100 Subject: [PATCH 1/7] BACKPORT-CONFLICT --- prdoc/pr_6562.prdoc | 14 +++ .../runtime/src/type_with_default.rs | 86 ++++++++++++++++++- 2 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 prdoc/pr_6562.prdoc diff --git a/prdoc/pr_6562.prdoc b/prdoc/pr_6562.prdoc new file mode 100644 index 000000000000..250b656aefb5 --- /dev/null +++ b/prdoc/pr_6562.prdoc @@ -0,0 +1,14 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Hide nonce implementation details in metadata + +doc: + - audience: Runtime Dev + description: | + Use custom implementation of TypeInfo for TypeWithDefault to show inner value's type info. + This should bring back nonce to u64 in metadata. + +crates: +- name: sp-runtime + bump: minor \ No newline at end of file diff --git a/substrate/primitives/runtime/src/type_with_default.rs b/substrate/primitives/runtime/src/type_with_default.rs index 1465393640dc..de9ff9507c73 100644 --- a/substrate/primitives/runtime/src/type_with_default.rs +++ b/substrate/primitives/runtime/src/type_with_default.rs @@ -31,7 +31,7 @@ use num_traits::{ CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedShl, CheckedShr, CheckedSub, Num, NumCast, PrimInt, Saturating, ToPrimitive, }; -use scale_info::TypeInfo; +use scale_info::{StaticTypeInfo, TypeInfo}; use sp_core::Get; #[cfg(feature = "serde")] @@ -40,7 +40,8 @@ use serde::{Deserialize, Serialize}; /// A type that wraps another type and provides a default value. /// /// Passes through arithmetical and many other operations to the inner value. -#[derive(Encode, Decode, TypeInfo, Debug, MaxEncodedLen)] +/// Type information for metadata is the same as the inner value's type. +#[derive(Encode, Decode, Debug, MaxEncodedLen)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct TypeWithDefault>(T, PhantomData); @@ -50,6 +51,17 @@ impl> TypeWithDefault { } } +// Hides implementation details from the outside (for metadata type information). +// +// The type info showed in metadata is the one of the inner value's type. +impl + 'static> TypeInfo for TypeWithDefault { + type Identity = Self; + + fn type_info() -> scale_info::Type { + T::type_info() + } +} + impl> Clone for TypeWithDefault { fn clone(&self) -> Self { Self(self.0.clone(), PhantomData) @@ -504,3 +516,73 @@ impl> CompactAs for TypeWithDefault { Ok(Self::new(val)) } } +<<<<<<< HEAD +======= + +#[cfg(test)] +mod tests { + use super::TypeWithDefault; + use scale_info::TypeInfo; + use sp_arithmetic::traits::{AtLeast16Bit, AtLeast32Bit, AtLeast8Bit}; + use sp_core::Get; + + #[test] + #[allow(dead_code)] + fn test_type_with_default_impl_base_arithmetic() { + trait WrapAtLeast8Bit: AtLeast8Bit {} + trait WrapAtLeast16Bit: AtLeast16Bit {} + trait WrapAtLeast32Bit: AtLeast32Bit {} + + struct Getu8; + impl Get for Getu8 { + fn get() -> u8 { + 0 + } + } + type U8WithDefault = TypeWithDefault; + impl WrapAtLeast8Bit for U8WithDefault {} + + struct Getu16; + impl Get for Getu16 { + fn get() -> u16 { + 0 + } + } + type U16WithDefault = TypeWithDefault; + impl WrapAtLeast16Bit for U16WithDefault {} + + struct Getu32; + impl Get for Getu32 { + fn get() -> u32 { + 0 + } + } + type U32WithDefault = TypeWithDefault; + impl WrapAtLeast32Bit for U32WithDefault {} + + struct Getu64; + impl Get for Getu64 { + fn get() -> u64 { + 0 + } + } + type U64WithDefault = TypeWithDefault; + impl WrapAtLeast32Bit for U64WithDefault {} + + struct Getu128; + impl Get for Getu128 { + fn get() -> u128 { + 0 + } + } + type U128WithDefault = TypeWithDefault; + impl WrapAtLeast32Bit for U128WithDefault {} + + assert_eq!(U8WithDefault::type_info(), ::type_info()); + assert_eq!(U16WithDefault::type_info(), ::type_info()); + assert_eq!(U32WithDefault::type_info(), ::type_info()); + assert_eq!(U64WithDefault::type_info(), ::type_info()); + assert_eq!(U128WithDefault::type_info(), ::type_info()); + } +} +>>>>>>> fc315ac5 (Hide nonce implementation details in metadata (#6562)) From ec11998e6a30c5fcc0311b68698a70e5b159f7cd Mon Sep 17 00:00:00 2001 From: Giuseppe Re Date: Thu, 28 Nov 2024 18:26:43 +0100 Subject: [PATCH 2/7] merge fix --- substrate/primitives/runtime/src/type_with_default.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/substrate/primitives/runtime/src/type_with_default.rs b/substrate/primitives/runtime/src/type_with_default.rs index de9ff9507c73..b70d0e1ef766 100644 --- a/substrate/primitives/runtime/src/type_with_default.rs +++ b/substrate/primitives/runtime/src/type_with_default.rs @@ -516,8 +516,6 @@ impl> CompactAs for TypeWithDefault { Ok(Self::new(val)) } } -<<<<<<< HEAD -======= #[cfg(test)] mod tests { @@ -585,4 +583,3 @@ mod tests { assert_eq!(U128WithDefault::type_info(), ::type_info()); } } ->>>>>>> fc315ac5 (Hide nonce implementation details in metadata (#6562)) From f24502d6165352b2482562802237a672b59e9bc6 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 29 Nov 2024 17:57:25 +0000 Subject: [PATCH 3/7] Update from re-gius running command 'prdoc --bump patch --audience runtime_dev' --- prdoc/pr_6700.prdoc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 prdoc/pr_6700.prdoc diff --git a/prdoc/pr_6700.prdoc b/prdoc/pr_6700.prdoc new file mode 100644 index 000000000000..86b76adf640f --- /dev/null +++ b/prdoc/pr_6700.prdoc @@ -0,0 +1,15 @@ +title: '[stable2412] Backport #6562' +doc: +- audience: Runtime Dev + description: |- + Backport #6562 into `stable2412` from re-gius. + + See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. + + +crates: +- name: sp-runtime + bump: patch From d8d687c147037ba3e399d6d0b47fc49ba64b5ed5 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Fri, 29 Nov 2024 19:03:05 +0100 Subject: [PATCH 4/7] Fix tests --- substrate/primitives/runtime/src/type_with_default.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/primitives/runtime/src/type_with_default.rs b/substrate/primitives/runtime/src/type_with_default.rs index b70d0e1ef766..2a5c0c4682dc 100644 --- a/substrate/primitives/runtime/src/type_with_default.rs +++ b/substrate/primitives/runtime/src/type_with_default.rs @@ -565,7 +565,7 @@ mod tests { } } type U64WithDefault = TypeWithDefault; - impl WrapAtLeast32Bit for U64WithDefault {} + impl WrapAtLeast64Bit for U64WithDefault {} struct Getu128; impl Get for Getu128 { @@ -574,7 +574,7 @@ mod tests { } } type U128WithDefault = TypeWithDefault; - impl WrapAtLeast32Bit for U128WithDefault {} + impl WrapAtLeast128Bit for U128WithDefault {} assert_eq!(U8WithDefault::type_info(), ::type_info()); assert_eq!(U16WithDefault::type_info(), ::type_info()); From 2c4c2a36687e4fbdf7a671629083864ed0cfed75 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Fri, 29 Nov 2024 19:07:25 +0100 Subject: [PATCH 5/7] Revert "Fix tests" This reverts commit d8d687c147037ba3e399d6d0b47fc49ba64b5ed5. --- substrate/primitives/runtime/src/type_with_default.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/primitives/runtime/src/type_with_default.rs b/substrate/primitives/runtime/src/type_with_default.rs index 2a5c0c4682dc..b70d0e1ef766 100644 --- a/substrate/primitives/runtime/src/type_with_default.rs +++ b/substrate/primitives/runtime/src/type_with_default.rs @@ -565,7 +565,7 @@ mod tests { } } type U64WithDefault = TypeWithDefault; - impl WrapAtLeast64Bit for U64WithDefault {} + impl WrapAtLeast32Bit for U64WithDefault {} struct Getu128; impl Get for Getu128 { @@ -574,7 +574,7 @@ mod tests { } } type U128WithDefault = TypeWithDefault; - impl WrapAtLeast128Bit for U128WithDefault {} + impl WrapAtLeast32Bit for U128WithDefault {} assert_eq!(U8WithDefault::type_info(), ::type_info()); assert_eq!(U16WithDefault::type_info(), ::type_info()); From a1d11e05de688966c9a0c1f09c631fbdbe8df24c Mon Sep 17 00:00:00 2001 From: giuseppere Date: Fri, 29 Nov 2024 19:10:39 +0100 Subject: [PATCH 6/7] Remove tests --- .../runtime/src/type_with_default.rs | 67 ------------------- 1 file changed, 67 deletions(-) diff --git a/substrate/primitives/runtime/src/type_with_default.rs b/substrate/primitives/runtime/src/type_with_default.rs index b70d0e1ef766..a75bcc2a9525 100644 --- a/substrate/primitives/runtime/src/type_with_default.rs +++ b/substrate/primitives/runtime/src/type_with_default.rs @@ -516,70 +516,3 @@ impl> CompactAs for TypeWithDefault { Ok(Self::new(val)) } } - -#[cfg(test)] -mod tests { - use super::TypeWithDefault; - use scale_info::TypeInfo; - use sp_arithmetic::traits::{AtLeast16Bit, AtLeast32Bit, AtLeast8Bit}; - use sp_core::Get; - - #[test] - #[allow(dead_code)] - fn test_type_with_default_impl_base_arithmetic() { - trait WrapAtLeast8Bit: AtLeast8Bit {} - trait WrapAtLeast16Bit: AtLeast16Bit {} - trait WrapAtLeast32Bit: AtLeast32Bit {} - - struct Getu8; - impl Get for Getu8 { - fn get() -> u8 { - 0 - } - } - type U8WithDefault = TypeWithDefault; - impl WrapAtLeast8Bit for U8WithDefault {} - - struct Getu16; - impl Get for Getu16 { - fn get() -> u16 { - 0 - } - } - type U16WithDefault = TypeWithDefault; - impl WrapAtLeast16Bit for U16WithDefault {} - - struct Getu32; - impl Get for Getu32 { - fn get() -> u32 { - 0 - } - } - type U32WithDefault = TypeWithDefault; - impl WrapAtLeast32Bit for U32WithDefault {} - - struct Getu64; - impl Get for Getu64 { - fn get() -> u64 { - 0 - } - } - type U64WithDefault = TypeWithDefault; - impl WrapAtLeast32Bit for U64WithDefault {} - - struct Getu128; - impl Get for Getu128 { - fn get() -> u128 { - 0 - } - } - type U128WithDefault = TypeWithDefault; - impl WrapAtLeast32Bit for U128WithDefault {} - - assert_eq!(U8WithDefault::type_info(), ::type_info()); - assert_eq!(U16WithDefault::type_info(), ::type_info()); - assert_eq!(U32WithDefault::type_info(), ::type_info()); - assert_eq!(U64WithDefault::type_info(), ::type_info()); - assert_eq!(U128WithDefault::type_info(), ::type_info()); - } -} From 47533974731ac5f355a0458992fc5912865b42c1 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Fri, 29 Nov 2024 19:13:03 +0100 Subject: [PATCH 7/7] Remove prdocs --- prdoc/pr_6562.prdoc | 14 -------------- prdoc/pr_6700.prdoc | 15 --------------- 2 files changed, 29 deletions(-) delete mode 100644 prdoc/pr_6562.prdoc delete mode 100644 prdoc/pr_6700.prdoc diff --git a/prdoc/pr_6562.prdoc b/prdoc/pr_6562.prdoc deleted file mode 100644 index 250b656aefb5..000000000000 --- a/prdoc/pr_6562.prdoc +++ /dev/null @@ -1,14 +0,0 @@ -# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 -# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json - -title: Hide nonce implementation details in metadata - -doc: - - audience: Runtime Dev - description: | - Use custom implementation of TypeInfo for TypeWithDefault to show inner value's type info. - This should bring back nonce to u64 in metadata. - -crates: -- name: sp-runtime - bump: minor \ No newline at end of file diff --git a/prdoc/pr_6700.prdoc b/prdoc/pr_6700.prdoc deleted file mode 100644 index 86b76adf640f..000000000000 --- a/prdoc/pr_6700.prdoc +++ /dev/null @@ -1,15 +0,0 @@ -title: '[stable2412] Backport #6562' -doc: -- audience: Runtime Dev - description: |- - Backport #6562 into `stable2412` from re-gius. - - See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. - - -crates: -- name: sp-runtime - bump: patch