Skip to content

Commit 8a36c1d

Browse files
Fix: Adding min threshold and duration for dao motion (#974)
* fix:adding min threshold and duration for dao motion * fix: adjusting dao benchmarks for new threshold validation * test: use MinThreshold defined in place of hardcoded value * refactor: tiny refactor * fix: adjust threshold in benchmarking tests * chore: update benchmark `weights.rs` file for all pallets --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 9f93646 commit 8a36c1d

File tree

16 files changed

+450
-396
lines changed

16 files changed

+450
-396
lines changed

substrate-node/pallets/pallet-burning/src/weights.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
//! Autogenerated weights for pallet_burning
33
//!
44
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
5-
//! DATE: 2024-05-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
5+
//! DATE: 2024-06-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
66
//! WORST CASE MAP SIZE: `1000000`
7-
//! HOSTNAME: `7f09c44a8947`, CPU: `AMD Ryzen 7 5800X 8-Core Processor`
7+
//! HOSTNAME: `4b80713dc969`, CPU: `AMD Ryzen 7 5800X 8-Core Processor`
88
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
99
1010
// Executed Command:
@@ -45,8 +45,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
4545
// Proof Size summary in bytes:
4646
// Measured: `109`
4747
// Estimated: `1594`
48-
// Minimum execution time: 27_162_000 picoseconds.
49-
Weight::from_parts(27_532_000, 1594)
48+
// Minimum execution time: 26_841_000 picoseconds.
49+
Weight::from_parts(27_372_000, 1594)
5050
.saturating_add(T::DbWeight::get().reads(1_u64))
5151
.saturating_add(T::DbWeight::get().writes(1_u64))
5252
}
@@ -60,8 +60,8 @@ impl WeightInfo for () {
6060
// Proof Size summary in bytes:
6161
// Measured: `109`
6262
// Estimated: `1594`
63-
// Minimum execution time: 27_162_000 picoseconds.
64-
Weight::from_parts(27_532_000, 1594)
63+
// Minimum execution time: 26_841_000 picoseconds.
64+
Weight::from_parts(27_372_000, 1594)
6565
.saturating_add(RocksDbWeight::get().reads(1_u64))
6666
.saturating_add(RocksDbWeight::get().writes(1_u64))
6767
}

substrate-node/pallets/pallet-dao/creating_proposal_farmers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ Open the Polkadot JS UI in your browser:
2121

2222
The proposal must include the following arguments:
2323

24-
* `threshold`: minimal number of farmer votes required to be able to close proposal before its end.
24+
* `threshold`: minimal number of farmer votes required to be able to close proposal before its end. should be at least 5 or more.
2525
* `action`: call/extrinsic to execute on chain. If there is no call to be executed (which is usually the case) then `system` -> `remark()` should be set.
2626
* `description`: a small description of what the proposal is about.
2727
* `link`: a link to a more elaborate explanation of the proposal.
28-
* `duration`: optional duration of the proposal after beeing created (default is 7 days, max value is 30 days), expressed in number of blocks (1 block = 6 sec).
28+
* `duration`: optional duration of the proposal after beeing created (default is 7 days, min value is 1 day, max value is 30 days), expressed in number of blocks (1 block = 6 sec).
2929

3030
![fill](./img/fill_proposal_farmers.png)
3131

