lib.rs 20.1 KB
Newer Older
Gav's avatar
Gav committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Copyright 2017 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.

17
//! The Polkadot runtime. This can be compiled with `#[no_std]`, ready for Wasm.
Gav's avatar
Gav committed
18
19

#![cfg_attr(not(feature = "std"), no_std)]
20
21
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit="256"]
Gav Wood's avatar
Gav Wood committed
22

23
24
mod attestations;
mod claims;
25
mod curated_grandpa;
26
mod parachains;
Gavin Wood's avatar
Gavin Wood committed
27
28
mod slot_range;
mod slots;
Gav Wood's avatar
Gav Wood committed
29

30
use rstd::prelude::*;
31
use substrate_primitives::u32_trait::{_1, _2, _3, _4};
32
use primitives::{
33
34
	AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment,
	parachain,
35
};
36
use client::{
37
	block_builder::api::{self as block_builder_api, InherentData, CheckInherentsResult},
38
	runtime_api as client_api, impl_runtime_apis,
39
};
Gav Wood's avatar
Gav Wood committed
40
use sr_primitives::{
41
	ApplyResult, generic, transaction_validity::TransactionValidity, create_runtime_str, key_types,
42
43
	traits::{BlakeTwo256, Block as BlockT, DigestFor, StaticLookup},
	impl_opaque_keys, weights::Weight,
Gav Wood's avatar
Gav Wood committed
44
};
Arkadiy Paronyan's avatar
Arkadiy Paronyan committed
45
use version::RuntimeVersion;
46
use grandpa::{AuthorityId as GrandpaId, fg_primitives::{self, ScheduledChange}};
47
use babe_primitives::AuthorityId as BabeId;
48
use elections::VoteIndex;
49
50
51
#[cfg(any(feature = "std", test))]
use version::NativeVersion;
use substrate_primitives::OpaqueMetadata;
Gavin Wood's avatar
Gavin Wood committed
52
use srml_support::{
53
	parameter_types, construct_runtime, traits::{SplitTwoWays, Currency}
Gavin Wood's avatar
Gavin Wood committed
54
};
55
use im_online::AuthorityId as ImOnlineId;
56

Gav Wood's avatar
Gav Wood committed
57
58
#[cfg(feature = "std")]
pub use staking::StakerStatus;
59
60
#[cfg(any(feature = "std", test))]
pub use sr_primitives::BuildStorage;
61
pub use timestamp::Call as TimestampCall;
62
pub use balances::Call as BalancesCall;
63
64
pub use attestations::{Call as AttestationsCall, MORE_ATTESTATIONS_IDENTIFIER};
pub use parachains::{Call as ParachainsCall, NEW_HEADS_IDENTIFIER};
65
pub use sr_primitives::{Permill, Perbill};
66
pub use srml_support::StorageValue;
67

68
69
70
71
72
73
74
75
/// Implementations of some helper traits passed into runtime modules as associated types.
pub mod impls;
use impls::{CurrencyToVoteHandler, WeightMultiplierUpdateHandler, ToAuthor, WeightToFee};

/// Constant values used within the runtime.
pub mod constants;
use constants::{time::*, currency::*};

76
77
78
79
// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

80
/// Runtime version.
Arkadiy Paronyan's avatar
Arkadiy Paronyan committed
81
pub const VERSION: RuntimeVersion = RuntimeVersion {
82
83
	spec_name: create_runtime_str!("polkadot"),
	impl_name: create_runtime_str!("parity-polkadot"),
Gav Wood's avatar
Gav Wood committed
84
	authoring_version: 1,
André Silva's avatar
André Silva committed
85
	spec_version: 1000,
86
	impl_version: 0,
87
	apis: RUNTIME_API_VERSIONS,
Arkadiy Paronyan's avatar
Arkadiy Paronyan committed
88
89
};

90
91
92
93
94
95
96
97
98
/// Native version.
#[cfg(any(feature = "std", test))]
pub fn native_version() -> NativeVersion {
	NativeVersion {
		runtime_version: VERSION,
		can_author_with: Default::default(),
	}
}

99
type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
Gavin Wood's avatar
Gavin Wood committed
100

101
parameter_types! {
102
	pub const BlockHashCount: BlockNumber = 250;
103
104
105
	pub const MaximumBlockWeight: Weight = 1_000_000_000;
	pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
	pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
106
107
}

