lib.rs 37 KB
Newer Older
ddorgan's avatar
ddorgan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Copyright 2017-2020 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/>.

//! The Polkadot runtime. This can be compiled with `#[no_std]`, ready for Wasm.

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

Albrecht's avatar
Albrecht committed
23
use pallet_transaction_payment::CurrencyAdapter;
ddorgan's avatar
ddorgan committed
24
use sp_std::prelude::*;
Sergey Pepyakin's avatar
Sergey Pepyakin committed
25
use sp_std::collections::btree_map::BTreeMap;
26
use parity_scale_codec::{Encode, Decode};
27
use primitives::v1::{
28
29
	AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CommittedCandidateReceipt,
	CoreState, GroupRotationInfo, Hash, Id, Moment, Nonce, OccupiedCoreAssumption,
30
	PersistedValidationData, Signature, ValidationCode, ValidatorId, ValidatorIndex,
31
	InboundDownwardMessage, InboundHrmpMessage, SessionInfo,
ddorgan's avatar
ddorgan committed
32
};
33
use runtime_common::{
34
35
	SlowAdjustingFeeUpdate, CurrencyToVote,
	impls::ToAuthor,
36
	BlockHashCount, BlockWeights, BlockLength, RocksDbWeight, OffchainSolutionWeightLimit,
37
	ParachainSessionKeyPlaceholder, AssignmentSessionKeyPlaceholder,
ddorgan's avatar
ddorgan committed
38
39
40
};
use sp_runtime::{
	create_runtime_str, generic, impl_opaque_keys,
41
	ApplyExtrinsicResult, KeyTypeId, Perbill, curve::PiecewiseLinear,
Gavin Wood's avatar
Gavin Wood committed
42
	transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority},
ddorgan's avatar
ddorgan committed
43
	traits::{
44
		BlakeTwo256, Block as BlockT, OpaqueKeys, ConvertInto, AccountIdLookup,
Gavin Wood's avatar
Gavin Wood committed
45
		Extrinsic as ExtrinsicT, SaturatedConversion, Verify,
ddorgan's avatar
ddorgan committed
46
47
48
49
	},
};
#[cfg(feature = "runtime-benchmarks")]
use sp_runtime::RuntimeString;
50
51
use sp_version::RuntimeVersion;
use pallet_grandpa::{AuthorityId as GrandpaId, fg_primitives};
ddorgan's avatar
ddorgan committed
52
#[cfg(any(feature = "std", test))]
53
use sp_version::NativeVersion;
ddorgan's avatar
ddorgan committed
54
55
use sp_core::OpaqueMetadata;
use sp_staking::SessionIndex;
56
use frame_support::{
57
	parameter_types, construct_runtime, RuntimeDebug,
58
	traits::{KeyOwnerProofSystem, Randomness, Filter, InstanceFilter},
59
	weights::Weight,
60
};
61
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
ddorgan's avatar
ddorgan committed
62
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
63
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
64
use pallet_session::historical as session_historical;
65
use frame_system::{EnsureRoot};
ddorgan's avatar
ddorgan committed
66
67

#[cfg(feature = "std")]
68
pub use pallet_staking::StakerStatus;
ddorgan's avatar
ddorgan committed
69
70
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
71
72
pub use pallet_timestamp::Call as TimestampCall;
pub use pallet_balances::Call as BalancesCall;
ddorgan's avatar
ddorgan committed
73
74
75
76
77

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

78
79
80
// Weights used in the runtime
mod weights;

ddorgan's avatar
ddorgan committed
81
82
83
84
// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

85
/// Runtime version (Westend).
ddorgan's avatar
ddorgan committed
86
87
88
89
pub const VERSION: RuntimeVersion = RuntimeVersion {
	spec_name: create_runtime_str!("westend"),
	impl_name: create_runtime_str!("parity-westend"),
	authoring_version: 2,
90
	spec_version: 50,
91
	impl_version: 0,
92
	#[cfg(not(feature = "disable-runtime-api"))]
ddorgan's avatar
ddorgan committed
93
	apis: RUNTIME_API_VERSIONS,
94
	#[cfg(feature = "disable-runtime-api")]
95
	apis: version::create_apis_vec![[]],
96
	transaction_version: 4,
ddorgan's avatar
ddorgan committed
97
98
};

99
100
101
102
103
104
105
/// The BABE epoch configuration at genesis.
pub const BABE_GENESIS_EPOCH_CONFIG: babe_primitives::BabeEpochConfiguration =
	babe_primitives::BabeEpochConfiguration {
		c: PRIMARY_PROBABILITY,
		allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryVRFSlots
	};

ddorgan's avatar
ddorgan committed
106
107
108
109
110
111
112
113
114
/// Native version.
#[cfg(any(feature = "std", test))]
pub fn native_version() -> NativeVersion {
	NativeVersion {
		runtime_version: VERSION,
		can_author_with: Default::default(),
	}
}

115
/// Accept all transactions.
116
117
pub struct BaseFilter;
impl Filter<Call> for BaseFilter {
118
119
	fn filter(_: &Call) -> bool {
		true
ddorgan's avatar
ddorgan committed
120
121
122
123
124
	}
}

parameter_types! {
	pub const Version: RuntimeVersion = VERSION;
125
	pub const SS58Prefix: u8 = 42;
ddorgan's avatar
ddorgan committed
126
127
}

