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
@@ -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(()) }