Skip to content

Fix: Adding min threshold and duration for dao motion #974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions substrate-node/pallets/pallet-burning/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//! Autogenerated weights for pallet_burning
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2024-05-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-06-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `7f09c44a8947`, CPU: `AMD Ryzen 7 5800X 8-Core Processor`
//! HOSTNAME: `4b80713dc969`, CPU: `AMD Ryzen 7 5800X 8-Core Processor`
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024

// Executed Command:
Expand Down Expand Up @@ -45,8 +45,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `109`
// Estimated: `1594`
// Minimum execution time: 27_162_000 picoseconds.
Weight::from_parts(27_532_000, 1594)
// Minimum execution time: 26_841_000 picoseconds.
Weight::from_parts(27_372_000, 1594)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
Expand All @@ -60,8 +60,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `109`
// Estimated: `1594`
// Minimum execution time: 27_162_000 picoseconds.
Weight::from_parts(27_532_000, 1594)
// Minimum execution time: 26_841_000 picoseconds.
Weight::from_parts(27_372_000, 1594)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ Open the Polkadot JS UI in your browser:

The proposal must include the following arguments:

* `threshold`: minimal number of farmer votes required to be able to close proposal before its end.
* `threshold`: minimal number of farmer votes required to be able to close proposal before its end. should be at least 5 or more.
* `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.
* `description`: a small description of what the proposal is about.
* `link`: a link to a more elaborate explanation of the proposal.
* `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).
* `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).

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

Expand Down
43 changes: 29 additions & 14 deletions substrate-node/pallets/pallet-dao/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ benchmarks! {
propose {
let caller: T::AccountId = whitelisted_caller();
assert_ok!(_add_council_member::<T>(caller.clone()));
let threshold = 1;
let threshold = 5;
let proposal: T::Proposal = SystemCall::<T>::remark { remark: b"remark".to_vec() }.into();
let description = b"some_description".to_vec();
let link = b"some_link".to_vec();
Expand All @@ -53,7 +53,7 @@ benchmarks! {
// vote()
vote {
let farmer: T::AccountId = account("Alice", 0, 0);
_prepare_farm_with_node::<T>(farmer.clone());
_prepare_farm_with_node::<T>(farmer.clone(), b"testfarm", 1);
let farm_id = 1;

let caller: T::AccountId = whitelisted_caller();
Expand All @@ -80,7 +80,7 @@ benchmarks! {
// veto()
veto {
let farmer: T::AccountId = account("Alice", 0, 0);
_prepare_farm_with_node::<T>(farmer.clone());
_prepare_farm_with_node::<T>(farmer.clone(), b"testfarm", 1);
let farm_id = 1;

let caller: T::AccountId = whitelisted_caller();
Expand All @@ -98,15 +98,30 @@ benchmarks! {
// close()
close {
let farmer: T::AccountId = account("Alice", 0, 0);
_prepare_farm_with_node::<T>(farmer.clone());
let farm_id = 1;
let farmer2: T::AccountId = account("Bob", 0, 0);
let farmer3: T::AccountId = account("Charlie", 0, 0);
let farmer4: T::AccountId = account("Dave", 0, 0);
let farmer5: T::AccountId = account("Eve", 0, 0);


_prepare_farm_with_node::<T>(farmer.clone(), b"testfarm", 1);
_prepare_farm_with_node::<T>(farmer2.clone(), b"testfarm2", 2);
_prepare_farm_with_node::<T>(farmer3.clone(), b"testfarm3", 3);
_prepare_farm_with_node::<T>(farmer4.clone(), b"testfarm4", 4);
_prepare_farm_with_node::<T>(farmer5.clone(), b"testfarm5", 5);


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

let approve = false;
DaoModule::<T>::vote(RawOrigin::Signed(farmer.clone()).into(), farm_id, proposal_hash, approve).unwrap();
DaoModule::<T>::vote(RawOrigin::Signed(farmer.clone()).into(), 1, proposal_hash, approve).unwrap();
DaoModule::<T>::vote(RawOrigin::Signed(farmer2.clone()).into(), 2, proposal_hash, approve).unwrap();
DaoModule::<T>::vote(RawOrigin::Signed(farmer3.clone()).into(), 3, proposal_hash, approve).unwrap();
DaoModule::<T>::vote(RawOrigin::Signed(farmer4.clone()).into(), 4, proposal_hash, approve).unwrap();
DaoModule::<T>::vote(RawOrigin::Signed(farmer5.clone()).into(), 5, proposal_hash, approve).unwrap();

}: _(RawOrigin::Signed(caller.clone()), proposal_hash, proposal_index)
verify {
assert!(DaoModule::<T>::proposal_list(proposal_hash).is_none());
Expand All @@ -127,10 +142,10 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
assert_eq!(event, &system_event);
}

pub fn _prepare_farm_with_node<T: Config>(source: T::AccountId) {
pub fn _prepare_farm_with_node<T: Config>(source: T::AccountId, farm_name: &[u8], farm_id : u32) {
_create_twin::<T>(source.clone());
_create_farm::<T>(source.clone());
_create_node::<T>(source.clone());
_create_farm::<T>(source.clone(), farm_name);
_create_node::<T>(source.clone(), farm_id);
}

fn _create_twin<T: Config>(source: T::AccountId) {
Expand All @@ -147,7 +162,7 @@ fn _create_twin<T: Config>(source: T::AccountId) {
));
}

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

assert_ok!(TfgridModule::<T>::create_farm(
RawOrigin::Signed(source).into(),
b"testfarm".to_vec().try_into().unwrap(),
farm_name.to_vec().try_into().unwrap(),
pub_ips.clone().try_into().unwrap(),
));
}

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

assert_ok!(TfgridModule::<T>::create_node(
RawOrigin::Signed(source.clone()).into(),
1,
farm_id,
resources,
location,
Vec::new().try_into().unwrap(),
Expand All @@ -196,7 +211,7 @@ fn _create_node<T: Config>(source: T::AccountId) {
pub fn _create_proposal<T: Config>(source: T::AccountId) -> T::Hash {
assert_ok!(_add_council_member::<T>(source.clone()));

let threshold = 1;
let threshold = 5;
let proposal: T::Proposal = SystemCall::<T>::remark {
remark: b"remark".to_vec(),
}
Expand Down
5 changes: 4 additions & 1 deletion substrate-node/pallets/pallet-dao/src/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ impl<T: Config> Pallet<T> {

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

let index = Self::proposal_count();
<ProposalCount<T>>::mutate(|i| *i += 1);
Expand Down
3 changes: 3 additions & 0 deletions substrate-node/pallets/pallet-dao/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub mod pallet {
/// The time-out for council motions.
type MotionDuration: Get<BlockNumberFor<Self>>;

type MotionMinThreshold: Get<u32>;

/// The minimum amount of vetos to dissaprove a proposal
type MinVetos: Get<u32>;

Expand Down Expand Up @@ -173,6 +175,7 @@ pub mod pallet {
OngoingVoteAndTresholdStillNotMet,
FarmHasNoNodes,
InvalidProposalDuration,
ThresholdTooLow,
}

#[pallet::call]
Expand Down
2 changes: 2 additions & 0 deletions substrate-node/pallets/pallet-dao/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub type BlockNumber = u32;
parameter_types! {
pub const DaoMotionDuration: BlockNumber = 4;
pub const MinVetos: u32 = 2;
pub const MinThreshold: u32 = 2;
}

pub(crate) type Serial = pallet_tfgrid::pallet::SerialNumberOf<TestRuntime>;
Expand Down Expand Up @@ -107,6 +108,7 @@ impl pallet_dao::pallet::Config for TestRuntime {
type CouncilOrigin = EnsureRoot<Self::AccountId>;
type Proposal = RuntimeCall;
type MotionDuration = DaoMotionDuration;
type MotionMinThreshold = MinThreshold;
type MinVetos = MinVetos;
type Tfgrid = TfgridModule;
type WeightInfo = weights::SubstrateWeight<TestRuntime>;
Expand Down
Loading