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 -13
View File
@@ -23,6 +23,7 @@
use rstd::{prelude::*, result};
use substrate_primitives::u32_trait::Value as U32;
use primitives::traits::{Hash, EnsureOrigin};
use primitives::weights::SimpleDispatchInfo;
use srml_support::{
dispatch::{Dispatchable, Parameter}, codec::{Encode, Decode}, traits::ChangeMembers,
StorageValue, StorageMap, decl_module, decl_event, decl_storage, ensure
@@ -118,6 +119,9 @@ decl_event!(
}
);
// Note: this module is not benchmarked. The weights are obtained based on the similarity fo the
// executed logic with other democracy function. Note that councillor operations are assigned to the
// operational class.
decl_module! {
pub struct Module<T: Trait<I>, I: Instance=DefaultInstance> for enum Call where origin: <T as system::Trait>::Origin {
fn deposit_event<T, I>() = default;
@@ -126,6 +130,7 @@ decl_module! {
/// provide it pre-sorted.
///
/// Requires root origin.
#[weight = SimpleDispatchInfo::FixedOperational(100_000)]
fn set_members(origin, new_members: Vec<T::AccountId>) {
ensure_root(origin)?;
@@ -168,6 +173,7 @@ decl_module! {
/// Dispatch a proposal from a member using the `Member` origin.
///
/// Origin must be a member of the collective.
#[weight = SimpleDispatchInfo::FixedOperational(100_000)]
fn execute(origin, proposal: Box<<T as Trait<I>>::Proposal>) {
let who = ensure_signed(origin)?;
ensure!(Self::is_member(&who), "proposer not a member");
@@ -181,9 +187,9 @@ decl_module! {
/// - Bounded storage reads and writes.
/// - Argument `threshold` has bearing on weight.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedOperational(5_000_000)]
fn propose(origin, #[compact] threshold: MemberCount, proposal: Box<<T as Trait<I>>::Proposal>) {
let who = ensure_signed(origin)?;
ensure!(Self::is_member(&who), "proposer not a member");
let proposal_hash = T::Hashing::hash_of(&proposal);
@@ -210,9 +216,9 @@ decl_module! {
/// - Bounded storage read and writes.
/// - Will be slightly heavier if the proposal is approved / disapproved after the vote.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedOperational(200_000)]
fn vote(origin, proposal: T::Hash, #[compact] index: ProposalIndex, approve: bool) {
let who = ensure_signed(origin)?;
ensure!(Self::is_member(&who), "voter not a member");
let mut voting = Self::voting(&proposal).ok_or("proposal must exist")?;
@@ -393,7 +399,7 @@ mod tests {
use runtime_io::with_externalities;
use substrate_primitives::{H256, Blake2Hasher};
use primitives::{
traits::{BlakeTwo256, IdentityLookup, Block as BlockT}, testing::Header, BuildStorage
Perbill, traits::{BlakeTwo256, IdentityLookup, Block as BlockT}, testing::Header, BuildStorage
};
use crate as collective;
@@ -401,6 +407,7 @@ mod tests {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl system::Trait for Test {
type Origin = Origin;
@@ -416,6 +423,7 @@ mod tests {
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
}
impl Trait<Instance1> for Test {
type Origin = Origin;
@@ -554,7 +562,7 @@ mod tests {
event: Event::collective_Instance1(RawEvent::Proposed(
1,
0,
hex!["10b209e55d0f37cd45574674bba42519a29bf0ccf3c85c3c773fcbacab820bb4"].into(),
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
3,
)),
topics: vec![],
@@ -622,7 +630,7 @@ mod tests {
event: Event::collective_Instance1(RawEvent::Proposed(
1,
0,
hex!["10b209e55d0f37cd45574674bba42519a29bf0ccf3c85c3c773fcbacab820bb4"].into(),
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
2,
)),
topics: vec![],
@@ -631,7 +639,7 @@ mod tests {
phase: Phase::Finalization,
event: Event::collective_Instance1(RawEvent::Voted(
1,
hex!["10b209e55d0f37cd45574674bba42519a29bf0ccf3c85c3c773fcbacab820bb4"].into(),
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
false,
0,
1,
@@ -658,7 +666,7 @@ mod tests {
RawEvent::Proposed(
1,
0,
hex!["10b209e55d0f37cd45574674bba42519a29bf0ccf3c85c3c773fcbacab820bb4"].into(),
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
3,
)),
topics: vec![],
@@ -667,7 +675,7 @@ mod tests {
phase: Phase::Finalization,
event: Event::collective_Instance1(RawEvent::Voted(
2,
hex!["10b209e55d0f37cd45574674bba42519a29bf0ccf3c85c3c773fcbacab820bb4"].into(),
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
false,
1,
1,
@@ -677,7 +685,7 @@ mod tests {
EventRecord {
phase: Phase::Finalization,
event: Event::collective_Instance1(RawEvent::Disapproved(
hex!["10b209e55d0f37cd45574674bba42519a29bf0ccf3c85c3c773fcbacab820bb4"].into(),
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
)),
topics: vec![],
}
@@ -700,7 +708,7 @@ mod tests {
event: Event::collective_Instance1(RawEvent::Proposed(
1,
0,
hex!["10b209e55d0f37cd45574674bba42519a29bf0ccf3c85c3c773fcbacab820bb4"].into(),
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
2,
)),
topics: vec![],
@@ -709,7 +717,7 @@ mod tests {
phase: Phase::Finalization,
event: Event::collective_Instance1(RawEvent::Voted(
2,
hex!["10b209e55d0f37cd45574674bba42519a29bf0ccf3c85c3c773fcbacab820bb4"].into(),
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
true,
2,
0,
@@ -719,14 +727,14 @@ mod tests {
EventRecord {
phase: Phase::Finalization,
event: Event::collective_Instance1(RawEvent::Approved(
hex!["10b209e55d0f37cd45574674bba42519a29bf0ccf3c85c3c773fcbacab820bb4"].into(),
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
)),
topics: vec![],
},
EventRecord {
phase: Phase::Finalization,
event: Event::collective_Instance1(RawEvent::Executed(
hex!["10b209e55d0f37cd45574674bba42519a29bf0ccf3c85c3c773fcbacab820bb4"].into(),
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
false,
)),
topics: vec![],