Skip to content

Commit

Permalink
Feat/sys 3623 opengov introduction (#242)
Browse files Browse the repository at this point in the history
Co-authored-by: aventus-ci-agent <ci-agent-bot@aventus.io>
  • Loading branch information
ivan-cholakov and aventus-ci-agent authored Oct 6, 2023
1 parent 7ff93da commit 59584e9
Show file tree
Hide file tree
Showing 12 changed files with 740 additions and 22 deletions.
46 changes: 28 additions & 18 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lto = "fat"
codegen-units = 1

[workspace.package]
version = "3.2.6"
version = "3.3.0"
authors = ["Aventus systems team"]
homepage = "https://www.aventus.io/"
repository = "https://github.com/Aventus-Network-Services/avn-node-parachain/"
Expand Down
17 changes: 17 additions & 0 deletions runtime/avn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ pallet-authority-discovery = { default-features = false, git = "https://github.c
pallet-offences = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" }
pallet-im-online = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" }
pallet-utility = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" }
pallet-referenda = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
pallet-conviction-voting = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
pallet-whitelist = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
pallet-scheduler = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
pallet-preimage = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }

# Polkadot
pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" }
Expand Down Expand Up @@ -164,6 +169,12 @@ std = [
"pallet-parachain-staking/std",
# Avn Common Runtime
"runtime-common/std",
# OpenGov
"pallet-referenda/std",
"pallet-conviction-voting/std",
"pallet-whitelist/std",
"pallet-scheduler/std",
"pallet-preimage/std",
]

runtime-benchmarks = [
Expand Down Expand Up @@ -196,6 +207,12 @@ runtime-benchmarks = [
"pallet-parachain-staking/runtime-benchmarks",
# Avn Common Runtime
"runtime-common/runtime-benchmarks",
# OpenGov
"pallet-referenda/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-whitelist/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
]

try-runtime = [
Expand Down
62 changes: 62 additions & 0 deletions runtime/avn/src/governance/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
pub use super::*;

pub mod origins;
use frame_support::traits::EitherOf;
pub use origins::{
pallet_custom_origins, ReferendumCanceller, ReferendumKiller, WhitelistedCaller,
};

pub mod tracks;
pub use tracks::TracksInfo;

parameter_types! {
pub const VoteLockingPeriod: BlockNumber = 28 * 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 = 50 * AVT;
pub const UndecidingTimeout: BlockNumber = 14 * DAYS;
}

impl 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 = ();
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;
}
75 changes: 75 additions & 0 deletions runtime/avn/src/governance/origins.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

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

// Polkadot 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 General Public License for more details.

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

//! Custom origins for governance interventions.

pub use pallet_custom_origins::*;

#[frame_support::pallet]
pub mod pallet_custom_origins {
use frame_support::pallet_prelude::*;

#[pallet::config]
pub trait Config: frame_system::Config {}

#[pallet::pallet]
pub struct Pallet<T>(_);

#[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)]
#[pallet::origin]
pub enum Origin {
/// Origin for managing the registrar and permissioned HRMP channel operations.
GeneralAdmin,
/// Origin able to cancel referenda.
ReferendumCanceller,
/// Origin able to kill referenda.
ReferendumKiller,
/// Origin able to dispatch a whitelisted call.
WhitelistedCaller,
}

macro_rules! decl_unit_ensures {
( $name:ident: $success_type:ty = $success:expr ) => {
pub struct $name;
impl<O: Into<Result<Origin, O>> + From<Origin>>
EnsureOrigin<O> for $name
{
type Success = $success_type;
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
Origin::$name => Ok($success),
r => Err(O::from(r)),
})
}
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<O, ()> {
Ok(O::from(Origin::$name))
}
}
};
( $name:ident ) => { decl_unit_ensures! { $name : () = () } };
( $name:ident: $success_type:ty = $success:expr, $( $rest:tt )* ) => {
decl_unit_ensures! { $name: $success_type = $success }
decl_unit_ensures! { $( $rest )* }
};
( $name:ident, $( $rest:tt )* ) => {
decl_unit_ensures! { $name }
decl_unit_ensures! { $( $rest )* }
};
() => {}
}
decl_unit_ensures!(GeneralAdmin, ReferendumCanceller, ReferendumKiller, WhitelistedCaller,);
}
Loading

0 comments on commit 59584e9

Please sign in to comment.