-
Notifications
You must be signed in to change notification settings - Fork 10
feat(mainnet): add gov: collective, membership, motion #448
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
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
45ae67b
feat(pallets): add pallet-motion
peterwht 8d0d7ad
build(mainnet): add gov pallets: collective, membership, motion
peterwht e777676
feat(mainnet): add gov configs: collective, membership, motion
peterwht 33e16e9
feat(node): add councillors at genesis
peterwht f8606e3
TEMPORARY COMMIT: Sets mainnet chain-spec to Development
peterwht 5a8a374
refactor(governance): apply feedback configuration changes
al3mart b5d76fa
test(governance): add council, membership & motion tests
al3mart c283432
refactor(governance): change mainnet ChainType to Live
al3mart 8049245
Update runtime/mainnet/src/config/governance.rs
al3mart 6196d22
refactor(governance): SuperMajorityOrigin is at least 3/4
al3mart 1325b57
docs(governance): update comments.
al3mart 6d87835
fix(governance): remove duplicated code
al3mart 7207135
style(mainnet): simplify syntax in Runtime struct
al3mart 31a9f52
style(mainnet): order dependencies
al3mart 508e3aa
fix(governance): amend motion origin tests
al3mart f9a573b
refactor(motion): feature gate simple majority
al3mart 1d1304b
docs(motion): include Config docs
al3mart 85242e8
docs(motion): credit source
al3mart 3c02141
add simple-majority feature to mainnet runtime & node
al3mart 99a4f24
refactor(motion): remove sp-std
al3mart c0cc278
fix(ci): temporary disabling zepter format feautures
al3mart 91cca9f
refactor(motion): revert simple-majority feature
al3mart f8e92a1
refactor(ci): reenable zepter
al3mart 5cdced0
refactor(governance): use MoreThanMajorityThenPrimeDefaultVote as Def…
al3mart aebe152
test(governance): runtime upgrade doesn't saturare weight limit
al3mart 880fb24
fix(motion): remve sp-std dependendency
al3mart 5d1d49e
style(governance): use change variable name
al3mart d86f49f
test(governance): remove irrelevant tests
al3mart 3c57991
docs(motion): add documentation to public elements
al3mart 01efc94
chore(governance): apply feedback
al3mart 604bb64
refactor(governance): AllMembersButOne as RemoveOrigin
al3mart 0e07b3c
chore(motion): update pallet author
al3mart 5319e04
docs(motion): sort documentation
al3mart d245359
chore(motion): fmt
al3mart 8790017
Update runtime/mainnet/src/config/governance.rs
al3mart a76aa2e
revert 604bb64
al3mart fd99104
chore(gov): remove CouncilMembership from the runtime
al3mart 15711ea
chore(motion): remove extra weight from docs
al3mart 8ba715f
chore(deps): remove pallet-membership from manifests"
peterwht File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| [package] | ||
| authors = [ "Parity Technologies <[email protected]>", "R0GUE <[email protected]>" ] | ||
| description = "FRAME pallet to wrap council calls providing root origin to the council." | ||
| edition = { workspace = true } | ||
| homepage = { workspace = true } | ||
| license = { workspace = true } | ||
| name = "pallet-motion" | ||
| publish = false | ||
| repository = { workspace = true } | ||
| version = "4.0.0-dev" | ||
|
|
||
| [package.metadata.docs.rs] | ||
| targets = [ "x86_64-unknown-linux-gnu" ] | ||
|
|
||
| [dependencies] | ||
| codec = { workspace = true, default-features = false, features = [ | ||
| "derive", | ||
| ] } | ||
| frame-benchmarking = { workspace = true, default-features = false, optional = true } | ||
| frame-support = { workspace = true } | ||
| frame-system = { workspace = true } | ||
| log = { workspace = true, default-features = false } | ||
| pallet-collective = { workspace = true, default-features = false } | ||
| scale-info = { workspace = true, default-features = false, features = [ | ||
| "derive", | ||
| ] } | ||
| sp-runtime = { workspace = true, default-features = false } | ||
|
|
||
| [dev-dependencies] | ||
| pallet-balances = { workspace = true, default-features = false } | ||
| sp-core = { workspace = true, default-features = false } | ||
| sp-io = { workspace = true, default-features = false } | ||
|
|
||
| [features] | ||
| default = [ "std" ] | ||
| runtime-benchmarks = [ | ||
| "frame-benchmarking/runtime-benchmarks", | ||
| "pallet-collective/runtime-benchmarks", | ||
| ] | ||
| std = [ | ||
| "codec/std", | ||
| "frame-benchmarking?/std", | ||
| "frame-support/std", | ||
| "frame-system/std", | ||
| "log/std", | ||
| "pallet-balances/std", | ||
| "pallet-collective/std", | ||
| "scale-info/std", | ||
| "sp-runtime/std", | ||
| ] | ||
| try-runtime = [ "frame-support/try-runtime" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Motion Pallet | ||
al3mart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| `pallet-motion` enables councils (`pallet-collective`) to make root-origin calls by providing three configurable origins: | ||
| - `SimpleMajority` (1/2) | ||
| - `SuperMajority` (2/3) | ||
| - `Unanimous` (1/1) | ||
|
|
||
| It is composed of three associated extrinsics, one for each origin: | ||
| - `simple_majority` | ||
| - Dispatches the call if and only if the number of votes is greater than `SimpleMajority`. | ||
| - `super_majority` | ||
| - Dispatches the call if and only if the number of votes is greater than or equal to `SuperMajority`. | ||
| - `unanimous` | ||
| - Dispatches the call if and only if all collective members have voted yes. | ||
|
|
||
|
|
||
| ## Configuration | ||
|
|
||
| You can configure `pallet-motion` in combination with `pallet-collective` the following way: | ||
|
|
||
| ```rust | ||
| type CouncilCollective = pallet_collective::Instance1; | ||
| impl pallet_motion::Config for Runtime { | ||
| // --- | ||
| type SimpleMajorityOrigin = | ||
| pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>; | ||
| type SuperMajorityOrigin = | ||
| pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 2, 3>; | ||
| type UnanimousOrigin = | ||
| pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 1>; | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### Credit: | ||
|
|
||
| Original source at: https://github.com/Watr-Protocol/watr/tree/main/pallets/motion | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| //! Benchmarking setup for pallet-motion | ||
|
|
||
| use frame_benchmarking::v2::*; | ||
| use frame_support::traits::EnsureOrigin; | ||
|
|
||
| use super::*; | ||
| #[allow(unused)] | ||
| use crate::Pallet as Motion; | ||
|
|
||
| fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) { | ||
| frame_system::Pallet::<T>::assert_last_event(generic_event.into()); | ||
| } | ||
|
|
||
| #[benchmarks( | ||
| where | ||
| <T as Config>::RuntimeCall: From<frame_system::Call<T>>, | ||
| )] | ||
| mod benchmarks { | ||
| use super::*; | ||
|
|
||
| #[benchmark] | ||
| fn simple_majority() { | ||
| let call: <T as Config>::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into(); | ||
| let origin = <T as Config>::SimpleMajorityOrigin::try_successful_origin().unwrap(); | ||
|
|
||
| #[extrinsic_call] | ||
al3mart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _(origin as T::RuntimeOrigin, Box::new(call)); | ||
|
|
||
| assert_last_event::<T>(Event::DispatchSimpleMajority { motion_result: Ok(()) }.into()) | ||
| } | ||
|
|
||
| #[benchmark] | ||
| fn super_majority() { | ||
| let call: <T as Config>::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into(); | ||
| let origin = <T as Config>::SuperMajorityOrigin::try_successful_origin().unwrap(); | ||
|
|
||
| #[extrinsic_call] | ||
al3mart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _(origin as T::RuntimeOrigin, Box::new(call)); | ||
|
|
||
| assert_last_event::<T>(Event::DispatchSuperMajority { motion_result: Ok(()) }.into()) | ||
| } | ||
|
|
||
| #[benchmark] | ||
| fn unanimous() { | ||
| let call: <T as Config>::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into(); | ||
| let origin = <T as Config>::UnanimousOrigin::try_successful_origin().unwrap(); | ||
|
|
||
| #[extrinsic_call] | ||
al3mart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _(origin as T::RuntimeOrigin, Box::new(call)); | ||
|
|
||
| assert_last_event::<T>(Event::DispatchUnanimous { motion_result: Ok(()) }.into()) | ||
| } | ||
|
|
||
| impl_benchmark_test_suite!(Motion, crate::mock::new_test_ext(), crate::mock::Test); | ||
al3mart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
|
|
||
| #[cfg(test)] | ||
| mod mock; | ||
| #[cfg(test)] | ||
| mod tests; | ||
|
|
||
| /// Dispatchable function benchmarks. | ||
evilrobot-01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #[cfg(feature = "runtime-benchmarks")] | ||
| mod benchmarking; | ||
|
|
||
| /// Dispatchable function weights. | ||
| pub mod weights; | ||
| pub use pallet::*; | ||
| use sp_runtime::DispatchResult; | ||
| pub use weights::WeightInfo; | ||
|
|
||
| extern crate alloc; | ||
| use alloc::{boxed::Box, vec}; | ||
|
|
||
| /// The motion pallet. | ||
| #[frame_support::pallet] | ||
| pub mod pallet { | ||
| use frame_support::{ | ||
| dispatch::GetDispatchInfo, pallet_prelude::*, traits::UnfilteredDispatchable, | ||
| }; | ||
| use frame_system::pallet_prelude::*; | ||
|
|
||
| use super::{DispatchResult, *}; | ||
|
|
||
| #[pallet::pallet] | ||
| pub struct Pallet<T>(_); | ||
|
|
||
| /// Configure the pallet by specifying the parameters and types on which it depends. | ||
| #[pallet::config] | ||
| pub trait Config: frame_system::Config { | ||
al3mart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// The runtime call type. | ||
| type RuntimeCall: Parameter | ||
| + UnfilteredDispatchable<RuntimeOrigin = Self::RuntimeOrigin> | ||
| + GetDispatchInfo; | ||
| /// The runtime event type. | ||
| type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
| /// Origin that can act as `Root` origin if a collective has achieved a simple majority | ||
| /// consensus. | ||
| type SimpleMajorityOrigin: EnsureOrigin<Self::RuntimeOrigin>; | ||
| /// Origin that can act as `Root` origin if a collective has achieved a super majority | ||
| /// consensus. | ||
| type SuperMajorityOrigin: EnsureOrigin<Self::RuntimeOrigin>; | ||
| /// Origin that can act as `Root` origin if a collective has achieved a unanimous consensus. | ||
| type UnanimousOrigin: EnsureOrigin<Self::RuntimeOrigin>; | ||
| /// Type representing the weight of this pallet | ||
| type WeightInfo: WeightInfo; | ||
| } | ||
|
|
||
| /// The events that can be emitted. | ||
| #[pallet::event] | ||
| #[pallet::generate_deposit(pub(super) fn deposit_event)] | ||
| pub enum Event<T: Config> { | ||
| /// A [SimpleMajorityOrigin] motion was executed. [motion_result] contains the call result | ||
| DispatchSimpleMajority { | ||
| /// Result of dispatching the proposed call. | ||
| motion_result: DispatchResult, | ||
| }, | ||
| /// A [SuperMajorityOrigin] motion was executed. [motion_result] contains the call result | ||
| DispatchSuperMajority { | ||
| /// Result of dispatching the proposed call. | ||
| motion_result: DispatchResult, | ||
| }, | ||
| /// A [UnanimousOrigin] motion was executed. [motion_result] contains the call result | ||
| DispatchUnanimous { | ||
| /// Result of dispatching the proposed call. | ||
| motion_result: DispatchResult, | ||
| }, | ||
| } | ||
|
|
||
| /// Errors inform users that something went wrong. | ||
| #[pallet::error] | ||
| pub enum Error<T> {} | ||
|
|
||
| /// The dispatchable functions available. | ||
| #[pallet::call] | ||
| impl<T: Config> Pallet<T> { | ||
| /// Ensures the simple majority is met and dispatches a call with `Root` origin. | ||
| /// | ||
| /// # <weight> | ||
| /// - O(1). | ||
| /// - Limited storage reads. | ||
| /// - One DB write (event). | ||
| /// - Weight of derivative `call` execution. | ||
| /// # </weight> | ||
| #[pallet::weight({ | ||
| let dispatch_info = call.get_dispatch_info(); | ||
| (T::WeightInfo::simple_majority().saturating_add(dispatch_info.call_weight), dispatch_info.class) | ||
| })] | ||
| #[pallet::call_index(1)] | ||
| pub fn simple_majority( | ||
| origin: OriginFor<T>, | ||
| call: Box<<T as Config>::RuntimeCall>, | ||
peterwht marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) -> DispatchResultWithPostInfo { | ||
| T::SimpleMajorityOrigin::ensure_origin(origin)?; | ||
|
|
||
| let motion_result = Self::do_dispatch(*call); | ||
| Self::deposit_event(Event::DispatchSimpleMajority { motion_result }); | ||
|
|
||
| Ok(Pays::No.into()) | ||
| } | ||
|
|
||
| /// Ensures the super majority is met and dispatches a call with `Root` origin. | ||
| /// | ||
| /// # <weight> | ||
| /// - O(1). | ||
| /// - Limited storage reads. | ||
| /// - One DB write (event). | ||
| /// - Weight of derivative `call` execution. | ||
| /// # </weight> | ||
| #[pallet::weight({ | ||
| let dispatch_info = call.get_dispatch_info(); | ||
| (T::WeightInfo::super_majority().saturating_add(dispatch_info.call_weight), dispatch_info.class) | ||
| })] | ||
| #[pallet::call_index(2)] | ||
| pub fn super_majority( | ||
| origin: OriginFor<T>, | ||
| call: Box<<T as Config>::RuntimeCall>, | ||
| ) -> DispatchResultWithPostInfo { | ||
| T::SuperMajorityOrigin::ensure_origin(origin)?; | ||
|
|
||
| let motion_result = Self::do_dispatch(*call); | ||
| Self::deposit_event(Event::DispatchSuperMajority { motion_result }); | ||
|
|
||
| Ok(Pays::No.into()) | ||
| } | ||
|
|
||
| /// Ensures unanimous voting is met and dispatches a call with `Root` origin. | ||
| /// | ||
| /// # <weight> | ||
| /// - O(1). | ||
| /// - Limited storage reads. | ||
| /// - One DB write (event). | ||
| /// - Weight of derivative `call` execution. | ||
| /// # </weight> | ||
| #[pallet::weight({ | ||
| let dispatch_info = call.get_dispatch_info(); | ||
| (T::WeightInfo::unanimous().saturating_add(dispatch_info.call_weight), dispatch_info.class) | ||
| })] | ||
| #[pallet::call_index(3)] | ||
| pub fn unanimous( | ||
| origin: OriginFor<T>, | ||
| call: Box<<T as Config>::RuntimeCall>, | ||
| ) -> DispatchResultWithPostInfo { | ||
| T::UnanimousOrigin::ensure_origin(origin)?; | ||
|
|
||
| let motion_result = Self::do_dispatch(*call); | ||
| Self::deposit_event(Event::DispatchUnanimous { motion_result }); | ||
|
|
||
| Ok(Pays::No.into()) | ||
| } | ||
| } | ||
|
|
||
| impl<T: Config> Pallet<T> { | ||
| /// Helper to actually dispatch RuntimeCall. | ||
| /// | ||
| /// Should only be called after the origin is ensured. | ||
| /// | ||
| /// Returns the `DispatchResult` from the dispatched call. | ||
| fn do_dispatch(call: <T as Config>::RuntimeCall) -> DispatchResult { | ||
| let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into()); | ||
| res.map(|_| ()).map_err(|e| e.error) | ||
| } | ||
| } | ||
| } | ||
|
Check warning on line 170 in pallets/motion/src/lib.rs
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.