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