Skip to content

Commit

Permalink
Merge pull request #2949 from autonomys/council
Browse files Browse the repository at this point in the history
Add council and democracy to consensus runtime
  • Loading branch information
vedhavyas authored Aug 15, 2024
2 parents 72575a0 + 1a508f0 commit 4b3cc60
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 38 deletions.
72 changes: 72 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/pallet-runtime-configs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ scale-info = { version = "2.11.2", default-features = false, features = ["derive
sp-core = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "5626154d0781ac9a6ffd5a6207ed237f425ae631", optional = true }
sp-runtime = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "5626154d0781ac9a6ffd5a6207ed237f425ae631" }
sp-std = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "5626154d0781ac9a6ffd5a6207ed237f425ae631", optional = true }
subspace-runtime-primitives = { version = "0.1.0", default-features = false, path = "../subspace-runtime-primitives" }

[features]
default = ["std"]
Expand All @@ -35,6 +36,7 @@ std = [
"scale-info/std",
"sp-runtime/std",
"sp-std?/std",
"subspace-runtime-primitives/std",
]
try-runtime = ["frame-support/try-runtime"]
runtime-benchmarks = [
Expand Down
11 changes: 11 additions & 0 deletions crates/pallet-runtime-configs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use sp_runtime::traits::Zero;
use subspace_runtime_primitives::CouncilDemocracyConfigParams;

#[pallet::pallet]
pub struct Pallet<T>(_);
Expand Down Expand Up @@ -58,6 +59,10 @@ mod pallet {
#[pallet::storage]
pub type ConfirmationDepthK<T: Config> = StorageValue<_, BlockNumberFor<T>, ValueQuery>;

#[pallet::storage]
pub type CouncilDemocracyConfig<T: Config> =
StorageValue<_, CouncilDemocracyConfigParams<BlockNumberFor<T>>, ValueQuery>;

#[pallet::config]
pub trait Config: frame_system::Config {
/// Weight information for extrinsics in this pallet.
Expand All @@ -76,6 +81,8 @@ mod pallet {
pub enable_non_root_calls: bool,
/// Confirmation depth k to use in the archiving process
pub confirmation_depth_k: BlockNumberFor<T>,
/// Council and democracy config params.
pub council_democracy_config_params: CouncilDemocracyConfigParams<BlockNumberFor<T>>,
}

impl<T: Config> Default for GenesisConfig<T> {
Expand All @@ -87,6 +94,8 @@ mod pallet {
enable_balance_transfers: false,
enable_non_root_calls: false,
confirmation_depth_k: BlockNumberFor::<T>::from(100u32),
council_democracy_config_params:
CouncilDemocracyConfigParams::<BlockNumberFor<T>>::default(),
}
}
}
Expand All @@ -100,6 +109,7 @@ mod pallet {
enable_balance_transfers,
enable_non_root_calls,
confirmation_depth_k,
council_democracy_config_params,
} = self;

assert!(
Expand All @@ -112,6 +122,7 @@ mod pallet {
<EnableBalanceTransfers<T>>::put(enable_balance_transfers);
<EnableNonRootCalls<T>>::put(enable_non_root_calls);
<ConfirmationDepthK<T>>::put(confirmation_depth_k);
CouncilDemocracyConfig::<T>::put(council_democracy_config_params);
}
}

Expand Down
30 changes: 20 additions & 10 deletions crates/sc-subspace-chain-specs/res/chain-spec-raw-devnet.json

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions crates/subspace-malicious-operator/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ use sp_runtime::{BuildStorage, MultiSigner, Percent};
use std::marker::PhantomData;
use std::num::NonZeroU32;
use subspace_runtime::{
AllowAuthoringBy, DomainsConfig, EnableRewardsAt, MaxDomainBlockSize, MaxDomainBlockWeight,
RewardsConfig, RuntimeConfigsConfig, SubspaceConfig, VestingConfig,
AllowAuthoringBy, CouncilConfig, DemocracyConfig, DomainsConfig, EnableRewardsAt,
MaxDomainBlockSize, MaxDomainBlockWeight, RewardsConfig, RuntimeConfigsConfig, SubspaceConfig,
VestingConfig,
};
use subspace_runtime_primitives::{
AccountId, Balance, BlockNumber, CouncilDemocracyConfigParams, SSC,
};
use subspace_runtime_primitives::{AccountId, Balance, BlockNumber, SSC};

fn endowed_accounts() -> Vec<(MultiAccountId, Balance)> {
[
Expand Down Expand Up @@ -236,12 +239,16 @@ fn subspace_genesis_config(
},
rewards: rewards_config,
vesting: VestingConfig { vesting },
council: CouncilConfig::default(),
democracy: DemocracyConfig::default(),
runtime_configs: RuntimeConfigsConfig {
enable_domains,
enable_dynamic_cost_of_storage,
enable_balance_transfers,
enable_non_root_calls,
confirmation_depth_k,
council_democracy_config_params:
CouncilDemocracyConfigParams::<BlockNumber>::fast_params(),
},
domains: DomainsConfig {
permissioned_action_allowed_by: Some(
Expand Down
18 changes: 14 additions & 4 deletions crates/subspace-node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ use std::marker::PhantomData;
use std::num::NonZeroU32;
use subspace_core_primitives::PotKey;
use subspace_runtime::{
AllowAuthoringBy, BalancesConfig, DomainsConfig, EnableRewardsAt, MaxDomainBlockSize,
MaxDomainBlockWeight, RewardsConfig, RuntimeConfigsConfig, RuntimeGenesisConfig,
SubspaceConfig, SudoConfig, SystemConfig, VestingConfig, MILLISECS_PER_BLOCK, WASM_BINARY,
AllowAuthoringBy, BalancesConfig, CouncilConfig, DemocracyConfig, DomainsConfig,
EnableRewardsAt, MaxDomainBlockSize, MaxDomainBlockWeight, RewardsConfig, RuntimeConfigsConfig,
RuntimeGenesisConfig, SubspaceConfig, SudoConfig, SystemConfig, VestingConfig, WASM_BINARY,
};
use subspace_runtime_primitives::time::MILLISECS_PER_BLOCK;
use subspace_runtime_primitives::{
AccountId, Balance, BlockNumber, CouncilDemocracyConfigParams, SSC,
};
use subspace_runtime_primitives::{AccountId, Balance, BlockNumber, SSC};

const SUBSPACE_TELEMETRY_URL: &str = "wss://telemetry.subspace.network/submit/";

Expand Down Expand Up @@ -206,6 +209,7 @@ pub fn gemini_3h_compiled() -> Result<GenericChainSpec, String> {
auto_id_chain_spec::get_genesis_domain(SpecId::Gemini, sudo_account)?,
],
},
CouncilDemocracyConfigParams::<BlockNumber>::production_params(),
)?)
.map_err(|error| format!("Failed to serialize genesis config: {error}"))?,
)
Expand Down Expand Up @@ -315,6 +319,7 @@ pub fn devnet_config_compiled() -> Result<GenericChainSpec, String> {
sudo_account,
)?],
},
CouncilDemocracyConfigParams::<BlockNumber>::fast_params(),
)?)
.map_err(|error| format!("Failed to serialize genesis config: {error}"))?,
)
Expand Down Expand Up @@ -374,6 +379,7 @@ pub fn dev_config() -> Result<GenericChainSpec, String> {
sudo_account,
)?],
},
CouncilDemocracyConfigParams::<BlockNumber>::fast_params(),
)?)
.map_err(|error| format!("Failed to serialize genesis config: {error}"))?,
))
Expand All @@ -388,6 +394,7 @@ fn subspace_genesis_config(
vesting: Vec<(AccountId, BlockNumber, BlockNumber, u32, Balance)>,
genesis_params: GenesisParams,
genesis_domain_params: GenesisDomainParams,
council_democracy_config_params: CouncilDemocracyConfigParams<BlockNumber>,
) -> Result<RuntimeGenesisConfig, String> {
let GenesisParams {
enable_rewards_at,
Expand Down Expand Up @@ -447,12 +454,15 @@ fn subspace_genesis_config(
},
rewards: rewards_config,
vesting: VestingConfig { vesting },
council: CouncilConfig::default(),
democracy: DemocracyConfig::default(),
runtime_configs: RuntimeConfigsConfig {
enable_domains,
enable_dynamic_cost_of_storage,
enable_balance_transfers,
enable_non_root_calls,
confirmation_depth_k,
council_democracy_config_params,
},
domains: DomainsConfig {
permissioned_action_allowed_by: enable_domains
Expand Down
2 changes: 2 additions & 0 deletions crates/subspace-runtime-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ frame-support = { default-features = false, git = "https://github.com/subspace/p
frame-system = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "5626154d0781ac9a6ffd5a6207ed237f425ae631" }
pallet-transaction-payment = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "5626154d0781ac9a6ffd5a6207ed237f425ae631" }
scale-info = { version = "2.11.1", default-features = false, features = ["derive"] }
serde = { version = "1.0.203", default-features = false, features = ["alloc", "derive"] }
sp-core = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "5626154d0781ac9a6ffd5a6207ed237f425ae631" }
sp-io = { default-features = false, optional = true, git = "https://github.com/subspace/polkadot-sdk", rev = "5626154d0781ac9a6ffd5a6207ed237f425ae631" }
sp-runtime = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "5626154d0781ac9a6ffd5a6207ed237f425ae631" }
Expand All @@ -34,6 +35,7 @@ std = [
"frame-system/std",
"pallet-transaction-payment/std",
"scale-info/std",
"serde/std",
"sp-core/std",
"sp-runtime/std",
"subspace-core-primitives/std",
Expand Down
80 changes: 79 additions & 1 deletion crates/subspace-runtime-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
#[cfg(not(feature = "std"))]
extern crate alloc;

use crate::time::{BLOCKS_IN_AN_MINUTE, BLOCKS_IN_A_DAY};
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use codec::{Codec, Decode, Encode};
use codec::{Codec, Decode, Encode, MaxEncodedLen};
use frame_support::pallet_prelude::Weight;
use frame_support::traits::tokens;
use frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND;
use frame_support::{Deserialize, Serialize};
use frame_system::limits::BlockLength;
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -97,6 +99,82 @@ pub mod opaque {
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
}

pub mod time {
/// Since Subspace is probabilistic this is the average expected block time that
/// we are targeting. Blocks will be produced at a minimum duration defined
/// by `SLOT_DURATION`, but some slots will not be allocated to any
/// farmer and hence no block will be produced. We expect to have this
/// block time on average following the defined slot duration and the value
/// of `c` configured for Subspace (where `1 - c` represents the probability of
/// a slot being empty).
/// This value is only used indirectly to define the unit constants below
/// that are expressed in blocks. The rest of the code should use
/// `SLOT_DURATION` instead (like the Timestamp pallet for calculating the
/// minimum period).
///
/// Based on:
/// <https://research.web3.foundation/en/latest/polkadot/block-production/Babe.html#-6.-practical-results>
pub const MILLISECS_PER_BLOCK: u64 = 6000;
/// Approximate number of block in a minute.
pub const BLOCKS_IN_AN_MINUTE: u32 = (60 * 1000) / MILLISECS_PER_BLOCK as u32;
/// Approximate number of blocks in an hour.
pub const BLOCKS_IN_AN_HOUR: u32 = 60 * BLOCKS_IN_AN_MINUTE;
/// Approximate number of blocks in a day.
pub const BLOCKS_IN_A_DAY: u32 = 24 * BLOCKS_IN_AN_HOUR;
}

#[derive(Copy, Clone, Encode, Decode, TypeInfo, Serialize, Deserialize, MaxEncodedLen, Debug)]
pub struct CouncilDemocracyConfigParams<BlockNumber> {
/// Council motion duration.
pub council_motion_duration: BlockNumber,
/// Democracy cooloff period.
pub democracy_cooloff_period: BlockNumber,
/// Democracy enactment period.
pub democracy_enactment_period: BlockNumber,
/// Fast track voting period.
pub democracy_fast_track_voting_period: BlockNumber,
/// Launch period.
pub democracy_launch_period: BlockNumber,
/// Vote locking period.
pub democracy_vote_locking_period: BlockNumber,
/// Voting period.
pub democracy_voting_period: BlockNumber,
}

impl<BlockNumber: From<u32>> Default for CouncilDemocracyConfigParams<BlockNumber> {
fn default() -> Self {
Self {
council_motion_duration: BLOCKS_IN_A_DAY.into(),
democracy_cooloff_period: BLOCKS_IN_A_DAY.into(),
democracy_enactment_period: BLOCKS_IN_A_DAY.into(),
democracy_fast_track_voting_period: (2 * BLOCKS_IN_A_DAY).into(),
democracy_launch_period: (2 * BLOCKS_IN_A_DAY).into(),
democracy_vote_locking_period: BLOCKS_IN_A_DAY.into(),
democracy_voting_period: BLOCKS_IN_A_DAY.into(),
}
}
}

impl<BlockNumber: From<u32>> CouncilDemocracyConfigParams<BlockNumber> {
/// Production params for Council democracy config.
pub fn production_params() -> Self {
Self::default()
}

/// Fast period params for Council democracy config.
pub fn fast_params() -> Self {
Self {
council_motion_duration: (15 * BLOCKS_IN_AN_MINUTE).into(),
democracy_cooloff_period: (5 * BLOCKS_IN_AN_MINUTE).into(),
democracy_enactment_period: (15 * BLOCKS_IN_AN_MINUTE).into(),
democracy_fast_track_voting_period: (5 * BLOCKS_IN_AN_MINUTE).into(),
democracy_launch_period: (15 * BLOCKS_IN_AN_MINUTE).into(),
democracy_vote_locking_period: BLOCKS_IN_AN_MINUTE.into(),
democracy_voting_period: (15 * BLOCKS_IN_AN_MINUTE).into(),
}
}
}

/// A trait for determining whether rewards are enabled or not
pub trait RewardsEnabled {
/// Determine whether rewards are enabled or not
Expand Down
Loading

0 comments on commit 4b3cc60

Please sign in to comment.