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 15 commits into
base: master
Choose a base branch
from
Open
8 changes: 1 addition & 7 deletions Cargo.lock

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

49 changes: 41 additions & 8 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,10 @@ 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::{DispatchInfo, GetDispatchInfo, PostDispatchInfo};
pub use frame_support::traits::{
Contains, EstimateNextSessionRotation, IsSubType, OnRuntimeUpgrade, OneSessionHandler,
OriginTrait,
};

/// Pallet prelude of `frame-system`.
Expand All @@ -219,8 +220,13 @@ pub mod prelude {
#[doc(no_inline)]
pub use super::derive::*;

/// All hashing related things
pub use super::hashing::*;
/// All crypto related things.
pub use super::cryptography::*;

/// All account related things.
pub use super::account::*;

pub use crate::transaction::*;

/// All arithmetic types and traits used for safe math.
pub use super::arithmetic::*;
Expand Down Expand Up @@ -375,7 +381,7 @@ pub mod runtime {
};

/// Used for simple fee calculation.
pub use frame_support::weights::{self, FixedFee, NoFee};
pub use frame_support::weights::{self, FixedFee, NoFee, Weight};

/// Primary types used to parameterize `EnsureOrigin` and `EnsureRootWithArg`.
pub use frame_system::{
Expand Down Expand Up @@ -504,7 +510,7 @@ pub mod runtime {
#[cfg(feature = "std")]
pub mod testing_prelude {
pub use sp_core::storage::Storage;
pub use sp_runtime::BuildStorage;
pub use sp_runtime::{testing::UintAuthorityId, BuildStorage};
}
}

Expand Down Expand Up @@ -540,9 +546,36 @@ pub mod derive {
pub use sp_runtime::RuntimeDebug;
}

pub mod hashing {
pub use sp_core::{hashing::*, H160, H256, H512, U256, U512};
pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256};
pub mod cryptography {
pub use sp_core::{
crypto::{VrfPublic, VrfSecret, Wraps},
hashing::*,
Pair, H160, H256, H512, U256, U512,
};
pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256, Verify};
}

/// All account management related traits.
///
/// This is already part of the [`prelude`].
pub mod account {
pub use frame_support::traits::{ChangeMembers, EitherOfDiverse, InitializeMembers};
pub use sp_runtime::traits::IdentifyAccount;
}

/// Systems involved in transaction fulfilment.
///
/// This is already part of the [`prelude`].
pub mod transaction {
pub use sp_runtime::{
generic::ExtensionVersion,
impl_tx_ext_default,
traits::{
AsTransactionAuthorizedOrigin, DispatchTransaction, TransactionExtension,
ValidateResult,
},
transaction_validity::{InvalidTransaction, ValidTransaction},
};
}

/// Access to all of the dependencies of this crate. In case the prelude re-exports are not enough,
Expand Down
26 changes: 4 additions & 22 deletions substrate/frame/verify-signature/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,36 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-weights = { features = ["serde"], workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }

[dev-dependencies]
pallet-balances = { workspace = true, default-features = true }
pallet-collective = { workspace = true, default-features = true }
pallet-root-testing = { 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-system/std",
"frame/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-system/runtime-benchmarks",
"frame/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-system/try-runtime",
"frame/try-runtime",
"pallet-balances/try-runtime",
"pallet-collective/try-runtime",
"pallet-root-testing/try-runtime",
"pallet-timestamp/try-runtime",
"sp-runtime/try-runtime",
]
13 changes: 1 addition & 12 deletions substrate/frame/verify-signature/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,12 @@
#![cfg(feature = "runtime-benchmarks")]

extern crate alloc;

use super::*;
use frame::benchmarking::prelude::{frame_system::Call as SystemCall, *};

#[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},
};

pub trait BenchmarkHelper<Signature, Signer> {
fn create_signature(entropy: &[u8], msg: &[u8]) -> (Signature, Signer);
Expand Down
14 changes: 2 additions & 12 deletions substrate/frame/verify-signature/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,13 @@

use crate::{Config, WeightInfo};
use codec::{Decode, Encode};
use frame_support::{pallet_prelude::TransactionSource, traits::OriginTrait};
use frame::runtime::prelude::*;
use scale_info::TypeInfo;
use sp_io::hashing::blake2_256;
use sp_runtime::{
impl_tx_ext_default,
traits::{
transaction_extension::TransactionExtension, AsTransactionAuthorizedOrigin, DispatchInfoOf,
Dispatchable, Verify,
},
transaction_validity::{InvalidTransaction, TransactionValidityError, ValidTransaction},
};
use sp_weights::Weight;

/// Extension that, if enabled, validates a signature type against the payload constructed from the
/// call and the rest of the transaction extension pipeline. This extension provides the
/// functionality that traditionally signed transactions had with the implicit signature checking
/// implemented in [`Checkable`](sp_runtime::traits::Checkable). It is meant to be placed ahead of
/// implemented in [`Checkable`](frame::traits::Checkable). It is meant to be placed ahead of
/// any other extensions that do authorization work in the [`TransactionExtension`] pipeline.
#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo)]
#[scale_info(skip_type_params(T))]
Expand Down
5 changes: 2 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,14 @@ extern crate alloc;
pub use benchmarking::BenchmarkHelper;
use codec::{Decode, Encode};
pub use extension::VerifySignature;
use frame_support::Parameter;
use frame::prelude::*;
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
23 changes: 5 additions & 18 deletions substrate/frame/verify-signature/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,11 @@
use super::*;

use extension::VerifySignature;
use frame_support::{
derive_impl,
dispatch::GetDispatchInfo,
pallet_prelude::{InvalidTransaction, TransactionSource, TransactionValidityError},
traits::OriginTrait,
};
use frame::{deps::sp_runtime::testing::TestSignature, testing_prelude::*};
use frame_system::Call as SystemCall;
use sp_io::hashing::blake2_256;
use sp_runtime::{
generic::ExtensionVersion,
testing::{TestSignature, UintAuthorityId},
traits::DispatchTransaction,
};
type Block = MockBlock<Test>;

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 +57,9 @@ 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 {
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.

Loading