108
109
impl system::Trait for Runtime {
	type Origin = Origin;
110
	type Call = Call;
Gav Wood's avatar
Gav Wood committed
111
	type Index = Nonce;
112
113
114
115
	type BlockNumber = BlockNumber;
	type Hash = Hash;
	type Hashing = BlakeTwo256;
	type AccountId = AccountId;
Gav Wood's avatar
Gav Wood committed
116
	type Lookup = Indices;
117
	type Header = generic::Header<BlockNumber, BlakeTwo256>;
118
	type WeightMultiplierUpdate = WeightMultiplierUpdateHandler;
Gav's avatar
Gav committed
119
	type Event = Event;
120
	type BlockHashCount = BlockHashCount;
121
122
123
	type MaximumBlockWeight = MaximumBlockWeight;
	type MaximumBlockLength = MaximumBlockLength;
	type AvailableBlockRatio = AvailableBlockRatio;
124
125
}

126
127
128
129
130
131
132
133
parameter_types! {
	pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS;
	pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
}

impl babe::Trait for Runtime {
	type EpochDuration = EpochDuration;
	type ExpectedBlockTime = ExpectedBlockTime;
134
135
}

Gav Wood's avatar
Gav Wood committed
136
137
138
139
140
141
142
impl indices::Trait for Runtime {
	type IsDeadAccount = Balances;
	type AccountIndex = AccountIndex;
	type ResolveHint = indices::SimpleResolveHint<Self::AccountId, Self::AccountIndex>;
	type Event = Event;
}

Gavin Wood's avatar
Gavin Wood committed
143
parameter_types! {
144
	pub const ExistentialDeposit: Balance = 10 * CENTS;
Gavin Wood's avatar
Gavin Wood committed
145
146
147
148
149
150
151
152
153
154
	pub const TransferFee: Balance = 1 * CENTS;
	pub const CreationFee: Balance = 1 * CENTS;
	pub const TransactionBaseFee: Balance = 1 * CENTS;
	pub const TransactionByteFee: Balance = 10 * MILLICENTS;
}

/// Splits fees 80/20 between treasury and block author.
pub type DealWithFees = SplitTwoWays<
	Balance,
	NegativeImbalance,
155
156
	_4, Treasury,   // 4 parts (80%) goes to the treasury.
	_1, ToAuthor,   // 1 part (20%) goes to the block author.
Gavin Wood's avatar
Gavin Wood committed
157
158
>;

159
impl balances::Trait for Runtime {
Gav's avatar
Gav committed
160
161
	type Balance = Balance;
	type OnFreeBalanceZero = Staking;
Gav Wood's avatar
Gav Wood committed
162
	type OnNewAccount = Indices;
Gav's avatar
Gav committed
163
	type Event = Event;
Gavin Wood's avatar
Gavin Wood committed
164
	type TransactionPayment = DealWithFees;
165
166
	type DustRemoval = ();
	type TransferPayment = ();
Gavin Wood's avatar
Gavin Wood committed
167
168
169
170
171
	type ExistentialDeposit = ExistentialDeposit;
	type TransferFee = TransferFee;
	type CreationFee = CreationFee;
	type TransactionBaseFee = TransactionBaseFee;
	type TransactionByteFee = TransactionByteFee;
172
	type WeightToFee = WeightToFee;
Gav's avatar
Gav committed
173
174
}

175
parameter_types! {
176
	pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
177
178
}

179
impl timestamp::Trait for Runtime {
180
	type Moment = u64;
181
	type OnTimestampSet = Babe;
182
	type MinimumPeriod = MinimumPeriod;
183
184
}

Gavin Wood's avatar
Gavin Wood committed
185
parameter_types! {
186
	pub const UncleGenerations: u32 = 0;
Gavin Wood's avatar
Gavin Wood committed
187
188
189
190
}

// TODO: substrate#2986 implement this properly
impl authorship::Trait for Runtime {
191
	type FindAuthor = session::FindAccountFromAuthorIndex<Self, Babe>;
Gavin Wood's avatar
Gavin Wood committed
192
193
194
195
196
	type UncleGenerations = UncleGenerations;
	type FilterUncle = ();
	type EventHandler = ();
}

197
198
199
200
201
parameter_types! {
	pub const Period: BlockNumber = 10 * MINUTES;
	pub const Offset: BlockNumber = 0;
}

