lib.rs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  1. //! The Joystream Substrate Node runtime.
  2. #![cfg_attr(not(feature = "std"), no_std)]
  3. // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
  4. #![recursion_limit = "256"]
  5. //Substrate internal issues.
  6. #![allow(clippy::large_enum_variant)]
  7. #![allow(clippy::unnecessary_mut_passed)]
  8. #![allow(non_fmt_panic)]
  9. #![allow(clippy::from_over_into)]
  10. // Mutually exclusive feature check
  11. #[cfg(all(feature = "staging_runtime", feature = "testing_runtime"))]
  12. compile_error!("feature \"staging_runtime\" and feature \"testing_runtime\" cannot be enabled at the same time");
  13. // Make the WASM binary available.
  14. // This is required only by the node build.
  15. // A dummy wasm_binary.rs will be built for the IDE.
  16. #[cfg(feature = "std")]
  17. include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
  18. #[cfg(feature = "std")]
  19. /// Wasm binary unwrapped. If built with `BUILD_DUMMY_WASM_BINARY`, the function panics.
  20. pub fn wasm_binary_unwrap() -> &'static [u8] {
  21. WASM_BINARY.expect(
  22. "Development wasm binary is not available. This means the client is \
  23. built with `BUILD_DUMMY_WASM_BINARY` flag and it is only usable for \
  24. production chains. Please rebuild with the flag disabled.",
  25. )
  26. }
  27. pub mod constants;
  28. mod integration;
  29. pub mod primitives;
  30. mod proposals_configuration;
  31. mod runtime_api;
  32. #[cfg(test)]
  33. mod tests;
  34. /// Weights for pallets used in the runtime.
  35. mod weights; // Runtime integration tests
  36. #[macro_use]
  37. extern crate lazy_static; // for proposals_configuration module
  38. use frame_support::traits::{Currency, KeyOwnerProofSystem, LockIdentifier, OnUnbalanced};
  39. use frame_support::weights::{
  40. constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},
  41. Weight,
  42. };
  43. use frame_support::weights::{WeightToFeeCoefficients, WeightToFeePolynomial};
  44. use frame_support::{construct_runtime, parameter_types};
  45. use frame_system::{EnsureOneOf, EnsureRoot, EnsureSigned};
  46. use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
  47. use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
  48. use pallet_session::historical as pallet_session_historical;
  49. use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
  50. use sp_core::crypto::KeyTypeId;
  51. use sp_core::Hasher;
  52. use sp_runtime::curve::PiecewiseLinear;
  53. use sp_runtime::traits::{BlakeTwo256, Block as BlockT, IdentityLookup, OpaqueKeys, Saturating};
  54. use sp_runtime::{create_runtime_str, generic, impl_opaque_keys, ModuleId, Perbill};
  55. use sp_std::boxed::Box;
  56. use sp_std::vec::Vec;
  57. #[cfg(feature = "std")]
  58. use sp_version::NativeVersion;
  59. use sp_version::RuntimeVersion;
  60. pub use constants::*;
  61. pub use primitives::*;
  62. pub use proposals_configuration::*;
  63. pub use runtime_api::*;
  64. use integration::proposals::{CouncilManager, ExtrinsicProposalEncoder};
  65. use common::working_group::{WorkingGroup, WorkingGroupBudgetHandler};
  66. use council::ReferendumConnection;
  67. use referendum::{CastVote, OptionResult};
  68. use staking_handler::{LockComparator, StakingManager};
  69. // Node dependencies
  70. pub use common;
  71. pub use council;
  72. pub use forum;
  73. pub use membership;
  74. #[cfg(any(feature = "std", test))]
  75. pub use pallet_balances::Call as BalancesCall;
  76. pub use pallet_staking::StakerStatus;
  77. pub use proposals_engine::ProposalParameters;
  78. pub use referendum;
  79. pub use working_group;
  80. pub use content;
  81. pub use content::MaxNumber;
  82. /// This runtime version.
  83. pub const VERSION: RuntimeVersion = RuntimeVersion {
  84. #[cfg(not(any(feature = "staging_runtime", feature = "testing_runtime")))]
  85. spec_name: create_runtime_str!("joystream-node"),
  86. #[cfg(feature = "staging_runtime")]
  87. spec_name: create_runtime_str!("joystream-node-staging"),
  88. #[cfg(feature = "testing_runtime")]
  89. spec_name: create_runtime_str!("joystream-node-testing"),
  90. impl_name: create_runtime_str!("joystream-node"),
  91. authoring_version: 10,
  92. spec_version: 4,
  93. impl_version: 0,
  94. apis: crate::runtime_api::EXPORTED_RUNTIME_API_VERSIONS,
  95. transaction_version: 1,
  96. };
  97. /// The version information used to identify this runtime when compiled natively.
  98. #[cfg(feature = "std")]
  99. pub fn native_version() -> NativeVersion {
  100. NativeVersion {
  101. runtime_version: VERSION,
  102. can_author_with: Default::default(),
  103. }
  104. }
  105. parameter_types! {
  106. pub const BlockHashCount: BlockNumber = 250;
  107. /// We allow for 2 seconds of compute with a 6 second average block time.
  108. pub const MaximumBlockWeight: Weight = 2 * frame_support::weights::constants::WEIGHT_PER_SECOND;
  109. pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
  110. pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
  111. pub const Version: RuntimeVersion = VERSION;
  112. /// Assume 10% of weight for average on_initialize calls.
  113. pub MaximumExtrinsicWeight: Weight =
  114. AvailableBlockRatio::get().saturating_sub(AVERAGE_ON_INITIALIZE_WEIGHT)
  115. * MaximumBlockWeight::get();
  116. }
  117. const AVERAGE_ON_INITIALIZE_WEIGHT: Perbill = Perbill::from_percent(10);
  118. // TODO: We need to adjust weight of this pallet
  119. // once we move to a newer version of substrate where parameters
  120. // are not discarded. See the comment in 'scripts/generate-weights.sh'
  121. impl frame_system::Trait for Runtime {
  122. type BaseCallFilter = ();
  123. type Origin = Origin;
  124. type Call = Call;
  125. type Index = Index;
  126. type BlockNumber = BlockNumber;
  127. type Hash = Hash;
  128. type Hashing = BlakeTwo256;
  129. type AccountId = AccountId;
  130. type Lookup = IdentityLookup<AccountId>;
  131. type Header = generic::Header<BlockNumber, BlakeTwo256>;
  132. type Event = Event;
  133. type BlockHashCount = BlockHashCount;
  134. type MaximumBlockWeight = MaximumBlockWeight;
  135. type DbWeight = RocksDbWeight;
  136. type BlockExecutionWeight = BlockExecutionWeight;
  137. type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
  138. type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
  139. type MaximumBlockLength = MaximumBlockLength;
  140. type AvailableBlockRatio = AvailableBlockRatio;
  141. type Version = Version;
  142. type PalletInfo = PalletInfo;
  143. type AccountData = pallet_balances::AccountData<Balance>;
  144. type OnNewAccount = ();
  145. type OnKilledAccount = ();
  146. type SystemWeightInfo = weights::frame_system::WeightInfo;
  147. }
  148. impl substrate_utility::Trait for Runtime {
  149. type Event = Event;
  150. type Call = Call;
  151. type WeightInfo = weights::substrate_utility::WeightInfo;
  152. }
  153. parameter_types! {
  154. pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS as u64;
  155. pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
  156. }
  157. impl pallet_babe::Trait for Runtime {
  158. type EpochDuration = EpochDuration;
  159. type ExpectedBlockTime = ExpectedBlockTime;
  160. type EpochChangeTrigger = pallet_babe::ExternalTrigger;
  161. type KeyOwnerProofSystem = Historical;
  162. type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
  163. KeyTypeId,
  164. pallet_babe::AuthorityId,
  165. )>>::Proof;
  166. type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
  167. KeyTypeId,
  168. pallet_babe::AuthorityId,
  169. )>>::IdentificationTuple;
  170. type HandleEquivocation =
  171. pallet_babe::EquivocationHandler<Self::KeyOwnerIdentification, Offences>;
  172. type WeightInfo = ();
  173. }
  174. impl pallet_grandpa::Trait for Runtime {
  175. type Event = Event;
  176. type Call = Call;
  177. type KeyOwnerProof =
  178. <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
  179. type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
  180. KeyTypeId,
  181. GrandpaId,
  182. )>>::IdentificationTuple;
  183. type KeyOwnerProofSystem = Historical;
  184. type HandleEquivocation =
  185. pallet_grandpa::EquivocationHandler<Self::KeyOwnerIdentification, Offences>;
  186. type WeightInfo = ();
  187. }
  188. impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime
  189. where
  190. Call: From<LocalCall>,
  191. {
  192. fn create_transaction<C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>>(
  193. call: Call,
  194. public: <Signature as sp_runtime::traits::Verify>::Signer,
  195. account: AccountId,
  196. nonce: Index,
  197. ) -> Option<(
  198. Call,
  199. <UncheckedExtrinsic as sp_runtime::traits::Extrinsic>::SignaturePayload,
  200. )> {
  201. integration::transactions::create_transaction::<C>(call, public, account, nonce)
  202. }
  203. }
  204. impl frame_system::offchain::SigningTypes for Runtime {
  205. type Public = <Signature as sp_runtime::traits::Verify>::Signer;
  206. type Signature = Signature;
  207. }
  208. impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
  209. where
  210. Call: From<C>,
  211. {
  212. type Extrinsic = UncheckedExtrinsic;
  213. type OverarchingCall = Call;
  214. }
  215. parameter_types! {
  216. pub const MinimumPeriod: Moment = SLOT_DURATION / 2;
  217. }
  218. impl pallet_timestamp::Trait for Runtime {
  219. type Moment = Moment;
  220. type OnTimestampSet = Babe;
  221. type MinimumPeriod = MinimumPeriod;
  222. type WeightInfo = weights::pallet_timestamp::WeightInfo;
  223. }
  224. parameter_types! {
  225. pub const MaxLocks: u32 = 50;
  226. }
  227. impl pallet_balances::Trait for Runtime {
  228. type Balance = Balance;
  229. type DustRemoval = ();
  230. type Event = Event;
  231. type ExistentialDeposit = ExistentialDeposit;
  232. type AccountStore = System;
  233. type WeightInfo = weights::pallet_balances::WeightInfo;
  234. type MaxLocks = MaxLocks;
  235. }
  236. parameter_types! {
  237. pub const TransactionByteFee: Balance = 0;
  238. }
  239. // Temporary commented for Olympia: https://github.com/Joystream/joystream/issues/3237
  240. // TODO: Restore after the Olympia release
  241. // parameter_types! {
  242. // pub const TransactionByteFee: Balance = 1;
  243. // }
  244. type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
  245. pub struct Author;
  246. impl OnUnbalanced<NegativeImbalance> for Author {
  247. fn on_nonzero_unbalanced(amount: NegativeImbalance) {
  248. Balances::resolve_creating(&Authorship::author(), amount);
  249. }
  250. }
  251. // Temporary commented for Olympia: https://github.com/Joystream/joystream/issues/3237
  252. // TODO: Restore after the Olympia release
  253. // pub struct DealWithFees;
  254. // impl OnUnbalanced<NegativeImbalance> for DealWithFees {
  255. // fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {
  256. // if let Some(fees) = fees_then_tips.next() {
  257. // // for fees, 20% to author, for now we don't have treasury so the 80% is ignored
  258. // let mut split = fees.ration(80, 20);
  259. // if let Some(tips) = fees_then_tips.next() {
  260. // // For tips %100 are for the author
  261. // tips.ration_merge_into(0, 100, &mut split);
  262. // }
  263. // Author::on_unbalanced(split.1);
  264. // }
  265. // }
  266. // }
  267. /// Stub for zero transaction weights.
  268. pub struct NoWeights;
  269. impl WeightToFeePolynomial for NoWeights {
  270. type Balance = Balance;
  271. fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
  272. Default::default()
  273. }
  274. fn calc(_weight: &u64) -> Self::Balance {
  275. Default::default()
  276. }
  277. }
  278. impl pallet_transaction_payment::Trait for Runtime {
  279. type Currency = Balances;
  280. type OnTransactionPayment = ();
  281. type TransactionByteFee = TransactionByteFee;
  282. type WeightToFee = NoWeights;
  283. type FeeMultiplierUpdate = ();
  284. }
  285. // Temporary commented for Olympia: https://github.com/Joystream/joystream/issues/3237
  286. // TODO: Restore after the Olympia release
  287. // impl pallet_transaction_payment::Trait for Runtime {
  288. // type Currency = Balances;
  289. // type OnTransactionPayment = DealWithFees;
  290. // type TransactionByteFee = TransactionByteFee;
  291. // type WeightToFee = constants::fees::WeightToFee;
  292. // type FeeMultiplierUpdate = constants::fees::SlowAdjustingFeeUpdate<Self>;
  293. // }
  294. impl pallet_sudo::Trait for Runtime {
  295. type Event = Event;
  296. type Call = Call;
  297. }
  298. parameter_types! {
  299. pub const UncleGenerations: BlockNumber = 0;
  300. }
  301. impl pallet_authorship::Trait for Runtime {
  302. type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
  303. type UncleGenerations = UncleGenerations;
  304. type FilterUncle = ();
  305. type EventHandler = (Staking, ImOnline);
  306. }
  307. impl_opaque_keys! {
  308. pub struct SessionKeys {
  309. pub grandpa: Grandpa,
  310. pub babe: Babe,
  311. pub im_online: ImOnline,
  312. pub authority_discovery: AuthorityDiscovery,
  313. }
  314. }
  315. // NOTE: `SessionHandler` and `SessionKeys` are co-dependent: One key will be used for each handler.
  316. // The number and order of items in `SessionHandler` *MUST* be the same number and order of keys in
  317. // `SessionKeys`.
  318. // TODO: Introduce some structure to tie these together to make it a bit less of a footgun. This
  319. // should be easy, since OneSessionHandler trait provides the `Key` as an associated type. #2858
  320. parameter_types! {
  321. pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
  322. }
  323. impl pallet_session::Trait for Runtime {
  324. type Event = Event;
  325. type ValidatorId = AccountId;
  326. type ValidatorIdOf = pallet_staking::StashOf<Self>;
  327. type ShouldEndSession = Babe;
  328. type NextSessionRotation = Babe;
  329. type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, Staking>;
  330. type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
  331. type Keys = SessionKeys;
  332. type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
  333. type WeightInfo = weights::pallet_session::WeightInfo;
  334. }
  335. impl pallet_session::historical::Trait for Runtime {
  336. type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
  337. type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
  338. }
  339. pallet_staking_reward_curve::build! {
  340. const REWARD_CURVE: PiecewiseLinear<'static> = curve!(
  341. min_inflation: 0_050_000,
  342. max_inflation: 0_750_000,
  343. ideal_stake: 0_300_000,
  344. falloff: 0_050_000,
  345. max_piece_count: 100,
  346. test_precision: 0_005_000,
  347. );
  348. }
  349. parameter_types! {
  350. pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_SLOTS as _;
  351. pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
  352. /// We prioritize im-online heartbeats over election solution submission.
  353. pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2;
  354. }
  355. parameter_types! {
  356. pub const SessionsPerEra: sp_staking::SessionIndex = 6;
  357. pub const BondingDuration: pallet_staking::EraIndex = BONDING_DURATION;
  358. pub const SlashDeferDuration: pallet_staking::EraIndex = BONDING_DURATION - 1; // 'slightly less' than the bonding duration.
  359. pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
  360. pub const MaxNominatorRewardedPerValidator: u32 = 64;
  361. pub const ElectionLookahead: BlockNumber = EPOCH_DURATION_IN_BLOCKS / 4;
  362. pub const MaxIterations: u32 = 10;
  363. // 0.05%. The higher the value, the more strict solution acceptance becomes.
  364. pub MinSolutionScoreBump: Perbill = Perbill::from_rational_approximation(5u32, 10_000);
  365. }
  366. impl pallet_staking::Trait for Runtime {
  367. type Currency = Balances;
  368. type UnixTime = Timestamp;
  369. type CurrencyToVote = CurrencyToVoteHandler;
  370. type RewardRemainder = (); // Could be Treasury.
  371. type Event = Event;
  372. type Slash = (); // Where to send the slashed funds. Could be Treasury.
  373. type Reward = (); // Rewards are minted from the void.
  374. type SessionsPerEra = SessionsPerEra;
  375. type BondingDuration = BondingDuration;
  376. type SlashDeferDuration = SlashDeferDuration;
  377. type SlashCancelOrigin = EnsureRoot<AccountId>; // Requires sudo. Parity recommends: a super-majority of the council can cancel the slash.
  378. type SessionInterface = Self;
  379. type RewardCurve = RewardCurve;
  380. type NextNewSession = Session;
  381. type ElectionLookahead = ElectionLookahead;
  382. type Call = Call;
  383. type MaxIterations = MaxIterations;
  384. type MinSolutionScoreBump = MinSolutionScoreBump;
  385. type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
  386. type UnsignedPriority = StakingUnsignedPriority;
  387. type WeightInfo = weights::pallet_staking::WeightInfo;
  388. }
  389. impl pallet_im_online::Trait for Runtime {
  390. type AuthorityId = ImOnlineId;
  391. type Event = Event;
  392. type SessionDuration = SessionDuration;
  393. type ReportUnresponsiveness = Offences;
  394. // Using the default weights until we check if we can run the benchmarks for this pallet in
  395. // the reference machine in an acceptable time.
  396. type WeightInfo = ();
  397. type UnsignedPriority = ImOnlineUnsignedPriority;
  398. }
  399. parameter_types! {
  400. pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
  401. }
  402. impl pallet_offences::Trait for Runtime {
  403. type Event = Event;
  404. type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
  405. type OnOffenceHandler = Staking;
  406. type WeightSoftLimit = OffencesWeightSoftLimit;
  407. }
  408. impl pallet_authority_discovery::Trait for Runtime {}
  409. parameter_types! {
  410. pub const WindowSize: BlockNumber = 101;
  411. pub const ReportLatency: BlockNumber = 1000;
  412. }
  413. impl pallet_finality_tracker::Trait for Runtime {
  414. type OnFinalizationStalled = ();
  415. type WindowSize = WindowSize;
  416. type ReportLatency = ReportLatency;
  417. }
  418. impl common::currency::GovernanceCurrency for Runtime {
  419. type Currency = pallet_balances::Module<Self>;
  420. }
  421. parameter_types! {
  422. pub const MaxNumberOfCuratorsPerGroup: MaxNumber = 50;
  423. pub const MaxModerators: u64 = 5; // TODO: update
  424. pub const CleanupMargin: u32 = 3; // TODO: update
  425. pub const CleanupCost: u32 = 1; // TODO: update
  426. pub const PricePerByte: u32 = 2; // TODO: update
  427. pub const ContentModuleId: ModuleId = ModuleId(*b"mContent"); // module content
  428. pub const BloatBondCap: u32 = 1000; // TODO: update
  429. }
  430. impl content::Trait for Runtime {
  431. type Event = Event;
  432. type ChannelCategoryId = ChannelCategoryId;
  433. type VideoId = VideoId;
  434. type VideoCategoryId = VideoCategoryId;
  435. type MaxNumberOfCuratorsPerGroup = MaxNumberOfCuratorsPerGroup;
  436. type DataObjectStorage = Storage;
  437. type VideoPostId = VideoPostId;
  438. type ReactionId = ReactionId;
  439. type MaxModerators = MaxModerators;
  440. type PricePerByte = PricePerByte;
  441. type BloatBondCap = BloatBondCap;
  442. type CleanupMargin = CleanupMargin;
  443. type CleanupCost = CleanupCost;
  444. type ModuleId = ContentModuleId;
  445. }
  446. // The referendum instance alias.
  447. pub type ReferendumInstance = referendum::Instance1;
  448. pub type ReferendumModule = referendum::Module<Runtime, ReferendumInstance>;
  449. pub type CouncilModule = council::Module<Runtime>;
  450. // Production coucil and elections configuration
  451. #[cfg(not(any(feature = "staging_runtime", feature = "testing_runtime")))]
  452. parameter_types! {
  453. // referendum parameters
  454. pub const MaxSaltLength: u64 = 32;
  455. pub const VoteStageDuration: BlockNumber = 14400;
  456. pub const RevealStageDuration: BlockNumber = 14400;
  457. pub const MinimumVotingStake: u64 = 10000;
  458. // council parameteres
  459. pub const MinNumberOfExtraCandidates: u64 = 0;
  460. pub const AnnouncingPeriodDuration: BlockNumber = 14400;
  461. pub const IdlePeriodDuration: BlockNumber = 57600;
  462. pub const CouncilSize: u64 = 12;
  463. pub const MinCandidateStake: u64 = 1000;
  464. pub const ElectedMemberRewardPeriod: BlockNumber = 14400;
  465. pub const DefaultBudgetIncrement: u64 = 5000000;
  466. pub const BudgetRefillPeriod: BlockNumber = 14400;
  467. pub const MaxWinnerTargetCount: u64 = 15; // should be greater than council size
  468. }
  469. // Common staging and testing coucil and elections configuration
  470. #[cfg(any(feature = "staging_runtime", feature = "testing_runtime"))]
  471. parameter_types! {
  472. // referendum parameters
  473. pub const MaxSaltLength: u64 = 32;
  474. pub const VoteStageDuration: BlockNumber = 100;
  475. pub const RevealStageDuration: BlockNumber = 50;
  476. pub const MinimumVotingStake: u64 = 10000;
  477. // council parameteres
  478. pub const MinNumberOfExtraCandidates: u64 = 1;
  479. pub const AnnouncingPeriodDuration: BlockNumber = 200;
  480. pub const IdlePeriodDuration: BlockNumber = 400;
  481. pub const MinCandidateStake: u64 = 1000;
  482. pub const ElectedMemberRewardPeriod: BlockNumber = 14400;
  483. pub const DefaultBudgetIncrement: u64 = 10000000;
  484. pub const BudgetRefillPeriod: BlockNumber = 1000;
  485. pub const MaxWinnerTargetCount: u64 = 10;
  486. }
  487. // Staging network council size
  488. #[cfg(feature = "staging_runtime")]
  489. #[cfg(not(feature = "playground_runtime"))]
  490. parameter_types! {
  491. pub const CouncilSize: u64 = 5;
  492. }
  493. // Staging but customized for playground council size
  494. #[cfg(feature = "staging_runtime")]
  495. #[cfg(feature = "playground_runtime")]
  496. parameter_types! {
  497. pub const CouncilSize: u64 = 1;
  498. }
  499. // Testing council size
  500. #[cfg(feature = "testing_runtime")]
  501. parameter_types! {
  502. pub const CouncilSize: u64 = 5;
  503. }
  504. impl referendum::Trait<ReferendumInstance> for Runtime {
  505. type Event = Event;
  506. type MaxSaltLength = MaxSaltLength;
  507. type StakingHandler = VotingStakingManager;
  508. type ManagerOrigin =
  509. EnsureOneOf<Self::AccountId, EnsureSigned<Self::AccountId>, EnsureRoot<Self::AccountId>>;
  510. type VotePower = Balance;
  511. type VoteStageDuration = VoteStageDuration;
  512. type RevealStageDuration = RevealStageDuration;
  513. type MinimumStake = MinimumVotingStake;
  514. type WeightInfo = weights::referendum::WeightInfo;
  515. type MaxWinnerTargetCount = MaxWinnerTargetCount;
  516. fn calculate_vote_power(
  517. _account_id: &<Self as frame_system::Trait>::AccountId,
  518. stake: &Balance,
  519. ) -> Self::VotePower {
  520. *stake
  521. }
  522. fn can_unlock_vote_stake(vote: &CastVote<Self::Hash, Balance, Self::MemberId>) -> bool {
  523. <CouncilModule as ReferendumConnection<Runtime>>::can_unlock_vote_stake(vote).is_ok()
  524. }
  525. fn process_results(winners: &[OptionResult<Self::MemberId, Self::VotePower>]) {
  526. let tmp_winners: Vec<OptionResult<Self::MemberId, Self::VotePower>> = winners
  527. .iter()
  528. .map(|item| OptionResult {
  529. option_id: item.option_id,
  530. vote_power: item.vote_power,
  531. })
  532. .collect();
  533. <CouncilModule as ReferendumConnection<Runtime>>::recieve_referendum_results(
  534. tmp_winners.as_slice(),
  535. );
  536. }
  537. fn is_valid_option_id(option_index: &u64) -> bool {
  538. <CouncilModule as ReferendumConnection<Runtime>>::is_valid_candidate_id(option_index)
  539. }
  540. fn get_option_power(option_id: &u64) -> Self::VotePower {
  541. <CouncilModule as ReferendumConnection<Runtime>>::get_option_power(option_id)
  542. }
  543. fn increase_option_power(option_id: &u64, amount: &Self::VotePower) {
  544. <CouncilModule as ReferendumConnection<Runtime>>::increase_option_power(option_id, amount);
  545. }
  546. }
  547. impl council::Trait for Runtime {
  548. type Event = Event;
  549. type Referendum = ReferendumModule;
  550. type MinNumberOfExtraCandidates = MinNumberOfExtraCandidates;
  551. type CouncilSize = CouncilSize;
  552. type AnnouncingPeriodDuration = AnnouncingPeriodDuration;
  553. type IdlePeriodDuration = IdlePeriodDuration;
  554. type MinCandidateStake = MinCandidateStake;
  555. type CandidacyLock = StakingManager<Self, CandidacyLockId>;
  556. type CouncilorLock = StakingManager<Self, CouncilorLockId>;
  557. type StakingAccountValidator = Members;
  558. type ElectedMemberRewardPeriod = ElectedMemberRewardPeriod;
  559. type BudgetRefillPeriod = BudgetRefillPeriod;
  560. type MemberOriginValidator = Members;
  561. type WeightInfo = weights::council::WeightInfo;
  562. fn new_council_elected(_elected_members: &[council::CouncilMemberOf<Self>]) {
  563. <proposals_engine::Module<Runtime>>::reject_active_proposals();
  564. <proposals_engine::Module<Runtime>>::reactivate_pending_constitutionality_proposals();
  565. }
  566. }
  567. impl common::StorageOwnership for Runtime {
  568. type ChannelId = ChannelId;
  569. type ContentId = ContentId;
  570. type DataObjectTypeId = DataObjectTypeId;
  571. }
  572. parameter_types! {
  573. pub const MaxDistributionBucketFamilyNumber: u64 = 200;
  574. pub const DataObjectDeletionPrize: Balance = 0; //TODO: Change during Olympia release
  575. pub const BlacklistSizeLimit: u64 = 10000; //TODO: adjust value
  576. pub const MaxRandomIterationNumber: u64 = 10; //TODO: adjust value
  577. pub const MaxNumberOfPendingInvitationsPerDistributionBucket: u64 = 20; //TODO: adjust value
  578. pub const StorageModuleId: ModuleId = ModuleId(*b"mstorage"); // module storage
  579. pub const StorageBucketsPerBagValueConstraint: storage::StorageBucketsPerBagValueConstraint =
  580. storage::StorageBucketsPerBagValueConstraint {min: 5, max_min_diff: 15}; //TODO: adjust value
  581. pub const DefaultMemberDynamicBagNumberOfStorageBuckets: u64 = 5; //TODO: adjust value
  582. pub const DefaultChannelDynamicBagNumberOfStorageBuckets: u64 = 5; //TODO: adjust value
  583. pub const DistributionBucketsPerBagValueConstraint: storage::DistributionBucketsPerBagValueConstraint =
  584. storage::DistributionBucketsPerBagValueConstraint {min: 1, max_min_diff: 100}; //TODO: adjust value
  585. pub const MaxDataObjectSize: u64 = 10 * 1024 * 1024 * 1024; // 10 GB
  586. }
  587. impl storage::Trait for Runtime {
  588. type Event = Event;
  589. type DataObjectId = DataObjectId;
  590. type StorageBucketId = StorageBucketId;
  591. type DistributionBucketIndex = DistributionBucketIndex;
  592. type DistributionBucketFamilyId = DistributionBucketFamilyId;
  593. type ChannelId = ChannelId;
  594. type DataObjectDeletionPrize = DataObjectDeletionPrize;
  595. type BlacklistSizeLimit = BlacklistSizeLimit;
  596. type ModuleId = StorageModuleId;
  597. type StorageBucketsPerBagValueConstraint = StorageBucketsPerBagValueConstraint;
  598. type DefaultMemberDynamicBagNumberOfStorageBuckets =
  599. DefaultMemberDynamicBagNumberOfStorageBuckets;
  600. type DefaultChannelDynamicBagNumberOfStorageBuckets =
  601. DefaultChannelDynamicBagNumberOfStorageBuckets;
  602. type Randomness = RandomnessCollectiveFlip;
  603. type MaxRandomIterationNumber = MaxRandomIterationNumber;
  604. type MaxDistributionBucketFamilyNumber = MaxDistributionBucketFamilyNumber;
  605. type DistributionBucketsPerBagValueConstraint = DistributionBucketsPerBagValueConstraint;
  606. type DistributionBucketOperatorId = DistributionBucketOperatorId;
  607. type MaxNumberOfPendingInvitationsPerDistributionBucket =
  608. MaxNumberOfPendingInvitationsPerDistributionBucket;
  609. type MaxDataObjectSize = MaxDataObjectSize;
  610. type ContentId = ContentId;
  611. type StorageWorkingGroup = StorageWorkingGroup;
  612. type DistributionWorkingGroup = DistributionWorkingGroup;
  613. }
  614. impl common::membership::MembershipTypes for Runtime {
  615. type MemberId = MemberId;
  616. type ActorId = ActorId;
  617. }
  618. parameter_types! {
  619. pub const DefaultMembershipPrice: Balance = 100;
  620. pub const ReferralCutMaximumPercent: u8 = 50;
  621. pub const DefaultInitialInvitationBalance: Balance = 100;
  622. // The candidate stake should be more than the transaction fee which currently is 53
  623. pub const CandidateStake: Balance = 200;
  624. }
  625. impl membership::Trait for Runtime {
  626. type Event = Event;
  627. type DefaultMembershipPrice = DefaultMembershipPrice;
  628. type DefaultInitialInvitationBalance = DefaultInitialInvitationBalance;
  629. type InvitedMemberStakingHandler = InvitedMemberStakingManager;
  630. type StakingCandidateStakingHandler = BoundStakingAccountStakingManager;
  631. type WorkingGroup = MembershipWorkingGroup;
  632. type WeightInfo = weights::membership::WeightInfo;
  633. type ReferralCutMaximumPercent = ReferralCutMaximumPercent;
  634. type CandidateStake = CandidateStake;
  635. }
  636. parameter_types! {
  637. pub const MaxCategoryDepth: u64 = 6;
  638. pub const MaxSubcategories: u64 = 20;
  639. pub const MaxThreadsInCategory: u64 = 20;
  640. pub const MaxPostsInThread: u64 = 20;
  641. pub const MaxModeratorsForCategory: u64 = 20;
  642. pub const MaxCategories: u64 = 20;
  643. pub const MaxPollAlternativesNumber: u64 = 20;
  644. pub const ThreadDeposit: u64 = 30;
  645. pub const PostDeposit: u64 = 10;
  646. pub const ForumModuleId: ModuleId = ModuleId(*b"mo:forum"); // module : forum
  647. pub const PostLifeTime: BlockNumber = 3600;
  648. }
  649. pub struct MapLimits;
  650. impl forum::StorageLimits for MapLimits {
  651. type MaxSubcategories = MaxSubcategories;
  652. type MaxModeratorsForCategory = MaxModeratorsForCategory;
  653. type MaxCategories = MaxCategories;
  654. type MaxPollAlternativesNumber = MaxPollAlternativesNumber;
  655. }
  656. impl forum::Trait for Runtime {
  657. type Event = Event;
  658. type ThreadId = ThreadId;
  659. type PostId = PostId;
  660. type CategoryId = u64;
  661. type PostReactionId = u64;
  662. type MaxCategoryDepth = MaxCategoryDepth;
  663. type ThreadDeposit = ThreadDeposit;
  664. type PostDeposit = PostDeposit;
  665. type ModuleId = ForumModuleId;
  666. type MapLimits = MapLimits;
  667. type WeightInfo = weights::forum::WeightInfo;
  668. type WorkingGroup = ForumWorkingGroup;
  669. type MemberOriginValidator = Members;
  670. type PostLifeTime = PostLifeTime;
  671. fn calculate_hash(text: &[u8]) -> Self::Hash {
  672. Self::Hashing::hash(text)
  673. }
  674. }
  675. impl LockComparator<<Runtime as pallet_balances::Trait>::Balance> for Runtime {
  676. fn are_locks_conflicting(new_lock: &LockIdentifier, existing_locks: &[LockIdentifier]) -> bool {
  677. let other_locks_present = !existing_locks.is_empty();
  678. let new_lock_is_rivalrous = !NON_RIVALROUS_LOCKS.contains(new_lock);
  679. let existing_locks_contain_rivalrous_lock = existing_locks
  680. .iter()
  681. .any(|lock_id| !NON_RIVALROUS_LOCKS.contains(lock_id));
  682. other_locks_present && new_lock_is_rivalrous && existing_locks_contain_rivalrous_lock
  683. }
  684. }
  685. parameter_types! {
  686. pub const MaxWorkerNumberLimit: u32 = 100;
  687. pub const MinUnstakingPeriodLimit: u32 = 43200;
  688. pub const ForumWorkingGroupRewardPeriod: u32 = 14400 + 10;
  689. pub const StorageWorkingGroupRewardPeriod: u32 = 14400 + 20;
  690. pub const ContentWorkingGroupRewardPeriod: u32 = 14400 + 30;
  691. pub const MembershipRewardPeriod: u32 = 14400 + 40;
  692. pub const GatewayRewardPeriod: u32 = 14400 + 50;
  693. pub const OperationsAlphaRewardPeriod: u32 = 14400 + 60;
  694. pub const OperationsBetaRewardPeriod: u32 = 14400 + 70;
  695. pub const OperationsGammaRewardPeriod: u32 = 14400 + 80;
  696. pub const DistributionRewardPeriod: u32 = 14400 + 90;
  697. // This should be more costly than `apply_on_opening` fee with the current configuration
  698. // the base cost of `apply_on_opening` in tokens is 193. And has a very slight slope
  699. // with the lenght with the length of rationale, with 2000 stake we are probably safe.
  700. pub const MinimumApplicationStake: Balance = 2000;
  701. // This should be more costly than `add_opening` fee with the current configuration
  702. // the base cost of `add_opening` in tokens is 81. And has a very slight slope
  703. // with the lenght with the length of rationale, with 2000 stake we are probably safe.
  704. pub const LeaderOpeningStake: Balance = 2000;
  705. }
  706. // Staking managers type aliases.
  707. pub type ForumWorkingGroupStakingManager =
  708. staking_handler::StakingManager<Runtime, ForumGroupLockId>;
  709. pub type VotingStakingManager = staking_handler::StakingManager<Runtime, VotingLockId>;
  710. pub type ContentWorkingGroupStakingManager =
  711. staking_handler::StakingManager<Runtime, ContentWorkingGroupLockId>;
  712. pub type StorageWorkingGroupStakingManager =
  713. staking_handler::StakingManager<Runtime, StorageWorkingGroupLockId>;
  714. pub type MembershipWorkingGroupStakingManager =
  715. staking_handler::StakingManager<Runtime, MembershipWorkingGroupLockId>;
  716. pub type InvitedMemberStakingManager =
  717. staking_handler::StakingManager<Runtime, InvitedMemberLockId>;
  718. pub type BoundStakingAccountStakingManager =
  719. staking_handler::StakingManager<Runtime, BoundStakingAccountLockId>;
  720. pub type GatewayWorkingGroupStakingManager =
  721. staking_handler::StakingManager<Runtime, GatewayWorkingGroupLockId>;
  722. pub type OperationsWorkingGroupAlphaStakingManager =
  723. staking_handler::StakingManager<Runtime, OperationsWorkingGroupAlphaLockId>;
  724. pub type OperationsWorkingGroupBetaStakingManager =
  725. staking_handler::StakingManager<Runtime, OperationsWorkingGroupBetaLockId>;
  726. pub type OperationsWorkingGroupGammaStakingManager =
  727. staking_handler::StakingManager<Runtime, OperationsWorkingGroupGammaLockId>;
  728. pub type DistributionWorkingGroupStakingManager =
  729. staking_handler::StakingManager<Runtime, DistributionWorkingGroupLockId>;
  730. // The forum working group instance alias.
  731. pub type ForumWorkingGroupInstance = working_group::Instance1;
  732. // The storage working group instance alias.
  733. pub type StorageWorkingGroupInstance = working_group::Instance2;
  734. // The content directory working group instance alias.
  735. pub type ContentWorkingGroupInstance = working_group::Instance3;
  736. // The builder working group instance alias.
  737. pub type OperationsWorkingGroupInstanceAlpha = working_group::Instance4;
  738. // The gateway working group instance alias.
  739. pub type GatewayWorkingGroupInstance = working_group::Instance5;
  740. // The membership working group instance alias.
  741. pub type MembershipWorkingGroupInstance = working_group::Instance6;
  742. // The builder working group instance alias.
  743. pub type OperationsWorkingGroupInstanceBeta = working_group::Instance7;
  744. // The builder working group instance alias.
  745. pub type OperationsWorkingGroupInstanceGamma = working_group::Instance8;
  746. // The distribution working group instance alias.
  747. pub type DistributionWorkingGroupInstance = working_group::Instance9;
  748. impl working_group::Trait<ForumWorkingGroupInstance> for Runtime {
  749. type Event = Event;
  750. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  751. type StakingHandler = ForumWorkingGroupStakingManager;
  752. type StakingAccountValidator = Members;
  753. type MemberOriginValidator = Members;
  754. type MinUnstakingPeriodLimit = MinUnstakingPeriodLimit;
  755. type RewardPeriod = ForumWorkingGroupRewardPeriod;
  756. type WeightInfo = weights::working_group::WeightInfo;
  757. type MinimumApplicationStake = MinimumApplicationStake;
  758. type LeaderOpeningStake = LeaderOpeningStake;
  759. }
  760. impl working_group::Trait<StorageWorkingGroupInstance> for Runtime {
  761. type Event = Event;
  762. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  763. type StakingHandler = StorageWorkingGroupStakingManager;
  764. type StakingAccountValidator = Members;
  765. type MemberOriginValidator = Members;
  766. type MinUnstakingPeriodLimit = MinUnstakingPeriodLimit;
  767. type RewardPeriod = StorageWorkingGroupRewardPeriod;
  768. type WeightInfo = weights::working_group::WeightInfo;
  769. type MinimumApplicationStake = MinimumApplicationStake;
  770. type LeaderOpeningStake = LeaderOpeningStake;
  771. }
  772. impl working_group::Trait<ContentWorkingGroupInstance> for Runtime {
  773. type Event = Event;
  774. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  775. type StakingHandler = ContentWorkingGroupStakingManager;
  776. type StakingAccountValidator = Members;
  777. type MemberOriginValidator = Members;
  778. type MinUnstakingPeriodLimit = MinUnstakingPeriodLimit;
  779. type RewardPeriod = ContentWorkingGroupRewardPeriod;
  780. type WeightInfo = weights::working_group::WeightInfo;
  781. type MinimumApplicationStake = MinimumApplicationStake;
  782. type LeaderOpeningStake = LeaderOpeningStake;
  783. }
  784. impl working_group::Trait<MembershipWorkingGroupInstance> for Runtime {
  785. type Event = Event;
  786. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  787. type StakingHandler = MembershipWorkingGroupStakingManager;
  788. type StakingAccountValidator = Members;
  789. type MemberOriginValidator = Members;
  790. type MinUnstakingPeriodLimit = MinUnstakingPeriodLimit;
  791. type RewardPeriod = MembershipRewardPeriod;
  792. type WeightInfo = weights::working_group::WeightInfo;
  793. type MinimumApplicationStake = MinimumApplicationStake;
  794. type LeaderOpeningStake = LeaderOpeningStake;
  795. }
  796. impl working_group::Trait<OperationsWorkingGroupInstanceAlpha> for Runtime {
  797. type Event = Event;
  798. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  799. type StakingHandler = OperationsWorkingGroupAlphaStakingManager;
  800. type StakingAccountValidator = Members;
  801. type MemberOriginValidator = Members;
  802. type MinUnstakingPeriodLimit = MinUnstakingPeriodLimit;
  803. type RewardPeriod = OperationsAlphaRewardPeriod;
  804. type WeightInfo = weights::working_group::WeightInfo;
  805. type MinimumApplicationStake = MinimumApplicationStake;
  806. type LeaderOpeningStake = LeaderOpeningStake;
  807. }
  808. impl working_group::Trait<GatewayWorkingGroupInstance> for Runtime {
  809. type Event = Event;
  810. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  811. type StakingHandler = GatewayWorkingGroupStakingManager;
  812. type StakingAccountValidator = Members;
  813. type MemberOriginValidator = Members;
  814. type MinUnstakingPeriodLimit = MinUnstakingPeriodLimit;
  815. type RewardPeriod = GatewayRewardPeriod;
  816. type WeightInfo = weights::working_group::WeightInfo;
  817. type MinimumApplicationStake = MinimumApplicationStake;
  818. type LeaderOpeningStake = LeaderOpeningStake;
  819. }
  820. impl working_group::Trait<OperationsWorkingGroupInstanceBeta> for Runtime {
  821. type Event = Event;
  822. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  823. type StakingHandler = OperationsWorkingGroupBetaStakingManager;
  824. type StakingAccountValidator = Members;
  825. type MemberOriginValidator = Members;
  826. type MinUnstakingPeriodLimit = MinUnstakingPeriodLimit;
  827. type RewardPeriod = OperationsBetaRewardPeriod;
  828. type WeightInfo = weights::working_group::WeightInfo;
  829. type MinimumApplicationStake = MinimumApplicationStake;
  830. type LeaderOpeningStake = LeaderOpeningStake;
  831. }
  832. impl working_group::Trait<OperationsWorkingGroupInstanceGamma> for Runtime {
  833. type Event = Event;
  834. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  835. type StakingHandler = OperationsWorkingGroupGammaStakingManager;
  836. type StakingAccountValidator = Members;
  837. type MemberOriginValidator = Members;
  838. type MinUnstakingPeriodLimit = MinUnstakingPeriodLimit;
  839. type RewardPeriod = OperationsGammaRewardPeriod;
  840. type WeightInfo = weights::working_group::WeightInfo;
  841. type MinimumApplicationStake = MinimumApplicationStake;
  842. type LeaderOpeningStake = LeaderOpeningStake;
  843. }
  844. impl working_group::Trait<DistributionWorkingGroupInstance> for Runtime {
  845. type Event = Event;
  846. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  847. type StakingHandler = DistributionWorkingGroupStakingManager;
  848. type StakingAccountValidator = Members;
  849. type MemberOriginValidator = Members;
  850. type MinUnstakingPeriodLimit = MinUnstakingPeriodLimit;
  851. type RewardPeriod = DistributionRewardPeriod;
  852. type WeightInfo = weights::working_group::WeightInfo;
  853. type MinimumApplicationStake = MinimumApplicationStake;
  854. type LeaderOpeningStake = LeaderOpeningStake;
  855. }
  856. parameter_types! {
  857. pub const ProposalCancellationFee: u64 = 10000;
  858. pub const ProposalRejectionFee: u64 = 5000;
  859. pub const ProposalTitleMaxLength: u32 = 40;
  860. pub const ProposalDescriptionMaxLength: u32 = 3000;
  861. pub const ProposalMaxActiveProposalLimit: u32 = 20;
  862. }
  863. impl proposals_engine::Trait for Runtime {
  864. type Event = Event;
  865. type ProposerOriginValidator = Members;
  866. type CouncilOriginValidator = Council;
  867. type TotalVotersCounter = CouncilManager<Self>;
  868. type ProposalId = u32;
  869. type StakingHandler = staking_handler::StakingManager<Self, ProposalsLockId>;
  870. type CancellationFee = ProposalCancellationFee;
  871. type RejectionFee = ProposalRejectionFee;
  872. type TitleMaxLength = ProposalTitleMaxLength;
  873. type DescriptionMaxLength = ProposalDescriptionMaxLength;
  874. type MaxActiveProposalLimit = ProposalMaxActiveProposalLimit;
  875. type DispatchableCallCode = Call;
  876. type ProposalObserver = ProposalsCodex;
  877. type WeightInfo = weights::proposals_engine::WeightInfo;
  878. type StakingAccountValidator = Members;
  879. }
  880. impl Default for Call {
  881. fn default() -> Self {
  882. panic!("shouldn't call default for Call");
  883. }
  884. }
  885. parameter_types! {
  886. pub const MaxWhiteListSize: u32 = 20;
  887. pub const ProposalsPostDeposit: Balance = 2000;
  888. // module : proposals_discussion
  889. pub const ProposalsDiscussionModuleId: ModuleId = ModuleId(*b"mo:prdis");
  890. pub const ForumPostLifeTime: BlockNumber = 3600;
  891. }
  892. macro_rules! call_wg {
  893. ($working_group:ident, $function:ident $(,$x:expr)*) => {{
  894. match $working_group {
  895. WorkingGroup::Content => <ContentWorkingGroup as WorkingGroupBudgetHandler<Runtime>>::$function($($x,)*),
  896. WorkingGroup::Storage => <StorageWorkingGroup as WorkingGroupBudgetHandler<Runtime>>::$function($($x,)*),
  897. WorkingGroup::Forum => <ForumWorkingGroup as WorkingGroupBudgetHandler<Runtime>>::$function($($x,)*),
  898. WorkingGroup::Membership => <MembershipWorkingGroup as WorkingGroupBudgetHandler<Runtime>>::$function($($x,)*),
  899. WorkingGroup::Gateway => <GatewayWorkingGroup as WorkingGroupBudgetHandler<Runtime>>::$function($($x,)*),
  900. WorkingGroup::Distribution => <DistributionWorkingGroup as WorkingGroupBudgetHandler<Runtime>>::$function($($x,)*),
  901. WorkingGroup::OperationsAlpha => <OperationsWorkingGroupAlpha as WorkingGroupBudgetHandler<Runtime>>::$function($($x,)*),
  902. WorkingGroup::OperationsBeta => <OperationsWorkingGroupBeta as WorkingGroupBudgetHandler<Runtime>>::$function($($x,)*),
  903. WorkingGroup::OperationsGamma => <OperationsWorkingGroupGamma as WorkingGroupBudgetHandler<Runtime>>::$function($($x,)*),
  904. }
  905. }};
  906. }
  907. impl proposals_discussion::Trait for Runtime {
  908. type Event = Event;
  909. type AuthorOriginValidator = Members;
  910. type CouncilOriginValidator = Council;
  911. type ThreadId = ThreadId;
  912. type PostId = PostId;
  913. type MaxWhiteListSize = MaxWhiteListSize;
  914. type WeightInfo = weights::proposals_discussion::WeightInfo;
  915. type PostDeposit = ProposalsPostDeposit;
  916. type ModuleId = ProposalsDiscussionModuleId;
  917. type PostLifeTime = ForumPostLifeTime;
  918. }
  919. impl joystream_utility::Trait for Runtime {
  920. type Event = Event;
  921. type WeightInfo = weights::joystream_utility::WeightInfo;
  922. fn get_working_group_budget(working_group: WorkingGroup) -> Balance {
  923. call_wg!(working_group, get_budget)
  924. }
  925. fn set_working_group_budget(working_group: WorkingGroup, budget: Balance) {
  926. call_wg!(working_group, set_budget, budget)
  927. }
  928. }
  929. parameter_types! {
  930. // Make sure to stay below MAX_BLOCK_SIZE of substrate consensus of ~4MB
  931. pub const RuntimeUpgradeWasmProposalMaxLength: u32 = 3_500_000;
  932. }
  933. impl proposals_codex::Trait for Runtime {
  934. type Event = Event;
  935. type MembershipOriginValidator = Members;
  936. type ProposalEncoder = ExtrinsicProposalEncoder;
  937. type SetMaxValidatorCountProposalParameters = SetMaxValidatorCountProposalParameters;
  938. type RuntimeUpgradeProposalParameters = RuntimeUpgradeProposalParameters;
  939. type SignalProposalParameters = SignalProposalParameters;
  940. type FundingRequestProposalParameters = FundingRequestProposalParameters;
  941. type CreateWorkingGroupLeadOpeningProposalParameters =
  942. CreateWorkingGroupLeadOpeningProposalParameters;
  943. type FillWorkingGroupLeadOpeningProposalParameters =
  944. FillWorkingGroupLeadOpeningProposalParameters;
  945. type UpdateWorkingGroupBudgetProposalParameters = UpdateWorkingGroupBudgetProposalParameters;
  946. type DecreaseWorkingGroupLeadStakeProposalParameters =
  947. DecreaseWorkingGroupLeadStakeProposalParameters;
  948. type SlashWorkingGroupLeadProposalParameters = SlashWorkingGroupLeadProposalParameters;
  949. type SetWorkingGroupLeadRewardProposalParameters = SetWorkingGroupLeadRewardProposalParameters;
  950. type TerminateWorkingGroupLeadProposalParameters = TerminateWorkingGroupLeadProposalParameters;
  951. type AmendConstitutionProposalParameters = AmendConstitutionProposalParameters;
  952. type CancelWorkingGroupLeadOpeningProposalParameters =
  953. CancelWorkingGroupLeadOpeningProposalParameters;
  954. type SetMembershipPriceProposalParameters = SetMembershipPriceProposalParameters;
  955. type SetCouncilBudgetIncrementProposalParameters = SetCouncilBudgetIncrementProposalParameters;
  956. type SetCouncilorRewardProposalParameters = SetCouncilorRewardProposalParameters;
  957. type SetInitialInvitationBalanceProposalParameters =
  958. SetInitialInvitationBalanceProposalParameters;
  959. type SetInvitationCountProposalParameters = SetInvitationCountProposalParameters;
  960. type SetMembershipLeadInvitationQuotaProposalParameters =
  961. SetMembershipLeadInvitationQuotaProposalParameters;
  962. type SetReferralCutProposalParameters = SetReferralCutProposalParameters;
  963. type CreateBlogPostProposalParameters = CreateBlogPostProposalParameters;
  964. type EditBlogPostProoposalParamters = EditBlogPostProoposalParamters;
  965. type LockBlogPostProposalParameters = LockBlogPostProposalParameters;
  966. type UnlockBlogPostProposalParameters = UnlockBlogPostProposalParameters;
  967. type VetoProposalProposalParameters = VetoProposalProposalParameters;
  968. type WeightInfo = weights::proposals_codex::WeightInfo;
  969. }
  970. impl pallet_constitution::Trait for Runtime {
  971. type Event = Event;
  972. type WeightInfo = weights::pallet_constitution::WeightInfo;
  973. }
  974. parameter_types! {
  975. pub const BountyModuleId: ModuleId = ModuleId(*b"m:bounty"); // module : bounty
  976. pub const ClosedContractSizeLimit: u32 = 50;
  977. pub const MinCherryLimit: Balance = 1000;
  978. pub const MinFundingLimit: Balance = 1000;
  979. pub const MinWorkEntrantStake: Balance = 1000;
  980. }
  981. impl bounty::Trait for Runtime {
  982. type Event = Event;
  983. type ModuleId = BountyModuleId;
  984. type BountyId = u64;
  985. type Membership = Members;
  986. type WeightInfo = weights::bounty::WeightInfo;
  987. type CouncilBudgetManager = Council;
  988. type StakingHandler = staking_handler::StakingManager<Self, BountyLockId>;
  989. type EntryId = u64;
  990. type ClosedContractSizeLimit = ClosedContractSizeLimit;
  991. type MinCherryLimit = MinCherryLimit;
  992. type MinFundingLimit = MinFundingLimit;
  993. type MinWorkEntrantStake = MinWorkEntrantStake;
  994. }
  995. parameter_types! {
  996. pub const PostsMaxNumber: u64 = 20;
  997. pub const RepliesMaxNumber: u64 = 100;
  998. pub const ReplyDeposit: Balance = 2000;
  999. pub const BlogModuleId: ModuleId = ModuleId(*b"mod:blog"); // module : forum
  1000. pub const ReplyLifetime: BlockNumber = 43_200;
  1001. }
  1002. pub type BlogInstance = blog::Instance1;
  1003. impl blog::Trait<BlogInstance> for Runtime {
  1004. type Event = Event;
  1005. type PostsMaxNumber = PostsMaxNumber;
  1006. type ParticipantEnsureOrigin = Members;
  1007. type WeightInfo = weights::blog::WeightInfo;
  1008. type ReplyId = u64;
  1009. type ReplyDeposit = ReplyDeposit;
  1010. type ModuleId = BlogModuleId;
  1011. type ReplyLifetime = ReplyLifetime;
  1012. }
  1013. /// Forum identifier for category
  1014. pub type CategoryId = u64;
  1015. /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
  1016. /// the specifics of the runtime. They can then be made to be agnostic over specific formats
  1017. /// of data like extrinsics, allowing for them to continue syncing the network through upgrades
  1018. /// to even the core datastructures.
  1019. pub mod opaque {
  1020. use super::*;
  1021. pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
  1022. /// Opaque block header type.
  1023. pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
  1024. /// Opaque block type.
  1025. pub type Block = generic::Block<Header, UncheckedExtrinsic>;
  1026. /// Opaque block identifier type.
  1027. pub type BlockId = generic::BlockId<Block>;
  1028. }
  1029. construct_runtime!(
  1030. pub enum Runtime where
  1031. Block = Block,
  1032. NodeBlock = opaque::Block,
  1033. UncheckedExtrinsic = UncheckedExtrinsic
  1034. {
  1035. // Substrate
  1036. System: frame_system::{Module, Call, Storage, Config, Event<T>},
  1037. Utility: substrate_utility::{Module, Call, Event},
  1038. Babe: pallet_babe::{Module, Call, Storage, Config, Inherent, ValidateUnsigned},
  1039. Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
  1040. Authorship: pallet_authorship::{Module, Call, Storage, Inherent},
  1041. Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
  1042. TransactionPayment: pallet_transaction_payment::{Module, Storage},
  1043. Staking: pallet_staking::{Module, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
  1044. Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
  1045. Historical: pallet_session_historical::{Module},
  1046. FinalityTracker: pallet_finality_tracker::{Module, Call, Inherent},
  1047. Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},
  1048. ImOnline: pallet_im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
  1049. AuthorityDiscovery: pallet_authority_discovery::{Module, Call, Config},
  1050. Offences: pallet_offences::{Module, Call, Storage, Event},
  1051. RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
  1052. Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},
  1053. // Joystream
  1054. Council: council::{Module, Call, Storage, Event<T>, Config<T>},
  1055. Referendum: referendum::<Instance1>::{Module, Call, Storage, Event<T>, Config<T>},
  1056. Members: membership::{Module, Call, Storage, Event<T>, Config<T>},
  1057. Forum: forum::{Module, Call, Storage, Event<T>, Config<T>},
  1058. Constitution: pallet_constitution::{Module, Call, Storage, Event},
  1059. Bounty: bounty::{Module, Call, Storage, Event<T>},
  1060. Blog: blog::<Instance1>::{Module, Call, Storage, Event<T>},
  1061. JoystreamUtility: joystream_utility::{Module, Call, Event<T>},
  1062. Content: content::{Module, Call, Storage, Event<T>, Config<T>},
  1063. Storage: storage::{Module, Call, Storage, Event<T>},
  1064. // --- Proposals
  1065. ProposalsEngine: proposals_engine::{Module, Call, Storage, Event<T>},
  1066. ProposalsDiscussion: proposals_discussion::{Module, Call, Storage, Event<T>},
  1067. ProposalsCodex: proposals_codex::{Module, Call, Storage, Event<T>},
  1068. // --- Working groups
  1069. ForumWorkingGroup: working_group::<Instance1>::{Module, Call, Storage, Event<T>},
  1070. StorageWorkingGroup: working_group::<Instance2>::{Module, Call, Storage, Event<T>},
  1071. ContentWorkingGroup: working_group::<Instance3>::{Module, Call, Storage, Event<T>},
  1072. OperationsWorkingGroupAlpha: working_group::<Instance4>::{Module, Call, Storage, Event<T>},
  1073. GatewayWorkingGroup: working_group::<Instance5>::{Module, Call, Storage, Event<T>},
  1074. MembershipWorkingGroup: working_group::<Instance6>::{Module, Call, Storage, Event<T>},
  1075. OperationsWorkingGroupBeta: working_group::<Instance7>::{Module, Call, Storage, Event<T>},
  1076. OperationsWorkingGroupGamma: working_group::<Instance8>::{Module, Call, Storage, Event<T>},
  1077. DistributionWorkingGroup: working_group::<Instance9>::{Module, Call, Storage, Event<T>},
  1078. }
  1079. );