Weight annotation. (#3157)

* Make extrinsics extensible.

Also Remove old extrinsic types.

* Rest of mockup. Add tips.

* Fix some build issues

* Runtiem builds :)

* Substrate builds.

* Fix a doc test

* Compact encoding

* Extract out the era logic into an extension

* Weight Check signed extension. (#3115)

* Weight signed extension.

* Revert a bit + test for check era.

* Update Cargo.toml

* Update node/cli/src/factory_impl.rs

* Update node/executor/src/lib.rs

* Update node/executor/src/lib.rs

* Don't use len for weight - use data.

* Operational Transaction; second attempt (#3138)

* working poc added.

* some fixes.

* Update doc.

* Fix all tests + final logic.

* more refactoring.

* nits.

* System block limit in bytes.

* Silent the storage macro warnings.

* More logic more tests.

* Fix import.

* Refactor names.

* Fix build.

* Update srml/balances/src/lib.rs

* Final refactor.

* Bump transaction version

* Fix weight mult test.

* Fix more tests and improve doc.

* Bump.

* Make some tests work again.

* Fix subkey.

* Remove todos + bump.

* First draft of annotating weights.

* Refactor weight to u64.

* More refactoring and tests.

* New convert for weight to fee

* more tests.

* remove merge redundancy.

* Fix system test.

* Bring back subkey stuff.

* a few stress tests.

* fix some of the grumbles.

* Final nits.

* Update srml/system/src/lib.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* Scale weights by 1000.

* Bump.

* Fix decl_storage test.
This commit is contained in:
Kian Peymani
2019-07-25 11:58:47 +02:00
committed by Bastian Köcher
parent 80472956f8
commit 002acb9373
44 changed files with 844 additions and 259 deletions
+21 -10
View File
@@ -182,11 +182,16 @@ impl Permill {
/// Everything.
pub fn one() -> Self { Self(1_000_000) }
/// create a new raw instance. This can be called at compile time.
pub const fn from_const_parts(parts: u32) -> Self {
Self([parts, 1_000_000][(parts > 1_000_000) as usize])
}
/// From an explicitly defined number of parts per maximum of the type.
pub fn from_parts(x: u32) -> Self { Self(x.min(1_000_000)) }
pub fn from_parts(parts: u32) -> Self { Self::from_const_parts(parts) }
/// Converts from a percent. Equal to `x / 100`.
pub fn from_percent(x: u32) -> Self { Self(x.min(100) * 10_000) }
pub const fn from_percent(x: u32) -> Self { Self([x, 100][(x > 100) as usize] * 10_000) }
/// Converts a fraction into `Permill`.
#[cfg(feature = "std")]
@@ -286,11 +291,16 @@ impl Perbill {
/// Everything.
pub fn one() -> Self { Self(1_000_000_000) }
/// create a new raw instance. This can be called at compile time.
pub const fn from_const_parts(parts: u32) -> Self {
Self([parts, 1_000_000_000][(parts > 1_000_000_000) as usize])
}
/// From an explicitly defined number of parts per maximum of the type.
pub fn from_parts(x: u32) -> Self { Self(x.min(1_000_000_000)) }
pub fn from_parts(parts: u32) -> Self { Self::from_const_parts(parts) }
/// Converts from a percent. Equal to `x / 100`.
pub fn from_percent(x: u32) -> Self { Self(x.min(100) * 10_000_000) }
pub const fn from_percent(x: u32) -> Self { Self([x, 100][(x > 100) as usize] * 10_000_000) }
/// Construct new instance where `x` is in millionths. Value equivalent to `x / 1,000,000`.
pub fn from_millionths(x: u32) -> Self { Self(x.min(1_000_000) * 1000) }
@@ -411,11 +421,12 @@ impl Fixed64 {
/// Performs a saturated multiply and accumulate.
///
/// Returns `n + (self * n)`.
/// Returns a saturated `n + (self * n)`.
/// TODO: generalize this to any weight type. #3189
pub fn saturated_multiply_accumulate(&self, int: u32) -> u32 {
let parts = self.0;
let positive = parts > 0;
// natural parts might overflow.
let natural_parts = self.clone().saturated_into::<u32>();
// fractional parts can always fit into u32.
@@ -459,8 +470,8 @@ impl Saturating for Fixed64 {
}
}
/// Note that this is a standard, _potentially-panicking_, implementation. Use `Saturating` trait for
/// safe addition.
/// Note that this is a standard, _potentially-panicking_, implementation. Use `Saturating` trait
/// for safe addition.
impl ops::Add for Fixed64 {
type Output = Self;
@@ -469,8 +480,8 @@ impl ops::Add for Fixed64 {
}
}
/// Note that this is a standard, _potentially-panicking_, implementation. Use `Saturating` trait for
/// safe subtraction.
/// Note that this is a standard, _potentially-panicking_, implementation. Use `Saturating` trait
/// for safe subtraction.
impl ops::Sub for Fixed64 {
type Output = Self;
+1 -1
View File
@@ -282,7 +282,7 @@ 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 u32,
weight: self.encode().len() as _,
..Default::default()
}
}
+9 -6
View File
@@ -166,7 +166,6 @@ impl<T> Convert<T, T> for Identity {
/// A structure that performs standard conversion using the standard Rust conversion traits.
pub struct ConvertInto;
impl<A, B: From<A>> Convert<A, B> for ConvertInto {
fn convert(a: A) -> B { a.into() }
}
@@ -771,6 +770,9 @@ pub enum DispatchError {
/// General error to do with the inability to pay some fees (e.g. account balance too low).
Payment,
/// General error to do with the exhaustion of block resources.
Resource,
/// General error to do with the permissions of the sender.
NoPermission,
@@ -794,11 +796,12 @@ impl From<DispatchError> for i8 {
fn from(e: DispatchError) -> i8 {
match e {
DispatchError::Payment => -64,
DispatchError::NoPermission => -65,
DispatchError::BadState => -66,
DispatchError::Stale => -67,
DispatchError::Future => -68,
DispatchError::BadProof => -69,
DispatchError::Resource => -65,
DispatchError::NoPermission => -66,
DispatchError::BadState => -67,
DispatchError::Stale => -68,
DispatchError::Future => -69,
DispatchError::BadProof => -70,
}
}
}
+2 -4
View File
@@ -163,10 +163,8 @@ impl<T> ClassifyDispatch<T> for SimpleDispatchInfo {
impl Default for SimpleDispatchInfo {
fn default() -> Self {
// This implies that the weight is currently equal to 100, nothing more
// for all substrate transactions that do NOT explicitly annotate weight.
// TODO #2431 needs to be updated with proper max values.
SimpleDispatchInfo::FixedNormal(100)
// Default weight of all transactions.
SimpleDispatchInfo::FixedNormal(10_000)
}
}