128
impl frame_system::Config for Runtime {
129
	type BaseCallFilter = BaseFilter;
130
131
	type BlockWeights = BlockWeights;
	type BlockLength = BlockLength;
ddorgan's avatar
ddorgan committed
132
133
134
135
136
137
138
	type Origin = Origin;
	type Call = Call;
	type Index = Nonce;
	type BlockNumber = BlockNumber;
	type Hash = Hash;
	type Hashing = BlakeTwo256;
	type AccountId = AccountId;
139
	type Lookup = AccountIdLookup<AccountId, ()>;
ddorgan's avatar
ddorgan committed
140
141
142
	type Header = generic::Header<BlockNumber, BlakeTwo256>;
	type Event = Event;
	type BlockHashCount = BlockHashCount;
143
	type DbWeight = RocksDbWeight;
ddorgan's avatar
ddorgan committed
144
	type Version = Version;
145
	type PalletInfo = PalletInfo;
146
	type AccountData = pallet_balances::AccountData<Balance>;
ddorgan's avatar
ddorgan committed
147
148
	type OnNewAccount = ();
	type OnKilledAccount = ();
149
	type SystemWeightInfo = weights::frame_system::WeightInfo<Runtime>;
150
	type SS58Prefix = SS58Prefix;
ddorgan's avatar
ddorgan committed
151
152
}

153
parameter_types! {
154
155
	pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *
		BlockWeights::get().max_block;
156
157
158
	pub const MaxScheduledPerBlock: u32 = 50;
}

159
impl pallet_scheduler::Config for Runtime {
ddorgan's avatar
ddorgan committed
160
161
	type Event = Event;
	type Origin = Origin;
162
	type PalletsOrigin = OriginCaller;
ddorgan's avatar
ddorgan committed
163
	type Call = Call;
164
	type MaximumWeight = MaximumSchedulerWeight;
165
	type ScheduleOrigin = EnsureRoot<AccountId>;
166
	type MaxScheduledPerBlock = MaxScheduledPerBlock;
167
	type WeightInfo = weights::pallet_scheduler::WeightInfo<Runtime>;
ddorgan's avatar
ddorgan committed
168
169
170
171
172
}

parameter_types! {
	pub const EpochDuration: u64 = EPOCH_DURATION_IN_BLOCKS as u64;
	pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
173
174
	pub const ReportLongevity: u64 =
		BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get();
ddorgan's avatar
ddorgan committed
175
176
}

177
impl pallet_babe::Config for Runtime {
ddorgan's avatar
ddorgan committed
178
179
180
181
	type EpochDuration = EpochDuration;
	type ExpectedBlockTime = ExpectedBlockTime;

	// session module is the trigger
182
	type EpochChangeTrigger = pallet_babe::ExternalTrigger;
183
184
185
186
187

	type KeyOwnerProofSystem = Historical;

	type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
		KeyTypeId,
188
		pallet_babe::AuthorityId,
189
190
191
192
	)>>::Proof;

	type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
		KeyTypeId,
193
		pallet_babe::AuthorityId,
194
195
196
	)>>::IdentificationTuple;

	type HandleEquivocation =
197
		pallet_babe::EquivocationHandler<Self::KeyOwnerIdentification, Offences, ReportLongevity>;
198
199

	type WeightInfo = ();
ddorgan's avatar
ddorgan committed
200
201
202
203
204
205
}

parameter_types! {
	pub const IndexDeposit: Balance = 1 * DOLLARS;
}

206
impl pallet_indices::Config for Runtime {
ddorgan's avatar
ddorgan committed
207
208
209
210
	type AccountIndex = AccountIndex;
	type Currency = Balances;
	type Deposit = IndexDeposit;
	type Event = Event;
211
	type WeightInfo = weights::pallet_indices::WeightInfo<Runtime>;
ddorgan's avatar
ddorgan committed
212
213
214
215
}

parameter_types! {
	pub const ExistentialDeposit: Balance = 1 * CENTS;
216
	pub const MaxLocks: u32 = 50;
ddorgan's avatar
ddorgan committed
217
218
}

219
impl pallet_balances::Config for Runtime {
ddorgan's avatar
ddorgan committed
220
221
222
223
224
	type Balance = Balance;
	type DustRemoval = ();
	type Event = Event;
	type ExistentialDeposit = ExistentialDeposit;
	type AccountStore = System;
225
	type MaxLocks = MaxLocks;
226
	type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
ddorgan's avatar
ddorgan committed
227
228
229
230
231
232
}

parameter_types! {
	pub const TransactionByteFee: Balance = 10 * MILLICENTS;
}

233
impl pallet_transaction_payment::Config for Runtime {
Albrecht's avatar
Albrecht committed
234
	type OnChargeTransaction = CurrencyAdapter<Balances, ToAuthor<Runtime>>;
ddorgan's avatar
ddorgan committed
235
236
	type TransactionByteFee = TransactionByteFee;
	type WeightToFee = WeightToFee;
237
	type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
ddorgan's avatar
ddorgan committed
238
239
240
241
242
}

parameter_types! {
	pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
}
243
impl pallet_timestamp::Config for Runtime {
ddorgan's avatar
ddorgan committed
244
245
246
	type Moment = u64;
	type OnTimestampSet = Babe;
	type MinimumPeriod = MinimumPeriod;
247
	type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
ddorgan's avatar
ddorgan committed
248
249
250
251
252
253
254
}

parameter_types! {
	pub const UncleGenerations: u32 = 0;
}

// TODO: substrate#2986 implement this properly
255
impl pallet_authorship::Config for Runtime {
256
	type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
ddorgan's avatar
ddorgan committed
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
	type UncleGenerations = UncleGenerations;
	type FilterUncle = ();
	type EventHandler = (Staking, ImOnline);
}

parameter_types! {
	pub const Period: BlockNumber = 10 * MINUTES;
	pub const Offset: BlockNumber = 0;
}

impl_opaque_keys! {
	pub struct SessionKeys {
		pub grandpa: Grandpa,
		pub babe: Babe,
		pub im_online: ImOnline,
272
273
		pub para_validator: ParachainSessionKeyPlaceholder<Runtime>,
		pub para_assignment: AssignmentSessionKeyPlaceholder<Runtime>,
ddorgan's avatar
ddorgan committed
274
275
276
277
278
279
280
281
		pub authority_discovery: AuthorityDiscovery,
	}
}

parameter_types! {
	pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
}

