Skip to content

Commit

Permalink
Align gov with bajun-parachain (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb authored Apr 24, 2024
1 parent 71abeb2 commit f7ba3db
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 163 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ajuna_runtime::{AccountId, AuraId, Signature};
use ajuna_runtime::{AccountId, AuraId, Signature, EXISTENTIAL_DEPOSIT};
use cumulus_primitives_core::ParaId;
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
Expand Down Expand Up @@ -185,7 +185,21 @@ fn testnet_genesis(
},
"collatorSelection": {
"invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::<Vec<_>>(),
"candidacyBond": 0_u64,
"candidacyBond": EXISTENTIAL_DEPOSIT * 16,
},
"council": {
"members": vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
]
},
"technicalCommittee": {
"members": vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
]
},
"session": {
"keys": invulnerables
Expand Down
4 changes: 4 additions & 0 deletions runtime/ajuna/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pallet-aura = { workspace = true }
pallet-authorship = { workspace = true }
pallet-balances = { workspace = true }
pallet-collective = { workspace = true }
pallet-democracy = { workspace = true }
pallet-identity = { workspace = true }
pallet-membership = { workspace = true }
pallet-message-queue = { workspace = true }
Expand Down Expand Up @@ -113,6 +114,7 @@ std = [
"pallet-balances/std",
"pallet-collective/std",
"pallet-collator-selection/std",
"pallet-democracy/std",
"pallet-identity/std",
"pallet-membership/std",
"pallet-message-queue/std",
Expand Down Expand Up @@ -160,6 +162,7 @@ runtime-benchmarks = [
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-membership/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
Expand Down Expand Up @@ -192,6 +195,7 @@ try-runtime = [
"pallet-balances/try-runtime",
"pallet-collator-selection/try-runtime",
"pallet-collective/try-runtime",
"pallet-democracy/try-runtime",
"pallet-identity/try-runtime",
"pallet-membership/try-runtime",
"pallet-message-queue/try-runtime",
Expand Down
169 changes: 169 additions & 0 deletions runtime/ajuna/src/gov.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// Ajuna Node
// Copyright (C) 2022 BlogaTech AG

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.

// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use crate::{
AccountId, Balance, BlockNumber, Council, CouncilMembership, OriginCaller, Runtime,
RuntimeBlockWeights, RuntimeCall, RuntimeEvent, RuntimeOrigin, TechnicalCommittee, AJUN, DAYS,
};
use frame_support::{
parameter_types,
traits::{ConstBool, ConstU32, EitherOfDiverse},
weights::Weight,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
use pallet_collective::{EnsureMember, EnsureProportionAtLeast, EnsureProportionMoreThan};
use sp_runtime::Perbill;

pub type EnsureRootOrMoreThanHalfCouncil = EitherOfDiverse<
EnsureRoot<AccountId>,
EnsureProportionMoreThan<AccountId, CouncilCollectiveInstance, 1, 2>,
>;

pub type EnsureRootOrMoreThanHalfTechnicalCommittee = EitherOfDiverse<
EnsureRoot<AccountId>,
EnsureProportionAtLeast<AccountId, TechnicalCommitteeInstance, 1, 2>,
>;

pub type EnsureRootOrAllTechnicalCommittee = EitherOfDiverse<
EnsureRoot<AccountId>,
EnsureProportionAtLeast<AccountId, TechnicalCommitteeInstance, 1, 1>,
>;

/// Council collective instance declaration.
///
/// The council primarily serves to optimize and balance the inclusive referendum system
/// by being allowed to propose external democracy proposals, which can be fast tracked and
/// bypass the one active referendum at a time rule.
///
/// It also controls the treasury.
type CouncilCollectiveInstance = pallet_collective::Instance2;

parameter_types! {
pub CouncilMotionDuration: BlockNumber = 3 * DAYS;
pub MaxProposalWeight: Weight = Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block;
pub CouncilMaxMembers: u32 = 100;
}

impl pallet_collective::Config<CouncilCollectiveInstance> for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type Proposal = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type MotionDuration = CouncilMotionDuration;
type MaxProposals = ConstU32<100>;
type MaxMembers = CouncilMaxMembers;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRootOrMoreThanHalfCouncil;
type MaxProposalWeight = MaxProposalWeight;
}

/// Helper pallet to manage Council members.
type CouncilMembershipInstance = pallet_membership::Instance2;
impl pallet_membership::Config<CouncilMembershipInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type AddOrigin = EnsureRootOrMoreThanHalfCouncil;
type RemoveOrigin = EnsureRootOrMoreThanHalfCouncil;
type SwapOrigin = EnsureRootOrMoreThanHalfCouncil;
type ResetOrigin = EnsureRootOrMoreThanHalfCouncil;
type PrimeOrigin = EnsureRootOrMoreThanHalfCouncil;
type MembershipInitialized = Council;
type MembershipChanged = Council;
type MaxMembers = CouncilMaxMembers;
type WeightInfo = pallet_membership::weights::SubstrateWeight<Runtime>;
}

/// The technical committee primarily serves to safeguard against malicious referenda
/// and fast track critical referenda.
pub type TechnicalCommitteeInstance = pallet_collective::Instance1;

parameter_types! {
pub const TechnicalMotionDuration: BlockNumber = 3 * DAYS;
pub const TechnicalCommitteeMaxMembers: u32 = 100;
}

impl pallet_collective::Config<TechnicalCommitteeInstance> for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type Proposal = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type MotionDuration = TechnicalMotionDuration;
type MaxProposals = ConstU32<100>;
type MaxMembers = TechnicalCommitteeMaxMembers;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRootOrMoreThanHalfCouncil;
type MaxProposalWeight = MaxProposalWeight;
}

/// Helper pallet to manage TechnicalCommittee members.
type TechnicalCommitteeMembershipInstance = pallet_membership::Instance1;
impl pallet_membership::Config<TechnicalCommitteeMembershipInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type AddOrigin = EnsureRootOrMoreThanHalfCouncil;
type RemoveOrigin = EnsureRootOrMoreThanHalfCouncil;
type SwapOrigin = EnsureRootOrMoreThanHalfCouncil;
type ResetOrigin = EnsureRootOrMoreThanHalfCouncil;
type PrimeOrigin = EnsureRootOrMoreThanHalfCouncil;
type MembershipInitialized = TechnicalCommittee;
type MembershipChanged = TechnicalCommittee;
type MaxMembers = TechnicalCommitteeMaxMembers;
type WeightInfo = pallet_membership::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const ThreeDays: BlockNumber = 3 * DAYS;
pub const TwentyEightDays: BlockNumber = 28 * DAYS;
pub const ThirtyDays: BlockNumber = 30 * DAYS;
pub EnactmentPeriod: BlockNumber = 7 * DAYS;
pub const MinimumDeposit: Balance = AJUN;
}

