git.delta.rocks / unique-network / refs/commits / 2e29cffb053e

difftreelog

Pallet Democracy

str-mv2020-12-04parent: #82ca9c1.patch.diff
in: master

3 files changed

modifiednode/src/chain_spec.rsdiffbeforeafterboth
--- a/node/src/chain_spec.rs
+++ b/node/src/chain_spec.rs
@@ -147,12 +147,24 @@
         pallet_aura: Some(AuraConfig {
             authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
         }),
-        pallet_grandpa: Some(GrandpaConfig {
+		pallet_collective_Instance1: Some(CouncilConfig {
+			members: vec![],
+			phantom: Default::default(),
+		}),
+		pallet_collective_Instance2: Some(TechnicalCommitteeConfig {
+			members: vec![],
+			phantom: Default::default(),
+		}),
+		pallet_democracy: Some(DemocracyConfig::default()),
+		pallet_grandpa: Some(GrandpaConfig {
             authorities: initial_authorities
                 .iter()
                 .map(|x| (x.1.clone(), 1))
                 .collect(),
-        }),
+		}),
+		pallet_elections_phragmen: Some(Default::default()),
+		pallet_membership: Some(Default::default()),
+		pallet_treasury: Some(Default::default()),
         pallet_sudo: Some(SudoConfig { key: root_key }),
         pallet_nft: Some(NftConfig {
             collection: vec![(
modifiedruntime/Cargo.tomldiffbeforeafterboth
--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -57,6 +57,13 @@
 sp-transaction-pool = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
 sp-version = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
 
+pallet-membership = { version = "2.0.0", default-features = false, git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
+pallet-collective = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
+pallet-democracy = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
+pallet-elections-phragmen = { version = "2.0.0", default-features = false, git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
+pallet-treasury = { version = "2.0.0", default-features = false, git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
+pallet-scheduler = { version = "2.0.0", default-features = false, git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
+
 [features]
 default = ['std']
 runtime-benchmarks = [
@@ -100,4 +107,11 @@
     'sp-std/std',
     'sp-transaction-pool/std',
     'sp-version/std',
+
+    'pallet-collective/std',
+    'pallet-democracy/std',
+    'pallet-elections-phragmen/std', 
+    'pallet-membership/std',
+    'pallet-treasury/std',
+    'pallet-scheduler/std',
 ]
modifiedruntime/src/lib.rsdiffbeforeafterboth
15use sp_consensus_aura::sr25519::AuthorityId as AuraId;15use sp_consensus_aura::sr25519::AuthorityId as AuraId;
16use sp_core::{crypto::KeyTypeId, OpaqueMetadata};16use sp_core::{
17 crypto::KeyTypeId,
18 OpaqueMetadata,
19 u32_trait::{_1, _2, _3, _4},
20};
17use sp_runtime::{21use sp_runtime::{
18 create_runtime_str, generic, impl_opaque_keys,22 create_runtime_str, generic, impl_opaque_keys,
19 traits::{23 traits::{
20 BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, NumberFor, Saturating,24 Convert, BlakeTwo256, Block as BlockT, IdentifyAccount,
21 Verify,25 IdentityLookup, NumberFor, Saturating, Verify,
22 },26 },
23 transaction_validity::{TransactionSource, TransactionValidity},27 transaction_validity::{TransactionSource, TransactionValidity},
37 parameter_types,41 parameter_types,
38 traits::{42 traits::{
39 Currency, ExistenceRequirement, Get, KeyOwnerProofSystem, OnUnbalanced, Randomness,43 Currency, ExistenceRequirement, Get, KeyOwnerProofSystem, OnUnbalanced, Randomness,
40 WithdrawReason,44 WithdrawReason, LockIdentifier,
41 },45 },
42 weights::{46 weights::{
43 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},47 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
48};52};
49#[cfg(any(feature = "std", test))]53#[cfg(any(feature = "std", test))]
50pub use sp_runtime::BuildStorage;54pub use sp_runtime::BuildStorage;
51use sp_runtime::Perbill;55use sp_runtime:: { Perbill, Permill, Percent, ModuleId };
52use frame_system::{self as system};56use frame_system::{self as system, EnsureRoot, EnsureOneOf };
5357
54pub use pallet_timestamp::Call as TimestampCall;58pub use pallet_timestamp::Call as TimestampCall;
59
60/// Struct that handles the conversion of Balance -> `u64`. This is used for
61/// staking's election calculation.
62pub struct CurrencyToVoteHandler;
63
64impl CurrencyToVoteHandler {
65 fn factor() -> Balance {
66 (Balances::total_issuance() / u64::max_value() as Balance).max(1)
67 }
68}
69
70impl Convert<Balance, u64> for CurrencyToVoteHandler {
71 fn convert(x: Balance) -> u64 {
72 (x / Self::factor()) as u64
73 }
74}
75
76impl Convert<u128, Balance> for CurrencyToVoteHandler {
77 fn convert(x: u128) -> Balance {
78 x * Self::factor()
79 }
80}
5581
56/// Re-export a nft pallet82/// Re-export a nft pallet
57/// TODO: Check this re-export. Is this safe and good style?83/// TODO: Check this re-export. Is this safe and good style?
303 type FeeMultiplierUpdate = ();329 type FeeMultiplierUpdate = ();
304}330}
331
332parameter_types! {
333 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * MaximumBlockWeight::get();
334 pub const MaxScheduledPerBlock: u32 = 50;
335}
336
337impl pallet_scheduler::Trait for Runtime {
338 type Event = Event;
339 type Origin = Origin;
340 type PalletsOrigin = OriginCaller;
341 type Call = Call;
342 type MaximumWeight = MaximumSchedulerWeight;
343 type ScheduleOrigin = EnsureRoot<AccountId>;
344 type MaxScheduledPerBlock = MaxScheduledPerBlock;
345 type WeightInfo = ();
346}
347
348parameter_types! {
349 pub const ProposalBond: Permill = Permill::from_percent(5);
350 pub const ProposalBondMinimum: Balance = 1 * DOLLARS;
351 pub const SpendPeriod: BlockNumber = 1 * DAYS;
352 pub const Burn: Permill = Permill::from_percent(50);
353 pub const TipCountdown: BlockNumber = 1 * DAYS;
354 pub const TipFindersFee: Percent = Percent::from_percent(20);
355 pub const TipReportDepositBase: Balance = 1 * DOLLARS;
356 pub const DataDepositPerByte: Balance = 1 * CENTS;
357 pub const BountyDepositBase: Balance = 1 * DOLLARS;
358 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;
359 pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry");
360 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;
361 pub const MaximumReasonLength: u32 = 16384;
362 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);
363 pub const BountyValueMinimum: Balance = 5 * DOLLARS;
364}
365
366impl pallet_treasury::Trait for Runtime {
367 type ModuleId = TreasuryModuleId;
368 type Currency = Balances;
369 type ApproveOrigin =
370 EnsureOneOf<
371 AccountId,
372 EnsureRoot<AccountId>,
373 pallet_collective::EnsureMembers<_4, AccountId, CouncilCollective>
374 >;
375 type RejectOrigin =
376 EnsureOneOf<
377 AccountId,
378 EnsureRoot<AccountId>,
379 pallet_collective::EnsureMembers<_2, AccountId, CouncilCollective>
380 >;
381 type Tippers = Elections;
382 type TipCountdown = TipCountdown;
383 type TipFindersFee = TipFindersFee;
384 type TipReportDepositBase = TipReportDepositBase;
385 type DataDepositPerByte = DataDepositPerByte;
386 type Event = Event;
387 type OnSlash = ();
388 type ProposalBond = ProposalBond;
389 type ProposalBondMinimum = ProposalBondMinimum;
390 type SpendPeriod = SpendPeriod;
391 type Burn = Burn;
392 type BountyDepositBase = BountyDepositBase;
393 type BountyDepositPayoutDelay = BountyDepositPayoutDelay;
394 type BountyUpdatePeriod = BountyUpdatePeriod;
395 type BountyCuratorDeposit = BountyCuratorDeposit;
396 type BountyValueMinimum = BountyValueMinimum;
397 type MaximumReasonLength = MaximumReasonLength;
398 type BurnDestination = ();
399 type WeightInfo = ();
400}
401
402parameter_types! {
403 pub const TechnicalMotionDuration: BlockNumber = 5 * DAYS;
404 pub const TechnicalMaxProposals: u32 = 100;
405 pub const TechnicalMaxMembers: u32 = 100;
406}
407
408type TechnicalCollective = pallet_collective::Instance2;
409impl pallet_collective::Trait<TechnicalCollective> for Runtime {
410 type Origin = Origin;
411 type Proposal = Call;
412 type Event = Event;
413 type MotionDuration = TechnicalMotionDuration;
414 type MaxProposals = TechnicalMaxProposals;
415 type MaxMembers = TechnicalMaxMembers;
416 type DefaultVote = pallet_collective::PrimeDefaultVote;
417 type WeightInfo = ();
418}
419
420parameter_types! {
421 pub const LaunchPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
422 pub const VotingPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
423 pub const FastTrackVotingPeriod: BlockNumber = 3 * 24 * 60 * MINUTES;
424 pub const InstantAllowed: bool = true;
425 pub const MinimumDeposit: Balance = 100 * DOLLARS;
426 pub const EnactmentPeriod: BlockNumber = 30 * 24 * 60 * MINUTES;
427 pub const CooloffPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
428 // One cent: $10,000 / MB
429 pub const PreimageByteDeposit: Balance = 1 * CENTS;
430 pub const MaxVotes: u32 = 100;
431}
432
433impl pallet_democracy::Trait for Runtime {
434 type Proposal = Call;
435 type Event = Event;
436 type Currency = Balances;
437 type EnactmentPeriod = EnactmentPeriod;
438 type LaunchPeriod = LaunchPeriod;
439 type VotingPeriod = VotingPeriod;
440 type MinimumDeposit = MinimumDeposit;
441 /// A straight majority of the council can decide what their next motion is.
442 type ExternalOrigin = pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>;
443 /// A super-majority can have the next scheduled referendum be a straight majority-carries vote.
444 type ExternalMajorityOrigin = pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>;
445 /// A unanimous council can have the next scheduled referendum be a straight default-carries
446 /// (NTB) vote.
447 type ExternalDefaultOrigin = pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilCollective>;
448 /// Two thirds of the technical committee can have an ExternalMajority/ExternalDefault vote
449 /// be tabled immediately and with a shorter voting/enactment period.
450 type FastTrackOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechnicalCollective>;
451 type InstantOrigin = pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>;
452 type InstantAllowed = InstantAllowed;
453 type FastTrackVotingPeriod = FastTrackVotingPeriod;
454 // To cancel a proposal which has been passed, 2/3 of the council must agree to it.
455 type CancellationOrigin = EnsureOneOf<
456 AccountId,
457 EnsureRoot<AccountId>,
458 pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>,
459 >;
460 // Any single technical committee member may veto a coming council proposal, however they can
461 // only do it once and it lasts only for the cooloff period.
462 type VetoOrigin = pallet_collective::EnsureMember<AccountId, TechnicalCollective>;
463 type CooloffPeriod = CooloffPeriod;
464 type PreimageByteDeposit = PreimageByteDeposit;
465 type OperationalPreimageOrigin = pallet_collective::EnsureMember<AccountId, CouncilCollective>;
466 type Slash = Treasury;
467 type Scheduler = Scheduler;
468 type PalletsOrigin = OriginCaller;
469 type MaxVotes = MaxVotes;
470 type WeightInfo = (); //weights::pallet_democracy::WeightInfo;
471}
472
473parameter_types! {
474 pub const CouncilMotionDuration: BlockNumber = 5 * DAYS;
475 pub const CouncilMaxProposals: u32 = 100;
476 pub const CouncilMaxMembers: u32 = 100;
477}
478
479type CouncilCollective = pallet_collective::Instance1;
480impl pallet_collective::Trait<CouncilCollective> for Runtime {
481 type Origin = Origin;
482 type Proposal = Call;
483 type Event = Event;
484 type MotionDuration = CouncilMotionDuration;
485 type MaxProposals = CouncilMaxProposals;
486 type MaxMembers = CouncilMaxMembers;
487 type DefaultVote = pallet_collective::PrimeDefaultVote;
488 type WeightInfo = (); //weights::pallet_collective::WeightInfo;
489}
490
491parameter_types! {
492 pub const CandidacyBond: Balance = 10 * DOLLARS;
493 pub const VotingBond: Balance = 1 * DOLLARS;
494 pub const TermDuration: BlockNumber = 7 * DAYS;
495 pub const DesiredMembers: u32 = 13;
496 pub const DesiredRunnersUp: u32 = 7;
497 pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect";
498}
499
500// Make sure that there are no more than `MaxMembers` members elected via elections-phragmen.
501// const_assert!(DesiredMembers::get() <= CouncilMaxMembers::get());
502
503impl pallet_elections_phragmen::Trait for Runtime {
504 type Event = Event;
505 type ModuleId = ElectionsPhragmenModuleId;
506 type Currency = Balances;
507 type ChangeMembers = Council;
508 // NOTE: this implies that council's genesis members cannot be set directly and must come from
509 // this module.
510 type InitializeMembers = Council;
511 type CurrencyToVote = CurrencyToVoteHandler;
512 type CandidacyBond = CandidacyBond;
513 type VotingBond = VotingBond;
514 type LoserCandidate = ();
515 type BadReport = ();
516 type KickedMember = ();
517 type DesiredMembers = DesiredMembers;
518 type DesiredRunnersUp = DesiredRunnersUp;
519 type TermDuration = TermDuration;
520 type WeightInfo = (); //weights::pallet_elections_phragmen::WeightInfo;
521}
522
523type EnsureRootOrHalfCouncil = EnsureOneOf<
524 AccountId,
525 EnsureRoot<AccountId>,
526 pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>
527>;
528impl pallet_membership::Trait for Runtime {
529 type Event = Event;
530 type AddOrigin = EnsureRootOrHalfCouncil;
531 type RemoveOrigin = EnsureRootOrHalfCouncil;
532 type SwapOrigin = EnsureRootOrHalfCouncil;
533 type ResetOrigin = EnsureRootOrHalfCouncil;
534 type PrimeOrigin = EnsureRootOrHalfCouncil;
535 type MembershipInitialized = TechnicalCommittee;
536 type MembershipChanged = TechnicalCommittee;
537}
305538
306impl pallet_sudo::Trait for Runtime {539impl pallet_sudo::Trait for Runtime {
307 type Event = Event;540 type Event = Event;
331 Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},564 Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},
332 Nft: pallet_nft::{Module, Call, Config<T>, Storage, Event<T>},565 Nft: pallet_nft::{Module, Call, Config<T>, Storage, Event<T>},
566
567 Democracy: pallet_democracy::{Module, Call, Storage, Config, Event<T>},
568 Council: pallet_collective::<Instance1>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
569 TechnicalCommittee: pallet_collective::<Instance2>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
570 Elections: pallet_elections_phragmen::{Module, Call, Storage, Event<T>, Config<T>},
571 TechnicalMembership: pallet_membership::{Module, Call, Storage, Event<T>, Config<T>},
572 Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
573 Scheduler: pallet_scheduler::{Module, Call, Storage, Event<T>},
333 }574 }
334);575);
335576