Skip to content

Commit

Permalink
Introduce OpenGov into Cere and CereDev (#238)
Browse files Browse the repository at this point in the history
### Description
Enabling the
[OpenGov](https://wiki.polkadot.network/docs/learn-polkadot-opengov).

<!-- Describe what change this PR is implementing -->

### Types of Changes
<!--- What types of changes does your code introduce? -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Dependency upgrade (A change in substrate or any 3rd party crate
version)

### Migrations and Hooks
<!--- Check the following box with an x if the following applies: -->
- [x] This change requires a runtime migration.
- [ ] Modifies `on_initialize`
- [ ] Modifies `on_finalize`

### Checklist
<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [x] Change has been tested locally.
- [x] Change adds / updates tests.
- [x] Changelog doc updated.
  • Loading branch information
yahortsaryk authored May 6, 2024
1 parent 7ad744e commit c8ff9ef
Show file tree
Hide file tree
Showing 18 changed files with 1,267 additions and 486 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- [C,D] Updated Substrate to polkadot-v1.1.0
- [C,D] Introduction of the OpenGov

## [5.2.0]

Expand Down
65 changes: 65 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/parityt
pallet-treasury = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.1.0", default-features = false }
pallet-utility = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.1.0", default-features = false }
pallet-vesting = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.1.0", default-features = false }
pallet-conviction-voting = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.1.0", default-features = false }
pallet-referenda = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.1.0", default-features = false }
pallet-whitelist = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.1.0", default-features = false }
sc-authority-discovery = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.1.0", default-features = false }
sc-basic-authorship = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0", default-features = false }
sc-chain-spec = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion node/cli/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cere_service::{self, IdentifyVariant};
use cere_service::IdentifyVariant;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use sc_cli::{Error, SubstrateCli};
use sc_service::error::Error as ServiceError;
Expand Down
21 changes: 0 additions & 21 deletions node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ pub fn cere_dev_genesis(
}))
.collect::<Vec<_>>();

let num_endowed_accounts = endowed_accounts.len();

const ENDOWMENT: Balance = 10_000_000_000 * TEST_UNITS;
const STASH: Balance = ENDOWMENT / 1000;

