Pārlūkot izejas kodu

runtime: working-group: fix weights and small fee-analysis fix

conectado 4 gadi atpakaļ
vecāks
revīzija
d71667b200

+ 1 - 1
Cargo.lock

@@ -4338,7 +4338,7 @@ dependencies = [
 
 [[package]]
 name = "pallet-working-group"
-version = "4.0.1"
+version = "4.1.0"
 dependencies = [
  "frame-benchmarking",
  "frame-support",

+ 1 - 1
analyses/fee-analysis/analysis_cli/analysis.py

@@ -63,7 +63,7 @@ def calc_total_price_given_params(extrinsic, weight_coeff, market_cap, issuance,
 
 
 def calc_total_fee(extrinsic, weight_coeff, length_coeff, params, lengths, weights):
-    return weight_to_fee(calc_weight(weights[extrinsic], extrinsic, params) + EXTRINSIC_BASE_WEIGHT, weight_coeff) + \
+    return weight_to_fee(calc_weight(weights[extrinsic], extrinsic, params), weight_coeff) + \
         length_to_fee(lengths.get(extrinsic, 0), length_coeff)
 
 

+ 1 - 1
analyses/fee-analysis/analysis_cli/config.json

@@ -1,5 +1,5 @@
 {
-    "weight_coefficient": 2,
+    "weight_coefficient": 0.00000016,
     "issuance": 250000000,
     "length_coefficient": 1,
     "min_market_cap": 1250000,

+ 1 - 1
runtime-modules/forum/src/benchmarking.rs

@@ -2,7 +2,7 @@
 use super::*;
 use balances::Module as Balances;
 use core::convert::TryInto;
-use frame_benchmarking::{account, benchmarks, Zero};
+use frame_benchmarking::{account, benchmarks};
 use frame_support::storage::StorageMap;
 use frame_support::traits::Currency;
 use frame_system::Module as System;

+ 1 - 5
runtime-modules/forum/src/mock.rs

@@ -217,11 +217,7 @@ impl working_group::WeightInfo for Weights {
         unimplemented!()
     }
 
-    fn leave_role_immediatly() -> u64 {
-        unimplemented!()
-    }
-
-    fn leave_role_later() -> u64 {
+    fn leave_role(_: u32) -> u64 {
         unimplemented!()
     }
 }

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

@@ -218,11 +218,7 @@ impl working_group::WeightInfo for Weights {
         unimplemented!()
     }
 
-    fn leave_role_immediatly() -> u64 {
-        unimplemented!()
-    }
-
-    fn leave_role_later() -> u64 {
+    fn leave_role(_: u32) -> u64 {
         unimplemented!()
     }
 }

+ 1 - 4
runtime-modules/proposals/codex/src/tests/mock.rs

@@ -426,10 +426,7 @@ impl working_group::WeightInfo for WorkingGroupWeightInfo {
     fn add_opening(_: u32) -> Weight {
         0
     }
-    fn leave_role_immediatly() -> Weight {
-        0
-    }
-    fn leave_role_later() -> Weight {
+    fn leave_role(_: u32) -> Weight {
         0
     }
 }

+ 1 - 4
runtime-modules/service-discovery/src/mock.rs

@@ -293,10 +293,7 @@ impl working_group::WeightInfo for WorkingGroupWeightInfo {
     fn add_opening(_: u32) -> Weight {
         0
     }
-    fn leave_role_immediatly() -> Weight {
-        0
-    }
-    fn leave_role_later() -> Weight {
+    fn leave_role(_: u32) -> Weight {
         0
     }
 }

+ 1 - 4
runtime-modules/storage/src/tests/mock.rs

@@ -237,10 +237,7 @@ impl working_group::WeightInfo for WorkingGroupWeightInfo {
     fn add_opening(_: u32) -> Weight {
         0
     }
-    fn leave_role_immediatly() -> Weight {
-        0
-    }
-    fn leave_role_later() -> Weight {
+    fn leave_role(_: u32) -> Weight {
         0
     }
 }

+ 1 - 4
runtime-modules/utility/src/tests/mocks.rs

@@ -414,10 +414,7 @@ impl working_group::WeightInfo for WorkingGroupWeightInfo {
     fn add_opening(_: u32) -> Weight {
         0
     }
-    fn leave_role_immediatly() -> Weight {
-        0
-    }
-    fn leave_role_later() -> Weight {
+    fn leave_role(_: u32) -> Weight {
         0
     }
 }

+ 1 - 1
runtime-modules/working-group/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "pallet-working-group"
-version = "4.0.1"
+version = "4.1.0"
 authors = ['Joystream contributors']
 edition = '2018'
 

+ 3 - 6
runtime-modules/working-group/src/benchmarking.rs

@@ -905,10 +905,7 @@ benchmarks_instance! {
         );
     }
 
-    // Generally speaking this seems to be always the best case scenario
-    // but since it's so obviously a different branch I think it's a good idea
-    // to leave this branch and use tha max between these 2
-    leave_role_later {
+    leave_role {
         let i in 0 .. MAX_BYTES;
         // Workers with stake can't leave immediatly
         let (caller_id, caller_worker_id) = insert_a_worker::<T, I>(
@@ -937,9 +934,9 @@ mod tests {
     use frame_support::assert_ok;
 
     #[test]
-    fn test_leave_role_later() {
+    fn test_leave_role() {
         build_test_externalities().execute_with(|| {
-            assert_ok!(test_benchmark_leave_role_later::<Test>());
+            assert_ok!(test_benchmark_leave_role::<Test>());
         });
     }
 

+ 12 - 4
runtime-modules/working-group/src/lib.rs

@@ -87,8 +87,7 @@ pub trait WeightInfo {
     fn update_reward_account() -> Weight;
     fn set_budget() -> Weight;
     fn add_opening(i: u32) -> Weight;
-    fn leave_role_immediatly() -> Weight;
-    fn leave_role_later() -> Weight;
+    fn leave_role(i: u32) -> Weight;
 }
 
 /// The _Group_ main _Trait_
@@ -601,8 +600,7 @@ decl_module! {
         /// - DB:
         ///    - O(1) doesn't depend on the state or parameters
         /// # </weight>
-        #[weight = WeightInfoWorkingGroup::<T, I>::leave_role_immediatly()
-            .max(WeightInfoWorkingGroup::<T, I>::leave_role_later())]
+        #[weight = Module::<T, I>::leave_role_weight(&rationale)]
         pub fn leave_role(
             origin,
             worker_id: WorkerId<T>,
@@ -1077,6 +1075,16 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
         ))
     }
 
+    // Calculate weight for `leave_role`
+    fn leave_role_weight(rationale: &Option<Vec<u8>>) -> Weight {
+        WeightInfoWorkingGroup::<T, I>::leave_role(
+            rationale
+                .as_ref()
+                .map(|rationale| rationale.len().saturated_into())
+                .unwrap_or_default(),
+        )
+    }
+
     // Calculate weights for terminate_role
     fn terminate_role_weight(penalty: &Option<Vec<u8>>) -> Weight {
         WeightInfoWorkingGroup::<T, I>::terminate_role_lead(

+ 1 - 4
runtime-modules/working-group/src/tests/mock.rs

@@ -264,10 +264,7 @@ impl crate::WeightInfo for () {
     fn add_opening(_: u32) -> Weight {
         0
     }
-    fn leave_role_immediatly() -> Weight {
-        0
-    }
-    fn leave_role_later() -> Weight {
+    fn leave_role(_: u32) -> Weight {
         0
     }
 }

+ 4 - 1
runtime/src/lib.rs

@@ -697,7 +697,10 @@ parameter_types! {
     pub const StorageWorkingGroupRewardPeriod: u32 = 14400 + 20;
     pub const ContentWorkingGroupRewardPeriod: u32 = 14400 + 30;
     pub const MembershipRewardPeriod: u32 = 14400 + 40;
-    pub const MinimumStakeForOpening: u32 = 100;
+    // This should be more costly than `add_opening` fee with the current configuration
+    // the base cost of `add_opening` in tokens is 193. And has a very slight slope
+    // with the lenght with the length of rationale, with 2000 stake we are probably safe.
+    pub const MinimumStakeForOpening: u32 = 2000;
 }
 
 // Staking managers type aliases.

+ 8 - 13
runtime/src/tests/proposals_integration/working_group_proposals.rs

@@ -582,7 +582,7 @@ fn run_create_decrease_group_leader_stake_proposal_execution_succeeds<
         let member_id: MemberId = 14;
 
         let account_id: [u8; 32] = [member_id as u8; 32];
-        let stake_amount: Balance = 100;
+        let stake_amount: Balance = 10_000;
 
         increase_total_balance_issuance_using_account_id(account_id.into(), 1_500_000);
 
@@ -728,7 +728,7 @@ fn run_create_slash_group_leader_stake_proposal_execution_succeeds<
         let member_id: MemberId = 14;
 
         let account_id: [u8; 32] = [member_id as u8; 32];
-        let stake_amount: Balance = 100;
+        let stake_amount: Balance = 10_000;
 
         let stake_policy = working_group::StakePolicy {
             stake_amount,
@@ -1196,7 +1196,7 @@ fn run_create_terminate_group_leader_role_proposal_execution_succeeds<
         let member_id: MemberId = 14;
 
         let account_id: [u8; 32] = [member_id as u8; 32];
-        let stake_amount = 100_u128;
+        let stake_amount = 100_000_u128;
 
         let stake_policy = working_group::StakePolicy {
             stake_amount,
@@ -1334,7 +1334,7 @@ fn run_create_terminate_group_leader_role_proposal_with_slashing_execution_succe
         let member_id: MemberId = 14;
 
         let account_id: [u8; 32] = [member_id as u8; 32];
-        let stake_amount = 100_u128;
+        let stake_amount = 100_000_u128;
 
         let stake_policy = working_group::StakePolicy {
             stake_amount,
@@ -1343,15 +1343,10 @@ fn run_create_terminate_group_leader_role_proposal_with_slashing_execution_succe
 
         increase_total_balance_issuance_using_account_id(account_id.clone().into(), 1_500_000);
 
-        let stake_parameters =
-            StakeParameters {
-                stake: <Runtime as working_group::Trait<
-                    MembershipWorkingGroupInstance,
-                >>::MinimumStakeForOpening::get()
-                .into(),
-                staking_account_id: account_id.into(),
-            }
-        ;
+        let stake_parameters = StakeParameters {
+            stake: stake_amount.into(),
+            staking_account_id: account_id.into(),
+        };
 
         let opening_id = add_opening(member_id, account_id, stake_policy, 1, working_group);
 

+ 35 - 39
runtime/src/weights/working_group.rs

@@ -9,133 +9,129 @@ pub struct WeightInfo;
 impl working_group::WeightInfo for WeightInfo {
     fn on_initialize_leaving(i: u32) -> Weight {
         (0 as Weight)
-            .saturating_add((744_041_000 as Weight).saturating_mul(i as Weight))
+            .saturating_add((496_301_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(4 as Weight))
             .saturating_add(DbWeight::get().reads((3 as Weight).saturating_mul(i as Weight)))
             .saturating_add(DbWeight::get().writes(3 as Weight))
             .saturating_add(DbWeight::get().writes((3 as Weight).saturating_mul(i as Weight)))
     }
     fn on_initialize_rewarding_with_missing_reward(i: u32) -> Weight {
-        (2_692_227_000 as Weight)
-            .saturating_add((490_219_000 as Weight).saturating_mul(i as Weight))
+        (32_208_000 as Weight)
+            .saturating_add((361_542_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight)))
             .saturating_add(DbWeight::get().writes(1 as Weight))
             .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
     }
     fn on_initialize_rewarding_with_missing_reward_cant_pay(i: u32) -> Weight {
-        (106_702_000 as Weight)
-            .saturating_add((382_691_000 as Weight).saturating_mul(i as Weight))
+        (129_133_000 as Weight)
+            .saturating_add((233_951_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
             .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
     }
     fn on_initialize_rewarding_without_missing_reward(i: u32) -> Weight {
-        (946_654_000 as Weight)
-            .saturating_add((326_825_000 as Weight).saturating_mul(i as Weight))
+        (82_724_000 as Weight)
+            .saturating_add((222_551_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight)))
             .saturating_add(DbWeight::get().writes(2 as Weight))
     }
     fn apply_on_opening(i: u32) -> Weight {
-        (583_905_000 as Weight)
-            .saturating_add((2_000 as Weight).saturating_mul(i as Weight))
-            .saturating_add(DbWeight::get().reads(5 as Weight))
+        (532_302_000 as Weight)
+            .saturating_add((144_000 as Weight).saturating_mul(i as Weight))
+            .saturating_add(DbWeight::get().reads(6 as Weight))
             .saturating_add(DbWeight::get().writes(4 as Weight))
     }
     fn fill_opening_lead() -> Weight {
-        (517_943_000 as Weight)
+        (441_600_000 as Weight)
             .saturating_add(DbWeight::get().reads(5 as Weight))
             .saturating_add(DbWeight::get().writes(6 as Weight))
     }
     fn fill_opening_worker(i: u32) -> Weight {
-        (0 as Weight)
-            .saturating_add((337_560_000 as Weight).saturating_mul(i as Weight))
+        (145_112_000 as Weight)
+            .saturating_add((257_669_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(5 as Weight))
             .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
             .saturating_add(DbWeight::get().writes(3 as Weight))
             .saturating_add(DbWeight::get().writes((2 as Weight).saturating_mul(i as Weight)))
     }
     fn update_role_account() -> Weight {
-        (405_699_000 as Weight)
+        (278_339_000 as Weight)
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn cancel_opening() -> Weight {
-        (284_090_000 as Weight)
+        (201_764_000 as Weight)
             .saturating_add(DbWeight::get().reads(3 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn withdraw_application() -> Weight {
-        (412_772_000 as Weight)
+        (291_554_000 as Weight)
             .saturating_add(DbWeight::get().reads(3 as Weight))
             .saturating_add(DbWeight::get().writes(3 as Weight))
     }
     fn slash_stake(i: u32) -> Weight {
-        (827_597_000 as Weight)
-            .saturating_add((4_000 as Weight).saturating_mul(i as Weight))
+        (605_562_000 as Weight)
+            .saturating_add((122_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(5 as Weight))
             .saturating_add(DbWeight::get().writes(2 as Weight))
     }
     fn terminate_role_worker(i: u32) -> Weight {
-        (1_268_966_000 as Weight)
-            .saturating_add((14_000 as Weight).saturating_mul(i as Weight))
+        (961_187_000 as Weight)
+            .saturating_add((249_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(7 as Weight))
             .saturating_add(DbWeight::get().writes(5 as Weight))
     }
     fn terminate_role_lead(i: u32) -> Weight {
-        (1_266_771_000 as Weight)
-            .saturating_add((5_000 as Weight).saturating_mul(i as Weight))
+        (986_954_000 as Weight)
+            .saturating_add((255_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(6 as Weight))
             .saturating_add(DbWeight::get().writes(6 as Weight))
     }
     fn increase_stake() -> Weight {
-        (783_675_000 as Weight)
+        (393_177_000 as Weight)
             .saturating_add(DbWeight::get().reads(3 as Weight))
             .saturating_add(DbWeight::get().writes(2 as Weight))
     }
     fn decrease_stake() -> Weight {
-        (895_623_000 as Weight)
+        (456_618_000 as Weight)
             .saturating_add(DbWeight::get().reads(5 as Weight))
             .saturating_add(DbWeight::get().writes(2 as Weight))
     }
     fn spend_from_budget() -> Weight {
-        (307_455_000 as Weight)
+        (227_722_000 as Weight)
             .saturating_add(DbWeight::get().reads(4 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn update_reward_amount() -> Weight {
-        (420_916_000 as Weight)
+        (309_008_000 as Weight)
             .saturating_add(DbWeight::get().reads(3 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn set_status_text(i: u32) -> Weight {
-        (238_830_000 as Weight)
-            .saturating_add((68_000 as Weight).saturating_mul(i as Weight))
+        (182_500_000 as Weight)
+            .saturating_add((127_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn update_reward_account() -> Weight {
-        (313_123_000 as Weight)
+        (240_377_000 as Weight)
             .saturating_add(DbWeight::get().reads(1 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn set_budget() -> Weight {
-        (81_417_000 as Weight).saturating_add(DbWeight::get().writes(1 as Weight))
+        (66_927_000 as Weight).saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn add_opening(i: u32) -> Weight {
-        (290_743_000 as Weight)
-            .saturating_add((2_000 as Weight).saturating_mul(i as Weight))
+        (233_945_000 as Weight)
+            .saturating_add((127_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(3 as Weight))
             .saturating_add(DbWeight::get().writes(2 as Weight))
     }
-    fn leave_role_immediatly() -> Weight {
-        (544_861_000 as Weight)
-            .saturating_add(DbWeight::get().reads(5 as Weight))
-            .saturating_add(DbWeight::get().writes(4 as Weight))
-    }
-    fn leave_role_later() -> Weight {
-        (341_012_000 as Weight)
+    fn leave_role(i: u32) -> Weight {
+        (221_051_000 as Weight)
+            .saturating_add((28_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }