Relocate weight to paint + decouple from extensions (#4124)

* Fisr migrated version of weight to paint

* Bump

* Minor nits

* Some review fixes.

* Line width

* Revert spec bump

* Fix build

* Update lock file

* Update palette/executive/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update palette/membership/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Kian Paimani
2019-11-22 11:23:32 +01:00
committed by GitHub
parent 8185ee925d
commit 11703a5916
40 changed files with 246 additions and 170 deletions
+31 -20
View File
@@ -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"
@@ -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;
@@ -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! {
+6 -2
View File
@@ -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};
+2 -3
View File
@@ -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<T: Get<Perbill>> Convert<Fixed64, Fixed64> for TargetedFeeAdjustment<T> {
#[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()
+4 -3
View File
@@ -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 =
<AllModules as WeighBlock<BlockNumber>>::on_initialize(b) +
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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};
+2 -2
View File
@@ -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};
+1 -1
View File
@@ -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,
+4 -3
View File
@@ -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<T: Trait + Send + Sync> SignedExtension for CheckBlockGasLimit<T> {
type AccountId = T::AccountId;
type Call = <T as Trait>::Call;
type AdditionalSigned = ();
type DispatchInfo = DispatchInfo;
type Pre = ();
fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) }
@@ -1042,7 +1043,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckBlockGasLimit<T> {
&self,
_: &Self::AccountId,
call: &Self::Call,
_: DispatchInfo,
_: Self::DispatchInfo,
_: usize,
) -> TransactionValidity {
let call = match call.is_sub_type() {
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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
@@ -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",
@@ -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<T: Trait> Module<T> {
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<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = sr_primitives::generic::UncheckedExtrinsic<u32, u64, Call, ()>;
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];
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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};
+8 -5
View File
@@ -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<T: Trait + Send + Sync> SignedExtension for WatchDummy<T> {
// other modules.
type Call = Call<T>;
type AdditionalSigned = ();
type DispatchInfo = DispatchInfo;
type Pre = ();
fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) }
@@ -610,7 +613,7 @@ impl<T: Trait + Send + Sync> SignedExtension for WatchDummy<T> {
&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<T: Trait + Send + Sync> SignedExtension for WatchDummy<T> {
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},
};
+10 -5
View File
@@ -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<Block> for Executive<System, Block, Context, UnsignedValidator, AllModules>
where
Block::Extrinsic: Checkable<Context> + Codec,
CheckedOf<Block::Extrinsic, Context>: Applyable<AccountId=System::AccountId> + GetDispatchInfo,
CheckedOf<Block::Extrinsic, Context>:
Applyable<AccountId=System::AccountId, DispatchInfo=DispatchInfo> +
GetDispatchInfo,
CallOf<Block::Extrinsic, Context>: Dispatchable,
OriginOf<Block::Extrinsic, Context>: From<Option<System::AccountId>>,
UnsignedValidator: ValidateUnsigned<Call=CallOf<Block::Extrinsic, Context>>,
@@ -143,7 +145,9 @@ impl<
> Executive<System, Block, Context, UnsignedValidator, AllModules>
where
Block::Extrinsic: Checkable<Context> + Codec,
CheckedOf<Block::Extrinsic, Context>: Applyable<AccountId=System::AccountId> + GetDispatchInfo,
CheckedOf<Block::Extrinsic, Context>:
Applyable<AccountId=System::AccountId, DispatchInfo=DispatchInfo> +
GetDispatchInfo,
CallOf<Block::Extrinsic, Context>: Dispatchable,
OriginOf<Block::Extrinsic, Context>: From<Option<System::AccountId>>,
UnsignedValidator: ValidateUnsigned<Call=CallOf<Block::Extrinsic, Context>>,
@@ -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 {}
+4 -2
View File
@@ -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<I=DefaultInstance>: system::Trait {
/// The overarching event type.
+4 -4
View File
@@ -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};
+1 -1
View File
@@ -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};
+1 -1
View File
@@ -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,
}
+5 -2
View File
@@ -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 {
+2
View File
@@ -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",
+5 -5
View File
@@ -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<u32> {
type Origin;
+1
View File
@@ -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};
@@ -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<Address, Call, Signature, Extra> GetDispatchInfo
for UncheckedExtrinsic<Address, Call, Signature, Extra>
where
Call: GetDispatchInfo,
Extra: SignedExtension,
{
fn get_dispatch_info(&self) -> DispatchInfo {
self.function.get_dispatch_info()
}
}
/// Implementation for checked extrinsic.
impl<AccountId, Call, Extra> GetDispatchInfo
for CheckedExtrinsic<AccountId, Call, Extra>
where
Call: GetDispatchInfo,
{
fn get_dispatch_info(&self) -> DispatchInfo {
self.function.get_dispatch_info()
}
}
/// Implementation for test extrinsic.
#[cfg(feature = "std")]
impl<Call: Encode, Extra: Encode> GetDispatchInfo for sr_primitives::testing::TestXt<Call, Extra> {
fn get_dispatch_info(&self) -> DispatchInfo {
// for testing: weight == size.
DispatchInfo {
weight: self.encode().len() as _,
..Default::default()
}
}
}
+19 -9
View File
@@ -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<T: Trait + Send + Sync> CheckWeight<T> {
/// 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<Weight, TransactionValidityError> {
fn check_weight(
info: <Self as SignedExtension>::DispatchInfo,
) -> Result<Weight, TransactionValidityError> {
let current_weight = Module::<T>::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<T: Trait + Send + Sync> CheckWeight<T> {
/// 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<u32, TransactionValidityError> {
fn check_block_length(
info: <Self as SignedExtension>::DispatchInfo,
len: usize,
) -> Result<u32, TransactionValidityError> {
let current_len = Module::<T>::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<T: Trait + Send + Sync> CheckWeight<T> {
}
/// get the priority of an extrinsic denoted by `info`.
fn get_priority(info: DispatchInfo) -> TransactionPriority {
fn get_priority(info: <Self as SignedExtension>::DispatchInfo) -> TransactionPriority {
match info.class {
DispatchClass::Normal => info.weight.into(),
DispatchClass::Operational => Bounded::max_value()
@@ -849,6 +854,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> {
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<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> {
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<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> {
&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<T: Trait> SignedExtension for CheckNonce<T> {
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<T: Trait> SignedExtension for CheckNonce<T> {
self,
who: &Self::AccountId,
_call: &Self::Call,
_info: DispatchInfo,
_info: Self::DispatchInfo,
_len: usize,
) -> Result<(), ApplyError> {
let expected = <AccountNonce<T>>::get(who);
@@ -958,7 +965,7 @@ impl<T: Trait> SignedExtension for CheckNonce<T> {
&self,
who: &Self::AccountId,
_call: &Self::Call,
info: DispatchInfo,
info: Self::DispatchInfo,
_len: usize,
) -> TransactionValidity {
// check index
@@ -1011,13 +1018,14 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckEra<T> {
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 = <Module<T>>::block_number().saturated_into::<u64>();
@@ -1066,6 +1074,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckGenesis<T> {
type AccountId = T::AccountId;
type Call = <T as Trait>::Call;
type AdditionalSigned = T::Hash;
type DispatchInfo = DispatchInfo;
type Pre = ();
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
@@ -1100,6 +1109,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckVersion<T> {
type AccountId = T::AccountId;
type Call = <T as Trait>::Call;
type AdditionalSigned = u32;
type DispatchInfo = DispatchInfo;
type Pre = ();
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
+1 -1
View File
@@ -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,
@@ -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"
@@ -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};
@@ -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<T> =
pub trait Trait: system::Trait {
/// The currency type in which fees will be paid.
type Currency: Currency<Self::AccountId>;
type Currency: Currency<Self::AccountId> + Send + Sync;
/// Handler for the unbalanced reduction when taking transaction fees.
type OnTransactionPayment: OnUnbalanced<NegativeImbalanceOf<Self>>;
@@ -113,7 +113,9 @@ impl<T: Trait> Module<T> {
unchecked_extrinsic: Extrinsic,
len: u32,
) -> RuntimeDispatchInfo<BalanceOf<T>>
where T: Send + Sync,
where
T: Send + Sync,
BalanceOf<T>: Send + Sync,
{
let dispatch_info = <Extrinsic as GetDispatchInfo>::get_dispatch_info(&unchecked_extrinsic);
@@ -144,7 +146,14 @@ impl<T: Trait + Send + Sync> ChargeTransactionPayment<T> {
/// 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<T>) -> BalanceOf<T> {
fn compute_fee(
len: u32,
info: <Self as SignedExtension>::DispatchInfo,
tip: BalanceOf<T>,
) -> BalanceOf<T>
where
BalanceOf<T>: Sync + Send,
{
let len_fee = if info.pay_length_fee() {
let len = <BalanceOf<T>>::from(len);
let base = T::TransactionBaseFee::get();
@@ -187,6 +196,7 @@ impl<T: Trait + Send + Sync> SignedExtension for ChargeTransactionPayment<T>
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<T: Trait + Send + Sync> SignedExtension for ChargeTransactionPayment<T>
&self,
who: &Self::AccountId,
_call: &Self::Call,
info: DispatchInfo,
info: Self::DispatchInfo,
len: usize,
) -> TransactionValidity {
// pay any fees.
@@ -227,13 +237,15 @@ impl<T: Trait + Send + Sync> SignedExtension for ChargeTransactionPayment<T>
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::<Runtime>::from(0)
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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 {
@@ -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<AccountId, Call, Extra> {
pub function: Call,
}
impl<AccountId, Call, Extra, Origin> traits::Applyable for
impl<AccountId, Call, Extra, Origin, Info> traits::Applyable for
CheckedExtrinsic<AccountId, Call, Extra>
where
AccountId: Member + MaybeDisplay,
Call: Member + Dispatchable<Origin=Origin>,
Extra: SignedExtension<AccountId=AccountId, Call=Call>,
Extra: SignedExtension<AccountId=AccountId, Call=Call, DispatchInfo=Info>,
Origin: From<Option<AccountId>>,
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<U: ValidateUnsigned<Call = Self::Call>>(
&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<U: ValidateUnsigned<Call=Self::Call>>(
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<AccountId, Call, Extra> GetDispatchInfo for CheckedExtrinsic<AccountId, Call, Extra>
where
Call: GetDispatchInfo,
{
fn get_dispatch_info(&self) -> DispatchInfo {
self.function.get_dispatch_info()
}
}
@@ -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<Address, Call, Signature, Extra> GetDispatchInfo
for UncheckedExtrinsic<Address, Call, Signature, Extra>
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(()) }
@@ -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};
@@ -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<Call: Codec + Sync + Send, Extra> traits::Extrinsic for TestXt<Call, Extra>
}
}
impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where
impl<Origin, Call, Extra, Info> Applyable for TestXt<Call, Extra> where
Call: 'static + Sized + Send + Sync + Clone + Eq + Codec + Debug + Dispatchable<Origin=Origin>,
Extra: SignedExtension<AccountId=u64, Call=Call>,
Extra: SignedExtension<AccountId=u64, Call=Call, DispatchInfo=Info>,
Origin: From<Option<u64>>,
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<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where
#[allow(deprecated)] // Allow ValidateUnsigned
fn validate<U: ValidateUnsigned<Call=Self::Call>>(
&self,
_info: DispatchInfo,
_info: Self::DispatchInfo,
_len: usize,
) -> TransactionValidity {
Ok(Default::default())
@@ -351,7 +352,7 @@ impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where
#[allow(deprecated)] // Allow ValidateUnsigned
fn apply<U: ValidateUnsigned<Call=Self::Call>>(
self,
info: DispatchInfo,
info: Self::DispatchInfo,
len: usize,
) -> ApplyResult {
let maybe_who = if let Some((who, extra)) = self.0 {
@@ -365,13 +366,3 @@ impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where
Ok(self.1.dispatch(maybe_who.into()).map_err(Into::into))
}
}
impl<Call: Encode, Extra: Encode> GetDispatchInfo for TestXt<Call, Extra> {
fn get_dispatch_info(&self) -> DispatchInfo {
// for testing: weight == size.
DispatchInfo {
weight: self.encode().len() as _,
..Default::default()
}
}
}
@@ -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<Self::AdditionalSigned, TransactionValidityError>;
@@ -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::Pre, crate::ApplyError> {
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::Pre, crate::ApplyError> {
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<AccountId, Call> SignedExtension for Tuple {
for_tuples!( where #( Tuple: SignedExtension<AccountId=AccountId, Call=Call> )* );
impl<AccountId, Call, Info: Clone> SignedExtension for Tuple {
for_tuples!( where #( Tuple: SignedExtension<AccountId=AccountId, Call=Call, DispatchInfo=Info> )* );
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<AccountId, Call> 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<Self::Pre, crate::ApplyError>
{
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<Self::Pre, crate::ApplyError> {
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<V: ValidateUnsigned<Call=Self::Call>>(
&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<V: ValidateUnsigned<Call=Self::Call>>(
self,
info: DispatchInfo,
info: Self::DispatchInfo,
len: usize,
) -> crate::ApplyResult;
}