Skip to content
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

Development fix dao proposal veto #865

Merged
merged 3 commits into from
Sep 14, 2023
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
16 changes: 16 additions & 0 deletions docs/architecture/0015-duplicate-veto.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 15. Prevent DAO proposal from duplicate veto

Date: 2023-09-14

## Status

Accepted

## Context

See [here](https://github.com/threefoldtech/tfchain/issues/858) for more details.

## Decision

Since we don't want a council member to veto a DAO proposal alone by being able to submit its veto more than once we need to prevent duplicate veto.
In `pallet-dao`, `veto()` extrinsic should return an appropriate error while this situation occures.
2 changes: 2 additions & 0 deletions substrate-node/pallets/pallet-dao/src/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ impl<T: Config> Pallet<T> {
Error::<T>::WrongIndex
);

ensure!(!voting.vetos.contains(&who), Error::<T>::DuplicateVeto);

voting.vetos.push(who.clone());

Self::deposit_event(Event::CouncilMemberVeto { proposal_hash, who });
Expand Down
1 change: 1 addition & 0 deletions substrate-node/pallets/pallet-dao/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ pub mod pallet {
ProposalMissing,
WrongIndex,
DuplicateVote,
DuplicateVeto,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also update the error list in the go client?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to do this but after I realized it is not needed since there is no pallet-dao call available in go client
correct me if I am wrong

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True! Let's not add it then

WrongProposalWeight,
TooEarly,
TimeLimitReached,
Expand Down
3 changes: 1 addition & 2 deletions substrate-node/pallets/pallet-dao/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use crate::{self as pallet_dao};
use frame_support::{construct_runtime, parameter_types, traits::ConstU32, BoundedVec};
use frame_system::EnsureRoot;
use pallet_collective;
use pallet_tfgrid::node::{CityName, CountryName};
use pallet_tfgrid::{
farm::FarmName,
interface::{InterfaceIp, InterfaceMac, InterfaceName},
node::{Location, SerialNumber},
node::{CityName, CountryName, Location, SerialNumber},
terms_cond::TermsAndConditions,
CityNameInput, CountryNameInput, DocumentHashInput, DocumentLinkInput, Gw4Input, Ip4Input,
LatitudeInput, LongitudeInput, PkInput, RelayInput,
Expand Down
27 changes: 27 additions & 0 deletions substrate-node/pallets/pallet-dao/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,33 @@ fn motion_veto_works() {
});
}

#[test]
fn motion_veto_duplicate_fails() {
new_test_ext().execute_with(|| {
let proposal = RuntimeCall::System(frame_system::Call::remark {
remark: b"some_proposal".to_vec(),
});
let hash = BlakeTwo256::hash_of(&proposal);

assert_ok!(DaoModule::propose(
RuntimeOrigin::signed(1),
2,
Box::new(proposal.clone()),
b"some_description".to_vec(),
b"some_link".to_vec(),
None
));

assert_ok!(DaoModule::veto(RuntimeOrigin::signed(2), hash.clone()));

// try to veto again
assert_noop!(
DaoModule::veto(RuntimeOrigin::signed(2), hash.clone()),
Error::<TestRuntime>::DuplicateVeto
);
});
}

#[test]
fn weighted_voting_works() {
new_test_ext().execute_with(|| {
Expand Down