202
type SessionHandlers = (Grandpa, Babe, ImOnline, Parachains);
203
impl_opaque_keys! {
204
	pub struct SessionKeys {
205
206
207
208
209
210
211
212
		#[id(key_types::GRANDPA)]
		pub grandpa: GrandpaId,
		#[id(key_types::BABE)]
		pub babe: BabeId,
		#[id(key_types::IM_ONLINE)]
		pub im_online: ImOnlineId,
		#[id(parachain::PARACHAIN_KEY_TYPE_ID)]
		pub parachain_validator: parachain::ValidatorId,
213
	}
214
215
216
217
218
219
220
221
}

// 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

222
impl session::Trait for Runtime {
223
224
	type OnSessionEnding = Staking;
	type SessionHandler = SessionHandlers;
225
	type ShouldEndSession = Babe;
Gav's avatar
Gav committed
226
	type Event = Event;
227
	type Keys = SessionKeys;
228
229
230
231
232
233
234
235
	type SelectInitialValidators = Staking;
	type ValidatorId = AccountId;
	type ValidatorIdOf = staking::StashOf<Self>;
}

impl session::historical::Trait for Runtime {
	type FullIdentification = staking::Exposure<AccountId, Balance>;
	type FullIdentificationOf = staking::ExposureOf<Self>;
236
237
}

238
239
240
241
parameter_types! {
	pub const SessionsPerEra: session::SessionIndex = 6;
	pub const BondingDuration: staking::EraIndex = 24 * 28;
}
242

243
244
impl staking::Trait for Runtime {
	type OnRewardMinted = Treasury;
245
	type CurrencyToVote = CurrencyToVoteHandler;
Gav's avatar
Gav committed
246
	type Event = Event;
247
	type Currency = Balances;
248
249
	type Slash = ();
	type Reward = ();
250
251
	type SessionsPerEra = SessionsPerEra;
	type BondingDuration = BondingDuration;
252
	type SessionInterface = Self;
253
	type Time = Timestamp;
254
255
}

256
257
258
parameter_types! {
	pub const LaunchPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
	pub const VotingPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
259
	pub const EmergencyVotingPeriod: BlockNumber = 3 * 24 * 60 * MINUTES;
260
	pub const MinimumDeposit: Balance = 100 * DOLLARS;
261
	pub const EnactmentPeriod: BlockNumber = 30 * 24 * 60 * MINUTES;
262
	pub const CooloffPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
263
264
}

265
266
267
impl democracy::Trait for Runtime {
	type Proposal = Call;
	type Event = Event;
268
	type Currency = Balances;
269
270
271
	type EnactmentPeriod = EnactmentPeriod;
	type LaunchPeriod = LaunchPeriod;
	type VotingPeriod = VotingPeriod;
272
	type EmergencyVotingPeriod = EmergencyVotingPeriod;
273
	type MinimumDeposit = MinimumDeposit;
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
	/// A straight majority of the council can decide what their next motion is.
	type ExternalOrigin = collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>;
	/// A super-majority can have the next scheduled referendum be a straight majority-carries vote.
	type ExternalMajorityOrigin = collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>;
	/// A unanimous council can have the next scheduled referendum be a straight default-carries
	/// (NTB) vote.
	type ExternalDefaultOrigin = collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilCollective>;
	/// Two thirds of the technical committee can have an ExternalMajority/ExternalDefault vote
	/// be tabled immediately and with a shorter voting/enactment period.
	type FastTrackOrigin = collective::EnsureProportionAtLeast<_2, _3, AccountId, TechnicalCollective>;
	// To cancel a proposal which has been passed, 2/3 of the council must agree to it.
	type CancellationOrigin = collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>;
	// Any single technical committee member may veto a coming council proposal, however they can
	// only do it once and it lasts only for the cooloff period.
	type VetoOrigin = collective::EnsureMember<AccountId, TechnicalCollective>;
289
	type CooloffPeriod = CooloffPeriod;
290
}
291

292
293
type CouncilCollective = collective::Instance1;
impl collective::Trait<CouncilCollective> for Runtime {
294
295
296
297
298
	type Origin = Origin;
	type Proposal = Call;
	type Event = Event;
}

Gavin Wood's avatar
Gavin Wood committed
299
parameter_types! {
300
301
302
	pub const CandidacyBond: Balance = 10 * DOLLARS;
	pub const VotingBond: Balance = 1 * DOLLARS;
	pub const VotingFee: Balance = 2 * DOLLARS;
Gavin Wood's avatar
Gavin Wood committed
303
304
305
	pub const PresentSlashPerVoter: Balance = 1 * CENTS;
	pub const CarryCount: u32 = 6;
	// one additional vote should go by before an inactive voter can be reaped.
306
307
	pub const InactiveGracePeriod: VoteIndex = 1;
	pub const ElectionsVotingPeriod: BlockNumber = 2 * DAYS;
Gavin Wood's avatar
Gavin Wood committed
308
309
310
	pub const DecayRatio: u32 = 0;
}

