-
Couldn't load subscription status.
- Fork 2.7k
Weight annotation. #3157
Weight annotation. #3157
Changes from all commits
b042a93
37f6ae0
2e5b1f4
b7646ec
a871c9f
8e7c803
a824b56
5de080f
a8789b9
7d96429
30b4ba7
2a9c9df
342efb5
b8f564e
07fdfe2
7f33006
36063fe
7a0fbc9
84fa279
f4d4579
def6425
d12713a
3350f9c
b788507
b9b6b53
045681e
bfcfa36
107801f
c100df9
f5d33c6
0c1c268
6a0a1d4
b06ef82
c3e0ee3
5b0c715
e683829
ce11fc5
0b592e2
ee970d1
58191a3
67b268a
0d9133f
ec6554f
a25e4be
5724771
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
kianenigma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should safety be the default here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The priority was to be consistent with how the std operations work. This implementation might panic. There are saturating/checked ones that don't. |
||
| impl ops::Sub for Fixed64 { | ||
| type Output = Self; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,17 +8,11 @@ | |
| #[cfg(feature = "std")] | ||
| include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); | ||
|
|
||
| #[cfg(feature = "std")] | ||
| use serde::{Serialize, Deserialize}; | ||
| use parity_codec::{Encode, Decode}; | ||
| use rstd::prelude::*; | ||
| #[cfg(feature = "std")] | ||
| use primitives::bytes; | ||
| use primitives::{ed25519, sr25519, OpaqueMetadata}; | ||
| use sr_primitives::{ | ||
| ApplyResult, transaction_validity::TransactionValidity, generic, create_runtime_str, | ||
| traits::{self, NumberFor, BlakeTwo256, Block as BlockT, StaticLookup, Verify}, weights::Weight, | ||
| }; | ||
| use sr_primitives::{ApplyResult, transaction_validity::TransactionValidity, generic, create_runtime_str}; | ||
| use sr_primitives::traits::{NumberFor, BlakeTwo256, Block as BlockT, StaticLookup, Verify, ConvertInto}; | ||
| use sr_primitives::weights::Weight; | ||
| use client::{ | ||
| block_builder::api::{CheckInherentsResult, InherentData, self as block_builder_api}, | ||
| runtime_api, impl_runtime_apis | ||
|
|
@@ -102,8 +96,9 @@ pub fn native_version() -> NativeVersion { | |
|
|
||
| parameter_types! { | ||
| pub const BlockHashCount: BlockNumber = 250; | ||
| pub const MaximumBlockWeight: Weight = 4 * 1024 * 1024; | ||
| pub const MaximumBlockLength: u32 = 4 * 1024 * 1024; | ||
| pub const MaximumBlockWeight: Weight = 1_000_000; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As updated in the sheet, weight scale is now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1_000_000 seems small for a block. why not make it 1_000_000_000 per block to allow more fine-grained transaction weighting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this also came hand in hand with the fact that a fixed multiplier of 1000 was removed from weights. So the limit hasn't actually changed at all. Could easily be reverted, yet, my arguments being:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kianenigma what about using powers of 2 instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not enough.
Not a good enough reason, since this is actually important logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not enough.
Not a good enough reason, since this is actually important logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, Po2 not a good idea here. weights are meant to be vaguely human-comprehensible, not things that are stored in memory or otherwise benefit from Po2 sizes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted to a scale of |
||
| pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); | ||
| pub const MaximumBlockLength: u32 = 5 * 1024 * 1024; | ||
| } | ||
|
|
||
| impl system::Trait for Runtime { | ||
|
|
@@ -133,6 +128,8 @@ impl system::Trait for Runtime { | |
| type MaximumBlockWeight = MaximumBlockWeight; | ||
| /// Maximum size of all encoded transactions (in bytes) that are allowed in one block. | ||
| type MaximumBlockLength = MaximumBlockLength; | ||
| /// Portion of the block weight that is available to all normal transactions. | ||
| type AvailableBlockRatio = AvailableBlockRatio; | ||
| } | ||
|
|
||
| impl aura::Trait for Runtime { | ||
|
|
@@ -166,8 +163,8 @@ parameter_types! { | |
| pub const ExistentialDeposit: u128 = 500; | ||
| pub const TransferFee: u128 = 0; | ||
| pub const CreationFee: u128 = 0; | ||
| pub const TransactionBaseFee: u128 = 1; | ||
| pub const TransactionByteFee: u128 = 0; | ||
| pub const TransactionBaseFee: u128 = 0; | ||
| pub const TransactionByteFee: u128 = 1; | ||
| } | ||
|
|
||
| impl balances::Trait for Runtime { | ||
|
|
@@ -188,6 +185,7 @@ impl balances::Trait for Runtime { | |
| type CreationFee = CreationFee; | ||
| type TransactionBaseFee = TransactionBaseFee; | ||
| type TransactionByteFee = TransactionByteFee; | ||
| type WeightToFee = ConvertInto; | ||
| } | ||
|
|
||
| impl sudo::Trait for Runtime { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,3 +34,4 @@ wabt = "~0.7.4" | |
|
|
||
| [features] | ||
| benchmarks = [] | ||
| stress-test = [] | ||
Uh oh!
There was an error while loading. Please reload this page.