diff --git a/Cargo.lock b/Cargo.lock index 8f815671a77b6..c8041d9cab76c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -653,8 +653,8 @@ dependencies = [ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xoshiro 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", @@ -678,7 +678,7 @@ dependencies = [ "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xoshiro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", @@ -743,6 +743,14 @@ dependencies = [ "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-queue" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam-utils" version = "0.6.6" @@ -1722,7 +1730,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1732,7 +1740,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2667,7 +2675,7 @@ dependencies = [ "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.9.52 (registry+https://github.com/rust-lang/crates.io-index)", "schannel 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "security-framework 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "security-framework-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3169,6 +3177,7 @@ dependencies = [ "paste 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-arithmetic 2.0.0", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3845,6 +3854,7 @@ dependencies = [ name = "pallet-transaction-payment-rpc-runtime-api" version = "2.0.0" dependencies = [ + "palette-support 2.0.0", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4542,22 +4552,22 @@ dependencies = [ [[package]] name = "rayon" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rayon-core" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-queue 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4824,7 +4834,7 @@ dependencies = [ [[package]] name = "security-framework" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6595,7 +6605,7 @@ dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "doc-comment 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -7117,10 +7127,10 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -7428,7 +7438,7 @@ dependencies = [ "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "more-asserts 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -7782,6 +7792,7 @@ dependencies = [ "checksum crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3aa945d63861bfe624b55d153a39684da1e8c0bc8fba932f7ee3a3c16cea3ca" "checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac" "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" +"checksum crossbeam-queue 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dfd6515864a82d2f877b42813d4553292c6659498c9a2aa31bab5a15243c2700" "checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" "checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" "checksum crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" @@ -8063,8 +8074,8 @@ dependencies = [ "checksum rand_xoshiro 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "03b418169fb9c46533f326efd6eed2576699c44ca92d3052a066214a8d828929" "checksum rand_xoshiro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0e18c91676f670f6f0312764c759405f13afb98d5d73819840cf72a518487bff" "checksum raw-cpuid 7.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4a349ca83373cfa5d6dbb66fd76e58b2cca08da71a5f6400de0a0a6a9bceeaf" -"checksum rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83a27732a533a1be0a0035a111fe76db89ad312f6f0347004c220c57f209a123" -"checksum rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "98dcf634205083b17d0861252431eb2acbfb698ab7478a2d20de07954f47ec7b" +"checksum rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43739f8831493b276363637423d3622d4bd6394ab6f0a9c4a552e208aeb7fddd" +"checksum rayon-core 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8bf17de6f23b05473c437eb958b9c850bfc8af0961fe17b4cc92d5a627b4791" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecedbca3bf205f8d8f5c2b44d83cd0690e39ee84b951ed649e9f1841132b66d" @@ -8096,7 +8107,7 @@ dependencies = [ "checksum scroll 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "abb2332cb595d33f7edd5700f4cbf94892e680c7f0ae56adab58a35190b66cb1" "checksum scroll_derive 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8584eea9b9ff42825b46faf46a8c24d2cff13ec152fa2a50df788b87c07ee28" "checksum sct 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" -"checksum security-framework 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "301c862a6d0ee78f124c5e1710205965fc5c553100dcda6d98f13ef87a763f04" +"checksum security-framework 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8ef2429d7cefe5fd28bd1d2ed41c944547d4ff84776f5935b456da44593a16df" "checksum security-framework-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e31493fc37615debb8c5090a7aeb4a9730bc61e77ab10b9af59f1a202284f895" "checksum semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" @@ -8189,7 +8200,7 @@ dependencies = [ "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "09c8070a9942f5e7cfccd93f490fdebd230ee3c3c9f107cb25bad5351ef671cf" +"checksum unicode-normalization 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "f0d98d53dfd9509a7c7f36fa8857b8f1fb699edbddd7dc2fb688db2ae5d0b2c1" "checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" "checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index 4b7a572da2337..26bace2eaa289 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -17,7 +17,6 @@ use sr_primitives::{ use sr_primitives::traits::{ NumberFor, BlakeTwo256, Block as BlockT, StaticLookup, Verify, ConvertInto, IdentifyAccount }; -use sr_primitives::weights::Weight; use sr_api::impl_runtime_apis; use aura_primitives::sr25519::AuthorityId as AuraId; use grandpa::AuthorityList as GrandpaAuthorityList; @@ -32,7 +31,11 @@ pub use sr_primitives::BuildStorage; pub use timestamp::Call as TimestampCall; pub use balances::Call as BalancesCall; pub use sr_primitives::{Permill, Perbill}; -pub use support::{StorageValue, construct_runtime, parameter_types, traits::Randomness}; +pub use support::{ + StorageValue, construct_runtime, parameter_types, + traits::Randomness, + weights::Weight, +}; /// An index to a block. pub type BlockNumber = u32; diff --git a/bin/node-template/runtime/src/template.rs b/bin/node-template/runtime/src/template.rs index 0942c04528cb5..f6a12e51ce6c1 100644 --- a/bin/node-template/runtime/src/template.rs +++ b/bin/node-template/runtime/src/template.rs @@ -70,9 +70,9 @@ mod tests { use super::*; use primitives::H256; - use support::{impl_outer_origin, assert_ok, parameter_types}; + use support::{impl_outer_origin, assert_ok, parameter_types, weights::Weight}; use sr_primitives::{ - traits::{BlakeTwo256, IdentityLookup}, testing::Header, weights::Weight, Perbill, + traits::{BlakeTwo256, IdentityLookup}, testing::Header, Perbill, }; impl_outer_origin! { diff --git a/bin/node/executor/src/lib.rs b/bin/node/executor/src/lib.rs index ebff2da1a4b96..0c3c9027b329b 100644 --- a/bin/node/executor/src/lib.rs +++ b/bin/node/executor/src/lib.rs @@ -34,7 +34,11 @@ mod tests { use super::Executor; use {balances, contracts, indices, system, timestamp}; use codec::{Encode, Decode, Joiner}; - use runtime_support::{Hashable, StorageValue, StorageMap, traits::Currency}; + use runtime_support::{ + Hashable, StorageValue, StorageMap, + traits::Currency, + weights::GetDispatchInfo, + }; use state_machine::TestExternalities as CoreTestExternalities; use primitives::{ Blake2Hasher, NeverNativeValue, NativeOrEncoded, map, @@ -43,7 +47,7 @@ mod tests { use sr_primitives::{ Fixed64, traits::{Header as HeaderT, Hash as HashT, Convert}, ApplyResult, - transaction_validity::InvalidTransaction, weights::GetDispatchInfo, + transaction_validity::InvalidTransaction, }; use contracts::ContractAddressFor; use substrate_executor::{NativeExecutor, WasmExecutionMethod}; diff --git a/bin/node/runtime/src/impls.rs b/bin/node/runtime/src/impls.rs index f6d31cc22507b..de2efdae4af2e 100644 --- a/bin/node/runtime/src/impls.rs +++ b/bin/node/runtime/src/impls.rs @@ -17,10 +17,9 @@ //! Some configurable implementations as associated type for the substrate runtime. use node_primitives::Balance; -use sr_primitives::weights::Weight; use sr_primitives::traits::{Convert, Saturating}; use sr_primitives::{Fixed64, Perbill}; -use support::traits::{OnUnbalanced, Currency, Get}; +use support::{traits::{OnUnbalanced, Currency, Get}, weights::Weight}; use crate::{Balances, System, Authorship, MaximumBlockWeight, NegativeImbalance}; pub struct Author; @@ -116,10 +115,10 @@ impl> Convert for TargetedFeeAdjustment { #[cfg(test)] mod tests { use super::*; - use sr_primitives::weights::Weight; use sr_primitives::assert_eq_error_rate; use crate::{MaximumBlockWeight, AvailableBlockRatio, Runtime}; use crate::{constants::currency::*, TransactionPayment, TargetBlockFullness}; + use support::weights::Weight; fn max() -> Weight { MaximumBlockWeight::get() diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 7018ed10eccb5..746508f23522b 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -22,7 +22,9 @@ use rstd::prelude::*; use support::{ - construct_runtime, parameter_types, traits::{SplitTwoWays, Currency, Randomness} + construct_runtime, parameter_types, + weights::Weight, + traits::{SplitTwoWays, Currency, Randomness}, }; use primitives::u32_trait::{_1, _2, _3, _4}; use node_primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Moment, Signature}; @@ -30,7 +32,6 @@ use sr_api::impl_runtime_apis; use sr_primitives::{Permill, Perbill, ApplyResult, impl_opaque_keys, generic, create_runtime_str}; use sr_primitives::curve::PiecewiseLinear; use sr_primitives::transaction_validity::TransactionValidity; -use sr_primitives::weights::Weight; use sr_primitives::traits::{ self, BlakeTwo256, Block as BlockT, NumberFor, StaticLookup, SaturatedConversion, OpaqueKeys, @@ -732,7 +733,7 @@ mod tests { #[test] fn block_hooks_weight_should_not_exceed_limits() { - use sr_primitives::weights::WeighBlock; + use support::weights::WeighBlock; let check_for_block = |b| { let block_hooks_weight = >::on_initialize(b) + diff --git a/palette/authorship/src/lib.rs b/palette/authorship/src/lib.rs index 154d1b6b8e1d0..b4118b93a0d61 100644 --- a/palette/authorship/src/lib.rs +++ b/palette/authorship/src/lib.rs @@ -28,7 +28,7 @@ use support::dispatch::Result as DispatchResult; use codec::{Encode, Decode}; use system::ensure_none; use sr_primitives::traits::{Header as HeaderT, One, Zero}; -use sr_primitives::weights::SimpleDispatchInfo; +use support::weights::SimpleDispatchInfo; use inherents::{InherentIdentifier, ProvideInherent, InherentData, MakeFatalError}; use sp_authorship::{ INHERENT_IDENTIFIER, UnclesInherentData, diff --git a/palette/balances/src/lib.rs b/palette/balances/src/lib.rs index 8f258c0da0732..e3e18be976b9d 100644 --- a/palette/balances/src/lib.rs +++ b/palette/balances/src/lib.rs @@ -169,6 +169,7 @@ use support::{ WithdrawReason, WithdrawReasons, LockIdentifier, LockableCurrency, ExistenceRequirement, Imbalance, SignedImbalance, ReservableCurrency, Get, }, + weights::SimpleDispatchInfo, dispatch::Result, }; use sr_primitives::{ @@ -177,7 +178,6 @@ use sr_primitives::{ Zero, SimpleArithmetic, StaticLookup, Member, CheckedAdd, CheckedSub, MaybeSerializeDeserialize, Saturating, Bounded, }, - weights::SimpleDispatchInfo, }; use system::{IsDeadAccount, OnNewAccount, ensure_signed, ensure_root}; diff --git a/palette/balances/src/mock.rs b/palette/balances/src/mock.rs index cd42fed6731fd..d90e7b2ce592e 100644 --- a/palette/balances/src/mock.rs +++ b/palette/balances/src/mock.rs @@ -18,12 +18,12 @@ #![cfg(test)] -use sr_primitives::{Perbill, traits::{ConvertInto, IdentityLookup}, testing::Header, - weights::{DispatchInfo, Weight}}; +use sr_primitives::{Perbill, traits::{ConvertInto, IdentityLookup}, testing::Header}; use primitives::H256; use runtime_io; use support::{impl_outer_origin, parameter_types}; use support::traits::Get; +use support::weights::{Weight, DispatchInfo}; use std::cell::RefCell; use crate::{GenesisConfig, Module, Trait}; diff --git a/palette/collective/src/lib.rs b/palette/collective/src/lib.rs index 37c1482f9ba15..eff8366f0707c 100644 --- a/palette/collective/src/lib.rs +++ b/palette/collective/src/lib.rs @@ -27,7 +27,7 @@ use rstd::{prelude::*, result}; use primitives::u32_trait::Value as U32; use sr_primitives::RuntimeDebug; use sr_primitives::traits::{Hash, EnsureOrigin}; -use sr_primitives::weights::SimpleDispatchInfo; +use support::weights::SimpleDispatchInfo; use support::{ dispatch::{Dispatchable, Parameter}, codec::{Encode, Decode}, traits::{ChangeMembers, InitializeMembers}, decl_module, decl_event, diff --git a/palette/contracts/src/lib.rs b/palette/contracts/src/lib.rs index bcb131aa77ccc..e84214a0195b5 100644 --- a/palette/contracts/src/lib.rs +++ b/palette/contracts/src/lib.rs @@ -114,7 +114,6 @@ use codec::{Codec, Encode, Decode}; use runtime_io::hashing::blake2_256; use sr_primitives::{ traits::{Hash, StaticLookup, Zero, MaybeSerializeDeserialize, Member, SignedExtension}, - weights::DispatchInfo, transaction_validity::{ ValidTransaction, InvalidTransaction, TransactionValidity, TransactionValidityError, }, @@ -123,7 +122,8 @@ use sr_primitives::{ use support::dispatch::{Result, Dispatchable}; use support::{ Parameter, decl_module, decl_event, decl_storage, storage::child, - parameter_types, IsSubType + parameter_types, IsSubType, + weights::DispatchInfo, }; use support::traits::{OnFreeBalanceZero, OnUnbalanced, Currency, Get, Time, Randomness}; use system::{ensure_signed, RawOrigin, ensure_root}; @@ -1034,6 +1034,7 @@ impl SignedExtension for CheckBlockGasLimit { type AccountId = T::AccountId; type Call = ::Call; type AdditionalSigned = (); + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } @@ -1042,7 +1043,7 @@ impl SignedExtension for CheckBlockGasLimit { &self, _: &Self::AccountId, call: &Self::Call, - _: DispatchInfo, + _: Self::DispatchInfo, _: usize, ) -> TransactionValidity { let call = match call.is_sub_type() { diff --git a/palette/contracts/src/tests.rs b/palette/contracts/src/tests.rs index 28ba77f0bbfc7..5532a0cc9aad3 100644 --- a/palette/contracts/src/tests.rs +++ b/palette/contracts/src/tests.rs @@ -30,12 +30,12 @@ use codec::{Decode, Encode, KeyedVec}; use sr_primitives::{ Perbill, BuildStorage, transaction_validity::{InvalidTransaction, ValidTransaction}, traits::{BlakeTwo256, Hash, IdentityLookup, SignedExtension}, - weights::{DispatchInfo, DispatchClass}, testing::{Digest, DigestItem, Header, UintAuthorityId, H256}, }; use support::{ assert_ok, assert_err, impl_outer_dispatch, impl_outer_event, impl_outer_origin, parameter_types, storage::child, StorageMap, StorageValue, traits::{Currency, Get}, + weights::{DispatchInfo, DispatchClass}, }; use std::{cell::RefCell, sync::atomic::{AtomicUsize, Ordering}}; use primitives::storage::well_known_keys; diff --git a/palette/democracy/src/lib.rs b/palette/democracy/src/lib.rs index 545666e493026..3ff6c1e2ecc72 100644 --- a/palette/democracy/src/lib.rs +++ b/palette/democracy/src/lib.rs @@ -23,12 +23,12 @@ use rstd::{result, convert::TryFrom}; use sr_primitives::{ RuntimeDebug, traits::{Zero, Bounded, CheckedMul, CheckedDiv, EnsureOrigin, Hash, Dispatchable}, - weights::SimpleDispatchInfo, }; use codec::{Ref, Encode, Decode, Input, Output, Error}; use support::{ decl_module, decl_storage, decl_event, ensure, Parameter, + weights::SimpleDispatchInfo, traits::{ Currency, ReservableCurrency, LockableCurrency, WithdrawReason, LockIdentifier, Get, OnFreeBalanceZero diff --git a/palette/elections-phragmen/Cargo.toml b/palette/elections-phragmen/Cargo.toml index a9b3da18c944c..fb13161bfc905 100644 --- a/palette/elections-phragmen/Cargo.toml +++ b/palette/elections-phragmen/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } sr-primitives = { path = "../../primitives/sr-primitives", default-features = false } phragmen = { package = "substrate-phragmen", path = "../../primitives/phragmen", default-features = false } -palette-support = { path = "../support", default-features = false } +support = { package = "palette-support", path = "../support", default-features = false } system = { package = "palette-system", path = "../system", default-features = false } rstd = { package = "sr-std", path = "../../primitives/sr-std", default-features = false } @@ -23,7 +23,7 @@ serde = { version = "1.0.101" } default = ["std"] std = [ "codec/std", - "palette-support/std", + "support/std", "sr-primitives/std", "phragmen/std", "system/std", diff --git a/palette/elections-phragmen/src/lib.rs b/palette/elections-phragmen/src/lib.rs index 7ecbfe84b8c74..978a2be0d79cb 100644 --- a/palette/elections-phragmen/src/lib.rs +++ b/palette/elections-phragmen/src/lib.rs @@ -79,8 +79,8 @@ use rstd::prelude::*; use codec::Decode; use sr_primitives::{print, traits::{Zero, StaticLookup, Bounded, Convert}}; -use sr_primitives::weights::SimpleDispatchInfo; -use palette_support::{ +use support::weights::SimpleDispatchInfo; +use support::{ decl_storage, decl_event, ensure, decl_module, dispatch, storage::unhashed, traits::{ @@ -667,7 +667,7 @@ impl Module { mod tests { use super::*; use std::cell::RefCell; - use palette_support::{assert_ok, assert_noop, parameter_types, assert_eq_uvec}; + use support::{assert_ok, assert_noop, parameter_types, assert_eq_uvec}; use primitives::H256; use sr_primitives::{ Perbill, testing::Header, BuildStorage, @@ -783,7 +783,7 @@ mod tests { pub type Block = sr_primitives::generic::Block; pub type UncheckedExtrinsic = sr_primitives::generic::UncheckedExtrinsic; - palette_support::construct_runtime!( + support::construct_runtime!( pub enum Test where Block = Block, NodeBlock = Block, @@ -863,7 +863,7 @@ mod tests { #[test] fn temp_migration_works() { ExtBuilder::default().build().execute_with(|| { - use palette_support::storage::unhashed; + use support::storage::unhashed; use codec::Encode; let old_members = vec![1u64, 2]; diff --git a/palette/elections/src/lib.rs b/palette/elections/src/lib.rs index 1e2349440f168..e4426c22d8109 100644 --- a/palette/elections/src/lib.rs +++ b/palette/elections/src/lib.rs @@ -28,10 +28,10 @@ use sr_primitives::{ RuntimeDebug, print, traits::{Zero, One, StaticLookup, Bounded, Saturating}, - weights::SimpleDispatchInfo, }; use support::{ dispatch::Result, decl_storage, decl_event, ensure, decl_module, + weights::SimpleDispatchInfo, traits::{ Currency, ExistenceRequirement, Get, LockableCurrency, LockIdentifier, OnUnbalanced, ReservableCurrency, WithdrawReason, WithdrawReasons, ChangeMembers diff --git a/palette/evm/src/lib.rs b/palette/evm/src/lib.rs index 30835986e2014..9a602d9077e52 100644 --- a/palette/evm/src/lib.rs +++ b/palette/evm/src/lib.rs @@ -28,7 +28,7 @@ use support::{dispatch::Result, decl_module, decl_storage, decl_event}; use support::traits::{Currency, WithdrawReason, ExistenceRequirement}; use system::ensure_signed; use sr_primitives::ModuleId; -use sr_primitives::weights::SimpleDispatchInfo; +use support::weights::SimpleDispatchInfo; use sr_primitives::traits::{UniqueSaturatedInto, AccountIdConversion}; use primitives::{U256, H256, H160}; use evm::{ExitReason, ExitSucceed, ExitError}; diff --git a/palette/example/src/lib.rs b/palette/example/src/lib.rs index 87693fcfa8bc6..42e8f28b768ed 100644 --- a/palette/example/src/lib.rs +++ b/palette/example/src/lib.rs @@ -254,12 +254,14 @@ #![cfg_attr(not(feature = "std"), no_std)] use rstd::marker::PhantomData; -use support::{dispatch::Result, decl_module, decl_storage, decl_event}; +use support::{ + dispatch::Result, decl_module, decl_storage, decl_event, + weights::{SimpleDispatchInfo, DispatchInfo, DispatchClass, ClassifyDispatch, WeighData, Weight}, +}; use system::{ensure_signed, ensure_root}; use codec::{Encode, Decode}; use sr_primitives::{ traits::{SignedExtension, Bounded, SaturatedConversion}, - weights::{SimpleDispatchInfo, DispatchInfo, DispatchClass, ClassifyDispatch, WeighData, Weight}, transaction_validity::{ ValidTransaction, TransactionValidityError, InvalidTransaction, TransactionValidity, }, @@ -602,6 +604,7 @@ impl SignedExtension for WatchDummy { // other modules. type Call = Call; type AdditionalSigned = (); + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } @@ -610,7 +613,7 @@ impl SignedExtension for WatchDummy { &self, _who: &Self::AccountId, call: &Self::Call, - _info: DispatchInfo, + _info: Self::DispatchInfo, len: usize, ) -> TransactionValidity { // if the transaction is too big, just drop it. @@ -636,12 +639,12 @@ impl SignedExtension for WatchDummy { mod tests { use super::*; - use support::{assert_ok, impl_outer_origin, parameter_types}; + use support::{assert_ok, impl_outer_origin, parameter_types, weights::GetDispatchInfo}; use primitives::H256; // The testing primitives are very useful for avoiding having to work with signatures // or public keys. `u64` is used as the `AccountId` and no `Signature`s are required. use sr_primitives::{ - Perbill, weights::GetDispatchInfo, testing::Header, + Perbill, testing::Header, traits::{BlakeTwo256, OnInitialize, OnFinalize, IdentityLookup}, }; diff --git a/palette/executive/src/lib.rs b/palette/executive/src/lib.rs index 998fb65eda004..6868d732a9165 100644 --- a/palette/executive/src/lib.rs +++ b/palette/executive/src/lib.rs @@ -77,9 +77,9 @@ #![cfg_attr(not(feature = "std"), no_std)] use rstd::{prelude::*, marker::PhantomData}; +use support::weights::{GetDispatchInfo, WeighBlock, DispatchInfo}; use sr_primitives::{ generic::Digest, ApplyResult, - weights::{GetDispatchInfo, WeighBlock}, traits::{ self, Header, Zero, One, Checkable, Applyable, CheckEqual, OnFinalize, OnInitialize, NumberFor, Block as BlockT, OffchainWorker, Dispatchable, @@ -119,7 +119,9 @@ impl< > ExecuteBlock for Executive where Block::Extrinsic: Checkable + Codec, - CheckedOf: Applyable + GetDispatchInfo, + CheckedOf: + Applyable + + GetDispatchInfo, CallOf: Dispatchable, OriginOf: From>, UnsignedValidator: ValidateUnsigned>, @@ -143,7 +145,9 @@ impl< > Executive where Block::Extrinsic: Checkable + Codec, - CheckedOf: Applyable + GetDispatchInfo, + CheckedOf: + Applyable + + GetDispatchInfo, CallOf: Dispatchable, OriginOf: From>, UnsignedValidator: ValidateUnsigned>, @@ -316,12 +320,13 @@ mod tests { use super::*; use primitives::H256; use sr_primitives::{ - generic::Era, Perbill, DispatchError, weights::Weight, testing::{Digest, Header, Block}, + generic::Era, Perbill, DispatchError, testing::{Digest, Header, Block}, traits::{Bounded, Header as HeaderT, BlakeTwo256, IdentityLookup, ConvertInto}, transaction_validity::{InvalidTransaction, UnknownTransaction}, ApplyError, }; use support::{ impl_outer_event, impl_outer_origin, parameter_types, impl_outer_dispatch, + weights::Weight, traits::{Currency, LockIdentifier, LockableCurrency, WithdrawReasons, WithdrawReason}, }; use system::{Call as SystemCall, ChainContext}; @@ -329,7 +334,7 @@ mod tests { use hex_literal::hex; mod custom { - use sr_primitives::weights::SimpleDispatchInfo; + use support::weights::SimpleDispatchInfo; pub trait Trait: system::Trait {} diff --git a/palette/membership/src/lib.rs b/palette/membership/src/lib.rs index 6cd2a914e6bff..472220cffdd51 100644 --- a/palette/membership/src/lib.rs +++ b/palette/membership/src/lib.rs @@ -24,10 +24,12 @@ use rstd::prelude::*; use support::{ - decl_module, decl_storage, decl_event, traits::{ChangeMembers, InitializeMembers}, + decl_module, decl_storage, decl_event, + traits::{ChangeMembers, InitializeMembers}, + weights::SimpleDispatchInfo, }; use system::ensure_root; -use sr_primitives::{traits::EnsureOrigin, weights::SimpleDispatchInfo}; +use sr_primitives::traits::EnsureOrigin; pub trait Trait: system::Trait { /// The overarching event type. diff --git a/palette/nicks/src/lib.rs b/palette/nicks/src/lib.rs index 6b914ca5dc220..94b7043c17c94 100644 --- a/palette/nicks/src/lib.rs +++ b/palette/nicks/src/lib.rs @@ -40,12 +40,12 @@ use rstd::prelude::*; use sr_primitives::{ - traits::{StaticLookup, EnsureOrigin, Zero}, weights::SimpleDispatchInfo + traits::{StaticLookup, EnsureOrigin, Zero} }; use support::{ - decl_module, decl_event, decl_storage, ensure, traits::{ - Currency, ReservableCurrency, OnUnbalanced, Get - }, + decl_module, decl_event, decl_storage, ensure, + traits::{Currency, ReservableCurrency, OnUnbalanced, Get}, + weights::SimpleDispatchInfo, }; use system::{ensure_signed, ensure_root}; diff --git a/palette/session/src/lib.rs b/palette/session/src/lib.rs index 2057900f79dcc..290bffed0fffa 100644 --- a/palette/session/src/lib.rs +++ b/palette/session/src/lib.rs @@ -122,7 +122,7 @@ use rstd::{prelude::*, marker::PhantomData, ops::{Sub, Rem}}; use codec::Decode; use sr_primitives::{KeyTypeId, Perbill, RuntimeAppPublic, BoundToRuntimeAppPublic}; -use sr_primitives::weights::SimpleDispatchInfo; +use support::weights::SimpleDispatchInfo; use sr_primitives::traits::{Convert, Zero, Member, OpaqueKeys}; use sr_staking_primitives::SessionIndex; use support::{dispatch::Result, ConsensusEngineId, decl_module, decl_event, decl_storage}; diff --git a/palette/staking/src/lib.rs b/palette/staking/src/lib.rs index d7681da76f491..29aeb7901c47b 100644 --- a/palette/staking/src/lib.rs +++ b/palette/staking/src/lib.rs @@ -255,6 +255,7 @@ use rstd::{prelude::*, result}; use codec::{HasCompact, Encode, Decode}; use support::{ decl_module, decl_event, decl_storage, ensure, + weights::SimpleDispatchInfo, traits::{ Currency, OnFreeBalanceZero, LockIdentifier, LockableCurrency, WithdrawReasons, OnUnbalanced, Imbalance, Get, Time @@ -265,7 +266,6 @@ use sr_primitives::{ Perbill, RuntimeDebug, curve::PiecewiseLinear, - weights::SimpleDispatchInfo, traits::{ Convert, Zero, One, StaticLookup, CheckedSub, Saturating, Bounded, SaturatedConversion, } diff --git a/palette/sudo/src/lib.rs b/palette/sudo/src/lib.rs index f67de6f6d885b..202734edb2b7a 100644 --- a/palette/sudo/src/lib.rs +++ b/palette/sudo/src/lib.rs @@ -88,9 +88,12 @@ use rstd::prelude::*; use sr_primitives::{ - traits::{StaticLookup, Dispatchable}, weights::SimpleDispatchInfo, DispatchError, + traits::{StaticLookup, Dispatchable}, DispatchError, +}; +use support::{ + Parameter, decl_module, decl_event, decl_storage, ensure, + weights::SimpleDispatchInfo, }; -use support::{Parameter, decl_module, decl_event, decl_storage, ensure}; use system::ensure_signed; pub trait Trait: system::Trait { diff --git a/palette/support/Cargo.toml b/palette/support/Cargo.toml index 2a098b6afa2e6..07d0fee96ea94 100644 --- a/palette/support/Cargo.toml +++ b/palette/support/Cargo.toml @@ -13,6 +13,7 @@ rstd = { package = "sr-std", path = "../../primitives/sr-std", default-features runtime-io ={ package = "sr-io", path = "../../primitives/sr-io", default-features = false } sr-primitives = { path = "../../primitives/sr-primitives", default-features = false } primitives = { package = "substrate-primitives", path = "../../primitives/core", default-features = false } +sr-arithmetic = { path = "../../primitives/sr-arithmetic", default-features = false } inherents = { package = "substrate-inherents", path = "../../primitives/inherents", default-features = false } palette-support-procedural = { package = "palette-support-procedural", path = "./procedural" } paste = "0.1.6" @@ -35,6 +36,7 @@ std = [ "codec/std", "rstd/std", "sr-primitives/std", + "sr-arithmetic/std", "palette-metadata/std", "inherents/std", "state-machine", diff --git a/palette/support/src/dispatch.rs b/palette/support/src/dispatch.rs index d8d2391734cf2..e53ce1cabca5f 100644 --- a/palette/support/src/dispatch.rs +++ b/palette/support/src/dispatch.rs @@ -23,11 +23,11 @@ pub use palette_metadata::{ FunctionMetadata, DecodeDifferent, DecodeDifferentArray, FunctionArgumentMetadata, ModuleConstantMetadata, DefaultByte, DefaultByteGetter, ModuleErrorMetadata, ErrorMetadata }; +pub use crate::weights::{ + SimpleDispatchInfo, GetDispatchInfo, DispatchInfo, WeighData, ClassifyDispatch, + TransactionPriority, Weight, WeighBlock, +}; pub use sr_primitives::{ - weights::{ - SimpleDispatchInfo, GetDispatchInfo, DispatchInfo, WeighData, ClassifyDispatch, - TransactionPriority, Weight, WeighBlock, - }, traits::{Dispatchable, DispatchResult, ModuleDispatchError}, DispatchError, }; @@ -1832,7 +1832,7 @@ macro_rules! __check_reserved_fn_name { mod tests { use super::*; use crate::sr_primitives::traits::{OnInitialize, OnFinalize}; - use sr_primitives::weights::{DispatchInfo, DispatchClass}; + use crate::weights::{DispatchInfo, DispatchClass}; pub trait Trait: system::Trait + Sized where Self::AccountId: From { type Origin; diff --git a/palette/support/src/lib.rs b/palette/support/src/lib.rs index 04b4a1e8912a3..b6578a56fd571 100644 --- a/palette/support/src/lib.rs +++ b/palette/support/src/lib.rs @@ -64,6 +64,7 @@ pub mod unsigned; #[macro_use] pub mod error; pub mod traits; +pub mod weights; pub use self::hash::{Twox256, Twox128, Blake2_256, Blake2_128, Twox64Concat, Hashable}; pub use self::storage::{StorageValue, StorageMap, StorageLinkedMap, StorageDoubleMap}; diff --git a/primitives/sr-primitives/src/weights.rs b/palette/support/src/weights.rs similarity index 87% rename from primitives/sr-primitives/src/weights.rs rename to palette/support/src/weights.rs index 09ebe3591394b..7aaa8b31366c0 100644 --- a/primitives/sr-primitives/src/weights.rs +++ b/palette/support/src/weights.rs @@ -39,11 +39,15 @@ use serde::{Serialize, Deserialize}; use impl_trait_for_tuples::impl_for_tuples; use codec::{Encode, Decode}; -use arithmetic::traits::{Bounded, Zero}; -use crate::RuntimeDebug; +use sr_arithmetic::traits::{Bounded, Zero}; +use sr_primitives::{ + RuntimeDebug, + traits::SignedExtension, + generic::{CheckedExtrinsic, UncheckedExtrinsic}, +}; /// Re-export priority as type -pub use crate::transaction_validity::TransactionPriority; +pub use sr_primitives::transaction_validity::TransactionPriority; /// Numeric range of a transaction weight. pub type Weight = u32; @@ -219,3 +223,39 @@ impl SimpleDispatchInfo { Self::FixedNormal(0) } } + +/// Implementation for unchecked extrinsic. +impl GetDispatchInfo + for UncheckedExtrinsic +where + Call: GetDispatchInfo, + Extra: SignedExtension, +{ + fn get_dispatch_info(&self) -> DispatchInfo { + self.function.get_dispatch_info() + } +} + +/// Implementation for checked extrinsic. +impl GetDispatchInfo + for CheckedExtrinsic +where + Call: GetDispatchInfo, +{ + fn get_dispatch_info(&self) -> DispatchInfo { + self.function.get_dispatch_info() + } +} + +/// Implementation for test extrinsic. +#[cfg(feature = "std")] +impl GetDispatchInfo for sr_primitives::testing::TestXt { + fn get_dispatch_info(&self) -> DispatchInfo { + // for testing: weight == size. + DispatchInfo { + weight: self.encode().len() as _, + ..Default::default() + } + } +} + diff --git a/palette/system/src/lib.rs b/palette/system/src/lib.rs index 51b7820a43f88..c7038f4168697 100644 --- a/palette/system/src/lib.rs +++ b/palette/system/src/lib.rs @@ -99,7 +99,6 @@ use sr_version::RuntimeVersion; use sr_primitives::{ RuntimeDebug, generic::{self, Era}, Perbill, ApplyError, ApplyOutcome, DispatchError, - weights::{Weight, DispatchInfo, DispatchClass, SimpleDispatchInfo}, transaction_validity::{ ValidTransaction, TransactionPriority, TransactionLongevity, TransactionValidityError, InvalidTransaction, TransactionValidity, @@ -115,6 +114,7 @@ use primitives::storage::well_known_keys; use support::{ decl_module, decl_event, decl_storage, decl_error, storage, Parameter, traits::{Contains, Get}, + weights::{Weight, DispatchInfo, DispatchClass, SimpleDispatchInfo}, }; use codec::{Encode, Decode}; @@ -802,7 +802,9 @@ impl CheckWeight { /// Checks if the current extrinsic can fit into the block with respect to block weight limits. /// /// Upon successes, it returns the new block weight as a `Result`. - fn check_weight(info: DispatchInfo) -> Result { + fn check_weight( + info: ::DispatchInfo, + ) -> Result { let current_weight = Module::::all_extrinsics_weight(); let maximum_weight = T::MaximumBlockWeight::get(); let limit = Self::get_dispatch_limit_ratio(info.class) * maximum_weight; @@ -818,7 +820,10 @@ impl CheckWeight { /// Checks if the current extrinsic can fit into the block with respect to block length limits. /// /// Upon successes, it returns the new block length as a `Result`. - fn check_block_length(info: DispatchInfo, len: usize) -> Result { + fn check_block_length( + info: ::DispatchInfo, + len: usize, + ) -> Result { let current_len = Module::::all_extrinsics_len(); let maximum_len = T::MaximumBlockLength::get(); let limit = Self::get_dispatch_limit_ratio(info.class) * maximum_len; @@ -832,7 +837,7 @@ impl CheckWeight { } /// get the priority of an extrinsic denoted by `info`. - fn get_priority(info: DispatchInfo) -> TransactionPriority { + fn get_priority(info: ::DispatchInfo) -> TransactionPriority { match info.class { DispatchClass::Normal => info.weight.into(), DispatchClass::Operational => Bounded::max_value() @@ -849,6 +854,7 @@ impl SignedExtension for CheckWeight { type AccountId = T::AccountId; type Call = T::Call; type AdditionalSigned = (); + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } @@ -857,7 +863,7 @@ impl SignedExtension for CheckWeight { self, _who: &Self::AccountId, _call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> Result<(), ApplyError> { let next_len = Self::check_block_length(info, len)?; @@ -871,7 +877,7 @@ impl SignedExtension for CheckWeight { &self, _who: &Self::AccountId, _call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> TransactionValidity { // There is no point in writing to storage here since changes are discarded. This basically @@ -928,6 +934,7 @@ impl SignedExtension for CheckNonce { type AccountId = T::AccountId; type Call = T::Call; type AdditionalSigned = (); + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } @@ -936,7 +943,7 @@ impl SignedExtension for CheckNonce { self, who: &Self::AccountId, _call: &Self::Call, - _info: DispatchInfo, + _info: Self::DispatchInfo, _len: usize, ) -> Result<(), ApplyError> { let expected = >::get(who); @@ -958,7 +965,7 @@ impl SignedExtension for CheckNonce { &self, who: &Self::AccountId, _call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, _len: usize, ) -> TransactionValidity { // check index @@ -1011,13 +1018,14 @@ impl SignedExtension for CheckEra { type AccountId = T::AccountId; type Call = T::Call; type AdditionalSigned = T::Hash; + type DispatchInfo = DispatchInfo; type Pre = (); fn validate( &self, _who: &Self::AccountId, _call: &Self::Call, - _info: DispatchInfo, + _info: Self::DispatchInfo, _len: usize, ) -> TransactionValidity { let current_u64 = >::block_number().saturated_into::(); @@ -1066,6 +1074,7 @@ impl SignedExtension for CheckGenesis { type AccountId = T::AccountId; type Call = ::Call; type AdditionalSigned = T::Hash; + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> Result { @@ -1100,6 +1109,7 @@ impl SignedExtension for CheckVersion { type AccountId = T::AccountId; type Call = ::Call; type AdditionalSigned = u32; + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> Result { diff --git a/palette/timestamp/src/lib.rs b/palette/timestamp/src/lib.rs index 52e3081c2ac7f..523d83e0acb29 100644 --- a/palette/timestamp/src/lib.rs +++ b/palette/timestamp/src/lib.rs @@ -100,7 +100,7 @@ use sr_primitives::{ SimpleArithmetic, Zero, SaturatedConversion, Scale } }; -use sr_primitives::weights::SimpleDispatchInfo; +use support::weights::SimpleDispatchInfo; use system::ensure_none; use sp_timestamp::{ InherentError, INHERENT_IDENTIFIER, InherentType, diff --git a/palette/transaction-payment/rpc/runtime-api/Cargo.toml b/palette/transaction-payment/rpc/runtime-api/Cargo.toml index dc4cc3807c002..82bbf977a42a8 100644 --- a/palette/transaction-payment/rpc/runtime-api/Cargo.toml +++ b/palette/transaction-payment/rpc/runtime-api/Cargo.toml @@ -10,6 +10,7 @@ sr-api = { path = "../../../../primitives/sr-api", default-features = false } codec = { package = "parity-scale-codec", version = "1.0.6", default-features = false, features = ["derive"] } rstd = { package = "sr-std", path = "../../../../primitives/sr-std", default-features = false } sr-primitives = { path = "../../../../primitives/sr-primitives", default-features = false } +support = { package = "palette-support", path = "../../../support", default-features = false } [dev-dependencies] serde_json = "1.0.41" diff --git a/palette/transaction-payment/rpc/runtime-api/src/lib.rs b/palette/transaction-payment/rpc/runtime-api/src/lib.rs index ab2636246d152..755e98a212bd8 100644 --- a/palette/transaction-payment/rpc/runtime-api/src/lib.rs +++ b/palette/transaction-payment/rpc/runtime-api/src/lib.rs @@ -19,7 +19,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use rstd::prelude::*; -use sr_primitives::weights::{Weight, DispatchClass}; +use support::weights::{Weight, DispatchClass}; use codec::{Encode, Codec, Decode}; #[cfg(feature = "std")] use serde::{Serialize, Deserialize}; diff --git a/palette/transaction-payment/src/lib.rs b/palette/transaction-payment/src/lib.rs index 2314edf053958..c3fa13c0ba869 100644 --- a/palette/transaction-payment/src/lib.rs +++ b/palette/transaction-payment/src/lib.rs @@ -36,6 +36,7 @@ use codec::{Encode, Decode}; use support::{ decl_storage, decl_module, traits::{Currency, Get, OnUnbalanced, ExistenceRequirement, WithdrawReason}, + weights::{Weight, DispatchInfo, GetDispatchInfo}, }; use sr_primitives::{ Fixed64, @@ -44,7 +45,6 @@ use sr_primitives::{ TransactionValidity, }, traits::{Zero, Saturating, SignedExtension, SaturatedConversion, Convert}, - weights::{Weight, DispatchInfo, GetDispatchInfo}, }; use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo; @@ -56,7 +56,7 @@ type NegativeImbalanceOf = pub trait Trait: system::Trait { /// The currency type in which fees will be paid. - type Currency: Currency; + type Currency: Currency + Send + Sync; /// Handler for the unbalanced reduction when taking transaction fees. type OnTransactionPayment: OnUnbalanced>; @@ -113,7 +113,9 @@ impl Module { unchecked_extrinsic: Extrinsic, len: u32, ) -> RuntimeDispatchInfo> - where T: Send + Sync, + where + T: Send + Sync, + BalanceOf: Send + Sync, { let dispatch_info = ::get_dispatch_info(&unchecked_extrinsic); @@ -144,7 +146,14 @@ impl ChargeTransactionPayment { /// and the time it consumes. /// - (optional) _tip_: if included in the transaction, it will be added on top. Only signed /// transactions can have a tip. - fn compute_fee(len: u32, info: DispatchInfo, tip: BalanceOf) -> BalanceOf { + fn compute_fee( + len: u32, + info: ::DispatchInfo, + tip: BalanceOf, + ) -> BalanceOf + where + BalanceOf: Sync + Send, + { let len_fee = if info.pay_length_fee() { let len = >::from(len); let base = T::TransactionBaseFee::get(); @@ -187,6 +196,7 @@ impl SignedExtension for ChargeTransactionPayment type AccountId = T::AccountId; type Call = T::Call; type AdditionalSigned = (); + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } @@ -194,7 +204,7 @@ impl SignedExtension for ChargeTransactionPayment &self, who: &Self::AccountId, _call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> TransactionValidity { // pay any fees. @@ -227,13 +237,15 @@ impl SignedExtension for ChargeTransactionPayment mod tests { use super::*; use codec::Encode; - use support::{parameter_types, impl_outer_origin, impl_outer_dispatch}; + use support::{ + parameter_types, impl_outer_origin, impl_outer_dispatch, + weights::{DispatchClass, DispatchInfo, GetDispatchInfo, Weight}, + }; use primitives::H256; use sr_primitives::{ Perbill, testing::{Header, TestXt}, traits::{BlakeTwo256, IdentityLookup, Extrinsic}, - weights::{DispatchClass, DispatchInfo, GetDispatchInfo}, }; use balances::Call as BalancesCall; use rstd::cell::RefCell; @@ -424,8 +436,6 @@ mod tests { .build() .execute_with(|| { - use sr_primitives::weights::Weight; - // maximum weight possible assert!( ChargeTransactionPayment::::from(0) diff --git a/palette/treasury/src/lib.rs b/palette/treasury/src/lib.rs index 4a613dfb7859c..d71f8731c43dd 100644 --- a/palette/treasury/src/lib.rs +++ b/palette/treasury/src/lib.rs @@ -69,7 +69,7 @@ use sr_primitives::{Permill, ModuleId}; use sr_primitives::traits::{ Zero, EnsureOrigin, StaticLookup, AccountIdConversion, Saturating }; -use sr_primitives::weights::SimpleDispatchInfo; +use support::weights::SimpleDispatchInfo; use codec::{Encode, Decode}; use system::ensure_signed; diff --git a/palette/utility/src/lib.rs b/palette/utility/src/lib.rs index d69e260ff9aac..ae5a4bd6cbc39 100644 --- a/palette/utility/src/lib.rs +++ b/palette/utility/src/lib.rs @@ -21,9 +21,9 @@ #![cfg_attr(not(feature = "std"), no_std)] use rstd::prelude::*; -use support::{decl_module, decl_event, Parameter}; +use support::{decl_module, decl_event, Parameter, weights::SimpleDispatchInfo}; use system::ensure_root; -use sr_primitives::{traits::Dispatchable, weights::SimpleDispatchInfo, DispatchError}; +use sr_primitives::{traits::Dispatchable, DispatchError}; /// Configuration trait. pub trait Trait: system::Trait { diff --git a/primitives/sr-primitives/src/generic/checked_extrinsic.rs b/primitives/sr-primitives/src/generic/checked_extrinsic.rs index 3fc7711ccc451..1243261882caf 100644 --- a/primitives/sr-primitives/src/generic/checked_extrinsic.rs +++ b/primitives/sr-primitives/src/generic/checked_extrinsic.rs @@ -22,7 +22,6 @@ use crate::traits::{ }; #[allow(deprecated)] use crate::traits::ValidateUnsigned; -use crate::weights::{GetDispatchInfo, DispatchInfo}; use crate::transaction_validity::TransactionValidity; /// Definition of something that the external world might want to say; its @@ -38,16 +37,18 @@ pub struct CheckedExtrinsic { pub function: Call, } -impl traits::Applyable for +impl traits::Applyable for CheckedExtrinsic where AccountId: Member + MaybeDisplay, Call: Member + Dispatchable, - Extra: SignedExtension, + Extra: SignedExtension, Origin: From>, + Info: Clone, { type AccountId = AccountId; type Call = Call; + type DispatchInfo = Info; fn sender(&self) -> Option<&Self::AccountId> { self.signed.as_ref().map(|x| &x.0) @@ -56,11 +57,11 @@ where #[allow(deprecated)] // Allow ValidateUnsigned fn validate>( &self, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> TransactionValidity { if let Some((ref id, ref extra)) = self.signed { - Extra::validate(extra, id, &self.function, info, len) + Extra::validate(extra, id, &self.function, info.clone(), len) } else { let valid = Extra::validate_unsigned(&self.function, info, len)?; let unsigned_validation = U::validate_unsigned(&self.function)?; @@ -71,28 +72,19 @@ where #[allow(deprecated)] // Allow ValidateUnsigned fn apply>( self, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> crate::ApplyResult { let (maybe_who, pre) = if let Some((id, extra)) = self.signed { - let pre = Extra::pre_dispatch(extra, &id, &self.function, info, len)?; + let pre = Extra::pre_dispatch(extra, &id, &self.function, info.clone(), len)?; (Some(id), pre) } else { - let pre = Extra::pre_dispatch_unsigned(&self.function, info, len)?; + let pre = Extra::pre_dispatch_unsigned(&self.function, info.clone(), len)?; U::pre_dispatch(&self.function)?; (None, pre) }; let res = self.function.dispatch(Origin::from(maybe_who)); - Extra::post_dispatch(pre, info, len); + Extra::post_dispatch(pre, info.clone(), len); Ok(res.map_err(Into::into)) } } - -impl GetDispatchInfo for CheckedExtrinsic -where - Call: GetDispatchInfo, -{ - fn get_dispatch_info(&self) -> DispatchInfo { - self.function.get_dispatch_info() - } -} diff --git a/primitives/sr-primitives/src/generic/unchecked_extrinsic.rs b/primitives/sr-primitives/src/generic/unchecked_extrinsic.rs index 79d86a0756d3c..e2bda54a313b9 100644 --- a/primitives/sr-primitives/src/generic/unchecked_extrinsic.rs +++ b/primitives/sr-primitives/src/generic/unchecked_extrinsic.rs @@ -22,7 +22,6 @@ use codec::{Decode, Encode, EncodeLike, Input, Error}; use crate::{ traits::{self, Member, MaybeDisplay, SignedExtension, Checkable, Extrinsic, IdentifyAccount}, generic::CheckedExtrinsic, transaction_validity::{TransactionValidityError, InvalidTransaction}, - weights::{GetDispatchInfo, DispatchInfo}, }; const TRANSACTION_VERSION: u8 = 4; @@ -280,17 +279,6 @@ where } } -impl GetDispatchInfo - for UncheckedExtrinsic -where - Call: GetDispatchInfo, - Extra: SignedExtension, -{ - fn get_dispatch_info(&self) -> DispatchInfo { - self.function.get_dispatch_info() - } -} - #[cfg(test)] mod tests { use super::*; @@ -331,6 +319,7 @@ mod tests { type AccountId = u64; type Call = (); type AdditionalSigned = (); + type DispatchInfo = (); type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } diff --git a/primitives/sr-primitives/src/lib.rs b/primitives/sr-primitives/src/lib.rs index 33759f5d7291d..4aaebe1e2209c 100644 --- a/primitives/sr-primitives/src/lib.rs +++ b/primitives/sr-primitives/src/lib.rs @@ -52,7 +52,6 @@ pub mod offchain; pub mod testing; pub mod traits; pub mod transaction_validity; -pub mod weights; /// Re-export these since they're only "kind of" generic. pub use generic::{DigestItem, Digest}; diff --git a/primitives/sr-primitives/src/testing.rs b/primitives/sr-primitives/src/testing.rs index bd3f673cd5c43..f59346232e8d4 100644 --- a/primitives/sr-primitives/src/testing.rs +++ b/primitives/sr-primitives/src/testing.rs @@ -26,7 +26,6 @@ use crate::traits::{ #[allow(deprecated)] use crate::traits::ValidateUnsigned; use crate::{generic, KeyTypeId, ApplyResult}; -use crate::weights::{GetDispatchInfo, DispatchInfo}; pub use primitives::{H256, sr25519}; use primitives::{crypto::{CryptoType, Dummy, key_types, Public}, U256}; use crate::transaction_validity::{TransactionValidity, TransactionValidityError}; @@ -326,13 +325,15 @@ impl traits::Extrinsic for TestXt } } -impl Applyable for TestXt where +impl Applyable for TestXt where Call: 'static + Sized + Send + Sync + Clone + Eq + Codec + Debug + Dispatchable, - Extra: SignedExtension, + Extra: SignedExtension, Origin: From>, + Info: Clone, { type AccountId = u64; type Call = Call; + type DispatchInfo = Info; fn sender(&self) -> Option<&Self::AccountId> { self.0.as_ref().map(|x| &x.0) } @@ -340,7 +341,7 @@ impl Applyable for TestXt where #[allow(deprecated)] // Allow ValidateUnsigned fn validate>( &self, - _info: DispatchInfo, + _info: Self::DispatchInfo, _len: usize, ) -> TransactionValidity { Ok(Default::default()) @@ -351,7 +352,7 @@ impl Applyable for TestXt where #[allow(deprecated)] // Allow ValidateUnsigned fn apply>( self, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> ApplyResult { let maybe_who = if let Some((who, extra)) = self.0 { @@ -365,13 +366,3 @@ impl Applyable for TestXt where Ok(self.1.dispatch(maybe_who.into()).map_err(Into::into)) } } - -impl GetDispatchInfo for TestXt { - fn get_dispatch_info(&self) -> DispatchInfo { - // for testing: weight == size. - DispatchInfo { - weight: self.encode().len() as _, - ..Default::default() - } - } -} diff --git a/primitives/sr-primitives/src/traits.rs b/primitives/sr-primitives/src/traits.rs index edddaf035aa95..f4143f0c20d33 100644 --- a/primitives/sr-primitives/src/traits.rs +++ b/primitives/sr-primitives/src/traits.rs @@ -29,7 +29,6 @@ use crate::transaction_validity::{ ValidTransaction, TransactionValidity, TransactionValidityError, UnknownTransaction, }; use crate::generic::{Digest, DigestItem}; -use crate::weights::DispatchInfo; pub use arithmetic::traits::{ SimpleArithmetic, UniqueSaturatedInto, UniqueSaturatedFrom, Saturating, SaturatedConversion, Zero, One, Bounded, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv, @@ -713,6 +712,11 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq /// The type that encodes information that can be passed from pre_dispatch to post-dispatch. type Pre: Default; + /// An opaque set of information attached to the transaction. This could be constructed anywhere + /// down the line in a runtime. The current substrate runtime uses a struct with the same name + /// to represent the dispatch class and weight. + type DispatchInfo: Clone; + /// Construct any additional data that should be in the signed payload of the transaction. Can /// also perform any pre-signature-verification checks and return an error if needed. fn additional_signed(&self) -> Result; @@ -730,7 +734,7 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq &self, _who: &Self::AccountId, _call: &Self::Call, - _info: DispatchInfo, + _info: Self::DispatchInfo, _len: usize, ) -> TransactionValidity { Ok(ValidTransaction::default()) @@ -748,10 +752,10 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq self, who: &Self::AccountId, call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> Result { - self.validate(who, call, info, len) + self.validate(who, call, info.clone(), len) .map(|_| Self::Pre::default()) .map_err(Into::into) } @@ -766,7 +770,7 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq /// Make sure to perform the same checks in `pre_dispatch_unsigned` function. fn validate_unsigned( _call: &Self::Call, - _info: DispatchInfo, + _info: Self::DispatchInfo, _len: usize, ) -> TransactionValidity { Ok(ValidTransaction::default()) @@ -782,16 +786,16 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq /// perform the same validation as in `validate_unsigned`. fn pre_dispatch_unsigned( call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> Result { - Self::validate_unsigned(call, info, len) + Self::validate_unsigned(call, info.clone(), len) .map(|_| Self::Pre::default()) .map_err(Into::into) } /// Do any post-flight stuff for a transaction. - fn post_dispatch(_pre: Self::Pre, _info: DispatchInfo, _len: usize) { } + fn post_dispatch(_pre: Self::Pre, _info: Self::DispatchInfo, _len: usize) { } } /// An error that is returned by a dispatchable function of a module. @@ -806,10 +810,11 @@ pub trait ModuleDispatchError { } #[impl_for_tuples(1, 12)] -impl SignedExtension for Tuple { - for_tuples!( where #( Tuple: SignedExtension )* ); +impl SignedExtension for Tuple { + for_tuples!( where #( Tuple: SignedExtension )* ); type AccountId = AccountId; type Call = Call; + type DispatchInfo = Info; for_tuples!( type AdditionalSigned = ( #( Tuple::AdditionalSigned ),* ); ); for_tuples!( type Pre = ( #( Tuple::Pre ),* ); ); @@ -821,44 +826,44 @@ impl SignedExtension for Tuple { &self, who: &Self::AccountId, call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> TransactionValidity { let valid = ValidTransaction::default(); - for_tuples!( #( let valid = valid.combine_with(Tuple.validate(who, call, info, len)?); )* ); + for_tuples!( #( let valid = valid.combine_with(Tuple.validate(who, call, info.clone(), len)?); )* ); Ok(valid) } - fn pre_dispatch(self, who: &Self::AccountId, call: &Self::Call, info: DispatchInfo, len: usize) + fn pre_dispatch(self, who: &Self::AccountId, call: &Self::Call, info: Self::DispatchInfo, len: usize) -> Result { - Ok(for_tuples!( ( #( Tuple.pre_dispatch(who, call, info, len)? ),* ) )) + Ok(for_tuples!( ( #( Tuple.pre_dispatch(who, call, info.clone(), len)? ),* ) )) } fn validate_unsigned( call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> TransactionValidity { let valid = ValidTransaction::default(); - for_tuples!( #( let valid = valid.combine_with(Tuple::validate_unsigned(call, info, len)?); )* ); + for_tuples!( #( let valid = valid.combine_with(Tuple::validate_unsigned(call, info.clone(), len)?); )* ); Ok(valid) } fn pre_dispatch_unsigned( call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> Result { - Ok(for_tuples!( ( #( Tuple::pre_dispatch_unsigned(call, info, len)? ),* ) )) + Ok(for_tuples!( ( #( Tuple::pre_dispatch_unsigned(call, info.clone(), len)? ),* ) )) } fn post_dispatch( pre: Self::Pre, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) { - for_tuples!( #( Tuple::post_dispatch(pre.Tuple, info, len); )* ) + for_tuples!( #( Tuple::post_dispatch(pre.Tuple, info.clone(), len); )* ) } } @@ -869,6 +874,7 @@ impl SignedExtension for () { type AdditionalSigned = (); type Call = (); type Pre = (); + type DispatchInfo = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } } @@ -885,6 +891,9 @@ pub trait Applyable: Sized + Send + Sync { /// Type by which we can dispatch. Restricts the UnsignedValidator type. type Call; + /// An opaque set of information attached to the transaction. + type DispatchInfo: Clone; + /// Returns a reference to the sender if any. fn sender(&self) -> Option<&Self::AccountId>; @@ -892,7 +901,7 @@ pub trait Applyable: Sized + Send + Sync { #[allow(deprecated)] // Allow ValidateUnsigned fn validate>( &self, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> TransactionValidity; @@ -901,7 +910,7 @@ pub trait Applyable: Sized + Send + Sync { #[allow(deprecated)] // Allow ValidateUnsigned fn apply>( self, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> crate::ApplyResult; }