311
impl elections::Trait for Runtime {
312
	type Event = Event;
313
	type Currency = Balances;
314
315
	type BadPresentation = ();
	type BadReaper = ();
316
317
	type BadVoterIndex = ();
	type LoserCandidate = ();
318
	type ChangeMembers = Council;
Gavin Wood's avatar
Gavin Wood committed
319
320
321
322
323
324
	type CandidacyBond = CandidacyBond;
	type VotingBond = VotingBond;
	type VotingFee = VotingFee;
	type PresentSlashPerVoter = PresentSlashPerVoter;
	type CarryCount = CarryCount;
	type InactiveGracePeriod = InactiveGracePeriod;
325
	type VotingPeriod = ElectionsVotingPeriod;
Gavin Wood's avatar
Gavin Wood committed
326
	type DecayRatio = DecayRatio;
327
328
}

329
330
type TechnicalCollective = collective::Instance2;
impl collective::Trait<TechnicalCollective> for Runtime {
331
332
333
334
335
	type Origin = Origin;
	type Proposal = Call;
	type Event = Event;
}

336
337
338
339
340
341
342
343
344
345
impl membership::Trait<membership::Instance1> for Runtime {
	type Event = Event;
	type AddOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
	type RemoveOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
	type SwapOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
	type ResetOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
	type MembershipInitialized = TechnicalCommittee;
	type MembershipChanged = TechnicalCommittee;
}

Gavin Wood's avatar
Gavin Wood committed
346
347
parameter_types! {
	pub const ProposalBond: Permill = Permill::from_percent(5);
348
	pub const ProposalBondMinimum: Balance = 1 * DOLLARS;
Gavin Wood's avatar
Gavin Wood committed
349
350
351
352
	pub const SpendPeriod: BlockNumber = 1 * DAYS;
	pub const Burn: Permill = Permill::from_percent(50);
}

353
impl treasury::Trait for Runtime {
Gavin Wood's avatar
Gavin Wood committed
354
	type Currency = Balances;
355
356
	type ApproveOrigin = collective::EnsureMembers<_4, AccountId, CouncilCollective>;
	type RejectOrigin = collective::EnsureMembers<_2, AccountId, CouncilCollective>;
357
	type Event = Event;
358
359
	type MintedForSpending = ();
	type ProposalRejection = ();
Gavin Wood's avatar
Gavin Wood committed
360
361
362
363
	type ProposalBond = ProposalBond;
	type ProposalBondMinimum = ProposalBondMinimum;
	type SpendPeriod = SpendPeriod;
	type Burn = Burn;
364
}
365

366
367
368
369
370
371
impl im_online::Trait for Runtime {
	type Call = Call;
	type Event = Event;
	type UncheckedExtrinsic = UncheckedExtrinsic;
}

372
373
374
375
impl grandpa::Trait for Runtime {
	type Event = Event;
}

Gavin Wood's avatar
Gavin Wood committed
376
377
378
379
380
381
382
383
384
385
386
parameter_types! {
	pub const WindowSize: BlockNumber = finality_tracker::DEFAULT_WINDOW_SIZE.into();
	pub const ReportLatency: BlockNumber = finality_tracker::DEFAULT_REPORT_LATENCY.into();
}

impl finality_tracker::Trait for Runtime {
	type OnFinalizationStalled = Grandpa;
	type WindowSize = WindowSize;
	type ReportLatency = ReportLatency;
}

387
388
389
390
parameter_types! {
	pub const AttestationPeriod: BlockNumber = 50;
}

391
392
393
394
395
impl attestations::Trait for Runtime {
	type AttestationPeriod = AttestationPeriod;
	type ValidatorIdentities = parachains::ValidatorIdentities<Runtime>;
}

396
397
398
impl parachains::Trait for Runtime {
	type Origin = Origin;
	type Call = Call;
399
	type ParachainCurrency = Balances;
400
}
401