Expand Down Expand Up @@ -194,24 +192,6 @@ pub fn cere_dev_genesis(
..Default::default()
},
ddc_staking: cere_dev::DdcStakingConfig::default(),
democracy: cere_dev::DemocracyConfig::default(),
elections: cere_dev::ElectionsConfig {
members: endowed_accounts
.iter()
.take((num_endowed_accounts + 1) / 2)
.cloned()
.map(|member| (member, STASH))
.collect(),
},
council: cere_dev::CouncilConfig::default(),
technical_committee: cere_dev::TechnicalCommitteeConfig {
members: endowed_accounts
.iter()
.take((num_endowed_accounts + 1) / 2)
.cloned()
.collect(),
phantom: Default::default(),
},
sudo: cere_dev::SudoConfig { key: Some(root_key) },
babe: cere_dev::BabeConfig {
authorities: Default::default(),
Expand All @@ -224,7 +204,6 @@ pub fn cere_dev_genesis(
..Default::default()
},
grandpa: Default::default(),
technical_membership: Default::default(),
treasury: Default::default(),
vesting: Default::default(),
transaction_payment: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use cere_dev_runtime;
pub use cere_runtime;
use futures::prelude::*;
use sc_client_api::{Backend, BlockBackend};
use sc_consensus_babe::{self, SlotProportion};
use sc_consensus_babe::SlotProportion;
pub use sc_executor::NativeExecutionDispatch;
use sc_network::{Event, NetworkEventStream};
use sc_service::{
Expand Down
1 change: 0 additions & 1 deletion pallets/ddc-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use frame_support::{
pallet_prelude::*,
parameter_types,
traits::{Currency, DefensiveSaturating, LockIdentifier, LockableCurrency, WithdrawReasons},
BoundedVec,
};
use frame_system::pallet_prelude::*;
pub use pallet::*;
Expand Down
14 changes: 14 additions & 0 deletions runtime/cere-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pallet-child-bounties = { workspace = true }
pallet-collective = { workspace = true }
pallet-contracts = { workspace = true }
pallet-contracts-primitives = { workspace = true }
pallet-conviction-voting = { workspace = true }
pallet-democracy = { workspace = true }
pallet-election-provider-multi-phase = { workspace = true }
pallet-election-provider-support-benchmarking = { workspace = true, optional = true }
Expand All @@ -59,6 +60,7 @@ pallet-offences-benchmarking = { workspace = true, optional = true }
pallet-preimage = { workspace = true }
pallet-proxy = { workspace = true }
pallet-recovery = { workspace = true }
pallet-referenda = { workspace = true }
pallet-scheduler = { workspace = true }
pallet-session = { workspace = true, features = ["historical"] }
pallet-session-benchmarking = { workspace = true, optional = true }
Expand All @@ -72,7 +74,9 @@ pallet-transaction-payment-rpc-runtime-api = { workspace = true }
pallet-treasury = { workspace = true }
pallet-utility = { workspace = true }
pallet-vesting = { workspace = true }
pallet-whitelist = { workspace = true }
sp-api = { workspace = true }
sp-arithmetic = { workspace = true }
sp-authority-discovery = { workspace = true }
sp-block-builder = { workspace = true }
sp-consensus-babe = { workspace = true }
Expand Down Expand Up @@ -182,6 +186,10 @@ std = [
"pallet-ddc-clusters/std",
"pallet-ddc-payouts/std",
"cere-runtime-common/std",
"sp-arithmetic/std",
"pallet-conviction-voting/std",
"pallet-referenda/std",
"pallet-whitelist/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down Expand Up @@ -228,6 +236,9 @@ runtime-benchmarks = [
"pallet-chainbridge/runtime-benchmarks",
"ddc-primitives/runtime-benchmarks",
"hex-literal",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-whitelist/runtime-benchmarks",
]
try-runtime = [
"frame-executive/try-runtime",
Expand Down Expand Up @@ -276,4 +287,7 @@ try-runtime = [
"pallet-ddc-staking/try-runtime",
"pallet-erc20/try-runtime",
"pallet-erc721/try-runtime",
"pallet-conviction-voting/try-runtime",
"pallet-referenda/try-runtime",
"pallet-whitelist/try-runtime",
]
70 changes: 70 additions & 0 deletions runtime/cere-dev/src/governance/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use frame_support::parameter_types;
use frame_system::EnsureRootWithSuccess;

use super::*;

mod origins;
pub use origins::{
pallet_custom_origins, GeneralAdmin, ReferendumCanceller, ReferendumKiller, Spender,
StakingAdmin, Treasurer, WhitelistedCaller,
};
mod tracks;
pub use tracks::TracksInfo;

parameter_types! {
pub const VoteLockingPeriod: BlockNumber = 7 * DAYS;
}

impl pallet_conviction_voting::Config for Runtime {
type WeightInfo = pallet_conviction_voting::weights::SubstrateWeight<Runtime>;
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type VoteLockingPeriod = VoteLockingPeriod;
type MaxVotes = ConstU32<512>;
type MaxTurnout =
frame_support::traits::tokens::currency::ActiveIssuanceOf<Balances, Self::AccountId>;
type Polls = Referenda;
}

parameter_types! {
pub const AlarmInterval: BlockNumber = 1;
pub const SubmissionDeposit: Balance = DOLLARS;
pub const UndecidingTimeout: BlockNumber = 14 * DAYS;
}

parameter_types! {
pub const MaxBalance: Balance = Balance::max_value();
}

pub type TreasurySpender = EitherOf<EnsureRootWithSuccess<AccountId, MaxBalance>, Spender>;

impl origins::pallet_custom_origins::Config for Runtime {}

impl pallet_whitelist::Config for Runtime {
type WeightInfo = pallet_whitelist::weights::SubstrateWeight<Runtime>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WhitelistOrigin = EnsureRoot<Self::AccountId>;
type DispatchWhitelistedOrigin = EitherOf<EnsureRoot<Self::AccountId>, WhitelistedCaller>;
type Preimages = Preimage;
}

impl pallet_referenda::Config for Runtime {
type WeightInfo = pallet_referenda::weights::SubstrateWeight<Runtime>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type Scheduler = Scheduler;
type Currency = Balances;
type SubmitOrigin = frame_system::EnsureSigned<AccountId>;
type CancelOrigin = EitherOf<EnsureRoot<AccountId>, ReferendumCanceller>;
type KillOrigin = EitherOf<EnsureRoot<AccountId>, ReferendumKiller>;
type Slash = Treasury;
type Votes = pallet_conviction_voting::VotesOf<Runtime>;
type Tally = pallet_conviction_voting::TallyOf<Runtime>;
type SubmissionDeposit = SubmissionDeposit;
type MaxQueued = ConstU32<100>;
type UndecidingTimeout = UndecidingTimeout;
type AlarmInterval = AlarmInterval;
type Tracks = TracksInfo;
type Preimages = Preimage;
}
Loading

0 comments on commit c8ff9ef

Please sign in to comment.