282
impl pallet_session::Config for Runtime {
ddorgan's avatar
ddorgan committed
283
284
	type Event = Event;
	type ValidatorId = AccountId;
285
	type ValidatorIdOf = pallet_staking::StashOf<Self>;
ddorgan's avatar
ddorgan committed
286
287
	type ShouldEndSession = Babe;
	type NextSessionRotation = Babe;
288
	type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, Staking>;
ddorgan's avatar
ddorgan committed
289
290
291
	type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
	type Keys = SessionKeys;
	type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
292
	type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
ddorgan's avatar
ddorgan committed
293
294
}

295
impl pallet_session::historical::Config for Runtime {
296
297
	type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
	type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
ddorgan's avatar
ddorgan committed
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
parameter_types! {
	// no signed phase for now, just unsigned.
	pub const SignedPhase: u32 = 0;
	// NOTE: length of unsigned phase is, for now, different than `ElectionLookahead` to make sure
	// that we won't run OCW threads at the same time with staking.
	pub const UnsignedPhase: u32 = ElectionLookahead::get() / 2;

	// fallback: no need to do on-chain phragmen while we re on a dry-run.
	pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy =
		pallet_election_provider_multi_phase::FallbackStrategy::Nothing;

	pub SolutionImprovementThreshold: Perbill = Perbill::from_rational_approximation(1u32, 10_000);

	// miner configs
	pub const MultiPhaseUnsignedPriority: TransactionPriority = StakingUnsignedPriority::get() - 1u64;
	pub const MinerMaxIterations: u32 = 10;
}

impl pallet_election_provider_multi_phase::Config for Runtime {
	type Event = Event;
	type Currency = Balances;
	type SignedPhase = SignedPhase;
	type UnsignedPhase = UnsignedPhase;
	type SolutionImprovementThreshold = MinSolutionScoreBump;
	type MinerMaxIterations = MinerMaxIterations;
	type MinerMaxWeight = OffchainSolutionWeightLimit; // For now use the one from staking.
	type MinerTxPriority = MultiPhaseUnsignedPriority;
	type DataProvider = Staking;
	type OnChainAccuracy = Perbill;
	type CompactSolution = pallet_staking::CompactAssignments;
	type Fallback = Fallback;
	type BenchmarkingConfig = ();
332
	type WeightInfo = weights::pallet_election_provider_multi_phase::WeightInfo<Runtime>;
333
334
}

ddorgan's avatar
ddorgan committed
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
pallet_staking_reward_curve::build! {
	const REWARD_CURVE: PiecewiseLinear<'static> = curve!(
		min_inflation: 0_025_000,
		max_inflation: 0_100_000,
		ideal_stake: 0_500_000,
		falloff: 0_050_000,
		max_piece_count: 40,
		test_precision: 0_005_000,
	);
}

parameter_types! {
	// Six sessions in an era (6 hours).
	pub const SessionsPerEra: SessionIndex = 6;
	// 28 eras for unbonding (7 days).
350
	pub const BondingDuration: pallet_staking::EraIndex = 28;
351
	// 27 eras in which slashes can be cancelled (slightly less than 7 days).
352
	pub const SlashDeferDuration: pallet_staking::EraIndex = 27;
ddorgan's avatar
ddorgan committed
353
354
355
356
	pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
	pub const MaxNominatorRewardedPerValidator: u32 = 64;
	// quarter of the last session will be for election.
	pub const ElectionLookahead: BlockNumber = EPOCH_DURATION_IN_BLOCKS / 4;
357
	pub const MaxIterations: u32 = 10;
358
	pub MinSolutionScoreBump: Perbill = Perbill::from_rational_approximation(5u32, 10_000);
ddorgan's avatar
ddorgan committed
359
360
}

361
impl pallet_staking::Config for Runtime {
ddorgan's avatar
ddorgan committed
362
363
	type Currency = Balances;
	type UnixTime = Timestamp;
364
	type CurrencyToVote = CurrencyToVote;
ddorgan's avatar
ddorgan committed
365
366
367
368
369
370
371
372
	type RewardRemainder = ();
	type Event = Event;
	type Slash = ();
	type Reward = ();
	type SessionsPerEra = SessionsPerEra;
	type BondingDuration = BondingDuration;
	type SlashDeferDuration = SlashDeferDuration;
	// A majority of the council can cancel the slash.
373
	type SlashCancelOrigin = EnsureRoot<AccountId>;
ddorgan's avatar
ddorgan committed
374
375
376
377
378
379
380
	type SessionInterface = Self;
	type RewardCurve = RewardCurve;
	type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
	type NextNewSession = Session;
	type ElectionLookahead = ElectionLookahead;
	type Call = Call;
	type UnsignedPriority = StakingUnsignedPriority;
381
	type MaxIterations = MaxIterations;
382
	type MinSolutionScoreBump = MinSolutionScoreBump;
383
	type OffchainSolutionWeightLimit = OffchainSolutionWeightLimit;
384
	type ElectionProvider = ElectionProviderMultiPhase;
385
	type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
ddorgan's avatar
ddorgan committed
386
387
388
389
390
391
392
393
394
395
396
397
398
399
}

parameter_types! {
	pub const LaunchPeriod: BlockNumber = 7 * DAYS;
	pub const VotingPeriod: BlockNumber = 7 * DAYS;
	pub const FastTrackVotingPeriod: BlockNumber = 3 * HOURS;
	pub const MinimumDeposit: Balance = 1 * DOLLARS;
	pub const EnactmentPeriod: BlockNumber = 8 * DAYS;
	pub const CooloffPeriod: BlockNumber = 7 * DAYS;
	// One cent: $10,000 / MB
	pub const PreimageByteDeposit: Balance = 10 * MILLICENTS;
	pub const InstantAllowed: bool = true;
}

400
parameter_types! {
401
	pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * BlockWeights::get().max_block;
402
403
}