Gavin Wood's avatar
Gavin Wood committed
402
parameter_types!{
403
	pub const LeasePeriod: BlockNumber = 100_000;
Gavin Wood's avatar
Gavin Wood committed
404
405
406
407
408
409
410
411
412
413
414
	pub const EndingPeriod: BlockNumber = 1000;
}

impl slots::Trait for Runtime {
	type Event = Event;
	type Currency = balances::Module<Self>;
	type Parachains = parachains::Module<Self>;
	type LeasePeriod = LeasePeriod;
	type EndingPeriod = EndingPeriod;
}

415
416
impl curated_grandpa::Trait for Runtime { }

417
418
419
420
421
422
423
424
425
426
parameter_types!{
	pub const Prefix: &'static [u8] = b"Pay KSMs to the Kusama account:";
}

impl claims::Trait for Runtime {
	type Event = Event;
	type Currency = Balances;
	type Prefix = Prefix;
}

Gav Wood's avatar
Gav Wood committed
427
428
429
430
431
impl sudo::Trait for Runtime {
	type Event = Event;
	type Proposal = Call;
}

432
construct_runtime!(
433
	pub enum Runtime where
434
		Block = Block,
435
		NodeBlock = primitives::Block,
436
		UncheckedExtrinsic = UncheckedExtrinsic
437
	{
Gavin Wood's avatar
Gavin Wood committed
438
		System: system::{Module, Call, Storage, Config, Event},
439
		Timestamp: timestamp::{Module, Call, Storage, Inherent},
440
		Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
Gavin Wood's avatar
Gavin Wood committed
441
		Authorship: authorship::{Module, Call, Storage},
Gav Wood's avatar
Gav Wood committed
442
		Indices: indices,
443
		Balances: balances,
Gavin Wood's avatar
Gavin Wood committed
444
		Staking: staking::{default, OfflineWorker},
445
		Session: session::{Module, Call, Storage, Event, Config<T>},
Gavin Wood's avatar
Gavin Wood committed
446
		Democracy: democracy::{Module, Call, Storage, Config, Event<T>},
447
448
449
		Council: collective::<Instance1>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
		TechnicalCommittee: collective::<Instance2>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
		Elections: elections::{Module, Call, Storage, Event<T>, Config<T>},
450
		TechnicalMembership: membership::<Instance1>::{Module, Call, Storage, Event<T>, Config<T>},
Gavin Wood's avatar
Gavin Wood committed
451
452
453
454
		FinalityTracker: finality_tracker::{Module, Call, Inherent},
		Grandpa: grandpa::{Module, Call, Storage, Config, Event},
		CuratedGrandpa: curated_grandpa::{Module, Call, Config<T>, Storage},
		Treasury: treasury::{Module, Call, Storage, Event<T>},
455
		Parachains: parachains::{Module, Call, Storage, Config<T>, Inherent, Origin},
456
		Attestations: attestations::{Module, Call, Storage},
Gavin Wood's avatar
Gavin Wood committed
457
		Slots: slots::{Module, Call, Storage, Event<T>},
458
		Claims: claims::{Module, Call, Storage, Event<T>, Config<T>, ValidateUnsigned},
Gav Wood's avatar
Gav Wood committed
459
		Sudo: sudo,
460
		ImOnline: im_online::{Module, Call, Storage, Event, ValidateUnsigned, Config<T>},
Gav's avatar
Gav committed
461
	}
462
463
464
);

/// The address format for describing accounts.
Gav Wood's avatar
Gav Wood committed
465
pub type Address = <Indices as StaticLookup>::Source;
466
/// Block header type as expected by this runtime.
467
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
468
469
470
471
472
473
/// 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>;
474
475
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
476
	system::CheckGenesis<Runtime>,
477
478
479
480
481
	system::CheckEra<Runtime>,
	system::CheckNonce<Runtime>,
	system::CheckWeight<Runtime>,
	balances::TakeFees<Runtime>
);
482
/// Unchecked extrinsic type as expected by this runtime.
483
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
484
/// Extrinsic type that has already been checked.
Gav Wood's avatar
Gav Wood committed
485
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Nonce, Call>;
486
/// Executive: handles dispatch to the various modules.
487
pub type Executive = executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;
488
489

