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
@@ -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;
}