Browse Source

Merge branch 'olympia' into membership_modify_module2

# Conflicts:
#	runtime-modules/membership/src/lib.rs
#	runtime-modules/membership/src/tests/mock.rs
#	runtime-modules/membership/src/tests/mod.rs
Shamil Gadelshin 4 years ago
parent
commit
6e04be9ad6

+ 1 - 0
Cargo.lock

@@ -4279,6 +4279,7 @@ dependencies = [
  "frame-system",
  "pallet-balances",
  "pallet-common",
+ "pallet-membership",
  "pallet-timestamp",
  "parity-scale-codec",
  "serde",

+ 0 - 3
runtime-modules/forum/src/lib.rs

@@ -595,9 +595,6 @@ decl_module! {
 
             Self::ensure_can_create_thread(account_id, &forum_user_id, &category_id)?;
 
-            // Check that thread can be added to category
-            Self::ensure_category_is_mutable(&category_id)?;
-
             // Ensure poll is valid
             if let Some(ref data) = poll {
                 // Check all poll alternatives

+ 1 - 2
runtime-modules/membership/Cargo.toml

@@ -15,12 +15,12 @@ sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://
 pallet-timestamp = { package = 'pallet-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
 balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
 common = { package = 'pallet-common', default-features = false, path = '../common'}
-working-group = { package = 'pallet-working-group', default-features = false, path = '../working-group'}
 
 [dev-dependencies]
 sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
 sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
 staking-handler = { package = 'staking-handler', default-features = false, path = '../staking-handler'}
+working-group = { package = 'pallet-working-group', default-features = false, path = '../working-group'}
 
 [features]
 default = ['std']
@@ -35,5 +35,4 @@ std = [
 	'pallet-timestamp/std',
 	'balances/std',
 	'common/std',
-	'working-group/std',
 ]

+ 0 - 3
runtime-modules/membership/src/lib.rs

@@ -55,9 +55,6 @@ use sp_std::vec::Vec;
 
 use common::working_group::WorkingGroupIntegration;
 
-/// The membership working group instance alias.
-pub type MembershipWorkingGroupInstance = working_group::Instance4;
-
 // Balance type alias
 type BalanceOf<T> = <T as balances::Trait>::Balance;
 

+ 5 - 3
runtime-modules/membership/src/tests/mock.rs

@@ -2,9 +2,9 @@
 
 pub use crate::{GenesisConfig, Trait};
 
-use crate::{genesis, MembershipWorkingGroupInstance};
 pub use frame_support::traits::{Currency, LockIdentifier};
 use frame_support::{impl_outer_event, impl_outer_origin, parameter_types};
+
 pub use frame_system;
 use frame_system::RawOrigin;
 use sp_core::H256;
@@ -14,6 +14,8 @@ use sp_runtime::{
     DispatchError, DispatchResult, Perbill,
 };
 
+pub(crate) type MembershipWorkingGroupInstance = working_group::Instance4;
+
 impl_outer_origin! {
     pub enum Origin for Test {}
 }
@@ -102,7 +104,7 @@ parameter_types! {
     pub const LockId: LockIdentifier = [9; 8];
 }
 
-impl working_group::Trait<crate::MembershipWorkingGroupInstance> for Test {
+impl working_group::Trait<MembershipWorkingGroupInstance> for Test {
     type Event = TestEvent;
     type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
     type StakingHandler = staking_handler::StakingManager<Self, LockId>;
@@ -288,7 +290,7 @@ pub fn build_test_externalities_with_initial_members(
 ) -> sp_io::TestExternalities {
     TestExternalitiesBuilder::<Test>::default()
         .set_membership_config(
-            genesis::GenesisConfigBuilder::default()
+            crate::genesis::GenesisConfigBuilder::default()
                 .members(initial_members)
                 .build(),
         )

+ 1 - 1
runtime-modules/membership/src/tests/mod.rs

@@ -3,7 +3,7 @@
 pub(crate) mod fixtures;
 pub(crate) mod mock;
 
-use crate::{Error, Event, MembershipWorkingGroupInstance};
+use crate::{Error, Event};
 use fixtures::*;
 use mock::*;
 

+ 11 - 7
runtime-modules/proposals/discussion/src/benchmarking.rs

@@ -60,13 +60,17 @@ fn member_account<T: common::Trait + balances::Trait + membership::Trait>(
         "Balance not added",
     );
 
-    Membership::<T>::buy_membership(
-        RawOrigin::Signed(account_id.clone()).into(),
-        Some(handle),
-        None,
-        None,
-    )
-    .unwrap();
+    let params = membership::BuyMembershipParameters {
+        root_account: account_id.clone(),
+        controller_account: account_id.clone(),
+        name: None,
+        handle: Some(handle),
+        avatar_uri: None,
+        about: None,
+        referrer_id: None,
+    };
+
+    Membership::<T>::buy_membership(RawOrigin::Signed(account_id.clone()).into(), params).unwrap();
 
     (account_id, T::MemberId::from(id.try_into().unwrap()))
 }

+ 11 - 7
runtime-modules/proposals/engine/src/benchmarking.rs

@@ -74,13 +74,17 @@ fn member_funded_account<T: Trait + membership::Trait>(
     // Give balance for buying membership
     let _ = Balances::<T>::make_free_balance_be(&account_id, T::Balance::max_value());
 
-    Membership::<T>::buy_membership(
-        RawOrigin::Signed(account_id.clone()).into(),
-        Some(handle),
-        None,
-        None,
-    )
-    .unwrap();
+    let params = membership::BuyMembershipParameters {
+        root_account: account_id.clone(),
+        controller_account: account_id.clone(),
+        name: None,
+        handle: Some(handle),
+        avatar_uri: None,
+        about: None,
+        referrer_id: None,
+    };
+
+    Membership::<T>::buy_membership(RawOrigin::Signed(account_id.clone()).into(), params).unwrap();
 
     let _ = Balances::<T>::make_free_balance_be(&account_id, T::Balance::max_value());
 

+ 21 - 9
runtime-modules/proposals/engine/src/lib.rs

@@ -332,6 +332,9 @@ decl_error! {
 
         /// There is not enough balance for a stake.
         InsufficientBalanceForStake,
+
+        /// The conflicting stake discovered. Cannot stake.
+        ConflictingStakes,
     }
 }
 
@@ -446,7 +449,9 @@ decl_module! {
 
             proposal.voting_results.add_vote(vote.clone());
 
-            // mutation
+            //
+            // == MUTATION SAFE ==
+            //
 
             <Proposals<T>>::insert(proposal_id, proposal);
             <VoteExistsByProposalByVoter<T>>::insert(proposal_id, voter_id, vote.clone());
@@ -474,7 +479,9 @@ decl_module! {
             ensure!(matches!(proposal.status, ProposalStatus::Active{..}), Error::<T>::ProposalFinalized);
             ensure!(proposal.voting_results.no_votes_yet(), Error::<T>::ProposalHasVotes);
 
-            // mutation
+            //
+            // == MUTATION SAFE ==
+            //
 
             Self::finalize_proposal(proposal_id, proposal, ProposalDecision::Canceled);
         }
@@ -500,7 +507,9 @@ decl_module! {
                 Error::<T>::ProposalFinalized
             );
 
-            // mutation
+            //
+            // == MUTATION SAFE ==
+            //
 
             Self::finalize_proposal(proposal_id, proposal, ProposalDecision::Vetoed);
         }
@@ -526,8 +535,9 @@ impl<T: Trait> Module<T> {
             creation_params.exact_execution_block,
         )?;
 
-        // checks passed
-        // mutation
+        //
+        // == MUTATION SAFE ==
+        //
 
         let next_proposal_count_value = Self::proposal_count() + 1;
         let new_proposal_id = next_proposal_count_value;
@@ -537,11 +547,8 @@ impl<T: Trait> Module<T> {
         if let Some(stake_balance) = creation_params.proposal_parameters.required_stake {
             if let Some(staking_account_id) = creation_params.staking_account_id.clone() {
                 T::StakingHandler::lock(&staking_account_id, stake_balance);
-            } else {
-                // Return an error if no staking account provided.
-                return Err(Error::<T>::EmptyStake.into());
             }
-        };
+        }
 
         let new_proposal = Proposal {
             activated_at: Self::current_block(),
@@ -619,6 +626,11 @@ impl<T: Trait> Module<T> {
 
         if let Some(stake_balance) = parameters.required_stake {
             if let Some(staking_account_id) = staking_account_id {
+                ensure!(
+                    T::StakingHandler::is_account_free_of_conflicting_stakes(&staking_account_id),
+                    Error::<T>::ConflictingStakes
+                );
+
                 ensure!(
                     T::StakingHandler::is_enough_balance_for_stake(
                         &staking_account_id,

+ 37 - 1
runtime-modules/proposals/engine/src/tests/mod.rs

@@ -6,7 +6,9 @@ use mock::*;
 
 use codec::Encode;
 use frame_support::dispatch::DispatchResult;
-use frame_support::traits::{Currency, OnFinalize, OnInitialize};
+use frame_support::traits::{
+    Currency, LockableCurrency, OnFinalize, OnInitialize, WithdrawReasons,
+};
 use frame_support::{StorageDoubleMap, StorageMap, StorageValue};
 use frame_system::RawOrigin;
 use frame_system::{EventRecord, Phase};
@@ -1104,6 +1106,40 @@ fn create_proposal_fais_with_insufficient_stake_parameters() {
     });
 }
 
+#[test]
+fn create_proposal_fais_with_empty_stake() {
+    initial_test_ext().execute_with(|| {
+        let parameters_fixture = ProposalParametersFixture::default().with_required_stake(300);
+        let dummy_proposal =
+            DummyProposalFixture::default().with_parameters(parameters_fixture.params());
+
+        dummy_proposal.create_proposal_and_assert(Err(Error::<Test>::EmptyStake.into()));
+    });
+}
+
+#[test]
+fn create_proposal_fais_with_conflicting_stakes() {
+    initial_test_ext().execute_with(|| {
+        let staking_account_id = 1;
+
+        let initial_balance = 100000;
+        increase_total_balance_issuance_using_account_id(staking_account_id, initial_balance);
+        Balances::set_lock(
+            LockId::get(),
+            &staking_account_id,
+            100,
+            WithdrawReasons::all(),
+        );
+
+        let parameters_fixture = ProposalParametersFixture::default().with_required_stake(300);
+        let dummy_proposal = DummyProposalFixture::default()
+            .with_parameters(parameters_fixture.params())
+            .with_stake(staking_account_id);
+
+        dummy_proposal.create_proposal_and_assert(Err(Error::<Test>::ConflictingStakes.into()));
+    });
+}
+
 #[test]
 fn finalize_expired_proposal_and_check_stake_removing_with_balance_checks_succeeds() {
     initial_test_ext().execute_with(|| {

+ 9 - 2
runtime-modules/working-group/Cargo.toml

@@ -14,17 +14,24 @@ sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'ht
 sp-std = { package = 'sp-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
 common = { package = 'pallet-common', default-features = false, path = '../common'}
 balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
-frame-benchmarking = { package = 'frame-benchmarking', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca', optional = true}
 staking-handler = { package = 'staking-handler', default-features = false, path = '../staking-handler'}
 
+# Benchmarking
+frame-benchmarking = { package = 'frame-benchmarking', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca', optional = true}
+membership = { package = 'pallet-membership', default-features = false, path = '../membership', optional = true}
+
 [dev-dependencies]
 sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
 sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
 pallet-timestamp = { package = 'pallet-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
+membership = { package = 'pallet-membership', default-features = false, path = '../membership'}
 
 [features]
 default = ['std']
-runtime-benchmarks = ["frame-benchmarking"]
+runtime-benchmarks = [
+	"frame-benchmarking",
+	"membership"
+]
 std = [
 	'serde',
 	'codec/std',

+ 18 - 14
runtime-modules/working-group/src/benchmarking.rs

@@ -109,7 +109,7 @@ fn apply_on_opening_helper<T: Trait<I>, I: Instance>(
     application_id
 }
 
-fn add_opening_and_apply_with_multiple_ids<T: Trait<I>, I: Instance>(
+fn add_opening_and_apply_with_multiple_ids<T: Trait<I> + membership::Trait, I: Instance>(
     ids: &Vec<u32>,
     add_opening_origin: &T::Origin,
     staking_role: &StakingRole,
@@ -174,7 +174,7 @@ fn handle_from_id<T: membership::Trait>(id: u32) -> Vec<u8> {
     handle
 }
 
-fn member_funded_account<T: Trait<I>, I: Instance>(
+fn member_funded_account<T: Trait<I> + membership::Trait, I: Instance>(
     name: &'static str,
     id: u32,
 ) -> (T::AccountId, T::MemberId) {
@@ -183,19 +183,19 @@ fn member_funded_account<T: Trait<I>, I: Instance>(
 
     let _ = Balances::<T>::make_free_balance_be(&account_id, BalanceOf::<T>::max_value());
 
-    let authority_account = account::<T::AccountId>(name, 0, SEED);
+    let params = membership::BuyMembershipParameters {
+        root_account: account_id.clone(),
+        controller_account: account_id.clone(),
+        name: None,
+        handle: Some(handle),
+        avatar_uri: None,
+        about: None,
+        referrer_id: None,
+    };
 
-    Membership::<T>::set_screening_authority(RawOrigin::Root.into(), authority_account.clone())
-        .unwrap();
+    Membership::<T>::buy_membership(RawOrigin::Signed(account_id.clone()).into(), params).unwrap();
 
-    Membership::<T>::add_screened_member(
-        RawOrigin::Signed(authority_account.clone()).into(),
-        account_id.clone(),
-        Some(handle),
-        None,
-        None,
-    )
-    .unwrap();
+    let _ = Balances::<T>::make_free_balance_be(&account_id, BalanceOf::<T>::max_value());
 
     (account_id, T::MemberId::from(id.try_into().unwrap()))
 }
@@ -208,7 +208,7 @@ fn force_missed_reward<T: Trait<I>, I: Instance>() {
     WorkingGroup::<T, _>::on_initialize(curr_block_number);
 }
 
-fn insert_a_worker<T: Trait<I>, I: Instance>(
+fn insert_a_worker<T: Trait<I> + membership::Trait, I: Instance>(
     staking_role: StakingRole,
     job_opening_type: OpeningType,
     id: u32,
@@ -254,6 +254,10 @@ where
 }
 
 benchmarks_instance! {
+    where_clause {
+        where T: membership::Trait
+    }
+
     _ { }
 
     on_initialize_leaving {

+ 7 - 0
runtime-modules/working-group/src/tests/mock.rs

@@ -24,6 +24,7 @@ impl_outer_event! {
         balances<T>,
         crate DefaultInstance <T>,
         frame_system<T>,
+        membership<T>,
     }
 }
 
@@ -95,6 +96,12 @@ impl common::Trait for Test {
     type ActorId = u64;
 }
 
+impl membership::Trait for Test {
+    type Event = TestEvent;
+    type MembershipFee = MembershipFee;
+    type WorkingGroup = Module<Test>;
+}
+
 pub type Balances = balances::Module<Test>;
 pub type System = frame_system::Module<Test>;
 

+ 0 - 1
runtime/Cargo.toml

@@ -163,7 +163,6 @@ runtime-benchmarks = [
     "pallet-timestamp/runtime-benchmarks",
     "frame-benchmarking",
     "frame-system-benchmarking",
-    "pallet-offences-benchmarking",
     "pallet-session-benchmarking",
     "pallet-utility/runtime-benchmarks",
     "proposals-discussion/runtime-benchmarks",

+ 4 - 2
runtime/src/lib.rs

@@ -377,8 +377,10 @@ impl pallet_im_online::Trait for Runtime {
     type Event = Event;
     type SessionDuration = SessionDuration;
     type ReportUnresponsiveness = Offences;
+    // Using the default weights until we check if we can run the benchmarks for this pallet in
+    // the reference machine in an acceptable time.
+    type WeightInfo = ();
     type UnsignedPriority = ImOnlineUnsignedPriority;
-    type WeightInfo = weights::pallet_im_online::WeightInfo;
 }
 
 parameter_types! {
@@ -600,7 +602,7 @@ pub type StorageWorkingGroupInstance = storage::StorageWorkingGroupInstance;
 pub type ContentDirectoryWorkingGroupInstance = working_group::Instance3;
 
 // The membership working group instance alias.
-pub type MembershipWorkingGroupInstance = membership::MembershipWorkingGroupInstance;
+pub type MembershipWorkingGroupInstance = working_group::Instance4;
 
 parameter_types! {
     pub const MaxWorkerNumberLimit: u32 = 100;

+ 27 - 3
runtime/src/runtime_api.rs

@@ -256,13 +256,23 @@ impl_runtime_apis! {
         ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
             use sp_std::vec;
             use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
-            use frame_system_benchmarking::Module as SystemBench;
-            impl frame_system_benchmarking::Trait for Runtime {}
 
+            use pallet_session_benchmarking::Module as SessionBench;
+            use frame_system_benchmarking::Module as SystemBench;
             use crate::ProposalsDiscussion;
             use crate::ProposalsEngine;
             use crate::Constitution;
             use crate::ContentDirectoryWorkingGroup;
+            use crate::Utility;
+            use crate::Timestamp;
+            use crate::ImOnline;
+
+
+            // Trying to add benchmarks directly to the Session Pallet caused cyclic dependency issues.
+            // To get around that, we separated the Session benchmarks into its own crate, which is why
+            // we need these two lines below.
+            impl pallet_session_benchmarking::Trait for Runtime {}
+            impl frame_system_benchmarking::Trait for Runtime {}
 
             let whitelist: Vec<TrackedStorageKey> = vec![
                 // Block Number
@@ -284,7 +294,21 @@ impl_runtime_apis! {
             let mut batches = Vec::<BenchmarkBatch>::new();
             let params = (&config, &whitelist);
 
-            add_benchmark!(params, batches, system, SystemBench::<Runtime>);
+            // Note: For benchmarking Stake and Balances we need to change ExistentialDeposit to
+            // a non-zero value.
+            // For now, due to the complexity grandpa and babe aren't benchmarked automatically
+            // we should use the default manually created weights.
+            // Finally, pallet_offences have no `WeightInfo` so there's no need to benchmark it
+            // the benchmark is only for illustrative pourpuses.
+
+            // Frame benchmarks
+            add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
+            add_benchmark!(params, batches, pallet_utility, Utility);
+            add_benchmark!(params, batches, pallet_timestamp, Timestamp);
+            add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
+            add_benchmark!(params, batches, pallet_im_online, ImOnline);
+
+            // Joystream Benchmarks
             add_benchmark!(params, batches, proposals_discussion, ProposalsDiscussion);
             add_benchmark!(params, batches, proposals_engine, ProposalsEngine);
             add_benchmark!(params, batches, pallet_constitution, Constitution);

+ 11 - 27
runtime/src/weights/frame_system.rs

@@ -1,23 +1,7 @@
-// This file is part of Substrate.
-
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
-// SPDX-License-Identifier: Apache-2.0
-
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// 	http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5
+//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0
 
 #![allow(unused_parens)]
+#![allow(unused_imports)]
 
 use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight};
 
@@ -25,33 +9,33 @@ pub struct WeightInfo;
 impl frame_system::WeightInfo for WeightInfo {
     // WARNING! Some components were not used: ["b"]
     fn remark() -> Weight {
-        (1305000 as Weight)
+        (9_342_000 as Weight)
     }
     fn set_heap_pages() -> Weight {
-        (2023000 as Weight).saturating_add(DbWeight::get().writes(1 as Weight))
+        (11_274_000 as Weight).saturating_add(DbWeight::get().writes(1 as Weight))
     }
     // WARNING! Some components were not used: ["d"]
     fn set_changes_trie_config() -> Weight {
-        (10026000 as Weight)
+        (32_325_000 as Weight)
             .saturating_add(DbWeight::get().reads(1 as Weight))
             .saturating_add(DbWeight::get().writes(2 as Weight))
     }
     fn set_storage(i: u32) -> Weight {
         (0 as Weight)
-            .saturating_add((656000 as Weight).saturating_mul(i as Weight))
+            .saturating_add((2_060_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
     }
     fn kill_storage(i: u32) -> Weight {
-        (4327000 as Weight)
-            .saturating_add((478000 as Weight).saturating_mul(i as Weight))
+        (27_686_000 as Weight)
+            .saturating_add((1_237_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
     }
     fn kill_prefix(p: u32) -> Weight {
-        (8349000 as Weight)
-            .saturating_add((838000 as Weight).saturating_mul(p as Weight))
+        (27_689_000 as Weight)
+            .saturating_add((1_205_000 as Weight).saturating_mul(p as Weight))
             .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight)))
     }
     fn suicide() -> Weight {
-        (29247000 as Weight)
+        (145_274_000 as Weight)
     }
 }

+ 2 - 1
runtime/src/weights/mod.rs

@@ -15,14 +15,15 @@
 
 //! A list of the different weight modules for our runtime.
 
+// FRAME pallets
 pub mod frame_system;
 pub mod pallet_balances;
-pub mod pallet_im_online;
 pub mod pallet_session;
 pub mod pallet_staking;
 pub mod pallet_timestamp;
 pub mod pallet_utility;
 
+// Joystream pallets
 pub mod pallet_constitution;
 pub mod proposals_discussion;
 pub mod proposals_engine;

+ 2 - 2
runtime/src/weights/pallet_constitution.rs

@@ -8,8 +8,8 @@ use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight};
 pub struct WeightInfo;
 impl pallet_constitution::WeightInfo for WeightInfo {
     fn amend_constitution(i: u32) -> Weight {
-        (145_984_000 as Weight)
-            .saturating_add((59_000 as Weight).saturating_mul(i as Weight))
+        (79_243_000 as Weight)
+            .saturating_add((64_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
 }

+ 0 - 34
runtime/src/weights/pallet_im_online.rs

@@ -1,34 +0,0 @@
-// This file is part of Substrate.
-
-// Copyright (C) 2020 Parity Technologies (UK) Ltd.
-// SPDX-License-Identifier: Apache-2.0
-
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// 	http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc6
-
-#![allow(unused_parens)]
-#![allow(unused_imports)]
-
-use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight};
-
-pub struct WeightInfo;
-impl pallet_im_online::WeightInfo for WeightInfo {
-    fn validate_unsigned_and_then_heartbeat(k: u32, e: u32) -> Weight {
-        (139830000 as Weight)
-            .saturating_add((211000 as Weight).saturating_mul(k as Weight))
-            .saturating_add((654000 as Weight).saturating_mul(e as Weight))
-            .saturating_add(DbWeight::get().reads(4 as Weight))
-            .saturating_add(DbWeight::get().writes(1 as Weight))
-    }
-}

+ 3 - 20
runtime/src/weights/pallet_session.rs

@@ -1,21 +1,4 @@
-// This file is part of Substrate.
-
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
-// SPDX-License-Identifier: Apache-2.0
-
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// 	http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc6
+//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0
 
 #![allow(unused_parens)]
 #![allow(unused_imports)]
@@ -25,12 +8,12 @@ use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight};
 pub struct WeightInfo;
 impl pallet_session::WeightInfo for WeightInfo {
     fn set_keys() -> Weight {
-        (88_411_000 as Weight)
+        (433_479_000 as Weight)
             .saturating_add(DbWeight::get().reads(6 as Weight))
             .saturating_add(DbWeight::get().writes(5 as Weight))
     }
     fn purge_keys() -> Weight {
-        (51_843_000 as Weight)
+        (299_139_000 as Weight)
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().writes(5 as Weight))
     }

+ 3 - 20
runtime/src/weights/pallet_utility.rs

@@ -1,21 +1,4 @@
-// This file is part of Substrate.
-
-// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
-// SPDX-License-Identifier: Apache-2.0
-
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// 	http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5
+//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0
 
 #![allow(unused_parens)]
 #![allow(unused_imports)]
@@ -25,10 +8,10 @@ use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight};
 pub struct WeightInfo;
 impl pallet_utility::WeightInfo for WeightInfo {
     fn batch(c: u32) -> Weight {
-        (16461000 as Weight).saturating_add((1982000 as Weight).saturating_mul(c as Weight))
+        (0 as Weight).saturating_add((105_180_000 as Weight).saturating_mul(c as Weight))
     }
     // WARNING! Some components were not used: ["u"]
     fn as_derivative() -> Weight {
-        (4086000 as Weight)
+        (67_812_000 as Weight)
     }
 }

+ 42 - 19
scripts/generate-weights.sh

@@ -2,22 +2,45 @@
 
 # Executes and replaces all benchmarks with the new weights
 
-echo "Benchmarking proposals_discussion..."
-./target/release/joystream-node benchmark --pallet=proposals_discussion --extrinsic=* --chain=dev --steps=50 --repeat=20 --execution=wasm --output=. > /dev/null
-mv proposals_discussion.rs runtime/src/weights/
-echo "proposals_discussion benchmarked"
-
-echo "Benchmarking proposals_engine..."
-./target/release/joystream-node benchmark --pallet=proposals_engine --extrinsic=* --chain=dev --steps=50 --repeat=20 --execution=wasm --output=. > /dev/null
-mv proposals_engine.rs runtime/src/weights/
-echo "proposals_engine benchmarked"
-
-echo "Benchmarking pallet_constitution..."
-./target/release/joystream-node benchmark --pallet=pallet_constitution --extrinsic=* --chain=dev --steps=50 --repeat=20 --execution=wasm --output=. > /dev/null
-mv pallet_constitution.rs runtime/src/weights/
-echo "pallet_constitution benchmarked"
-
-echo "Benchmarking working_group..."
-./target/release/joystream-node benchmark --pallet=working_group --extrinsic=* --chain=dev --steps=50 --repeat=20 --execution=wasm --output=. > /dev/null
-mv working_group.rs runtime/src/weights/
-echo "working_group benchmarked"
+SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
+
+benchmark() {
+  echo "Generating weights for $1..."
+  start=`date +%s`
+  $SCRIPT_DIR/../target/release/joystream-node benchmark \
+      --pallet=$1 \
+      --extrinsic=* \
+      --chain=dev \
+      --steps=50 \
+      --repeat=20 \
+      --execution=wasm \
+      --output=.  > /dev/null
+
+  end=`date +%s`
+
+  if [ $? -eq 0 ]; then
+      mv $SCRIPT_DIR/../*.rs $SCRIPT_DIR/../runtime/src/weights/
+      echo "Weights generated successfully for $1"
+      echo "It took $((end-start)) seconds"
+  else
+      echo "There was a problem generating the weights for $1, check the error above"
+  fi
+}
+
+# FRAME benchmarks
+benchmark frame_system
+benchmark pallet_utility
+benchmark pallet_session
+benchmark pallet_timestamp
+
+# This benchmark takes too long with 50 steps and 20 repeats in a normal laptop.
+# Will have it commented out until we test it in the reference machine. If there
+# it still takes too long we will get rid of this benchmark for good and use always
+# the default weights.
+# benchmark pallet_im_online
+
+# Joystrem benchmarks
+benchmark proposals_discussion
+benchmark proposals_engine
+benchmark pallet_constitution
+benchmark working_group