impl_runtime_apis! {
490
	impl client_api::Core<Block> for Runtime {
491
492
493
494
495
496
497
		fn version() -> RuntimeVersion {
			VERSION
		}

		fn execute_block(block: Block) {
			Executive::execute_block(block)
		}
498

499
500
		fn initialize_block(header: &<Block as BlockT>::Header) {
			Executive::initialize_block(header)
501
502
		}
	}
Gav's avatar
Gav committed
503

504
	impl client_api::Metadata<Block> for Runtime {
505
506
507
		fn metadata() -> OpaqueMetadata {
			Runtime::metadata().into()
		}
Gav's avatar
Gav committed
508
509
	}

510
	impl block_builder_api::BlockBuilder<Block> for Runtime {
511
512
513
514
		fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyResult {
			Executive::apply_extrinsic(extrinsic)
		}

515
516
		fn finalize_block() -> <Block as BlockT>::Header {
			Executive::finalize_block()
517
		}
518

519
520
		fn inherent_extrinsics(data: InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
			data.create_extrinsics()
521
		}
522

523
524
		fn check_inherents(block: Block, data: InherentData) -> CheckInherentsResult {
			data.check_extrinsics(&block)
525
		}
526

527
528
529
		fn random_seed() -> <Block as BlockT>::Hash {
			System::random_seed()
		}
530
531
	}

532
	impl client_api::TaggedTransactionQueue<Block> for Runtime {
533
534
535
		fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity {
			Executive::validate_transaction(tx)
		}
Gav's avatar
Gav committed
536
	}
537

538
539
540
541
542
543
	impl offchain_primitives::OffchainWorkerApi<Block> for Runtime {
		fn offchain_worker(number: sr_primitives::traits::NumberFor<Block>) {
			Executive::offchain_worker(number)
		}
	}

544
	impl parachain::ParachainHost<Block> for Runtime {
Gav Wood's avatar
Gav Wood committed
545
		fn validators() -> Vec<parachain::ValidatorId> {
546
			Parachains::authorities()
547
548
		}
		fn duty_roster() -> parachain::DutyRoster {
549
			Parachains::calculate_duty_roster().0
550
551
552
553
		}
		fn active_parachains() -> Vec<parachain::Id> {
			Parachains::active_parachains()
		}
554
555
		fn parachain_status(id: parachain::Id) -> Option<parachain::Status> {
			Parachains::parachain_status(&id)
556
557
558
559
		}
		fn parachain_code(id: parachain::Id) -> Option<Vec<u8>> {
			Parachains::parachain_code(&id)
		}
560
561
		fn ingress(to: parachain::Id) -> Option<parachain::StructuredUnroutedIngress> {
			Parachains::ingress(to).map(parachain::StructuredUnroutedIngress)
562
		}
563
	}
564
565

	impl fg_primitives::GrandpaApi<Block> for Runtime {
Gav Wood's avatar
Gav Wood committed
566
		fn grandpa_pending_change(digest: &DigestFor<Block>)
567
568
			-> Option<ScheduledChange<BlockNumber>>
		{
569
			Grandpa::pending_change(digest)
570
571
		}

572
573
574
575
576
577
		fn grandpa_forced_change(_digest: &DigestFor<Block>)
			-> Option<(BlockNumber, ScheduledChange<BlockNumber>)>
		{
			None // disable forced changes.
		}

578
		fn grandpa_authorities() -> Vec<(GrandpaId, u64)> {
579
580
581
582
			Grandpa::grandpa_authorities()
		}
	}

583
584
585
586
587
588
589
590
591
592
593
594
	impl babe_primitives::BabeApi<Block> for Runtime {
		fn startup_data() -> babe_primitives::BabeConfiguration {
			// The choice of `c` parameter (where `1 - c` represents the
			// probability of a slot being empty), is done in accordance to the
			// slot duration and expected target block time, for safely
			// resisting network delays of maximum two seconds.
			// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results>
			babe_primitives::BabeConfiguration {
				median_required_blocks: 1000,
				slot_duration: Babe::slot_duration(),
				c: (278, 1000),
			}
595
		}
596

597
598
599
600
601
602
603
604
		fn epoch() -> babe_primitives::Epoch {
			babe_primitives::Epoch {
				start_slot: Babe::epoch_start_slot(),
				authorities: Babe::authorities(),
				epoch_index: Babe::epoch_index(),
				randomness: Babe::randomness(),
				duration: EpochDuration::get(),
			}
605
606
607
		}
	}

608
609
610
611
612
613
	impl substrate_session::SessionKeys<Block> for Runtime {
		fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
			let seed = seed.as_ref().map(|s| rstd::str::from_utf8(&s).expect("Seed is an utf8 string"));
			SessionKeys::generate(seed)
		}
	}
Gav's avatar
Gav committed
614
}