404
impl pallet_offences::Config for Runtime {
ddorgan's avatar
ddorgan committed
405
	type Event = Event;
406
	type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
ddorgan's avatar
ddorgan committed
407
	type OnOffenceHandler = Staking;
408
	type WeightSoftLimit = OffencesWeightSoftLimit;
ddorgan's avatar
ddorgan committed
409
410
}

411
impl pallet_authority_discovery::Config for Runtime {}
ddorgan's avatar
ddorgan committed
412
413
414
415
416
417
418
419
420
421

parameter_types! {
	pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_BLOCKS as _;
}

parameter_types! {
	pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2;
	pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
}

422
impl pallet_im_online::Config for Runtime {
ddorgan's avatar
ddorgan committed
423
424
	type AuthorityId = ImOnlineId;
	type Event = Event;
425
	type ValidatorSet = Historical;
ddorgan's avatar
ddorgan committed
426
427
428
	type ReportUnresponsiveness = Offences;
	type SessionDuration = SessionDuration;
	type UnsignedPriority = StakingUnsignedPriority;
429
	type WeightInfo = weights::pallet_im_online::WeightInfo<Runtime>;
ddorgan's avatar
ddorgan committed
430
431
}

432
impl pallet_grandpa::Config for Runtime {
ddorgan's avatar
ddorgan committed
433
	type Event = Event;
434
435
436
437
438
439
440
441
442
443
444
445
	type Call = Call;

	type KeyOwnerProofSystem = Historical;

	type KeyOwnerProof =
		<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;

	type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
		KeyTypeId,
		GrandpaId,
	)>>::IdentificationTuple;

446
447
	type HandleEquivocation =
		pallet_grandpa::EquivocationHandler<Self::KeyOwnerIdentification, Offences, ReportLongevity>;
448
449

	type WeightInfo = ();
ddorgan's avatar
ddorgan committed
450
451
}

452
453
/// Submits a transaction with the node's public and signature type. Adheres to the signed extension
/// format of the chain.
454
impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
455
456
	Call: From<LocalCall>,
{
457
	fn create_transaction<C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>>(
458
459
460
		call: Call,
		public: <Signature as Verify>::Signer,
		account: AccountId,
461
		nonce: <Runtime as frame_system::Config>::Index,
462
	) -> Option<(Call, <UncheckedExtrinsic as ExtrinsicT>::SignaturePayload)> {
463
		use sp_runtime::traits::StaticLookup;
464
		// take the biggest period possible.
465
466
467
468
469
470
471
		let period = BlockHashCount::get()
			.checked_next_power_of_two()
			.map(|c| c / 2)
			.unwrap_or(2) as u64;

		let current_block = System::block_number()
			.saturated_into::<u64>()
472
473
			// The `System::block_number` is initialized with `n+1`,
			// so the actual block number is `n`.
474
475
476
			.saturating_sub(1);
		let tip = 0;
		let extra: SignedExtra = (
477
478
479
480
481
482
483
			frame_system::CheckSpecVersion::<Runtime>::new(),
			frame_system::CheckTxVersion::<Runtime>::new(),
			frame_system::CheckGenesis::<Runtime>::new(),
			frame_system::CheckMortality::<Runtime>::from(generic::Era::mortal(period, current_block)),
			frame_system::CheckNonce::<Runtime>::from(nonce),
			frame_system::CheckWeight::<Runtime>::new(),
			pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
484
485
		);
		let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
486
			log::warn!("Unable to create signed payload: {:?}", e);
487
		}).ok()?;
488
489
490
		let signature = raw_payload.using_encoded(|payload| {
			C::sign(payload, public)
		})?;
491
		let (call, extra, _) = raw_payload.deconstruct();
492
493
		let address = <Runtime as frame_system::Config>::Lookup::unlookup(account);
		Some((call, (address, signature, extra)))
494
	}
ddorgan's avatar
ddorgan committed
495
496
}

497
impl frame_system::offchain::SigningTypes for Runtime {
498
499
500
501
	type Public = <Signature as Verify>::Signer;
	type Signature = Signature;
}

502
impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime where
503
504
505
506
507
508
	Call: From<C>,
{
	type OverarchingCall = Call;
	type Extrinsic = UncheckedExtrinsic;
}

ddorgan's avatar
ddorgan committed
509
510
511
512
513
514
515
parameter_types! {
	// Minimum 100 bytes/KSM deposited (1 CENT/byte)
	pub const BasicDeposit: Balance = 10 * DOLLARS;       // 258 bytes on-chain
	pub const FieldDeposit: Balance = 250 * CENTS;        // 66 bytes on-chain
	pub const SubAccountDeposit: Balance = 2 * DOLLARS;   // 53 bytes on-chain
	pub const MaxSubAccounts: u32 = 100;
	pub const MaxAdditionalFields: u32 = 100;
516
	pub const MaxRegistrars: u32 = 20;
ddorgan's avatar
ddorgan committed
517
518
}

519
impl pallet_identity::Config for Runtime {
ddorgan's avatar
ddorgan committed
520
521
522
523
524
525
526
527
	type Event = Event;
	type Currency = Balances;
	type Slashed = ();
	type BasicDeposit = BasicDeposit;
	type FieldDeposit = FieldDeposit;
	type SubAccountDeposit = SubAccountDeposit;
	type MaxSubAccounts = MaxSubAccounts;
	type MaxAdditionalFields = MaxAdditionalFields;
528
	type MaxRegistrars = MaxRegistrars;
529
530
	type RegistrarOrigin = frame_system::EnsureRoot<AccountId>;
	type ForceOrigin = frame_system::EnsureRoot<AccountId>;
531
	type WeightInfo = weights::pallet_identity::WeightInfo<Runtime>;
ddorgan's avatar
ddorgan committed
532
533
}

534
impl pallet_utility::Config for Runtime {
535
536
	type Event = Event;
	type Call = Call;
537
	type WeightInfo = weights::pallet_utility::WeightInfo<Runtime>;
538
539
}

