-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathlib.rs
More file actions
895 lines (795 loc) · 32 KB
/
lib.rs
File metadata and controls
895 lines (795 loc) · 32 KB
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
#![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"]
// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
pub use frame_support::{
construct_runtime, log, parameter_types,
traits::{
Currency, EstimateNextNewSession, Imbalance, KeyOwnerProofSystem, LockIdentifier, Nothing,
OnUnbalanced, Randomness, ValidatorSet,
},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
IdentityFee, Weight,
},
StorageValue,
};
use frame_support::{
sp_runtime::Perquintill,
traits::{ConstU32, EqualPrivilegeOnly, SortedMembers, U128CurrencyToVote},
weights::constants::WEIGHT_PER_MILLIS,
PalletId,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
pub use pallet_balances::Call as BalancesCall;
pub use pallet_timestamp::Call as TimestampCall;
use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment};
pub use primitives::Balance;
use primitives::{
staking::MAX_NOMINATORS_REWARDED_PER_VALIDATOR, wrap_methods, ApiError as AlephApiError,
AuthorityId as AlephId, SessionAuthorityData, Version as FinalityVersion, ADDRESSES_ENCODING,
DEFAULT_BAN_REASON_LENGTH, DEFAULT_SESSIONS_PER_ERA, DEFAULT_SESSION_PERIOD,
MILLISECS_PER_BLOCK, TOKEN,
};
use sp_api::impl_runtime_apis;
use sp_consensus_aura::{sr25519::AuthorityId as AuraId, SlotDuration};
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto, IdentifyAccount, One,
OpaqueKeys, Verify,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedU128, MultiSignature, RuntimeAppPublic,
};
pub use sp_runtime::{FixedPointNumber, Perbill, Permill};
use sp_staking::EraIndex;
use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
/// An index to a block.
pub type BlockNumber = u32;
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
pub type Signature = MultiSignature;
/// Some way of identifying an account on the chain. We intentionally make it equivalent
/// to the public key of our transaction signing scheme.
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
/// The type for looking up accounts. We don't expect more than 4 billion of them, but you
/// never know...
pub type AccountIndex = u32;
/// Index of a transaction in the chain.
pub type Index = u32;
/// A hash of some data used by the chain.
pub type Hash = sp_core::H256;
/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
/// to even the core data structures.
pub mod opaque {
pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
use super::*;
/// Opaque block header type.
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Opaque block type.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// Opaque block identifier type.
pub type BlockId = generic::BlockId<Block>;
impl_opaque_keys! {
pub struct SessionKeys {
pub aura: Aura,
pub aleph: Aleph,
}
}
}
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("aleph-node"),
impl_name: create_runtime_str!("aleph-node"),
authoring_version: 1,
spec_version: 46,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 14,
state_version: 0,
};
/// 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(),
}
}
pub const BLOCKS_PER_HOUR: u32 = 60 * 60 * 1000 / (MILLISECS_PER_BLOCK as u32);
pub const MILLI_AZERO: Balance = TOKEN / 1000;
pub const MICRO_AZERO: Balance = MILLI_AZERO / 1000;
pub const NANO_AZERO: Balance = MICRO_AZERO / 1000;
pub const PICO_AZERO: Balance = NANO_AZERO / 1000;
// 75% block weight is dedicated to normal extrinsics
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
// The whole process for a single block should take 1s, of which 400ms is for creation,
// 200ms for propagation and 400ms for validation. Hence the block weight should be within 400ms.
pub const MAX_BLOCK_WEIGHT: Weight = 400 * WEIGHT_PER_MILLIS;
// We agreed to 5MB as the block size limit.
pub const MAX_BLOCK_SIZE: u32 = 5 * 1024 * 1024;
// The storage deposit is roughly 1 TOKEN per 1kB
pub const DEPOSIT_PER_BYTE: Balance = MILLI_AZERO;
parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub const BlockHashCount: BlockNumber = 2400;
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
::with_sensible_defaults(MAX_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(MAX_BLOCK_SIZE, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u8 = ADDRESSES_ENCODING;
}
// Configure FRAME pallets to include in runtime.
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = frame_support::traits::Everything;
/// Block & extrinsics weights: base values and limits.
type BlockWeights = BlockWeights;
/// The maximum length of a block (in bytes).
type BlockLength = BlockLength;
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
/// The aggregated dispatch type that is available for extrinsics.
type Call = Call;
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = AccountIdLookup<AccountId, ()>;
/// The index type for storing how many extrinsics an account has signed.
type Index = Index;
/// The index type for blocks.
type BlockNumber = BlockNumber;
/// The type for hashing blocks and tries.
type Hash = Hash;
/// The hashing algorithm used.
type Hashing = BlakeTwo256;
/// The header type.
type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// The ubiquitous event type.
type Event = Event;
/// The ubiquitous origin type.
type Origin = Origin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
/// The weight of database operations that the runtime can invoke.
type DbWeight = RocksDbWeight;
/// Version of the runtime.
type Version = Version;
/// Converts a module to the index of the module in `construct_runtime!`.
///
/// This type is being generated by `construct_runtime!`.
type PalletInfo = PalletInfo;
/// What to do if a new account is created.
type OnNewAccount = ();
/// What to do if an account is fully reaped from the system.
type OnKilledAccount = ();
/// The data to be stored in an account.
type AccountData = pallet_balances::AccountData<Balance>;
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = ();
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}
parameter_types! {
// https://github.com/paritytech/polkadot/blob/9ce5f7ef5abb1a4291454e8c9911b304d80679f9/runtime/polkadot/src/lib.rs#L784
pub const MaxAuthorities: u32 = 100_000;
}
impl pallet_aura::Config for Runtime {
type MaxAuthorities = MaxAuthorities;
type AuthorityId = AuraId;
type DisabledValidators = ();
}
parameter_types! {
pub const UncleGenerations: BlockNumber = 0;
}
impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
type EventHandler = (Elections,);
}
parameter_types! {
pub const ExistentialDeposit: u128 = 500 * PICO_AZERO;
pub const MaxLocks: u32 = 50;
}
impl pallet_balances::Config for Runtime {
type MaxLocks = MaxLocks;
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
/// The type for recording an account's balance.
type Balance = Balance;
/// The ubiquitous event type.
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
}
type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
pub struct EverythingToTheTreasury;
impl OnUnbalanced<NegativeImbalance> for EverythingToTheTreasury {
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {
if let Some(fees) = fees_then_tips.next() {
Treasury::on_unbalanced(fees);
if let Some(tips) = fees_then_tips.next() {
Treasury::on_unbalanced(tips);
}
}
}
}
parameter_types! {
// This value increases the priority of `Operational` transactions by adding
// a "virtual tip" that's equal to the `OperationalFeeMultiplier * final_fee`.
// follows polkadot : https://github.com/paritytech/polkadot/blob/9ce5f7ef5abb1a4291454e8c9911b304d80679f9/runtime/polkadot/src/lib.rs#L369
pub const OperationalFeeMultiplier: u8 = 5;
// We expect that on average 25% of the normal capacity will be occupied with normal txs.
pub const TargetSaturationLevel: Perquintill = Perquintill::from_percent(25);
// During 20 blocks the fee may not change more than by 100%. This, together with the
// `TargetSaturationLevel` value, results in variability ~0.067. For the corresponding
// formulas please refer to Substrate code at `frame/transaction-payment/src/lib.rs`.
pub FeeVariability: Multiplier = Multiplier::saturating_from_rational(67, 1000);
// Fee should never be lower than the computational cost.
pub MinimumMultiplier: Multiplier = Multiplier::one();
}
impl pallet_transaction_payment::Config for Runtime {
type Event = Event;
type OnChargeTransaction = CurrencyAdapter<Balances, EverythingToTheTreasury>;
type LengthToFee = IdentityFee<Balance>;
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate =
TargetedFeeAdjustment<Self, TargetSaturationLevel, FeeVariability, MinimumMultiplier>;
type OperationalFeeMultiplier = OperationalFeeMultiplier;
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50;
}
impl pallet_scheduler::Config for Runtime {
type Event = Event;
type Origin = Origin;
type PalletsOrigin = OriginCaller;
type Call = Call;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = frame_system::EnsureRoot<AccountId>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = pallet_scheduler::weights::SubstrateWeight<Runtime>;
type OriginPrivilegeCmp = EqualPrivilegeOnly;
type PreimageProvider = ();
type NoPreimagePostponement = ();
}
impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
}
impl pallet_aleph::Config for Runtime {
type AuthorityId = AlephId;
type Event = Event;
type SessionInfoProvider = Session;
type SessionManager = Elections;
}
impl_opaque_keys! {
pub struct SessionKeys {
pub aura: Aura,
pub aleph: Aleph,
}
}
parameter_types! {
pub const SessionPeriod: u32 = DEFAULT_SESSION_PERIOD;
pub const MaximumBanReasonLength: u32 = DEFAULT_BAN_REASON_LENGTH;
}
impl pallet_elections::Config for Runtime {
type EraInfoProvider = Staking;
type Event = Event;
type DataProvider = Staking;
type SessionInfoProvider = Session;
type SessionPeriod = SessionPeriod;
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Runtime, Staking>;
type ValidatorRewardsHandler = Staking;
type MaximumBanReasonLength = MaximumBanReasonLength;
}
impl pallet_randomness_collective_flip::Config for Runtime {}
parameter_types! {
pub const Offset: u32 = 0;
}
impl pallet_session::Config for Runtime {
type Event = Event;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = pallet_staking::StashOf<Self>;
type ShouldEndSession = pallet_session::PeriodicSessions<SessionPeriod, Offset>;
type NextSessionRotation = pallet_session::PeriodicSessions<SessionPeriod, Offset>;
type SessionManager = Aleph;
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type WeightInfo = pallet_session::weights::SubstrateWeight<Runtime>;
}
impl pallet_session::historical::Config for Runtime {
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
}
parameter_types! {
pub const PostUnbondPoolsWindow: u32 = 4;
pub const NominationPoolsPalletId: PalletId = PalletId(*b"py/nopls");
pub const MaxPointsToBalance: u8 = 10;
}
use sp_runtime::traits::Convert;
pub struct BalanceToU256;
impl Convert<Balance, sp_core::U256> for BalanceToU256 {
fn convert(balance: Balance) -> sp_core::U256 {
sp_core::U256::from(balance)
}
}
pub struct U256ToBalance;
impl Convert<sp_core::U256, Balance> for U256ToBalance {
fn convert(n: sp_core::U256) -> Balance {
n.try_into().unwrap_or(Balance::max_value())
}
}
impl pallet_nomination_pools::Config for Runtime {
type WeightInfo = ();
type Event = Event;
type Currency = Balances;
type CurrencyBalance = Balance;
type RewardCounter = FixedU128;
type BalanceToU256 = BalanceToU256;
type U256ToBalance = U256ToBalance;
type StakingInterface = pallet_staking::Pallet<Self>;
type PostUnbondingPoolsWindow = PostUnbondPoolsWindow;
type MaxMetadataLen = ConstU32<256>;
type MaxUnbonding = ConstU32<8>;
type PalletId = NominationPoolsPalletId;
type MaxPointsToBalance = MaxPointsToBalance;
}
parameter_types! {
pub const BondingDuration: EraIndex = 14;
pub const SlashDeferDuration: EraIndex = 13;
// this is coupled with weights for payout_stakers() call
// see custom implementation of WeightInfo below
pub const MaxNominatorRewardedPerValidator: u32 = MAX_NOMINATORS_REWARDED_PER_VALIDATOR;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(33);
pub const SessionsPerEra: EraIndex = DEFAULT_SESSIONS_PER_ERA;
}
pub struct UniformEraPayout;
impl pallet_staking::EraPayout<Balance> for UniformEraPayout {
fn era_payout(_: Balance, _: Balance, era_duration_millis: u64) -> (Balance, Balance) {
primitives::staking::era_payout(era_duration_millis)
}
}
type SubstrateStakingWeights = pallet_staking::weights::SubstrateWeight<Runtime>;
pub struct PayoutStakersDecreasedWeightInfo;
impl pallet_staking::WeightInfo for PayoutStakersDecreasedWeightInfo {
// To make possible to change nominators per validator we need to decrease weight for payout_stakers
fn payout_stakers_alive_staked(n: u32) -> Weight {
SubstrateStakingWeights::payout_stakers_alive_staked(n) / 2
}
wrap_methods!(
(bond(), SubstrateStakingWeights, Weight),
(bond_extra(), SubstrateStakingWeights, Weight),
(unbond(), SubstrateStakingWeights, Weight),
(
withdraw_unbonded_update(s: u32),
SubstrateStakingWeights,
Weight
),
(
withdraw_unbonded_kill(s: u32),
SubstrateStakingWeights,
Weight
),
(validate(), SubstrateStakingWeights, Weight),
(kick(k: u32), SubstrateStakingWeights, Weight),
(nominate(n: u32), SubstrateStakingWeights, Weight),
(chill(), SubstrateStakingWeights, Weight),
(set_payee(), SubstrateStakingWeights, Weight),
(set_controller(), SubstrateStakingWeights, Weight),
(set_validator_count(), SubstrateStakingWeights, Weight),
(force_no_eras(), SubstrateStakingWeights, Weight),
(force_new_era(), SubstrateStakingWeights, Weight),
(force_new_era_always(), SubstrateStakingWeights, Weight),
(set_invulnerables(v: u32), SubstrateStakingWeights, Weight),
(force_unstake(s: u32), SubstrateStakingWeights, Weight),
(
cancel_deferred_slash(s: u32),
SubstrateStakingWeights,
Weight
),
(
payout_stakers_dead_controller(n: u32),
SubstrateStakingWeights,
Weight
),
(rebond(l: u32), SubstrateStakingWeights, Weight),
(set_history_depth(e: u32), SubstrateStakingWeights, Weight),
(reap_stash(s: u32), SubstrateStakingWeights, Weight),
(new_era(v: u32, n: u32), SubstrateStakingWeights, Weight),
(
get_npos_voters(v: u32, n: u32, s: u32),
SubstrateStakingWeights,
Weight
),
(get_npos_targets(v: u32), SubstrateStakingWeights, Weight),
(chill_other(), SubstrateStakingWeights, Weight),
(
set_staking_configs_all_set(),
SubstrateStakingWeights,
Weight
),
(
set_staking_configs_all_remove(),
SubstrateStakingWeights,
Weight
),
(
force_apply_min_commission(),
SubstrateStakingWeights,
Weight
)
);
}
pub struct StakingBenchmarkingConfig;
impl pallet_staking::BenchmarkingConfig for StakingBenchmarkingConfig {
type MaxValidators = ConstU32<1000>;
type MaxNominators = ConstU32<1000>;
}
impl pallet_staking::Config for Runtime {
// Do not change this!!! It guarantees that we have DPoS instead of NPoS.
type Currency = Balances;
type UnixTime = Timestamp;
type CurrencyToVote = U128CurrencyToVote;
type ElectionProvider = Elections;
type GenesisElectionProvider = Elections;
type MaxNominations = ConstU32<1>;
type RewardRemainder = Treasury;
type Event = Event;
type Slash = Treasury;
type Reward = ();
type SessionsPerEra = SessionsPerEra;
type BondingDuration = BondingDuration;
type SlashDeferDuration = SlashDeferDuration;
type SlashCancelOrigin = EnsureRoot<AccountId>;
type SessionInterface = Self;
type EraPayout = UniformEraPayout;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type VoterList = pallet_staking::UseNominatorsAndValidatorsMap<Runtime>;
type MaxUnlockingChunks = ConstU32<16>;
type BenchmarkingConfig = StakingBenchmarkingConfig;
type WeightInfo = PayoutStakersDecreasedWeightInfo;
type CurrencyBalance = Balance;
type OnStakerSlash = NominationPools;
}
parameter_types! {
pub const MinimumPeriod: u64 = MILLISECS_PER_BLOCK / 2;
}
impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = u64;
type OnTimestampSet = Aura;
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}
impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
where
Call: From<C>,
{
type Extrinsic = UncheckedExtrinsic;
type OverarchingCall = Call;
}
parameter_types! {
pub const MinVestedTransfer: Balance = MICRO_AZERO;
}
impl pallet_vesting::Config for Runtime {
type Event = Event;
type Currency = Balances;
type BlockNumberToBalance = ConvertInto;
type MinVestedTransfer = MinVestedTransfer;
type WeightInfo = pallet_vesting::weights::SubstrateWeight<Runtime>;
// Maximum number of vesting schedules an account may have at a given moment
// follows polkadot https://github.com/paritytech/polkadot/blob/9ce5f7ef5abb1a4291454e8c9911b304d80679f9/runtime/polkadot/src/lib.rs#L980
const MAX_VESTING_SCHEDULES: u32 = 28;
}
parameter_types! {
// One storage item; key size is 32+32; value is size 4+4+16+32 bytes = 56 bytes.
pub const DepositBase: Balance = 120 * DEPOSIT_PER_BYTE;
// Additional storage item size of 32 bytes.
pub const DepositFactor: Balance = 32 * DEPOSIT_PER_BYTE;
pub const MaxSignatories: u16 = 100;
}
impl pallet_multisig::Config for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
type DepositBase = DepositBase;
type DepositFactor = DepositFactor;
type MaxSignatories = MaxSignatories;
type WeightInfo = pallet_multisig::weights::SubstrateWeight<Runtime>;
}
#[cfg(not(feature = "enable_treasury_proposals"))]
// This value effectively disables treasury.
pub const TREASURY_PROPOSAL_BOND: Balance = 100_000_000_000 * TOKEN;
#[cfg(feature = "enable_treasury_proposals")]
pub const TREASURY_PROPOSAL_BOND: Balance = 100 * TOKEN;
parameter_types! {
// We do not burn any money within treasury.
pub const Burn: Permill = Permill::from_percent(0);
// The fraction of the proposal that the proposer should deposit.
// We agreed on non-progressive deposit.
pub const ProposalBond: Permill = Permill::from_percent(0);
// The minimal deposit for proposal.
pub const ProposalBondMinimum: Balance = TREASURY_PROPOSAL_BOND;
// The upper bound of the deposit for the proposal.
pub const ProposalBondMaximum: Balance = TREASURY_PROPOSAL_BOND;
// Maximum number of approvals that can wait in the spending queue.
pub const MaxApprovals: u32 = 20;
// Every 4 hours we fund accepted proposals.
pub const SpendPeriod: BlockNumber = 4 * BLOCKS_PER_HOUR;
pub const TreasuryPalletId: PalletId = PalletId(*b"a0/trsry");
}
pub struct TreasuryGovernance;
impl SortedMembers<AccountId> for TreasuryGovernance {
fn sorted_members() -> Vec<AccountId> {
pallet_sudo::Pallet::<Runtime>::key().into_iter().collect()
}
}
impl pallet_treasury::Config for Runtime {
type ApproveOrigin = EnsureSignedBy<TreasuryGovernance, AccountId>;
type Burn = Burn;
type BurnDestination = ();
type Currency = Balances;
type Event = Event;
type MaxApprovals = MaxApprovals;
type OnSlash = ();
type PalletId = TreasuryPalletId;
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type ProposalBondMaximum = ProposalBondMaximum;
type RejectOrigin = EnsureSignedBy<TreasuryGovernance, AccountId>;
type SpendFunds = ();
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<u128>;
type SpendPeriod = SpendPeriod;
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
}
impl pallet_utility::Config for Runtime {
type Event = Event;
type Call = Call;
type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
type PalletsOrigin = OriginCaller;
}
parameter_types! {
// bytes count taken from:
// https://github.com/paritytech/polkadot/blob/016dc7297101710db0483ab6ef199e244dff711d/runtime/kusama/src/lib.rs#L995
pub const BasicDeposit: Balance = 258 * DEPOSIT_PER_BYTE;
pub const FieldDeposit: Balance = 66 * DEPOSIT_PER_BYTE;
pub const SubAccountDeposit: Balance = 53 * DEPOSIT_PER_BYTE;
pub const MaxSubAccounts: u32 = 100;
pub const MaxAdditionalFields: u32 = 100;
pub const MaxRegistrars: u32 = 20;
}
impl pallet_identity::Config for Runtime {
type Event = Event;
type Currency = Balances;
type BasicDeposit = BasicDeposit;
type FieldDeposit = FieldDeposit;
type SubAccountDeposit = SubAccountDeposit;
type MaxSubAccounts = MaxSubAccounts;
type MaxAdditionalFields = MaxAdditionalFields;
type MaxRegistrars = MaxRegistrars;
type Slashed = Treasury;
type ForceOrigin = EnsureRoot<AccountId>;
type RegistrarOrigin = EnsureRoot<AccountId>;
type WeightInfo = pallet_identity::weights::SubstrateWeight<Self>;
}
// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system,
RandomnessCollectiveFlip: pallet_randomness_collective_flip,
Scheduler: pallet_scheduler,
Aura: pallet_aura,
Timestamp: pallet_timestamp,
Balances: pallet_balances,
TransactionPayment: pallet_transaction_payment,
Authorship: pallet_authorship,
Staking: pallet_staking,
History: pallet_session::historical,
Session: pallet_session,
Aleph: pallet_aleph,
Elections: pallet_elections,
Treasury: pallet_treasury,
Vesting: pallet_vesting,
Utility: pallet_utility,
Multisig: pallet_multisig,
Sudo: pallet_sudo,
NominationPools: pallet_nomination_pools,
Identity: pallet_identity,
}
);
/// The address format for describing accounts.
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Block type as expected by this runtime.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// A Block signed with a Justification
pub type SignedBlock = generic::SignedBlock<Block>;
/// BlockId type as expected by this runtime.
pub type BlockId = generic::BlockId<Block>;
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
frame_system::CheckGenesis<Runtime>,
frame_system::CheckEra<Runtime>,
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;
/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
>;
impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
}
fn execute_block(block: Block) {
Executive::execute_block(block);
}
fn initialize_block(header: &<Block as BlockT>::Header) {
Executive::initialize_block(header)
}
}
impl sp_api::Metadata<Block> for Runtime {
fn metadata() -> OpaqueMetadata {
OpaqueMetadata::new(Runtime::metadata().into())
}
}
impl sp_block_builder::BlockBuilder<Block> for Runtime {
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
Executive::apply_extrinsic(extrinsic)
}
fn finalize_block() -> <Block as BlockT>::Header {
Executive::finalize_block()
}
fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
data.create_extrinsics()
}
fn check_inherents(
block: Block,
data: sp_inherents::InherentData,
) -> sp_inherents::CheckInherentsResult {
data.check_extrinsics(&block)
}
}
impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
fn validate_transaction(
source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
block_hash: <Block as BlockT>::Hash,
) -> TransactionValidity {
Executive::validate_transaction(source, tx, block_hash)
}
}
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> SlotDuration {
SlotDuration::from_millis(Aura::slot_duration())
}
fn authorities() -> Vec<AuraId> {
Aura::authorities().to_vec()
}
}
impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
fn offchain_worker(header: &<Block as BlockT>::Header) {
Executive::offchain_worker(header)
}
}
impl sp_session::SessionKeys<Block> for Runtime {
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
opaque::SessionKeys::generate(seed)
}
fn decode_session_keys(
encoded: Vec<u8>,
) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
opaque::SessionKeys::decode_into_raw_public_keys(&encoded)
}
}
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
fn account_nonce(account: AccountId) -> Index {
System::account_nonce(account)
}
}
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
fn query_info(
uxt: <Block as BlockT>::Extrinsic,
len: u32,
) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
TransactionPayment::query_info(uxt, len)
}
fn query_fee_details(
uxt: <Block as BlockT>::Extrinsic,
len: u32,
) -> pallet_transaction_payment::FeeDetails<Balance> {
TransactionPayment::query_fee_details(uxt, len)
}
}
impl primitives::AlephSessionApi<Block> for Runtime {
fn millisecs_per_block() -> u64 {
MILLISECS_PER_BLOCK
}
fn session_period() -> u32 {
SessionPeriod::get()
}
fn authorities() -> Vec<AlephId> {
Aleph::authorities()
}
fn next_session_authorities() -> Result<Vec<AlephId>, AlephApiError> {
Session::queued_keys()
.iter()
.map(|(_, key)| key.get(AlephId::ID).ok_or(AlephApiError::DecodeKey))
.collect::<Result<Vec<AlephId>, AlephApiError>>()
}
fn authority_data() -> SessionAuthorityData {
SessionAuthorityData::new(Aleph::authorities(), Aleph::emergency_finalizer())
}
fn next_session_authority_data() -> Result<SessionAuthorityData, AlephApiError> {
Ok(SessionAuthorityData::new(Session::queued_keys()
.iter()
.map(|(_, key)| key.get(AlephId::ID).ok_or(AlephApiError::DecodeKey))
.collect::<Result<Vec<AlephId>, AlephApiError>>()?,
Aleph::queued_emergency_finalizer(),
))
}
fn finality_version() -> FinalityVersion {
Aleph::finality_version()
}
fn next_session_finality_version() -> FinalityVersion {
Aleph::next_session_finality_version()
}
}
impl pallet_nomination_pools_runtime_api::NominationPoolsApi<Block, AccountId, Balance> for Runtime {
fn pending_rewards(member_account: AccountId) -> Balance {
NominationPools::pending_rewards(member_account)
}
}
#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade() -> (frame_support::weights::Weight, frame_support::weights::Weight) {
log::info!(target: "aleph-runtime", "try-runtime::on_runtime_upgrade");
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, BlockWeights::get().max_block)
}
fn execute_block_no_check(block: Block) -> frame_support::weights::Weight {
Executive::execute_block_no_check(block)
}
}
}
#[cfg(test)]
mod tests {
use crate::VERSION;
#[test]
fn state_version_must_be_zero() {
assert_eq!(0, VERSION.state_version);
}
}