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

Migrate pallet-verify-signature to umbrella crate #6515

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions prdoc/pr_6515.prdoc
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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};
}
}

Expand Down
20 changes: 4 additions & 16 deletions substrate/frame/verify-signature/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,41 @@ 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]
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",
]
19 changes: 7 additions & 12 deletions substrate/frame/verify-signature/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@
#![cfg(feature = "runtime-benchmarks")]

extern crate alloc;

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<Signature, Signer> {
fn create_signature(entropy: &[u8], msg: &[u8]) -> (Signature, Signer);
Expand Down
17 changes: 9 additions & 8 deletions substrate/frame/verify-signature/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@

use crate::{Config, WeightInfo};
use codec::{Decode, Encode};
use frame_support::{pallet_prelude::TransactionSource, traits::OriginTrait};
use scale_info::TypeInfo;
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 scale_info::TypeInfo;
use sp_weights::Weight;

/// Extension that, if enabled, validates a signature type against the payload constructed from the
Expand Down
8 changes: 5 additions & 3 deletions substrate/frame/verify-signature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
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<T>(_);
Expand Down
24 changes: 8 additions & 16 deletions substrate/frame/verify-signature/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,15 @@
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 frame_system::Call as SystemCall;
use sp_io::hashing::blake2_256;
use sp_runtime::{
generic::ExtensionVersion,
testing::{TestSignature, UintAuthorityId},
traits::DispatchTransaction,
};

type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down Expand Up @@ -69,10 +61,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::<Test>::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
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/verify-signature/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.