substrate-node/pallets/pallet-dao/src/benchmarking.rs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ benchmarks! {
2626
propose {
2727
let caller: T::AccountId = whitelisted_caller();
2828
assert_ok!(_add_council_member::<T>(caller.clone()));
29-
let threshold = 1;
29+
let threshold = 5;
3030
let proposal: T::Proposal = SystemCall::<T>::remark { remark: b"remark".to_vec() }.into();
3131
let description = b"some_description".to_vec();
3232
let link = b"some_link".to_vec();
@@ -53,7 +53,7 @@ benchmarks! {
5353
// vote()
5454
vote {
5555
let farmer: T::AccountId = account("Alice", 0, 0);
56-
_prepare_farm_with_node::<T>(farmer.clone());
56+
_prepare_farm_with_node::<T>(farmer.clone(), b"testfarm", 1);
5757
let farm_id = 1;
5858

5959
let caller: T::AccountId = whitelisted_caller();
@@ -80,7 +80,7 @@ benchmarks! {
8080
// veto()
8181
veto {
8282
let farmer: T::AccountId = account("Alice", 0, 0);
83-
_prepare_farm_with_node::<T>(farmer.clone());
83+
_prepare_farm_with_node::<T>(farmer.clone(), b"testfarm", 1);
8484
let farm_id = 1;
8585

8686
let caller: T::AccountId = whitelisted_caller();
@@ -98,15 +98,30 @@ benchmarks! {
9898
// close()
9999
close {
100100
let farmer: T::AccountId = account("Alice", 0, 0);
101-
_prepare_farm_with_node::<T>(farmer.clone());
102-
let farm_id = 1;
101+
let farmer2: T::AccountId = account("Bob", 0, 0);
102+
let farmer3: T::AccountId = account("Charlie", 0, 0);
103+
let farmer4: T::AccountId = account("Dave", 0, 0);
104+
let farmer5: T::AccountId = account("Eve", 0, 0);
105+
106+
107+
_prepare_farm_with_node::<T>(farmer.clone(), b"testfarm", 1);
108+
_prepare_farm_with_node::<T>(farmer2.clone(), b"testfarm2", 2);
109+
_prepare_farm_with_node::<T>(farmer3.clone(), b"testfarm3", 3);
110+
_prepare_farm_with_node::<T>(farmer4.clone(), b"testfarm4", 4);
111+
_prepare_farm_with_node::<T>(farmer5.clone(), b"testfarm5", 5);
112+
103113

104114
let caller: T::AccountId = whitelisted_caller();
105115
let proposal_hash = _create_proposal::<T>(caller.clone());
106116
let proposal_index = 0;
107117

108118
let approve = false;
109-
DaoModule::<T>::vote(RawOrigin::Signed(farmer.clone()).into(), farm_id, proposal_hash, approve).unwrap();
119+
DaoModule::<T>::vote(RawOrigin::Signed(farmer.clone()).into(), 1, proposal_hash, approve).unwrap();
120+
DaoModule::<T>::vote(RawOrigin::Signed(farmer2.clone()).into(), 2, proposal_hash, approve).unwrap();
121+
DaoModule::<T>::vote(RawOrigin::Signed(farmer3.clone()).into(), 3, proposal_hash, approve).unwrap();
122+
DaoModule::<T>::vote(RawOrigin::Signed(farmer4.clone()).into(), 4, proposal_hash, approve).unwrap();
123+
DaoModule::<T>::vote(RawOrigin::Signed(farmer5.clone()).into(), 5, proposal_hash, approve).unwrap();
124+
110125
}: _(RawOrigin::Signed(caller.clone()), proposal_hash, proposal_index)
111126
verify {
112127
assert!(DaoModule::<T>::proposal_list(proposal_hash).is_none());
@@ -127,10 +142,10 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
127142
assert_eq!(event, &system_event);
128143
}
129144

130-
pub fn _prepare_farm_with_node<T: Config>(source: T::AccountId) {
145+
pub fn _prepare_farm_with_node<T: Config>(source: T::AccountId, farm_name: &[u8], farm_id : u32) {
131146
_create_twin::<T>(source.clone());
132-
_create_farm::<T>(source.clone());
133-
_create_node::<T>(source.clone());
147+
_create_farm::<T>(source.clone(), farm_name);
148+
_create_node::<T>(source.clone(), farm_id);
134149
}
135150

136151
fn _create_twin<T: Config>(source: T::AccountId) {
@@ -147,7 +162,7 @@ fn _create_twin<T: Config>(source: T::AccountId) {
147162
));
148163
}
149164

150-
fn _create_farm<T: Config>(source: T::AccountId) {
165+
fn _create_farm<T: Config>(source: T::AccountId, farm_name: &[u8]) {
151166
let mut pub_ips = Vec::new();
152167
pub_ips.push(IP4 {
153168
ip: get_public_ip_ip_input(b"185.206.122.33/24"),
@@ -160,12 +175,12 @@ fn _create_farm<T: Config>(source: T::AccountId) {
160175

161176
assert_ok!(TfgridModule::<T>::create_farm(
162177
RawOrigin::Signed(source).into(),
163-
b"testfarm".to_vec().try_into().unwrap(),
178+
farm_name.to_vec().try_into().unwrap(),
164179
pub_ips.clone().try_into().unwrap(),
165180
));
166181
}
167182

168-
fn _create_node<T: Config>(source: T::AccountId) {
183+
fn _create_node<T: Config>(source: T::AccountId, farm_id: u32) {
169184
let resources = ResourcesInput {
170185
hru: 1024 * GIGABYTE,
171186
sru: 512 * GIGABYTE,
@@ -183,7 +198,7 @@ fn _create_node<T: Config>(source: T::AccountId) {
183198

184199
assert_ok!(TfgridModule::<T>::create_node(
185200
RawOrigin::Signed(source.clone()).into(),
186-
1,
201+
farm_id,
187202
resources,
188203
location,
189204
Vec::new().try_into().unwrap(),
@@ -196,7 +211,7 @@ fn _create_node<T: Config>(source: T::AccountId) {
196211
pub fn _create_proposal<T: Config>(source: T::AccountId) -> T::Hash {
197212
assert_ok!(_add_council_member::<T>(source.clone()));
198213

199-
let threshold = 1;
214+
let threshold = 5;
200215
let proposal: T::Proposal = SystemCall::<T>::remark {
201216
remark: b"remark".to_vec(),
202217
}

substrate-node/pallets/pallet-dao/src/dao.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ impl<T: Config> Pallet<T> {
4242

4343
let now = frame_system::Pallet::<T>::block_number();
4444
let mut end = now + T::MotionDuration::get();
45+
// Check if duration is set and is less than 30 days and more than 1 Day
4546
if let Some(motion_duration) = duration {
4647
ensure!(
47-
motion_duration < BlockNumberFor::<T>::from(constants::time::DAYS * 30),
48+
motion_duration <= BlockNumberFor::<T>::from(constants::time::DAYS * 30) && motion_duration >= BlockNumberFor::<T>::from(constants::time::DAYS * 1),
4849
Error::<T>::InvalidProposalDuration
4950
);
5051
end = now + motion_duration;
5152
}
53+
// threshold should be at least the configured minimum threshold for a motion in runtime
54+
ensure!(threshold >= T::MotionMinThreshold::get(), Error::<T>::ThresholdTooLow);
5255

5356
let index = Self::proposal_count();
5457
<ProposalCount<T>>::mutate(|i| *i += 1);

substrate-node/pallets/pallet-dao/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub mod pallet {
5656
/// The time-out for council motions.
5757
type MotionDuration: Get<BlockNumberFor<Self>>;
5858

59+
type MotionMinThreshold: Get<u32>;
60+
5961
/// The minimum amount of vetos to dissaprove a proposal
6062
type MinVetos: Get<u32>;
6163

@@ -173,6 +175,7 @@ pub mod pallet {
173175
OngoingVoteAndTresholdStillNotMet,
174176
FarmHasNoNodes,
175177
InvalidProposalDuration,
178+
ThresholdTooLow,
176179
}
177180

178181
#[pallet::call]

substrate-node/pallets/pallet-dao/src/mock.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub type BlockNumber = u32;
6969
parameter_types! {
7070
pub const DaoMotionDuration: BlockNumber = 4;
7171
pub const MinVetos: u32 = 2;
72+
pub const MinThreshold: u32 = 2;
7273
}
7374

7475
pub(crate) type Serial = pallet_tfgrid::pallet::SerialNumberOf<TestRuntime>;
@@ -107,6 +108,7 @@ impl pallet_dao::pallet::Config for TestRuntime {
107108
type CouncilOrigin = EnsureRoot<Self::AccountId>;
108109
type Proposal = RuntimeCall;
109110
type MotionDuration = DaoMotionDuration;
111+
type MotionMinThreshold = MinThreshold;
110112
type MinVetos = MinVetos;
111113
type Tfgrid = TfgridModule;
112114
type WeightInfo = weights::SubstrateWeight<TestRuntime>;

0 commit comments

Comments
 (0)