From bacffb9f65cf570384bac35ed023222a7737650b Mon Sep 17 00:00:00 2001 From: bennethxyz Date: Sun, 17 Nov 2024 16:26:09 -0800 Subject: [PATCH 1/2] frame-verify-signature --- Cargo.lock | 6 +----- substrate/frame/src/lib.rs | 5 +++-- substrate/frame/verify-signature/Cargo.toml | 20 ++++--------------- .../verify-signature/src/benchmarking.rs | 8 ++++++-- .../frame/verify-signature/src/extension.rs | 5 ++++- substrate/frame/verify-signature/src/lib.rs | 8 +++++--- substrate/frame/verify-signature/src/tests.rs | 15 ++++++++------ .../frame/verify-signature/src/weights.rs | 3 ++- 8 files changed, 34 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 182d8f6bacad..dfd2a2374783 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15778,18 +15778,14 @@ dependencies = [ name = "pallet-verify-signature" version = "1.0.0" dependencies = [ - "frame-benchmarking 28.0.0", - "frame-support 28.0.0", "frame-system 28.0.0", "pallet-balances 28.0.0", "pallet-collective 28.0.0", "pallet-root-testing 4.0.0", "pallet-timestamp 27.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", - "sp-core 28.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", "sp-weights 27.0.0", ] diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 0ca36ca8545a..dafadc910dbd 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -202,7 +202,7 @@ pub mod prelude { /// Dispatch types from `frame-support`, other fundamental traits #[doc(no_inline)] - pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; + pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo, DispatchInfo}; pub use frame_support::traits::{Contains, IsSubType, OnRuntimeUpgrade}; /// Pallet prelude of `frame-system`. @@ -392,7 +392,7 @@ pub mod runtime { }; pub use sp_inherents::{CheckInherentsResult, InherentData}; pub use sp_keyring::AccountKeyring; - pub use sp_runtime::{ApplyExtrinsicResult, ExtrinsicInclusionMode}; + pub use sp_runtime::{ApplyExtrinsicResult, ExtrinsicInclusionMode, impl_tx_ext_default}; } /// Types and traits for runtimes that implement runtime APIs. @@ -494,6 +494,7 @@ pub mod runtime { pub mod testing_prelude { pub use sp_core::storage::Storage; pub use sp_runtime::BuildStorage; + pub use sp_runtime::{testing::{TestSignature, UintAuthorityId}, generic::ExtensionVersion}; } } diff --git a/substrate/frame/verify-signature/Cargo.toml b/substrate/frame/verify-signature/Cargo.toml index 3c5fd5e65157..7443f5be9e0a 100644 --- a/substrate/frame/verify-signature/Cargo.toml +++ b/substrate/frame/verify-signature/Cargo.toml @@ -18,12 +18,8 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { workspace = true } scale-info = { features = ["derive"], workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } frame-system = { workspace = true } -sp-core = { workspace = true } -sp-io = { workspace = true } -sp-runtime = { workspace = true } sp-weights = { features = ["serde"], workspace = true } [dev-dependencies] @@ -31,40 +27,32 @@ pallet-balances = { workspace = true, default-features = true } pallet-root-testing = { workspace = true, default-features = true } pallet-collective = { workspace = true, default-features = true } pallet-timestamp = { workspace = true, default-features = true } -sp-core = { workspace = true, default-features = true } [features] default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", + "frame/std", "frame-system/std", "pallet-balances/std", "pallet-collective/std", "pallet-root-testing/std", "pallet-timestamp/std", "scale-info/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", "sp-weights/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", + "frame/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", + "frame/try-runtime", "frame-system/try-runtime", "pallet-balances/try-runtime", "pallet-collective/try-runtime", "pallet-root-testing/try-runtime", "pallet-timestamp/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/substrate/frame/verify-signature/src/benchmarking.rs b/substrate/frame/verify-signature/src/benchmarking.rs index 99e893e6f6ab..0457b20179cd 100644 --- a/substrate/frame/verify-signature/src/benchmarking.rs +++ b/substrate/frame/verify-signature/src/benchmarking.rs @@ -20,23 +20,27 @@ #![cfg(feature = "runtime-benchmarks")] extern crate alloc; - +use frame::{benchmarking::prelude::*, prelude::{DispatchInfo, Dispatchable}, testing_prelude::ExtensionVersion, traits::{AsTransactionAuthorizedOrigin, DispatchTransaction}}; use super::*; #[allow(unused)] use crate::{extension::VerifySignature, Config, Pallet as VerifySignaturePallet}; use alloc::vec; +/* use frame_benchmarking::{v2::*, BenchmarkError}; use frame_support::{ dispatch::{DispatchInfo, GetDispatchInfo}, pallet_prelude::TransactionSource, }; -use frame_system::{Call as SystemCall, RawOrigin}; +*/ +use frame_system::Call as SystemCall; //RawOrigin}; +/* use sp_io::hashing::blake2_256; use sp_runtime::{ generic::ExtensionVersion, traits::{AsTransactionAuthorizedOrigin, DispatchTransaction, Dispatchable}, }; +*/ pub trait BenchmarkHelper { fn create_signature(entropy: &[u8], msg: &[u8]) -> (Signature, Signer); diff --git a/substrate/frame/verify-signature/src/extension.rs b/substrate/frame/verify-signature/src/extension.rs index d48991e7a1da..945dcf36dc3f 100644 --- a/substrate/frame/verify-signature/src/extension.rs +++ b/substrate/frame/verify-signature/src/extension.rs @@ -20,8 +20,9 @@ use crate::{Config, WeightInfo}; use codec::{Decode, Encode}; -use frame_support::{pallet_prelude::TransactionSource, traits::OriginTrait}; use scale_info::TypeInfo; +/* +use frame_support::{pallet_prelude::TransactionSource, traits::OriginTrait}; use sp_io::hashing::blake2_256; use sp_runtime::{ impl_tx_ext_default, @@ -31,6 +32,8 @@ use sp_runtime::{ }, transaction_validity::{InvalidTransaction, TransactionValidityError, ValidTransaction}, }; +*/ +use frame::{traits::{TransactionExtension, Dispatchable, AsTransactionAuthorizedOrigin, DispatchInfoOf, Verify, OriginTrait}, runtime::prelude::{TransactionSource, ValidTransaction, InvalidTransaction, TransactionValidityError, impl_tx_ext_default}, hashing::blake2_256}; use sp_weights::Weight; /// Extension that, if enabled, validates a signature type against the payload constructed from the diff --git a/substrate/frame/verify-signature/src/lib.rs b/substrate/frame/verify-signature/src/lib.rs index 96d83dbef9f7..fa53504bf05b 100644 --- a/substrate/frame/verify-signature/src/lib.rs +++ b/substrate/frame/verify-signature/src/lib.rs @@ -34,15 +34,17 @@ extern crate alloc; pub use benchmarking::BenchmarkHelper; use codec::{Decode, Encode}; pub use extension::VerifySignature; -use frame_support::Parameter; +// use frame_support::Parameter; +use frame::{prelude::*, traits::{IdentifyAccount, Verify}}; pub use weights::WeightInfo; pub use pallet::*; -#[frame_support::pallet] +// #[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; - use sp_runtime::traits::{IdentifyAccount, Verify}; + // use sp_runtime::traits::{IdentifyAccount, Verify}; #[pallet::pallet] pub struct Pallet(_); diff --git a/substrate/frame/verify-signature/src/tests.rs b/substrate/frame/verify-signature/src/tests.rs index 63a310506eec..b08e4d5c4c86 100644 --- a/substrate/frame/verify-signature/src/tests.rs +++ b/substrate/frame/verify-signature/src/tests.rs @@ -22,23 +22,26 @@ use super::*; use extension::VerifySignature; +/* use frame_support::{ derive_impl, dispatch::GetDispatchInfo, pallet_prelude::{InvalidTransaction, TransactionSource, TransactionValidityError}, traits::OriginTrait, }; -use frame_system::Call as SystemCall; +; use sp_io::hashing::blake2_256; use sp_runtime::{ generic::ExtensionVersion, testing::{TestSignature, UintAuthorityId}, traits::DispatchTransaction, }; - +*/ +use frame_system::Call as SystemCall; +use frame::{testing_prelude::*, pallet_macros::derive_impl, traits::{DispatchTransaction, OriginTrait}}; type Block = frame_system::mocking::MockBlock; -frame_support::construct_runtime!( +construct_runtime!( pub enum Test { System: frame_system, @@ -69,10 +72,10 @@ impl crate::Config for Test { } #[cfg(feature = "runtime-benchmarks")] -pub fn new_test_ext() -> sp_io::TestExternalities { - use sp_runtime::BuildStorage; +pub fn new_test_ext() -> TestExternalities { + // use sp_runtime::BuildStorage; let t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - let mut ext = sp_io::TestExternalities::new(t); + let mut ext = TestExternalities::new(t); ext.execute_with(|| System::set_block_number(1)); ext } diff --git a/substrate/frame/verify-signature/src/weights.rs b/substrate/frame/verify-signature/src/weights.rs index a8bfa9ea902d..9b6ddb0eac64 100644 --- a/substrate/frame/verify-signature/src/weights.rs +++ b/substrate/frame/verify-signature/src/weights.rs @@ -46,7 +46,8 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +// use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use frame::weights_prelude::*; use core::marker::PhantomData; /// Weight functions needed for `pallet_verify_signature`. From 418709c5fa5f4d717a13d7d10a80a52f218727b4 Mon Sep 17 00:00:00 2001 From: bennethxyz Date: Sun, 24 Nov 2024 13:03:18 -0800 Subject: [PATCH 2/2] cargo +nightly fmt, add prdoc --- prdoc/pr_6515.prdoc | 17 ++++++++++++++ .../verify-signature/src/benchmarking.rs | 23 ++++++------------- .../frame/verify-signature/src/extension.rs | 20 ++++++++-------- substrate/frame/verify-signature/src/lib.rs | 8 +++---- substrate/frame/verify-signature/src/tests.rs | 19 ++++----------- .../frame/verify-signature/src/weights.rs | 1 - 6 files changed, 41 insertions(+), 47 deletions(-) create mode 100644 prdoc/pr_6515.prdoc diff --git a/prdoc/pr_6515.prdoc b/prdoc/pr_6515.prdoc new file mode 100644 index 000000000000..c64db4aea22d --- /dev/null +++ b/prdoc/pr_6515.prdoc @@ -0,0 +1,17 @@ +# 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: migrate pallet-verify-signature to umbrella crate + +doc: + - audience: Runtime Dev + description: | + This pull request adapts the frame umbrella crate into pallet-verify-signature + by importing existing systems into the pallet. + + +crates: + - name: polkadot-sdk-frame + bump: minor + - name: pallet-verify-signature + bump: minor \ No newline at end of file diff --git a/substrate/frame/verify-signature/src/benchmarking.rs b/substrate/frame/verify-signature/src/benchmarking.rs index 0457b20179cd..947f26ac5143 100644 --- a/substrate/frame/verify-signature/src/benchmarking.rs +++ b/substrate/frame/verify-signature/src/benchmarking.rs @@ -20,27 +20,18 @@ #![cfg(feature = "runtime-benchmarks")] extern crate alloc; -use frame::{benchmarking::prelude::*, prelude::{DispatchInfo, Dispatchable}, testing_prelude::ExtensionVersion, traits::{AsTransactionAuthorizedOrigin, DispatchTransaction}}; use super::*; +use frame::{ + benchmarking::prelude::*, + prelude::{DispatchInfo, Dispatchable}, + testing_prelude::ExtensionVersion, + traits::{AsTransactionAuthorizedOrigin, DispatchTransaction}, +}; #[allow(unused)] use crate::{extension::VerifySignature, Config, Pallet as VerifySignaturePallet}; use alloc::vec; -/* -use frame_benchmarking::{v2::*, BenchmarkError}; -use frame_support::{ - dispatch::{DispatchInfo, GetDispatchInfo}, - pallet_prelude::TransactionSource, -}; -*/ -use frame_system::Call as SystemCall; //RawOrigin}; -/* -use sp_io::hashing::blake2_256; -use sp_runtime::{ - generic::ExtensionVersion, - traits::{AsTransactionAuthorizedOrigin, DispatchTransaction, Dispatchable}, -}; -*/ +use frame_system::Call as SystemCall; pub trait BenchmarkHelper { fn create_signature(entropy: &[u8], msg: &[u8]) -> (Signature, Signer); diff --git a/substrate/frame/verify-signature/src/extension.rs b/substrate/frame/verify-signature/src/extension.rs index 945dcf36dc3f..7ef355bb0480 100644 --- a/substrate/frame/verify-signature/src/extension.rs +++ b/substrate/frame/verify-signature/src/extension.rs @@ -20,20 +20,18 @@ use crate::{Config, WeightInfo}; use codec::{Decode, Encode}; -use scale_info::TypeInfo; -/* -use frame_support::{pallet_prelude::TransactionSource, traits::OriginTrait}; -use sp_io::hashing::blake2_256; -use sp_runtime::{ - impl_tx_ext_default, +use frame::{ + hashing::blake2_256, + runtime::prelude::{ + impl_tx_ext_default, InvalidTransaction, TransactionSource, TransactionValidityError, + ValidTransaction, + }, traits::{ - transaction_extension::TransactionExtension, AsTransactionAuthorizedOrigin, DispatchInfoOf, - Dispatchable, Verify, + AsTransactionAuthorizedOrigin, DispatchInfoOf, Dispatchable, OriginTrait, + TransactionExtension, Verify, }, - transaction_validity::{InvalidTransaction, TransactionValidityError, ValidTransaction}, }; -*/ -use frame::{traits::{TransactionExtension, Dispatchable, AsTransactionAuthorizedOrigin, DispatchInfoOf, Verify, OriginTrait}, runtime::prelude::{TransactionSource, ValidTransaction, InvalidTransaction, TransactionValidityError, impl_tx_ext_default}, hashing::blake2_256}; +use scale_info::TypeInfo; use sp_weights::Weight; /// Extension that, if enabled, validates a signature type against the payload constructed from the diff --git a/substrate/frame/verify-signature/src/lib.rs b/substrate/frame/verify-signature/src/lib.rs index fa53504bf05b..e4f1370e2c5d 100644 --- a/substrate/frame/verify-signature/src/lib.rs +++ b/substrate/frame/verify-signature/src/lib.rs @@ -34,17 +34,17 @@ extern crate alloc; pub use benchmarking::BenchmarkHelper; use codec::{Decode, Encode}; pub use extension::VerifySignature; -// use frame_support::Parameter; -use frame::{prelude::*, traits::{IdentifyAccount, Verify}}; +use frame::{ + prelude::*, + traits::{IdentifyAccount, Verify}, +}; pub use weights::WeightInfo; pub use pallet::*; -// #[frame_support::pallet] #[frame::pallet] pub mod pallet { use super::*; - // use sp_runtime::traits::{IdentifyAccount, Verify}; #[pallet::pallet] pub struct Pallet(_); diff --git a/substrate/frame/verify-signature/src/tests.rs b/substrate/frame/verify-signature/src/tests.rs index b08e4d5c4c86..6364cfd809a7 100644 --- a/substrate/frame/verify-signature/src/tests.rs +++ b/substrate/frame/verify-signature/src/tests.rs @@ -22,23 +22,12 @@ use super::*; use extension::VerifySignature; -/* -use frame_support::{ - derive_impl, - dispatch::GetDispatchInfo, - pallet_prelude::{InvalidTransaction, TransactionSource, TransactionValidityError}, - traits::OriginTrait, +use frame::{ + pallet_macros::derive_impl, + testing_prelude::*, + traits::{DispatchTransaction, OriginTrait}, }; -; -use sp_io::hashing::blake2_256; -use sp_runtime::{ - generic::ExtensionVersion, - testing::{TestSignature, UintAuthorityId}, - traits::DispatchTransaction, -}; -*/ use frame_system::Call as SystemCall; -use frame::{testing_prelude::*, pallet_macros::derive_impl, traits::{DispatchTransaction, OriginTrait}}; type Block = frame_system::mocking::MockBlock; construct_runtime!( diff --git a/substrate/frame/verify-signature/src/weights.rs b/substrate/frame/verify-signature/src/weights.rs index 9b6ddb0eac64..d9779da9fc85 100644 --- a/substrate/frame/verify-signature/src/weights.rs +++ b/substrate/frame/verify-signature/src/weights.rs @@ -46,7 +46,6 @@ #![allow(unused_imports)] #![allow(missing_docs)] -// use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use frame::weights_prelude::*; use core::marker::PhantomData;