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
+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> {