ddorgan's avatar
ddorgan committed
540
parameter_types! {
541
542
	// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes.
	pub const DepositBase: Balance = deposit(1, 88);
ddorgan's avatar
ddorgan committed
543
	// Additional storage item size of 32 bytes.
544
	pub const DepositFactor: Balance = deposit(0, 32);
ddorgan's avatar
ddorgan committed
545
546
547
	pub const MaxSignatories: u16 = 100;
}

548
impl pallet_multisig::Config for Runtime {
ddorgan's avatar
ddorgan committed
549
550
551
	type Event = Event;
	type Call = Call;
	type Currency = Balances;
552
553
	type DepositBase = DepositBase;
	type DepositFactor = DepositFactor;
ddorgan's avatar
ddorgan committed
554
	type MaxSignatories = MaxSignatories;
555
	type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
ddorgan's avatar
ddorgan committed
556
557
558
559
560
561
562
563
564
}

parameter_types! {
	pub const ConfigDepositBase: Balance = 5 * DOLLARS;
	pub const FriendDepositFactor: Balance = 50 * CENTS;
	pub const MaxFriends: u16 = 9;
	pub const RecoveryDeposit: Balance = 5 * DOLLARS;
}

565
impl pallet_recovery::Config for Runtime {
ddorgan's avatar
ddorgan committed
566
567
568
569
570
571
572
573
574
575
576
577
578
	type Event = Event;
	type Call = Call;
	type Currency = Balances;
	type ConfigDepositBase = ConfigDepositBase;
	type FriendDepositFactor = FriendDepositFactor;
	type MaxFriends = MaxFriends;
	type RecoveryDeposit = RecoveryDeposit;
}

parameter_types! {
	pub const MinVestedTransfer: Balance = 100 * DOLLARS;
}

579
impl pallet_vesting::Config for Runtime {
ddorgan's avatar
ddorgan committed
580
581
582
583
	type Event = Event;
	type Currency = Balances;
	type BlockNumberToBalance = ConvertInto;
	type MinVestedTransfer = MinVestedTransfer;
584
	type WeightInfo = weights::pallet_vesting::WeightInfo<Runtime>;
ddorgan's avatar
ddorgan committed
585
586
}

587
impl pallet_sudo::Config for Runtime {
ddorgan's avatar
ddorgan committed
588
589
590
591
	type Event = Event;
	type Call = Call;
}

592
593
594
595
596
597
parameter_types! {
	// One storage item; key size 32, value size 8; .
	pub const ProxyDepositBase: Balance = deposit(1, 8);
	// Additional storage item size of 33 bytes.
	pub const ProxyDepositFactor: Balance = deposit(0, 33);
	pub const MaxProxies: u16 = 32;
598
599
600
	pub const AnnouncementDepositBase: Balance = deposit(1, 8);
	pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
	pub const MaxPending: u16 = 32;
601
602
603
604
605
606
607
608
}

/// The type used to represent the kinds of proxying allowed.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug)]
pub enum ProxyType {
	Any,
	NonTransfer,
	Staking,
609
	SudoBalances,
Chevdor's avatar
Chevdor committed
610
	IdentityJudgement,
Shawn Tabrizi's avatar
Shawn Tabrizi committed
611
	CancelProxy,
612
613
614
615
616
617
}
impl Default for ProxyType { fn default() -> Self { Self::Any } }
impl InstanceFilter<Call> for ProxyType {
	fn filter(&self, c: &Call) -> bool {
		match self {
			ProxyType::Any => true,
618
619
620
621
			ProxyType::NonTransfer => matches!(c,
				Call::System(..) |
				Call::Babe(..) |
				Call::Timestamp(..) |
622
623
624
				Call::Indices(pallet_indices::Call::claim(..)) |
				Call::Indices(pallet_indices::Call::free(..)) |
				Call::Indices(pallet_indices::Call::freeze(..)) |
625
626
627
628
629
630
631
632
633
634
635
				// Specifically omitting Indices `transfer`, `force_transfer`
				// Specifically omitting the entire Balances pallet
				Call::Authorship(..) |
				Call::Staking(..) |
				Call::Offences(..) |
				Call::Session(..) |
				Call::Grandpa(..) |
				Call::ImOnline(..) |
				Call::AuthorityDiscovery(..) |
				Call::Utility(..) |
				Call::Identity(..) |
636
637
638
639
640
641
				Call::Recovery(pallet_recovery::Call::as_recovered(..)) |
				Call::Recovery(pallet_recovery::Call::vouch_recovery(..)) |
				Call::Recovery(pallet_recovery::Call::claim_recovery(..)) |
				Call::Recovery(pallet_recovery::Call::close_recovery(..)) |
				Call::Recovery(pallet_recovery::Call::remove_recovery(..)) |
				Call::Recovery(pallet_recovery::Call::cancel_recovered(..)) |
642
				// Specifically omitting Recovery `create_recovery`, `initiate_recovery`
643
644
				Call::Vesting(pallet_vesting::Call::vest(..)) |
				Call::Vesting(pallet_vesting::Call::vest_other(..)) |
645
646
647
648
649
				// Specifically omitting Vesting `vested_transfer`, and `force_vested_transfer`
				Call::Scheduler(..) |
				// Specifically omitting Sudo pallet
				Call::Proxy(..) |
				Call::Multisig(..)
650
651
			),
			ProxyType::Staking => matches!(c,
Shawn Tabrizi's avatar
Shawn Tabrizi committed
652
653
654
				Call::Staking(..) |
				Call::Session(..) |
				Call::Utility(..)
655
			),
656
			ProxyType::SudoBalances => match c {
657
				Call::Sudo(pallet_sudo::Call::sudo(ref x)) => matches!(x.as_ref(), &Call::Balances(..)),
Gavin Wood's avatar
Gavin Wood committed
658
				Call::Utility(..) => true,
659
660
				_ => false,
			},
Chevdor's avatar
Chevdor committed
661
			ProxyType::IdentityJudgement => matches!(c,
Shawn Tabrizi's avatar
Shawn Tabrizi committed
662
663
				Call::Identity(pallet_identity::Call::provide_judgement(..)) |
				Call::Utility(..)
Shawn Tabrizi's avatar
Shawn Tabrizi committed
664
665
			),
			ProxyType::CancelProxy => matches!(c,
666
				Call::Proxy(pallet_proxy::Call::reject_announcement(..))
Chevdor's avatar
Chevdor committed
667
			)
668
669
670
671
672
673
674
675
676
		}
	}
	fn is_superset(&self, o: &Self) -> bool {
		match (self, o) {
			(x, y) if x == y => true,
			(ProxyType::Any, _) => true,
			(_, ProxyType::Any) => false,
			(ProxyType::NonTransfer, _) => true,
			_ => false,
677
678
679
680
		}
	}
}