impl pallet_democracy::Config for Runtime {
type WeightInfo = pallet_democracy::weights::SubstrateWeight<Runtime>;
type RuntimeEvent = RuntimeEvent;
type Scheduler = pallet_scheduler::Pallet<Runtime>;
type Preimages = pallet_preimage::Pallet<Runtime>;
type Currency = pallet_balances::Pallet<Runtime>;
type EnactmentPeriod = EnactmentPeriod;
type LaunchPeriod = TwentyEightDays;
type VotingPeriod = TwentyEightDays;
type VoteLockingPeriod = EnactmentPeriod;
type MinimumDeposit = MinimumDeposit;
type InstantAllowed = ConstBool<true>;
type FastTrackVotingPeriod = ThreeDays;
type CooloffPeriod = TwentyEightDays;
type MaxVotes = ConstU32<100>;
type MaxProposals = ConstU32<100>;
type MaxDeposits = ConstU32<100>;
type MaxBlacklisted = ConstU32<100>;
type ExternalOrigin = EnsureRootOrMoreThanHalfCouncil;
type ExternalMajorityOrigin = EnsureRootOrMoreThanHalfCouncil;
type ExternalDefaultOrigin = EnsureRootOrMoreThanHalfCouncil;
// Initially, we want that only the council can submit proposals to
// prevent malicious proposals.
type SubmitOrigin = EnsureSignedBy<CouncilMembership, AccountId>;
type FastTrackOrigin = EnsureRootOrMoreThanHalfTechnicalCommittee;
type InstantOrigin = EnsureRootOrMoreThanHalfTechnicalCommittee;
// To cancel a proposal that has passed.
type CancellationOrigin = EnsureRoot<AccountId>;
type BlacklistOrigin = EnsureRootOrMoreThanHalfCouncil;
// To cancel a proposal before it has passed, and slash its backers.
type CancelProposalOrigin = EnsureRootOrAllTechnicalCommittee;
// Any single technical committee member may veto a coming council proposal, however they can
// only do it once and it lasts only for the cooloff period.
type VetoOrigin = EnsureMember<AccountId, TechnicalCommitteeInstance>;
type PalletsOrigin = OriginCaller;
type Slash = pallet_treasury::Pallet<Runtime>;
}
Loading

0 comments on commit f7ba3db

Please sign in to comment.