lib.rs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  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. // Make the WASM binary available.
  9. // This is required only by the node build.
  10. // A dummy wasm_binary.rs will be built for the IDE.
  11. #[cfg(feature = "std")]
  12. include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
  13. mod constants;
  14. mod integration;
  15. pub mod primitives;
  16. mod proposals_configuration;
  17. mod runtime_api;
  18. #[cfg(test)]
  19. mod tests;
  20. /// Weights for pallets used in the runtime.
  21. mod weights; // Runtime integration tests
  22. #[macro_use]
  23. extern crate lazy_static; // for proposals_configuration module
  24. use frame_support::traits::{KeyOwnerProofSystem, LockIdentifier};
  25. use frame_support::weights::{
  26. constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},
  27. Weight,
  28. };
  29. use frame_support::{construct_runtime, parameter_types};
  30. use frame_system::EnsureRoot;
  31. use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
  32. use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
  33. use pallet_session::historical as pallet_session_historical;
  34. use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
  35. use sp_core::crypto::KeyTypeId;
  36. use sp_runtime::curve::PiecewiseLinear;
  37. use sp_runtime::traits::{BlakeTwo256, Block as BlockT, IdentityLookup, OpaqueKeys, Saturating};
  38. use sp_runtime::{create_runtime_str, generic, impl_opaque_keys, Perbill};
  39. use sp_std::boxed::Box;
  40. use sp_std::vec::Vec;
  41. #[cfg(feature = "std")]
  42. use sp_version::NativeVersion;
  43. use sp_version::RuntimeVersion;
  44. pub use constants::*;
  45. pub use primitives::*;
  46. pub use proposals_configuration::*;
  47. pub use runtime_api::*;
  48. use integration::proposals::{CouncilManager, ExtrinsicProposalEncoder, MembershipOriginValidator};
  49. use governance::{council, election};
  50. use storage::data_object_storage_registry;
  51. // Node dependencies
  52. pub use common;
  53. pub use content_directory;
  54. pub use content_directory::{
  55. HashedTextMaxLength, InputValidationLengthConstraint, MaxNumber, TextMaxLength, VecMaxLength,
  56. };
  57. pub use forum;
  58. pub use governance::election_params::ElectionParameters;
  59. pub use membership;
  60. #[cfg(any(feature = "std", test))]
  61. pub use pallet_balances::Call as BalancesCall;
  62. pub use pallet_staking::StakerStatus;
  63. pub use proposals_engine::ProposalParameters;
  64. pub use storage::{data_directory, data_object_type_registry};
  65. pub use working_group;
  66. #[cfg(feature = "std")]
  67. /// Wasm binary unwrapped. If built with `BUILD_DUMMY_WASM_BINARY`, the function panics.
  68. pub fn wasm_binary_unwrap() -> &'static [u8] {
  69. WASM_BINARY.expect(
  70. "Development wasm binary is not available. This means the client is \
  71. built with `BUILD_DUMMY_WASM_BINARY` flag and it is only usable for \
  72. production chains. Please rebuild with the flag disabled.",
  73. )
  74. }
  75. /// This runtime version.
  76. pub const VERSION: RuntimeVersion = RuntimeVersion {
  77. spec_name: create_runtime_str!("joystream-node"),
  78. impl_name: create_runtime_str!("joystream-node"),
  79. authoring_version: 7,
  80. spec_version: 8,
  81. impl_version: 0,
  82. apis: crate::runtime_api::EXPORTED_RUNTIME_API_VERSIONS,
  83. transaction_version: 1,
  84. };
  85. /// The version information used to identify this runtime when compiled natively.
  86. #[cfg(feature = "std")]
  87. pub fn native_version() -> NativeVersion {
  88. NativeVersion {
  89. runtime_version: VERSION,
  90. can_author_with: Default::default(),
  91. }
  92. }
  93. parameter_types! {
  94. pub const BlockHashCount: BlockNumber = 250;
  95. /// We allow for 2 seconds of compute with a 6 second average block time.
  96. pub const MaximumBlockWeight: Weight = 2 * frame_support::weights::constants::WEIGHT_PER_SECOND;
  97. pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
  98. pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
  99. pub const Version: RuntimeVersion = VERSION;
  100. /// Assume 10% of weight for average on_initialize calls.
  101. pub MaximumExtrinsicWeight: Weight =
  102. AvailableBlockRatio::get().saturating_sub(AVERAGE_ON_INITIALIZE_WEIGHT)
  103. * MaximumBlockWeight::get();
  104. }
  105. const AVERAGE_ON_INITIALIZE_WEIGHT: Perbill = Perbill::from_percent(10);
  106. // TODO: adjust weight
  107. impl frame_system::Trait for Runtime {
  108. type BaseCallFilter = ();
  109. type Origin = Origin;
  110. type Call = Call;
  111. type Index = Index;
  112. type BlockNumber = BlockNumber;
  113. type Hash = Hash;
  114. type Hashing = BlakeTwo256;
  115. type AccountId = AccountId;
  116. type Lookup = IdentityLookup<AccountId>;
  117. type Header = generic::Header<BlockNumber, BlakeTwo256>;
  118. type Event = Event;
  119. type BlockHashCount = BlockHashCount;
  120. type MaximumBlockWeight = MaximumBlockWeight;
  121. type DbWeight = RocksDbWeight;
  122. type BlockExecutionWeight = BlockExecutionWeight;
  123. type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
  124. type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
  125. type MaximumBlockLength = MaximumBlockLength;
  126. type AvailableBlockRatio = AvailableBlockRatio;
  127. type Version = Version;
  128. type PalletInfo = PalletInfo;
  129. type AccountData = pallet_balances::AccountData<Balance>;
  130. type OnNewAccount = ();
  131. type OnKilledAccount = ();
  132. type SystemWeightInfo = weights::frame_system::WeightInfo;
  133. }
  134. impl pallet_utility::Trait for Runtime {
  135. type Event = Event;
  136. type Call = Call;
  137. type WeightInfo = weights::pallet_utility::WeightInfo;
  138. }
  139. parameter_types! {
  140. pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS as u64;
  141. pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
  142. }
  143. impl pallet_babe::Trait for Runtime {
  144. type EpochDuration = EpochDuration;
  145. type ExpectedBlockTime = ExpectedBlockTime;
  146. type EpochChangeTrigger = pallet_babe::ExternalTrigger;
  147. type KeyOwnerProofSystem = Historical;
  148. type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
  149. KeyTypeId,
  150. pallet_babe::AuthorityId,
  151. )>>::Proof;
  152. type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
  153. KeyTypeId,
  154. pallet_babe::AuthorityId,
  155. )>>::IdentificationTuple;
  156. type HandleEquivocation =
  157. pallet_babe::EquivocationHandler<Self::KeyOwnerIdentification, Offences>;
  158. type WeightInfo = ();
  159. }
  160. impl pallet_grandpa::Trait for Runtime {
  161. type Event = Event;
  162. type Call = Call;
  163. type KeyOwnerProof =
  164. <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
  165. type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
  166. KeyTypeId,
  167. GrandpaId,
  168. )>>::IdentificationTuple;
  169. type KeyOwnerProofSystem = Historical;
  170. type HandleEquivocation =
  171. pallet_grandpa::EquivocationHandler<Self::KeyOwnerIdentification, Offences>;
  172. type WeightInfo = ();
  173. }
  174. impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime
  175. where
  176. Call: From<LocalCall>,
  177. {
  178. fn create_transaction<C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>>(
  179. call: Call,
  180. public: <Signature as sp_runtime::traits::Verify>::Signer,
  181. account: AccountId,
  182. nonce: Index,
  183. ) -> Option<(
  184. Call,
  185. <UncheckedExtrinsic as sp_runtime::traits::Extrinsic>::SignaturePayload,
  186. )> {
  187. integration::transactions::create_transaction::<C>(call, public, account, nonce)
  188. }
  189. }
  190. impl frame_system::offchain::SigningTypes for Runtime {
  191. type Public = <Signature as sp_runtime::traits::Verify>::Signer;
  192. type Signature = Signature;
  193. }
  194. impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
  195. where
  196. Call: From<C>,
  197. {
  198. type Extrinsic = UncheckedExtrinsic;
  199. type OverarchingCall = Call;
  200. }
  201. parameter_types! {
  202. pub const MinimumPeriod: Moment = SLOT_DURATION / 2;
  203. }
  204. impl pallet_timestamp::Trait for Runtime {
  205. type Moment = Moment;
  206. type OnTimestampSet = Babe;
  207. type MinimumPeriod = MinimumPeriod;
  208. type WeightInfo = weights::pallet_timestamp::WeightInfo;
  209. }
  210. parameter_types! {
  211. pub const ExistentialDeposit: u128 = 0;
  212. pub const TransferFee: u128 = 0;
  213. pub const CreationFee: u128 = 0;
  214. pub const MaxLocks: u32 = 50;
  215. }
  216. impl pallet_balances::Trait for Runtime {
  217. type Balance = Balance;
  218. type DustRemoval = ();
  219. type Event = Event;
  220. type ExistentialDeposit = ExistentialDeposit;
  221. type AccountStore = System;
  222. type WeightInfo = weights::pallet_balances::WeightInfo;
  223. type MaxLocks = MaxLocks;
  224. }
  225. parameter_types! {
  226. pub const TransactionByteFee: Balance = 0; // TODO: adjust fee
  227. }
  228. impl pallet_transaction_payment::Trait for Runtime {
  229. type Currency = Balances;
  230. type OnTransactionPayment = ();
  231. type TransactionByteFee = TransactionByteFee;
  232. type WeightToFee = integration::transactions::NoWeights; // TODO: adjust weight
  233. type FeeMultiplierUpdate = (); // TODO: adjust fee
  234. }
  235. impl pallet_sudo::Trait for Runtime {
  236. type Event = Event;
  237. type Call = Call;
  238. }
  239. parameter_types! {
  240. pub const UncleGenerations: BlockNumber = 0;
  241. }
  242. impl pallet_authorship::Trait for Runtime {
  243. type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
  244. type UncleGenerations = UncleGenerations;
  245. type FilterUncle = ();
  246. type EventHandler = (Staking, ImOnline);
  247. }
  248. impl_opaque_keys! {
  249. pub struct SessionKeys {
  250. pub grandpa: Grandpa,
  251. pub babe: Babe,
  252. pub im_online: ImOnline,
  253. pub authority_discovery: AuthorityDiscovery,
  254. }
  255. }
  256. // NOTE: `SessionHandler` and `SessionKeys` are co-dependent: One key will be used for each handler.
  257. // The number and order of items in `SessionHandler` *MUST* be the same number and order of keys in
  258. // `SessionKeys`.
  259. // TODO: Introduce some structure to tie these together to make it a bit less of a footgun. This
  260. // should be easy, since OneSessionHandler trait provides the `Key` as an associated type. #2858
  261. parameter_types! {
  262. pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
  263. }
  264. impl pallet_session::Trait for Runtime {
  265. type Event = Event;
  266. type ValidatorId = AccountId;
  267. type ValidatorIdOf = pallet_staking::StashOf<Self>;
  268. type ShouldEndSession = Babe;
  269. type NextSessionRotation = Babe;
  270. type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, Staking>;
  271. type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
  272. type Keys = SessionKeys;
  273. type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
  274. type WeightInfo = weights::pallet_session::WeightInfo;
  275. }
  276. impl pallet_session::historical::Trait for Runtime {
  277. type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
  278. type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
  279. }
  280. pallet_staking_reward_curve::build! {
  281. const REWARD_CURVE: PiecewiseLinear<'static> = curve!(
  282. min_inflation: 0_050_000,
  283. max_inflation: 0_750_000,
  284. ideal_stake: 0_250_000,
  285. falloff: 0_050_000,
  286. max_piece_count: 100,
  287. test_precision: 0_005_000,
  288. );
  289. }
  290. parameter_types! {
  291. pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_SLOTS as _;
  292. pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
  293. /// We prioritize im-online heartbeats over election solution submission.
  294. pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2;
  295. }
  296. parameter_types! {
  297. pub const SessionsPerEra: sp_staking::SessionIndex = 6;
  298. pub const BondingDuration: pallet_staking::EraIndex = BONDING_DURATION;
  299. pub const SlashDeferDuration: pallet_staking::EraIndex = BONDING_DURATION - 1; // 'slightly less' than the bonding duration.
  300. pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
  301. pub const MaxNominatorRewardedPerValidator: u32 = 64;
  302. pub const ElectionLookahead: BlockNumber = EPOCH_DURATION_IN_BLOCKS / 4;
  303. pub const MaxIterations: u32 = 10;
  304. // 0.05%. The higher the value, the more strict solution acceptance becomes.
  305. pub MinSolutionScoreBump: Perbill = Perbill::from_rational_approximation(5u32, 10_000);
  306. }
  307. impl pallet_staking::Trait for Runtime {
  308. type Currency = Balances;
  309. type UnixTime = Timestamp;
  310. type CurrencyToVote = common::currency::CurrencyToVoteHandler;
  311. type RewardRemainder = (); // Could be Treasury.
  312. type Event = Event;
  313. type Slash = (); // Where to send the slashed funds. Could be Treasury.
  314. type Reward = (); // Rewards are minted from the void.
  315. type SessionsPerEra = SessionsPerEra;
  316. type BondingDuration = BondingDuration;
  317. type SlashDeferDuration = SlashDeferDuration;
  318. type SlashCancelOrigin = EnsureRoot<AccountId>; // Requires sudo. Parity recommends: a super-majority of the council can cancel the slash.
  319. type SessionInterface = Self;
  320. type RewardCurve = RewardCurve;
  321. type NextNewSession = Session;
  322. type ElectionLookahead = ElectionLookahead;
  323. type Call = Call;
  324. type MaxIterations = MaxIterations;
  325. type MinSolutionScoreBump = MinSolutionScoreBump;
  326. type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
  327. type UnsignedPriority = StakingUnsignedPriority;
  328. type WeightInfo = weights::pallet_staking::WeightInfo;
  329. }
  330. impl pallet_im_online::Trait for Runtime {
  331. type AuthorityId = ImOnlineId;
  332. type Event = Event;
  333. type SessionDuration = SessionDuration;
  334. type ReportUnresponsiveness = Offences;
  335. type UnsignedPriority = ImOnlineUnsignedPriority;
  336. type WeightInfo = weights::pallet_im_online::WeightInfo;
  337. }
  338. parameter_types! {
  339. pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
  340. }
  341. impl pallet_offences::Trait for Runtime {
  342. type Event = Event;
  343. type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
  344. type OnOffenceHandler = Staking;
  345. type WeightSoftLimit = OffencesWeightSoftLimit;
  346. }
  347. impl pallet_authority_discovery::Trait for Runtime {}
  348. parameter_types! {
  349. pub const WindowSize: BlockNumber = 101;
  350. pub const ReportLatency: BlockNumber = 1000;
  351. }
  352. impl pallet_finality_tracker::Trait for Runtime {
  353. type OnFinalizationStalled = ();
  354. type WindowSize = WindowSize;
  355. type ReportLatency = ReportLatency;
  356. }
  357. type EntityId = <Runtime as content_directory::Trait>::EntityId;
  358. parameter_types! {
  359. pub const PropertyNameLengthConstraint: InputValidationLengthConstraint = InputValidationLengthConstraint::new(1, 49);
  360. pub const PropertyDescriptionLengthConstraint: InputValidationLengthConstraint = InputValidationLengthConstraint::new(1, 500);
  361. pub const ClassNameLengthConstraint: InputValidationLengthConstraint = InputValidationLengthConstraint::new(1, 49);
  362. pub const ClassDescriptionLengthConstraint: InputValidationLengthConstraint = InputValidationLengthConstraint::new(1, 500);
  363. pub const MaxNumberOfClasses: MaxNumber = 100;
  364. pub const MaxNumberOfMaintainersPerClass: MaxNumber = 10;
  365. pub const MaxNumberOfSchemasPerClass: MaxNumber = 20;
  366. pub const MaxNumberOfPropertiesPerSchema: MaxNumber = 40;
  367. pub const MaxNumberOfEntitiesPerClass: MaxNumber = 400;
  368. pub const MaxNumberOfCuratorsPerGroup: MaxNumber = 50;
  369. pub const MaxNumberOfOperationsDuringAtomicBatching: MaxNumber = 500;
  370. pub const VecMaxLengthConstraint: VecMaxLength = 200;
  371. pub const TextMaxLengthConstraint: TextMaxLength = 5000;
  372. pub const HashedTextMaxLengthConstraint: HashedTextMaxLength = Some(25000);
  373. pub const IndividualEntitiesCreationLimit: EntityId = 50;
  374. }
  375. impl content_directory::Trait for Runtime {
  376. type Event = Event;
  377. type Nonce = u64;
  378. type ClassId = u64;
  379. type EntityId = u64;
  380. type PropertyNameLengthConstraint = PropertyNameLengthConstraint;
  381. type PropertyDescriptionLengthConstraint = PropertyDescriptionLengthConstraint;
  382. type ClassNameLengthConstraint = ClassNameLengthConstraint;
  383. type ClassDescriptionLengthConstraint = ClassDescriptionLengthConstraint;
  384. type MaxNumberOfClasses = MaxNumberOfClasses;
  385. type MaxNumberOfMaintainersPerClass = MaxNumberOfMaintainersPerClass;
  386. type MaxNumberOfSchemasPerClass = MaxNumberOfSchemasPerClass;
  387. type MaxNumberOfPropertiesPerSchema = MaxNumberOfPropertiesPerSchema;
  388. type MaxNumberOfEntitiesPerClass = MaxNumberOfEntitiesPerClass;
  389. type MaxNumberOfCuratorsPerGroup = MaxNumberOfCuratorsPerGroup;
  390. type MaxNumberOfOperationsDuringAtomicBatching = MaxNumberOfOperationsDuringAtomicBatching;
  391. type VecMaxLengthConstraint = VecMaxLengthConstraint;
  392. type TextMaxLengthConstraint = TextMaxLengthConstraint;
  393. type HashedTextMaxLengthConstraint = HashedTextMaxLengthConstraint;
  394. type IndividualEntitiesCreationLimit = IndividualEntitiesCreationLimit;
  395. }
  396. impl minting::Trait for Runtime {
  397. type Currency = <Self as common::currency::GovernanceCurrency>::Currency;
  398. type MintId = u64;
  399. }
  400. impl recurring_rewards::Trait for Runtime {
  401. type PayoutStatusHandler = (); // TODO - deal with successful and failed payouts
  402. type RecipientId = u64;
  403. type RewardRelationshipId = u64;
  404. }
  405. impl common::currency::GovernanceCurrency for Runtime {
  406. type Currency = pallet_balances::Module<Self>;
  407. }
  408. impl governance::election::Trait for Runtime {
  409. type Event = Event;
  410. type CouncilElected = (Council, integration::proposals::CouncilElectedHandler);
  411. }
  412. impl governance::council::Trait for Runtime {
  413. type Event = Event;
  414. type CouncilTermEnded = (CouncilElection,);
  415. }
  416. impl memo::Trait for Runtime {
  417. type Event = Event;
  418. }
  419. parameter_types! {
  420. pub const MaxObjectsPerInjection: u32 = 100;
  421. pub const MembershipFee: Balance = 100;
  422. }
  423. impl storage::data_object_type_registry::Trait for Runtime {
  424. type Event = Event;
  425. type DataObjectTypeId = u64;
  426. }
  427. impl storage::data_directory::Trait for Runtime {
  428. type Event = Event;
  429. type ContentId = ContentId;
  430. type StorageProviderHelper = integration::storage::StorageProviderHelper;
  431. type IsActiveDataObjectType = DataObjectTypeRegistry;
  432. type MemberOriginValidator = MembershipOriginValidator<Self>;
  433. type MaxObjectsPerInjection = MaxObjectsPerInjection;
  434. }
  435. impl storage::data_object_storage_registry::Trait for Runtime {
  436. type Event = Event;
  437. type DataObjectStorageRelationshipId = u64;
  438. type ContentIdExists = DataDirectory;
  439. }
  440. impl membership::Trait for Runtime {
  441. type Event = Event;
  442. type MemberId = MemberId;
  443. type ActorId = ActorId;
  444. type MembershipFee = MembershipFee;
  445. }
  446. parameter_types! {
  447. pub const MaxCategoryDepth: u64 = 5;
  448. pub const MaxSubcategories: u64 = 20;
  449. pub const MaxThreadsInCategory: u64 = 20;
  450. pub const MaxPostsInThread: u64 = 20;
  451. pub const MaxModeratorsForCategory: u64 = 20;
  452. pub const MaxCategories: u64 = 20;
  453. pub const MaxPollAlternativesNumber: u64 = 20;
  454. }
  455. pub struct MapLimits;
  456. impl forum::StorageLimits for MapLimits {
  457. type MaxSubcategories = MaxSubcategories;
  458. type MaxThreadsInCategory = MaxThreadsInCategory;
  459. type MaxPostsInThread = MaxPostsInThread;
  460. type MaxModeratorsForCategory = MaxModeratorsForCategory;
  461. type MaxCategories = MaxCategories;
  462. type MaxPollAlternativesNumber = MaxPollAlternativesNumber;
  463. }
  464. // Alias for forum working group
  465. type ForumGroup<T> = working_group::Module<T, ForumWorkingGroupInstance>;
  466. impl forum::Trait for Runtime {
  467. type Event = Event;
  468. //type MembershipRegistry = ShimMembershipRegistry;
  469. type ThreadId = ThreadId;
  470. type PostId = PostId;
  471. type ForumUserId = ForumUserId;
  472. type ModeratorId = ModeratorId;
  473. type CategoryId = u64;
  474. type PostReactionId = u64;
  475. type MaxCategoryDepth = MaxCategoryDepth;
  476. type MapLimits = MapLimits;
  477. fn is_lead(_account_id: &AccountId) -> bool {
  478. // get current lead id
  479. let maybe_current_lead_id = ForumGroup::<Runtime>::current_lead();
  480. if let Some(ref current_lead_id) = maybe_current_lead_id {
  481. if let Ok(worker) = working_group::ensure_worker_exists::<
  482. Runtime,
  483. ForumWorkingGroupInstance,
  484. >(current_lead_id)
  485. {
  486. *_account_id == worker.role_account_id
  487. } else {
  488. false
  489. }
  490. } else {
  491. false
  492. }
  493. }
  494. fn is_forum_member(_account_id: &Self::AccountId, _forum_user_id: &Self::ForumUserId) -> bool {
  495. membership::Module::<Runtime>::ensure_is_controller_account_for_member(
  496. _forum_user_id,
  497. _account_id,
  498. )
  499. .is_ok()
  500. }
  501. fn is_moderator(_account_id: &Self::AccountId, _moderator_id: &Self::ModeratorId) -> bool {
  502. if let Ok(worker) =
  503. working_group::ensure_worker_exists::<Runtime, ForumWorkingGroupInstance>(_moderator_id)
  504. {
  505. *_account_id == worker.role_account_id
  506. } else {
  507. false
  508. }
  509. }
  510. fn calculate_hash(text: &[u8]) -> Self::Hash {
  511. Self::Hash::from_slice(text)
  512. }
  513. }
  514. // The forum working group instance alias.
  515. pub type ForumWorkingGroupInstance = working_group::Instance1;
  516. // The storage working group instance alias.
  517. pub type StorageWorkingGroupInstance = working_group::Instance2;
  518. // The content directory working group instance alias.
  519. pub type ContentDirectoryWorkingGroupInstance = working_group::Instance3;
  520. parameter_types! {
  521. pub const MaxWorkerNumberLimit: u32 = 100;
  522. pub const MinUnstakingPeriodLimit: u32 = 43200;
  523. pub const ForumWorkingGroupRewardPeriod: u32 = 14400 + 10;
  524. pub const StorageWorkingGroupRewardPeriod: u32 = 14400 + 20;
  525. pub const ContentWorkingGroupRewardPeriod: u32 = 14400 + 30;
  526. pub const StorageWorkingGroupLockId: LockIdentifier = [6; 8];
  527. pub const ContentWorkingGroupLockId: LockIdentifier = [7; 8];
  528. pub const ForumGroupLockId: LockIdentifier = [8; 8];
  529. }
  530. // Staking managers type aliases.
  531. pub type ForumWorkingGroupStakingManager =
  532. staking_handler::StakingManager<Runtime, ForumGroupLockId>;
  533. pub type ContentDirectoryWorkingGroupStakingManager =
  534. staking_handler::StakingManager<Runtime, ContentWorkingGroupLockId>;
  535. pub type StorageWorkingGroupStakingManager =
  536. staking_handler::StakingManager<Runtime, StorageWorkingGroupLockId>;
  537. impl working_group::Trait<ForumWorkingGroupInstance> for Runtime {
  538. type Event = Event;
  539. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  540. type StakingHandler = ForumWorkingGroupStakingManager;
  541. type MemberOriginValidator = MembershipOriginValidator<Self>;
  542. type MinUnstakingPeriodLimit = MinUnstakingPeriodLimit;
  543. type RewardPeriod = ForumWorkingGroupRewardPeriod;
  544. type WeightInfo = weights::working_group::WeightInfo;
  545. }
  546. impl working_group::Trait<StorageWorkingGroupInstance> for Runtime {
  547. type Event = Event;
  548. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  549. type StakingHandler = StorageWorkingGroupStakingManager;
  550. type MemberOriginValidator = MembershipOriginValidator<Self>;
  551. type MinUnstakingPeriodLimit = MinUnstakingPeriodLimit;
  552. type RewardPeriod = StorageWorkingGroupRewardPeriod;
  553. type WeightInfo = weights::working_group::WeightInfo;
  554. }
  555. impl working_group::Trait<ContentDirectoryWorkingGroupInstance> for Runtime {
  556. type Event = Event;
  557. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  558. type StakingHandler = ContentDirectoryWorkingGroupStakingManager;
  559. type MemberOriginValidator = MembershipOriginValidator<Self>;
  560. type MinUnstakingPeriodLimit = MinUnstakingPeriodLimit;
  561. type RewardPeriod = ContentWorkingGroupRewardPeriod;
  562. type WeightInfo = weights::working_group::WeightInfo;
  563. }
  564. impl service_discovery::Trait for Runtime {
  565. type Event = Event;
  566. }
  567. parameter_types! {
  568. pub const ProposalCancellationFee: u64 = 10000;
  569. pub const ProposalRejectionFee: u64 = 5000;
  570. pub const ProposalTitleMaxLength: u32 = 40;
  571. pub const ProposalDescriptionMaxLength: u32 = 3000;
  572. pub const ProposalMaxActiveProposalLimit: u32 = 5;
  573. pub const ProposalsLockId: LockIdentifier = [5; 8];
  574. }
  575. impl proposals_engine::Trait for Runtime {
  576. type Event = Event;
  577. type ProposerOriginValidator = MembershipOriginValidator<Self>;
  578. type VoterOriginValidator = CouncilManager<Self>;
  579. type TotalVotersCounter = CouncilManager<Self>;
  580. type ProposalId = u32;
  581. type StakingHandler = staking_handler::StakingManager<Self, ProposalsLockId>;
  582. type CancellationFee = ProposalCancellationFee;
  583. type RejectionFee = ProposalRejectionFee;
  584. type TitleMaxLength = ProposalTitleMaxLength;
  585. type DescriptionMaxLength = ProposalDescriptionMaxLength;
  586. type MaxActiveProposalLimit = ProposalMaxActiveProposalLimit;
  587. type DispatchableCallCode = Call;
  588. type ProposalObserver = ProposalsCodex;
  589. type WeightInfo = weights::proposals_engine::WeightInfo;
  590. }
  591. impl Default for Call {
  592. fn default() -> Self {
  593. panic!("shouldn't call default for Call");
  594. }
  595. }
  596. parameter_types! {
  597. pub const MaxWhiteListSize: u32 = 20;
  598. }
  599. impl proposals_discussion::Trait for Runtime {
  600. type Event = Event;
  601. type AuthorOriginValidator = MembershipOriginValidator<Self>;
  602. type CouncilOriginValidator = CouncilManager<Self>;
  603. type ThreadId = ThreadId;
  604. type PostId = PostId;
  605. type MaxWhiteListSize = MaxWhiteListSize;
  606. type WeightInfo = weights::proposals_discussion::WeightInfo;
  607. }
  608. parameter_types! {
  609. pub const TextProposalMaxLength: u32 = 5_000;
  610. pub const RuntimeUpgradeWasmProposalMaxLength: u32 = 3_000_000;
  611. }
  612. impl proposals_codex::Trait for Runtime {
  613. type TextProposalMaxLength = TextProposalMaxLength;
  614. type RuntimeUpgradeWasmProposalMaxLength = RuntimeUpgradeWasmProposalMaxLength;
  615. type MembershipOriginValidator = MembershipOriginValidator<Self>;
  616. type ProposalEncoder = ExtrinsicProposalEncoder;
  617. type SetValidatorCountProposalParameters = SetValidatorCountProposalParameters;
  618. type RuntimeUpgradeProposalParameters = RuntimeUpgradeProposalParameters;
  619. type TextProposalParameters = TextProposalParameters;
  620. type SpendingProposalParameters = SpendingProposalParameters;
  621. type AddWorkingGroupOpeningProposalParameters = AddWorkingGroupOpeningProposalParameters;
  622. type FillWorkingGroupOpeningProposalParameters = FillWorkingGroupOpeningProposalParameters;
  623. type SetWorkingGroupBudgetCapacityProposalParameters =
  624. SetWorkingGroupBudgetCapacityProposalParameters;
  625. type DecreaseWorkingGroupLeaderStakeProposalParameters =
  626. DecreaseWorkingGroupLeaderStakeProposalParameters;
  627. type SlashWorkingGroupLeaderStakeProposalParameters =
  628. SlashWorkingGroupLeaderStakeProposalParameters;
  629. type SetWorkingGroupLeaderRewardProposalParameters =
  630. SetWorkingGroupLeaderRewardProposalParameters;
  631. type TerminateWorkingGroupLeaderRoleProposalParameters =
  632. TerminateWorkingGroupLeaderRoleProposalParameters;
  633. type AmendConstitutionProposalParameters = AmendConstitutionProposalParameters;
  634. }
  635. impl pallet_constitution::Trait for Runtime {
  636. type Event = Event;
  637. type WeightInfo = weights::pallet_constitution::WeightInfo;
  638. }
  639. parameter_types! {
  640. pub const TombstoneDeposit: Balance = 1; // TODO: adjust fee
  641. pub const RentByteFee: Balance = 1; // TODO: adjust fee
  642. pub const RentDepositOffset: Balance = 0; // no rent deposit
  643. pub const SurchargeReward: Balance = 0; // no reward
  644. }
  645. /// Forum identifiers for user, moderator and category
  646. pub type ForumUserId = u64;
  647. pub type ModeratorId = u64;
  648. pub type CategoryId = u64;
  649. /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
  650. /// the specifics of the runtime. They can then be made to be agnostic over specific formats
  651. /// of data like extrinsics, allowing for them to continue syncing the network through upgrades
  652. /// to even the core datastructures.
  653. pub mod opaque {
  654. use super::*;
  655. pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
  656. /// Opaque block header type.
  657. pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
  658. /// Opaque block type.
  659. pub type Block = generic::Block<Header, UncheckedExtrinsic>;
  660. /// Opaque block identifier type.
  661. pub type BlockId = generic::BlockId<Block>;
  662. }
  663. construct_runtime!(
  664. pub enum Runtime where
  665. Block = Block,
  666. NodeBlock = opaque::Block,
  667. UncheckedExtrinsic = UncheckedExtrinsic
  668. {
  669. // Substrate
  670. System: frame_system::{Module, Call, Storage, Config, Event<T>},
  671. Utility: pallet_utility::{Module, Call, Event},
  672. Babe: pallet_babe::{Module, Call, Storage, Config, Inherent, ValidateUnsigned},
  673. Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
  674. Authorship: pallet_authorship::{Module, Call, Storage, Inherent},
  675. Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
  676. TransactionPayment: pallet_transaction_payment::{Module, Storage},
  677. Staking: pallet_staking::{Module, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
  678. Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
  679. Historical: pallet_session_historical::{Module},
  680. FinalityTracker: pallet_finality_tracker::{Module, Call, Inherent},
  681. Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},
  682. ImOnline: pallet_im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
  683. AuthorityDiscovery: pallet_authority_discovery::{Module, Call, Config},
  684. Offences: pallet_offences::{Module, Call, Storage, Event},
  685. RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
  686. Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},
  687. // Joystream
  688. CouncilElection: election::{Module, Call, Storage, Event<T>, Config<T>},
  689. Council: council::{Module, Call, Storage, Event<T>, Config<T>},
  690. Memo: memo::{Module, Call, Storage, Event<T>},
  691. Members: membership::{Module, Call, Storage, Event<T>, Config<T>},
  692. Forum: forum::{Module, Call, Storage, Event<T>, Config<T>},
  693. Minting: minting::{Module, Call, Storage},
  694. RecurringRewards: recurring_rewards::{Module, Call, Storage},
  695. ContentDirectory: content_directory::{Module, Call, Storage, Event<T>, Config<T>},
  696. Constitution: pallet_constitution::{Module, Call, Storage, Event},
  697. // --- Storage
  698. DataObjectTypeRegistry: data_object_type_registry::{Module, Call, Storage, Event<T>, Config<T>},
  699. DataDirectory: data_directory::{Module, Call, Storage, Event<T>},
  700. DataObjectStorageRegistry: data_object_storage_registry::{Module, Call, Storage, Event<T>, Config<T>},
  701. Discovery: service_discovery::{Module, Call, Storage, Event<T>},
  702. // --- Proposals
  703. ProposalsEngine: proposals_engine::{Module, Call, Storage, Event<T>},
  704. ProposalsDiscussion: proposals_discussion::{Module, Call, Storage, Event<T>},
  705. ProposalsCodex: proposals_codex::{Module, Call, Storage},
  706. // --- Working groups
  707. ForumWorkingGroup: working_group::<Instance1>::{Module, Call, Storage, Event<T>},
  708. StorageWorkingGroup: working_group::<Instance2>::{Module, Call, Storage, Event<T>},
  709. ContentDirectoryWorkingGroup: working_group::<Instance3>::{Module, Call, Storage, Event<T>},
  710. }
  711. );