681
impl pallet_proxy::Config for Runtime {
682
683
684
685
686
687
688
	type Event = Event;
	type Call = Call;
	type Currency = Balances;
	type ProxyType = ProxyType;
	type ProxyDepositBase = ProxyDepositBase;
	type ProxyDepositFactor = ProxyDepositFactor;
	type MaxProxies = MaxProxies;
689
	type WeightInfo = weights::pallet_proxy::WeightInfo<Runtime>;
690
691
692
693
	type MaxPending = MaxPending;
	type CallHasher = BlakeTwo256;
	type AnnouncementDepositBase = AnnouncementDepositBase;
	type AnnouncementDepositFactor = AnnouncementDepositFactor;
694
695
}

ddorgan's avatar
ddorgan committed
696
697
698
construct_runtime! {
	pub enum Runtime where
		Block = Block,
699
		NodeBlock = primitives::v1::Block,
ddorgan's avatar
ddorgan committed
700
701
702
		UncheckedExtrinsic = UncheckedExtrinsic
	{
		// Basic stuff; balances is uncallable initially.
703
704
		System: frame_system::{Module, Call, Storage, Config, Event<T>} = 0,
		RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Storage} = 25,
ddorgan's avatar
ddorgan committed
705
706

		// Must be before session.
707
		Babe: pallet_babe::{Module, Call, Storage, Config, ValidateUnsigned} = 1,
ddorgan's avatar
ddorgan committed
708

709
710
711
712
		Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent} = 2,
		Indices: pallet_indices::{Module, Call, Storage, Config<T>, Event<T>} = 3,
		Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>} = 4,
		TransactionPayment: pallet_transaction_payment::{Module, Storage} = 26,
ddorgan's avatar
ddorgan committed
713
714

		// Consensus support.
715
716
717
718
719
720
721
722
		Authorship: pallet_authorship::{Module, Call, Storage} = 5,
		Staking: pallet_staking::{Module, Call, Storage, Config<T>, Event<T>, ValidateUnsigned} = 6,
		Offences: pallet_offences::{Module, Call, Storage, Event} = 7,
		Historical: session_historical::{Module} = 27,
		Session: pallet_session::{Module, Call, Storage, Event, Config<T>} = 8,
		Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event, ValidateUnsigned} = 10,
		ImOnline: pallet_im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>} = 11,
		AuthorityDiscovery: pallet_authority_discovery::{Module, Call, Config} = 12,
ddorgan's avatar
ddorgan committed
723
724

		// Utility module.
725
		Utility: pallet_utility::{Module, Call, Event} = 16,
ddorgan's avatar
ddorgan committed
726
727

		// Less simple identity module.
728
		Identity: pallet_identity::{Module, Call, Storage, Event<T>} = 17,
ddorgan's avatar
ddorgan committed
729
730

		// Social recovery module.
731
		Recovery: pallet_recovery::{Module, Call, Storage, Event<T>} = 18,
ddorgan's avatar
ddorgan committed
732
733

		// Vesting. Usable initially, but removed once all vesting is finished.
734
		Vesting: pallet_vesting::{Module, Call, Storage, Event<T>, Config<T>} = 19,
ddorgan's avatar
ddorgan committed
735
736

		// System scheduler.
737
		Scheduler: pallet_scheduler::{Module, Call, Storage, Event<T>} = 20,
ddorgan's avatar
ddorgan committed
738
739

		// Sudo.
740
		Sudo: pallet_sudo::{Module, Call, Storage, Event<T>, Config<T>} = 21,
741
742

		// Proxy module. Late addition.
743
		Proxy: pallet_proxy::{Module, Call, Storage, Event<T>} = 22,
744
745

		// Multisig module. Late addition.
746
		Multisig: pallet_multisig::{Module, Call, Storage, Event<T>} = 23,
747
748
749

		// Election pallet. Only works with staking, but placed here to maintain indices.
		ElectionProviderMultiPhase: pallet_election_provider_multi_phase::{Module, Call, Storage, Event<T>, ValidateUnsigned} = 24,
ddorgan's avatar
ddorgan committed
750
751
752
	}
}

753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
impl pallet_babe::migrations::BabePalletPrefix for Runtime {
	fn pallet_prefix() -> &'static str {
		"Babe"
	}
}

pub struct BabeEpochConfigMigrations;
impl frame_support::traits::OnRuntimeUpgrade for BabeEpochConfigMigrations {
	fn on_runtime_upgrade() -> frame_support::weights::Weight {
		pallet_babe::migrations::add_epoch_configuration::<Runtime>(
			BABE_GENESIS_EPOCH_CONFIG,
		)
	}
}

ddorgan's avatar
ddorgan committed
768
/// The address format for describing accounts.
769
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
ddorgan's avatar
ddorgan committed
770
771
772
773
774
775
776
777
778
779
/// 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 = (
780
781
782
783
784
785
786
	frame_system::CheckSpecVersion<Runtime>,
	frame_system::CheckTxVersion<Runtime>,
	frame_system::CheckGenesis<Runtime>,
	frame_system::CheckMortality<Runtime>,
	frame_system::CheckNonce<Runtime>,
	frame_system::CheckWeight<Runtime>,
	pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
