diff --git a/Cargo.lock b/Cargo.lock index e5442a5828..e5aadca2f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6226,7 +6226,6 @@ dependencies = [ "parity-scale-codec 3.6.9", "polymesh-common-utilities", "polymesh-contracts", - "polymesh-extensions", "polymesh-node-rpc", "polymesh-primitives", "polymesh-runtime-common", @@ -6340,22 +6339,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "polymesh-extensions" -version = "0.1.0" -dependencies = [ - "frame-support", - "frame-system", - "pallet-permissions", - "pallet-transaction-payment", - "parity-scale-codec 3.6.9", - "polymesh-common-utilities", - "polymesh-primitives", - "scale-info", - "sp-runtime", - "sp-std", -] - [[package]] name = "polymesh-node-rpc" version = "0.1.0" @@ -6516,7 +6499,6 @@ dependencies = [ "polymesh-build-tool", "polymesh-common-utilities", "polymesh-contracts", - "polymesh-extensions", "polymesh-primitives", "polymesh-runtime-common", "polymesh-weights", @@ -6600,7 +6582,6 @@ dependencies = [ "polymesh-build-tool", "polymesh-common-utilities", "polymesh-contracts", - "polymesh-extensions", "polymesh-primitives", "polymesh-runtime-common", "polymesh-weights", @@ -6687,7 +6668,6 @@ dependencies = [ "polymesh-build-tool", "polymesh-common-utilities", "polymesh-contracts", - "polymesh-extensions", "polymesh-primitives", "polymesh-runtime-common", "polymesh-weights", @@ -6781,7 +6761,6 @@ dependencies = [ "polymesh-common-utilities", "polymesh-contracts", "polymesh-exec-macro", - "polymesh-extensions", "polymesh-primitives", "polymesh-runtime-common", "polymesh-runtime-develop", diff --git a/Cargo.toml b/Cargo.toml index 05ae889355..890c538342 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -189,7 +189,6 @@ polymesh-common-utilities = { path = "pallets/common", default-features = false polymesh-runtime-common = { path = "pallets/runtime/common", default-features = false } polymesh-primitives = { path = "primitives", default-features = false } polymesh-weights = { path = "pallets/weights/", default-features = false } -polymesh-extensions = { path = "pallets/runtime/extensions", default-features = false } # RPC node-rpc = { path = "rpc" } @@ -281,7 +280,6 @@ polymesh-contracts = { workspace = true, default-features = false } polymesh-common-utilities = { workspace = true, default-features = false } polymesh-primitives = { workspace = true, default-features = false } polymesh-runtime-common = { workspace = true, default-features = false } -polymesh-extensions = { workspace = true, default-features = false } # RPC node-rpc = { workspace = true } diff --git a/pallets/common/src/context.rs b/pallets/common/src/context.rs index 117aaafc72..419ab0e782 100644 --- a/pallets/common/src/context.rs +++ b/pallets/common/src/context.rs @@ -27,7 +27,7 @@ mod test { use polymesh_primitives::{AccountId, IdentityId}; use sp_keyring::AccountKeyring; - use std::{collections::BTreeMap, convert::From, sync::RwLock, thread}; + use std::{collections::BTreeMap, convert::From}; struct IdentityTest {} diff --git a/pallets/runtime/common/src/runtime.rs b/pallets/runtime/common/src/runtime.rs index 036a87529a..f385981c08 100644 --- a/pallets/runtime/common/src/runtime.rs +++ b/pallets/runtime/common/src/runtime.rs @@ -584,7 +584,7 @@ macro_rules! misc_pallet_impls { frame_system::CheckGenesis::new(), frame_system::CheckEra::from(generic::Era::mortal(period, current_block)), frame_system::CheckNonce::from(nonce), - polymesh_extensions::CheckWeight::new(), + frame_system::CheckWeight::new(), pallet_transaction_payment::ChargeTransactionPayment::from(tip), pallet_permissions::StoreCallMetadata::new(), ); @@ -749,7 +749,7 @@ macro_rules! runtime_apis { frame_system::CheckGenesis, frame_system::CheckEra, frame_system::CheckNonce, - polymesh_extensions::CheckWeight, + frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, pallet_permissions::StoreCallMetadata, ); diff --git a/pallets/runtime/develop/Cargo.toml b/pallets/runtime/develop/Cargo.toml index 4e0417bfe8..4e3944663b 100644 --- a/pallets/runtime/develop/Cargo.toml +++ b/pallets/runtime/develop/Cargo.toml @@ -13,7 +13,6 @@ polymesh-common-utilities = { path = "../../common", default-features = false } polymesh-runtime-common = { path = "../common", default-features = false } polymesh-primitives = { path = "../../../primitives", default-features = false } polymesh-weights = { path = "../../weights", default-features = false } -polymesh-extensions = { path = "../extensions", default-features = false } # Our pallets pallet-asset = { path = "../../asset", default-features = false } @@ -199,7 +198,6 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "polymesh-contracts/std", - "polymesh-extensions/std", ] runtime-benchmarks = [ "getrandom/js", diff --git a/pallets/runtime/extensions/Cargo.toml b/pallets/runtime/extensions/Cargo.toml deleted file mode 100644 index cfea846d0c..0000000000 --- a/pallets/runtime/extensions/Cargo.toml +++ /dev/null @@ -1,35 +0,0 @@ -[package] -name = "polymesh-extensions" -version = "0.1.0" -authors = ["PolymeshAssociation"] -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -polymesh-primitives = { path = "../../../primitives", default-features = false } -polymesh-common-utilities = { path = "../../common", default-features = false } - -pallet-transaction-payment = { path = "../../transaction-payment", default-features = false } -pallet-permissions = { path = "../../permissions", default-features = false } - -# Substrate -frame-system = { version = "4.0.0-dev", default-features = false } -frame-support = { version = "4.0.0-dev", default-features = false } -codec = { workspace = true, default-features = false, features = ["derive"] } -scale-info = { version = "2.0", default-features = false, features = ["derive"] } -sp-runtime = { version = "7.0.0", default-features = false } -sp-std = { version = "5.0.0", default-features = false } - -[features] -default = ["std"] -std = [ - "polymesh-primitives/std", - "polymesh-common-utilities/std", - "pallet-transaction-payment/std", - "pallet-permissions/std", - "frame-system/std", - "frame-support/std", - "sp-runtime/std", - "sp-std/std", -] diff --git a/pallets/runtime/extensions/src/check_weight.rs b/pallets/runtime/extensions/src/check_weight.rs deleted file mode 100644 index 84d0dfe9ca..0000000000 --- a/pallets/runtime/extensions/src/check_weight.rs +++ /dev/null @@ -1,164 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Modified by Polymesh Association - 2nd February 2021 -// - Priority of a transaction is always zero. - -use codec::{Decode, Encode}; -use frame_support::dispatch::{DispatchClass, DispatchInfo, PostDispatchInfo}; -use frame_system::{CheckWeight as CW, Config}; -use scale_info::TypeInfo; -use sp_runtime::{ - traits::{DispatchInfoOf, Dispatchable, PostDispatchInfoOf, SignedExtension}, - transaction_validity::{InvalidTransaction, TransactionValidity, TransactionValidityError}, - DispatchResult, -}; - -/// Block resource (weight) limit check. -#[derive(Encode, Decode, Clone, Eq, PartialEq, Default, TypeInfo)] -#[scale_info(skip_type_params(T))] -pub struct CheckWeight(CW); - -impl CheckWeight -where - T::RuntimeCall: Dispatchable, -{ - /// Creates new `SignedExtension` to check weight of the extrinsic. - pub fn new() -> Self { - Self(CW::new()) - } - - /// Do the validate checks. This can be applied to both signed and unsigned. - /// - /// It only checks that the block weight and length limit will not exceed. - fn do_validate(info: &DispatchInfoOf, len: usize) -> TransactionValidity { - let tv = CW::::do_validate(info, len)?; - Ok(tv) - } -} - -impl SignedExtension for CheckWeight -where - T::RuntimeCall: Dispatchable, -{ - type AccountId = T::AccountId; - type Call = T::RuntimeCall; - type AdditionalSigned = (); - type Pre = (); - const IDENTIFIER: &'static str = "CheckWeight"; - - fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> { - Ok(()) - } - - fn pre_dispatch( - self, - who: &Self::AccountId, - call: &Self::Call, - info: &DispatchInfoOf, - len: usize, - ) -> Result<(), TransactionValidityError> { - self.0.pre_dispatch(who, call, info, len) - } - - fn validate( - &self, - _who: &Self::AccountId, - _call: &Self::Call, - info: &DispatchInfoOf, - len: usize, - ) -> TransactionValidity { - if info.class == DispatchClass::Mandatory { - Err(InvalidTransaction::MandatoryValidation)? - } - Self::do_validate(info, len) - } - - fn pre_dispatch_unsigned( - call: &Self::Call, - info: &DispatchInfoOf, - len: usize, - ) -> Result<(), TransactionValidityError> { - CW::::pre_dispatch_unsigned(call, info, len) - } - - fn validate_unsigned( - _call: &Self::Call, - info: &DispatchInfoOf, - len: usize, - ) -> TransactionValidity { - Self::do_validate(info, len) - } - - fn post_dispatch( - pre: Option, - info: &DispatchInfoOf, - post_info: &PostDispatchInfoOf, - len: usize, - result: &DispatchResult, - ) -> Result<(), TransactionValidityError> { - CW::::post_dispatch(pre, info, post_info, len, result) - } -} - -impl sp_std::fmt::Debug for CheckWeight { - #[cfg(feature = "std")] - fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { - write!(f, "CheckWeight") - } - - #[cfg(not(feature = "std"))] - fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { - Ok(()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::mock::{new_test_ext, Test, CALL}; - use frame_support::weights::Pays; - - #[test] - fn signed_ext_check_weight_works() { - new_test_ext().execute_with(|| { - let normal = DispatchInfo { - weight: 100, - class: DispatchClass::Normal, - pays_fee: Pays::Yes, - }; - let op = DispatchInfo { - weight: 100, - class: DispatchClass::Operational, - pays_fee: Pays::Yes, - }; - let len = 0_usize; - - let priority = CheckWeight::::new() - .validate(&1, CALL, &normal, len) - .unwrap() - .priority; - assert_eq!(priority, 0); - - let priority = CheckWeight::::new() - .validate(&1, CALL, &op, len) - .unwrap() - .priority; - assert_eq!(priority, 0); - }) - } -} diff --git a/pallets/runtime/extensions/src/lib.rs b/pallets/runtime/extensions/src/lib.rs deleted file mode 100644 index 7f806fbc83..0000000000 --- a/pallets/runtime/extensions/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -mod check_weight; -pub use check_weight::CheckWeight; diff --git a/pallets/runtime/mainnet/Cargo.toml b/pallets/runtime/mainnet/Cargo.toml index 03009254d5..1d012a2081 100644 --- a/pallets/runtime/mainnet/Cargo.toml +++ b/pallets/runtime/mainnet/Cargo.toml @@ -10,7 +10,6 @@ build = "build.rs" [dependencies] # Common polymesh-common-utilities = { path = "../../common", default-features = false } -polymesh-extensions = { path = "../extensions", default-features = false } polymesh-primitives = { path = "../../../primitives", default-features = false } polymesh-runtime-common = { path = "../common", default-features = false} polymesh-weights = { path = "../../weights", default-features = false } diff --git a/pallets/runtime/testnet/Cargo.toml b/pallets/runtime/testnet/Cargo.toml index f7e4780ee2..caba28d1ca 100644 --- a/pallets/runtime/testnet/Cargo.toml +++ b/pallets/runtime/testnet/Cargo.toml @@ -13,7 +13,6 @@ polymesh-common-utilities = { path = "../../common", default-features = false } polymesh-runtime-common = { path = "../common", default-features = false} polymesh-primitives = { path = "../../../primitives", default-features = false } polymesh-weights = { path = "../../weights", default-features = false } -polymesh-extensions = { path = "../extensions", default-features = false } # Our pallets pallet-asset = { path = "../../asset", default-features = false } diff --git a/pallets/runtime/tests/Cargo.toml b/pallets/runtime/tests/Cargo.toml index 4f99d38715..5b04afca87 100644 --- a/pallets/runtime/tests/Cargo.toml +++ b/pallets/runtime/tests/Cargo.toml @@ -37,7 +37,6 @@ pallet-treasury = { path = "../../treasury", default-features = false } pallet-utility = { path = "../../utility", default-features = false } polymesh-common-utilities = { path = "../../common", default-features = false } polymesh-contracts = { path = "../../contracts", default-features = false } -polymesh-extensions = { path = "../extensions", default-features = false } polymesh-primitives = { path = "../../../primitives", default-features = false } polymesh-runtime-common = { path = "../common", default-features = false, features = ["testing"] } polymesh-runtime-develop = { path = "../develop" } diff --git a/pallets/runtime/tests/src/signed_extra.rs b/pallets/runtime/tests/src/signed_extra.rs index a3b12d58c8..32a4d48b09 100644 --- a/pallets/runtime/tests/src/signed_extra.rs +++ b/pallets/runtime/tests/src/signed_extra.rs @@ -7,7 +7,9 @@ use polymesh_runtime_develop::{ }; use frame_support::dispatch::{DispatchClass, DispatchInfo, Weight}; -use frame_system::{CheckEra, CheckGenesis, CheckNonce, CheckSpecVersion, CheckTxVersion}; +use frame_system::{ + CheckEra, CheckGenesis, CheckNonce, CheckSpecVersion, CheckTxVersion, CheckWeight, +}; use sp_io::TestExternalities; use sp_runtime::{generic, traits::SignedExtension}; use sp_std::convert::From; @@ -33,7 +35,7 @@ fn make_signed_extra(current_block: u64, period: u64, nonce: Index, tip: u128) - CheckGenesis::::new(), CheckEra::::from(generic::Era::mortal(period, current_block)), CheckNonce::::from(nonce), - polymesh_extensions::CheckWeight::::new(), + CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(tip), pallet_permissions::StoreCallMetadata::::new(), ) diff --git a/pallets/runtime/tests/src/storage.rs b/pallets/runtime/tests/src/storage.rs index 27cca73de2..5c57f793b0 100644 --- a/pallets/runtime/tests/src/storage.rs +++ b/pallets/runtime/tests/src/storage.rs @@ -1053,7 +1053,7 @@ fn signed_extra(nonce: Index) -> SignedExtra { frame_system::CheckGenesis::new(), frame_system::CheckEra::from(Era::mortal(256, 0)), frame_system::CheckNonce::from(nonce), - polymesh_extensions::CheckWeight::new(), + frame_system::CheckWeight::new(), pallet_transaction_payment::ChargeTransactionPayment::from(0), pallet_permissions::StoreCallMetadata::new(), ) diff --git a/src/benchmarking.rs b/src/benchmarking.rs index df9df41d2d..2c00bbe7bc 100644 --- a/src/benchmarking.rs +++ b/src/benchmarking.rs @@ -135,7 +135,7 @@ pub fn create_benchmark_extrinsic( best_block.saturated_into(), )), frame_system::CheckNonce::::from(nonce), - polymesh_extensions::CheckWeight::new(), + frame_system::CheckWeight::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(0), pallet_permissions::StoreCallMetadata::new(), );