lib.rs 27 KB

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