ddorgan's avatar
ddorgan committed
787
788
789
790
791
792
);
/// 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, Nonce, Call>;
/// Executive: handles dispatch to the various modules.
793
794
795
796
797
798
pub type Executive = frame_executive::Executive<
	Runtime,
	Block,
	frame_system::ChainContext<Runtime>,
	Runtime,
	AllModules,
799
	BabeEpochConfigMigrations,
800
>;
801
802
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
ddorgan's avatar
ddorgan committed
803

804
805
806
pub struct CustomOnRuntimeUpgrade;
impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
	fn on_runtime_upgrade() -> frame_support::weights::Weight {
Shawn Tabrizi's avatar
Shawn Tabrizi committed
807
		0
808
809
810
	}
}

811
#[cfg(not(feature = "disable-runtime-api"))]
ddorgan's avatar
ddorgan committed
812
813
814
815
816
817
818
sp_api::impl_runtime_apis! {
	impl sp_api::Core<Block> for Runtime {
		fn version() -> RuntimeVersion {
			VERSION
		}

		fn execute_block(block: Block) {
819
			Executive::execute_block(block);
ddorgan's avatar
ddorgan committed
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
		}

		fn initialize_block(header: &<Block as BlockT>::Header) {
			Executive::initialize_block(header)
		}
	}

	impl sp_api::Metadata<Block> for Runtime {
		fn metadata() -> OpaqueMetadata {
			Runtime::metadata().into()
		}
	}

	impl block_builder_api::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: inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
			data.create_extrinsics()
		}

		fn check_inherents(
			block: Block,
			data: inherents::InherentData,
		) -> inherents::CheckInherentsResult {
			data.check_extrinsics(&block)
		}

		fn random_seed() -> <Block as BlockT>::Hash {
854
			pallet_babe::RandomnessFromOneEpochAgo::<Runtime>::random_seed().0
ddorgan's avatar
ddorgan committed
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
		}
	}

	impl tx_pool_api::runtime_api::TaggedTransactionQueue<Block> for Runtime {
		fn validate_transaction(
			source: TransactionSource,
			tx: <Block as BlockT>::Extrinsic,
		) -> TransactionValidity {
			Executive::validate_transaction(source, tx)
		}
	}

	impl offchain_primitives::OffchainWorkerApi<Block> for Runtime {
		fn offchain_worker(header: &<Block as BlockT>::Header) {
			Executive::offchain_worker(header)
		}
	}

873
874
875
	impl primitives::v1::ParachainHost<Block, Hash, BlockNumber> for Runtime {
		fn validators() -> Vec<ValidatorId> {
			Vec::new()
ddorgan's avatar
ddorgan committed
876
		}
877
878
879

		fn validator_groups() -> (Vec<Vec<ValidatorIndex>>, GroupRotationInfo<BlockNumber>) {
			(Vec::new(), GroupRotationInfo { session_start_block: 0, group_rotation_frequency: 0, now: 0 })
ddorgan's avatar
ddorgan committed
880
		}
881

882
		fn availability_cores() -> Vec<CoreState<Hash, BlockNumber>> {
883
			Vec::new()
ddorgan's avatar
ddorgan committed
884
		}
885
886
887

		fn persisted_validation_data(_: Id, _: OccupiedCoreAssumption)
			-> Option<PersistedValidationData<BlockNumber>> {
888
			None
ddorgan's avatar
ddorgan committed
889
		}
890

891
892
893
894
		fn historical_validation_code(_: Id, _: BlockNumber) -> Option<ValidationCode> {
			None
		}

895
896
		fn check_validation_outputs(
			_: Id,
897
			_: primitives::v1::CandidateCommitments
898
899
900
901
		) -> bool {
			false
		}

902
903
904
905
		fn session_index_for_child() -> SessionIndex {
			0
		}

906
907
908
909
		fn session_info(_: SessionIndex) -> Option<SessionInfo> {
			None
		}

910
		fn validation_code(_: Id, _: OccupiedCoreAssumption) -> Option<ValidationCode> {
911
			None
ddorgan's avatar
ddorgan committed
912
		}
913
914
915

		fn candidate_pending_availability(_: Id) -> Option<CommittedCandidateReceipt<Hash>> {
			None
ddorgan's avatar
ddorgan committed
916
		}
917
918

		fn candidate_events() -> Vec<CandidateEvent<Hash>> {
919
			Vec::new()
920
		}
921

922
923
		fn dmq_contents(
			_recipient: Id,
Sergey Pepyakin's avatar
Sergey Pepyakin committed
924
		) -> Vec<InboundDownwardMessage<BlockNumber>> {
925
926
			Vec::new()
		}
Sergey Pepyakin's avatar
Sergey Pepyakin committed
927
928
929
930
931
932

		fn inbound_hrmp_channels_contents(
			_recipient: Id
		) -> BTreeMap<Id, Vec<InboundHrmpMessage<BlockNumber>>> {
			BTreeMap::new()
		}
ddorgan's avatar
ddorgan committed
933
934
935
936
937
938
	}

	impl fg_primitives::GrandpaApi<Block> for Runtime {
		fn grandpa_authorities() -> Vec<(GrandpaId, u64)> {
			Grandpa::grandpa_authorities()
		}
939

940
		fn submit_report_equivocation_unsigned_extrinsic(
941
942
943
944
945
946
947
948
			equivocation_proof: fg_primitives::EquivocationProof<
				<Block as BlockT>::Hash,
				sp_runtime::traits::NumberFor<Block>,
			>,
			key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,
		) -> Option<()> {
			let key_owner_proof = key_owner_proof.decode()?;

949
			Grandpa::submit_unsigned_equivocation_report(
950
951
952
953
954
955
956
957
958
				equivocation_proof,
				key_owner_proof,
			)
		}

		fn generate_key_ownership_proof(
			_set_id: fg_primitives::SetId,
			authority_id: fg_primitives::AuthorityId,
		) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {
959
			use parity_scale_codec::Encode;
960
961
962
963
964

			Historical::prove((fg_primitives::KEY_TYPE, authority_id))
				.map(|p| p.encode())
				.map(fg_primitives::OpaqueKeyOwnershipProof::new)
		}
ddorgan's avatar
ddorgan committed
965
966
967
	}

	impl babe_primitives::BabeApi<Block> for Runtime {
968
		fn configuration() -> babe_primitives::BabeGenesisConfiguration {
ddorgan's avatar
ddorgan committed
969
970
971
972
973
			// 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>
974
			babe_primitives::BabeGenesisConfiguration {
ddorgan's avatar
ddorgan committed
975
976
				slot_duration: Babe::slot_duration(),
				epoch_length: EpochDuration::get(),
977
				c: BABE_GENESIS_EPOCH_CONFIG.c,
ddorgan's avatar
ddorgan committed
978
979
				genesis_authorities: Babe::authorities(),
				randomness: Babe::randomness(),
980
				allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
ddorgan's avatar
ddorgan committed
981
982
983
			}
		}

Bastian Köcher's avatar
Bastian Köcher committed
984
		fn current_epoch_start() -> babe_primitives::Slot {
ddorgan's avatar
ddorgan committed
985
986
			Babe::current_epoch_start()
		}
987

988
989
990
991
		fn current_epoch() -> babe_primitives::Epoch {
			Babe::current_epoch()
		}

992
993
994
995
		fn next_epoch() -> babe_primitives::Epoch {
			Babe::next_epoch()
		}

996
		fn generate_key_ownership_proof(
Bastian Köcher's avatar
Bastian Köcher committed
997
			_slot: babe_primitives::Slot,
998
999
			authority_id: babe_primitives::AuthorityId,
		) -> Option<babe_primitives::OpaqueKeyOwnershipProof> {
1000
			use parity_scale_codec::Encode;
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017

			Historical::prove((babe_primitives::KEY_TYPE, authority_id))
				.map(|p| p.encode())
				.map(babe_primitives::OpaqueKeyOwnershipProof::new)
		}

		fn submit_report_equivocation_unsigned_extrinsic(
			equivocation_proof: babe_primitives::EquivocationProof<<Block as BlockT>::Header>,
			key_owner_proof: babe_primitives::OpaqueKeyOwnershipProof,
		) -> Option<()> {
			let key_owner_proof = key_owner_proof.decode()?;

			Babe::submit_unsigned_equivocation_report(
				equivocation_proof,
				key_owner_proof,
			)
		}
ddorgan's avatar
ddorgan committed
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
	}

	impl authority_discovery_primitives::AuthorityDiscoveryApi<Block> for Runtime {
		fn authorities() -> Vec<AuthorityDiscoveryId> {
			AuthorityDiscovery::authorities()
		}
	}

	impl sp_session::SessionKeys<Block> for Runtime {
		fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
			SessionKeys::generate(seed)
		}

		fn decode_session_keys(
			encoded: Vec<u8>,
		) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
			SessionKeys::decode_into_raw_public_keys(&encoded)
		}
	}

1038
	impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
ddorgan's avatar
ddorgan committed
1039
1040
1041
1042
1043
		fn account_nonce(account: AccountId) -> Nonce {
			System::account_nonce(account)
		}
	}

1044
	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<
ddorgan's avatar
ddorgan committed
1045
1046
1047
		Block,
		Balance,
	> for Runtime {
1048
		fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
ddorgan's avatar
ddorgan committed
1049
1050
			TransactionPayment::query_info(uxt, len)
		}
1051
1052
1053
		fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {
			TransactionPayment::query_fee_details(uxt, len)
		}
ddorgan's avatar
ddorgan committed
1054
1055
	}

Kian Paimani's avatar
Kian Paimani committed
1056
1057
1058
1059
1060
1061
1062
1063
	#[cfg(feature = "try-runtime")]
	impl frame_try_runtime::TryRuntime<Block> for Runtime {
		fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> {
			let weight = Executive::try_runtime_upgrade()?;
			Ok((weight, BlockWeights::get().max_block))
		}
	}

ddorgan's avatar
ddorgan committed
1064
1065
1066
	#[cfg(feature = "runtime-benchmarks")]
	impl frame_benchmarking::Benchmark<Block> for Runtime {
		fn dispatch_benchmark(
1067
			config: frame_benchmarking::BenchmarkConfig,
ddorgan's avatar
ddorgan committed
1068
		) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, RuntimeString> {
1069
			use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
1070
1071
1072
1073
1074
			// Trying to add benchmarks directly to the Session Pallet caused cyclic dependency issues.
			// To get around that, we separated the Session benchmarks into its own crate, which is why
			// we need these two lines below.
			use pallet_session_benchmarking::Module as SessionBench;
			use pallet_offences_benchmarking::Module as OffencesBench;
1075
			use frame_system_benchmarking::Module as SystemBench;
1076

1077
1078
1079
			impl pallet_session_benchmarking::Config for Runtime {}
			impl pallet_offences_benchmarking::Config for Runtime {}
			impl frame_system_benchmarking::Config for Runtime {}
ddorgan's avatar
ddorgan committed
1080

1081
			let whitelist: Vec<TrackedStorageKey> = vec![
1082
				// Block Number
1083
				hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
1084
				// Total Issuance
1085
				hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),
1086
				// Execution Phase
1087
				hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),
1088
				// Event Count
1089
				hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
1090
				// System Events
1091
				hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
1092
				// Treasury Account
1093
				hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da95ecffd7b6c0f78751baa9d281e0bfa3a6d6f646c70792f74727372790000000000000000000000000000000000000000").to_vec().into(),