1#![cfg_attr(not(feature = "std"), no_std)]
2#![feature(const_trait_impl, variant_count)]
3#![allow(incomplete_features)]
5#![feature(generic_const_exprs)]
8#![recursion_limit = "256"]
10#![allow(
12 non_camel_case_types,
13 reason = "https://github.com/rust-lang/rust-analyzer/issues/16514"
14)]
15
16mod domains;
17mod fees;
18mod object_mapping;
19mod weights;
20
21extern crate alloc;
22
23#[cfg(feature = "std")]
25include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
26
27use crate::fees::{OnChargeTransaction, TransactionByteFee};
28use crate::object_mapping::extract_block_object_mapping;
29use alloc::borrow::Cow;
30use core::mem;
31use core::num::NonZeroU64;
32use domain_runtime_primitives::opaque::Header as DomainHeader;
33use domain_runtime_primitives::{
34 AccountIdConverter, BlockNumber as DomainNumber, EthereumAccountId, Hash as DomainHash,
35 MAX_OUTGOING_MESSAGES, maximum_domain_block_weight,
36};
37use frame_support::genesis_builder_helper::{build_state, get_preset};
38use frame_support::inherent::ProvideInherent;
39use frame_support::traits::fungible::HoldConsideration;
40use frame_support::traits::{
41 ConstU8, ConstU16, ConstU32, ConstU64, Currency, EitherOfDiverse, EqualPrivilegeOnly,
42 Everything, Get, LinearStoragePrice, OnUnbalanced, VariantCount,
43};
44use frame_support::weights::constants::ParityDbWeight;
45use frame_support::weights::{ConstantMultiplier, Weight};
46use frame_support::{PalletId, construct_runtime, parameter_types};
47use frame_system::EnsureRoot;
48use frame_system::limits::{BlockLength, BlockWeights};
49use frame_system::pallet_prelude::RuntimeCallFor;
50use pallet_collective::{EnsureMember, EnsureProportionAtLeast};
51pub use pallet_rewards::RewardPoint;
52pub use pallet_subspace::{AllowAuthoringBy, EnableRewardsAt};
53use pallet_transporter::EndpointHandler;
54use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
55use scale_info::TypeInfo;
56use sp_api::impl_runtime_apis;
57use sp_consensus_slots::{Slot, SlotDuration};
58use sp_consensus_subspace::{ChainConstants, PotParameters, SignedVote, SolutionRanges, Vote};
59use sp_core::crypto::KeyTypeId;
60use sp_core::{ConstBool, H256, OpaqueMetadata};
61use sp_domains::bundle::BundleVersion;
62use sp_domains::bundle_producer_election::BundleProducerElectionParams;
63use sp_domains::execution_receipt::{
64 ExecutionReceiptFor, ExecutionReceiptVersion, SealedSingletonReceipt,
65};
66use sp_domains::{
67 BundleAndExecutionReceiptVersion, ChannelId, DomainAllowlistUpdates, DomainId,
68 DomainInstanceData, EpochIndex, INITIAL_DOMAIN_TX_RANGE, OperatorId, OperatorPublicKey,
69 PermissionedActionAllowedBy,
70};
71use sp_domains_fraud_proof::fraud_proof::FraudProof;
72use sp_domains_fraud_proof::storage_proof::{
73 FraudProofStorageKeyProvider, FraudProofStorageKeyRequest,
74};
75use sp_messenger::endpoint::{Endpoint, EndpointHandler as EndpointHandlerT, EndpointId};
76use sp_messenger::messages::{
77 BlockMessagesQuery, ChainId, ChannelStateWithNonce, CrossDomainMessage, MessageId, MessageKey,
78 MessagesWithStorageKey, Nonce as XdmNonce,
79};
80use sp_messenger::{ChannelNonce, XdmId};
81use sp_messenger_host_functions::{StorageKeyRequest, get_storage_key};
82use sp_mmr_primitives::EncodableOpaqueLeaf;
83use sp_runtime::traits::{
84 AccountIdConversion, AccountIdLookup, BlakeTwo256, ConstU128, Keccak256, NumberFor,
85};
86use sp_runtime::transaction_validity::{TransactionSource, TransactionValidity};
87use sp_runtime::type_with_default::TypeWithDefault;
88use sp_runtime::{AccountId32, ApplyExtrinsicResult, ExtrinsicInclusionMode, Perbill, generic};
89use sp_std::collections::btree_map::BTreeMap;
90use sp_std::collections::btree_set::BTreeSet;
91use sp_std::marker::PhantomData;
92use sp_std::prelude::*;
93use sp_subspace_mmr::ConsensusChainMmrLeafProof;
94use sp_subspace_mmr::subspace_mmr_runtime_interface::consensus_block_hash;
95use sp_version::RuntimeVersion;
96use static_assertions::const_assert;
97use subspace_core_primitives::objects::BlockObjectMapping;
98use subspace_core_primitives::pieces::Piece;
99use subspace_core_primitives::segments::{
100 HistorySize, SegmentCommitment, SegmentHeader, SegmentIndex,
101};
102use subspace_core_primitives::solutions::{
103 SolutionRange, pieces_to_solution_range, solution_range_to_pieces,
104};
105use subspace_core_primitives::{PublicKey, Randomness, SlotNumber, U256};
106pub use subspace_runtime_primitives::extension::BalanceTransferCheckExtension;
107use subspace_runtime_primitives::extension::{BalanceTransferChecks, MaybeBalancesCall};
108use subspace_runtime_primitives::utility::{
109 DefaultNonceProvider, MaybeMultisigCall, MaybeNestedCall, MaybeUtilityCall,
110};
111use subspace_runtime_primitives::{
112 AI3, AccountId, BLOCK_WEIGHT_FOR_2_SEC, Balance, BlockHashFor, BlockNumber,
113 ConsensusEventSegmentSize, ExtrinsicFor, FindBlockRewardAddress, Hash, HeaderFor,
114 HoldIdentifier, MAX_BLOCK_LENGTH, MIN_REPLICATION_FACTOR, Moment, NORMAL_DISPATCH_RATIO, Nonce,
115 SHANNON, SLOT_PROBABILITY, Signature, SlowAdjustingFeeUpdate, TargetBlockFullness,
116 XdmAdjustedWeightToFee, XdmFeeMultipler, maximum_normal_block_length,
117};
118
119sp_runtime::impl_opaque_keys! {
120 pub struct SessionKeys {
121 }
122}
123
124const MAX_PIECES_IN_SECTOR: u16 = 1000;
126
127#[sp_version::runtime_version]
130pub const VERSION: RuntimeVersion = RuntimeVersion {
131 spec_name: Cow::Borrowed("subspace"),
132 impl_name: Cow::Borrowed("subspace"),
133 authoring_version: 0,
134 spec_version: 6,
135 impl_version: 0,
136 apis: RUNTIME_API_VERSIONS,
137 transaction_version: 1,
138 system_version: 2,
139};
140
141const SLOT_DURATION: u64 = 1000;
146
147const BLOCK_AUTHORING_DELAY: SlotNumber = 4;
149
150const POT_ENTROPY_INJECTION_INTERVAL: BlockNumber = 50;
152
153const POT_ENTROPY_INJECTION_LOOKBACK_DEPTH: u8 = 2;
155
156const POT_ENTROPY_INJECTION_DELAY: SlotNumber = 15;
158
159const_assert!(POT_ENTROPY_INJECTION_INTERVAL as u64 > POT_ENTROPY_INJECTION_DELAY);
162const_assert!(POT_ENTROPY_INJECTION_DELAY > BLOCK_AUTHORING_DELAY + 1);
166
167const ERA_DURATION_IN_BLOCKS: BlockNumber = 2016;
169
170const TX_RANGE_ADJUSTMENT_INTERVAL_BLOCKS: u64 = 100;
172
173const INITIAL_SOLUTION_RANGE: SolutionRange =
175 pieces_to_solution_range(MAX_PIECES_IN_SECTOR as u64, SLOT_PROBABILITY);
176
177const EXPECTED_VOTES_PER_BLOCK: u32 = 9;
181
182const RECENT_SEGMENTS: HistorySize = HistorySize::new(NonZeroU64::new(5).expect("Not zero; qed"));
184const RECENT_HISTORY_FRACTION: (HistorySize, HistorySize) = (
186 HistorySize::new(NonZeroU64::new(1).expect("Not zero; qed")),
187 HistorySize::new(NonZeroU64::new(10).expect("Not zero; qed")),
188);
189const MIN_SECTOR_LIFETIME: HistorySize =
191 HistorySize::new(NonZeroU64::new(4).expect("Not zero; qed"));
192
193parameter_types! {
194 pub const Version: RuntimeVersion = VERSION;
195 pub const BlockHashCount: BlockNumber = 250;
196 pub SubspaceBlockWeights: BlockWeights = BlockWeights::with_sensible_defaults(BLOCK_WEIGHT_FOR_2_SEC, NORMAL_DISPATCH_RATIO);
198 pub SubspaceBlockLength: BlockLength = maximum_normal_block_length();
200}
201
202pub type SS58Prefix = ConstU16<6094>;
203
204impl frame_system::Config for Runtime {
207 type BaseCallFilter = Everything;
212 type BlockWeights = SubspaceBlockWeights;
214 type BlockLength = SubspaceBlockLength;
216 type AccountId = AccountId;
218 type RuntimeCall = RuntimeCall;
220 type RuntimeTask = RuntimeTask;
222 type Lookup = AccountIdLookup<AccountId, ()>;
224 type Nonce = TypeWithDefault<Nonce, DefaultNonceProvider<System, Nonce>>;
226 type Hash = Hash;
228 type Hashing = BlakeTwo256;
230 type Block = Block;
232 type RuntimeEvent = RuntimeEvent;
234 type RuntimeOrigin = RuntimeOrigin;
236 type BlockHashCount = BlockHashCount;
238 type DbWeight = ParityDbWeight;
240 type Version = Version;
242 type PalletInfo = PalletInfo;
246 type OnNewAccount = ();
248 type OnKilledAccount = ();
250 type AccountData = pallet_balances::AccountData<Balance>;
252 type SystemWeightInfo = weights::frame_system::WeightInfo<Runtime>;
254 type SS58Prefix = SS58Prefix;
256 type OnSetCode = subspace_runtime_primitives::SetCode<Runtime, Domains>;
258 type SingleBlockMigrations = ();
259 type MultiBlockMigrator = ();
260 type PreInherents = ();
261 type PostInherents = ();
262 type PostTransactions = ();
263 type MaxConsumers = ConstU32<16>;
264 type ExtensionsWeightInfo = frame_system::ExtensionsWeight<Runtime>;
265 type EventSegmentSize = ConsensusEventSegmentSize;
266}
267
268parameter_types! {
269 pub const BlockAuthoringDelay: SlotNumber = BLOCK_AUTHORING_DELAY;
270 pub const PotEntropyInjectionInterval: BlockNumber = POT_ENTROPY_INJECTION_INTERVAL;
271 pub const PotEntropyInjectionLookbackDepth: u8 = POT_ENTROPY_INJECTION_LOOKBACK_DEPTH;
272 pub const PotEntropyInjectionDelay: SlotNumber = POT_ENTROPY_INJECTION_DELAY;
273 pub const EraDuration: u32 = ERA_DURATION_IN_BLOCKS;
274 pub const SlotProbability: (u64, u64) = SLOT_PROBABILITY;
275 pub const ExpectedVotesPerBlock: u32 = EXPECTED_VOTES_PER_BLOCK;
276 pub const RecentSegments: HistorySize = RECENT_SEGMENTS;
277 pub const RecentHistoryFraction: (HistorySize, HistorySize) = RECENT_HISTORY_FRACTION;
278 pub const MinSectorLifetime: HistorySize = MIN_SECTOR_LIFETIME;
279 pub const ShouldAdjustSolutionRange: bool = false;
282 pub const BlockSlotCount: u32 = 6;
283}
284
285pub struct ConfirmationDepthK;
286
287impl Get<BlockNumber> for ConfirmationDepthK {
288 fn get() -> BlockNumber {
289 pallet_runtime_configs::ConfirmationDepthK::<Runtime>::get()
290 }
291}
292
293impl pallet_subspace::Config for Runtime {
294 type RuntimeEvent = RuntimeEvent;
295 type SubspaceOrigin = pallet_subspace::EnsureSubspaceOrigin;
296 type BlockAuthoringDelay = BlockAuthoringDelay;
297 type PotEntropyInjectionInterval = PotEntropyInjectionInterval;
298 type PotEntropyInjectionLookbackDepth = PotEntropyInjectionLookbackDepth;
299 type PotEntropyInjectionDelay = PotEntropyInjectionDelay;
300 type EraDuration = EraDuration;
301 type InitialSolutionRange = ConstU64<INITIAL_SOLUTION_RANGE>;
302 type SlotProbability = SlotProbability;
303 type ConfirmationDepthK = ConfirmationDepthK;
304 type RecentSegments = RecentSegments;
305 type RecentHistoryFraction = RecentHistoryFraction;
306 type MinSectorLifetime = MinSectorLifetime;
307 type ExpectedVotesPerBlock = ExpectedVotesPerBlock;
308 type MaxPiecesInSector = ConstU16<{ MAX_PIECES_IN_SECTOR }>;
309 type ShouldAdjustSolutionRange = ShouldAdjustSolutionRange;
310 type EraChangeTrigger = pallet_subspace::NormalEraChange;
311 type WeightInfo = weights::pallet_subspace::WeightInfo<Runtime>;
312 type BlockSlotCount = BlockSlotCount;
313 type ExtensionWeightInfo = weights::pallet_subspace_extension::WeightInfo<Runtime>;
314}
315
316impl pallet_timestamp::Config for Runtime {
317 type Moment = Moment;
319 type OnTimestampSet = ();
320 type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
321 type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
322}
323
324parameter_types! {
325 pub const ExistentialDeposit: Balance = 10_000_000_000_000 * SHANNON;
332}
333
334#[derive(
335 PartialEq, Eq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, Ord, PartialOrd, Copy, Debug,
336)]
337pub struct HoldIdentifierWrapper(HoldIdentifier);
338
339impl pallet_domains::HoldIdentifier<Runtime> for HoldIdentifierWrapper {
340 fn staking_staked() -> Self {
341 Self(HoldIdentifier::DomainStaking)
342 }
343
344 fn domain_instantiation_id() -> Self {
345 Self(HoldIdentifier::DomainInstantiation)
346 }
347
348 fn storage_fund_withdrawal() -> Self {
349 Self(HoldIdentifier::DomainStorageFund)
350 }
351}
352
353impl pallet_messenger::HoldIdentifier<Runtime> for HoldIdentifierWrapper {
354 fn messenger_channel() -> Self {
355 Self(HoldIdentifier::MessengerChannel)
356 }
357}
358
359impl VariantCount for HoldIdentifierWrapper {
360 const VARIANT_COUNT: u32 = mem::variant_count::<HoldIdentifier>() as u32;
361}
362
363impl pallet_balances::Config for Runtime {
364 type RuntimeFreezeReason = RuntimeFreezeReason;
365 type MaxLocks = ConstU32<50>;
366 type MaxReserves = ();
367 type ReserveIdentifier = [u8; 8];
368 type Balance = Balance;
370 type RuntimeEvent = RuntimeEvent;
372 type DustRemoval = ();
373 type ExistentialDeposit = ExistentialDeposit;
374 type AccountStore = System;
375 type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
376 type FreezeIdentifier = ();
377 type MaxFreezes = ();
378 type RuntimeHoldReason = HoldIdentifierWrapper;
379 type DoneSlashHandler = ();
380}
381
382parameter_types! {
383 pub CreditSupply: Balance = Balances::total_issuance();
384 pub TotalSpacePledged: u128 = {
385 let pieces = solution_range_to_pieces(Subspace::solution_ranges().current, SLOT_PROBABILITY);
386 pieces as u128 * Piece::SIZE as u128
387 };
388 pub BlockchainHistorySize: u128 = u128::from(Subspace::archived_history_size());
389 pub DynamicCostOfStorage: bool = RuntimeConfigs::enable_dynamic_cost_of_storage();
390 pub TransactionWeightFee: Balance = 100_000 * SHANNON;
391}
392
393impl pallet_transaction_fees::Config for Runtime {
394 type RuntimeEvent = RuntimeEvent;
395 type MinReplicationFactor = ConstU16<MIN_REPLICATION_FACTOR>;
396 type CreditSupply = CreditSupply;
397 type TotalSpacePledged = TotalSpacePledged;
398 type BlockchainHistorySize = BlockchainHistorySize;
399 type Currency = Balances;
400 type FindBlockRewardAddress = Subspace;
401 type DynamicCostOfStorage = DynamicCostOfStorage;
402 type WeightInfo = pallet_transaction_fees::weights::SubstrateWeight<Runtime>;
403}
404
405impl pallet_transaction_payment::Config for Runtime {
406 type RuntimeEvent = RuntimeEvent;
407 type OnChargeTransaction = OnChargeTransaction;
408 type OperationalFeeMultiplier = ConstU8<5>;
409 type WeightToFee = ConstantMultiplier<Balance, TransactionWeightFee>;
410 type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
411 type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Runtime, TargetBlockFullness>;
412 type WeightInfo = weights::pallet_transaction_payment::WeightInfo<Runtime>;
413}
414
415impl pallet_utility::Config for Runtime {
416 type RuntimeEvent = RuntimeEvent;
417 type RuntimeCall = RuntimeCall;
418 type PalletsOrigin = OriginCaller;
419 type WeightInfo = weights::pallet_utility::WeightInfo<Runtime>;
420}
421
422impl MaybeBalancesCall<Runtime> for RuntimeCall {
423 fn maybe_balance_call(&self) -> Option<&pallet_balances::Call<Runtime>> {
424 match self {
425 RuntimeCall::Balances(call) => Some(call),
426 _ => None,
427 }
428 }
429}
430
431impl BalanceTransferChecks for Runtime {
432 fn is_balance_transferable() -> bool {
433 let enabled = RuntimeConfigs::enable_balance_transfers();
434 if cfg!(feature = "runtime-benchmarks") {
437 false
438 } else {
439 enabled
440 }
441 }
442}
443
444impl MaybeMultisigCall<Runtime> for RuntimeCall {
445 fn maybe_multisig_call(&self) -> Option<&pallet_multisig::Call<Runtime>> {
447 match self {
448 RuntimeCall::Multisig(call) => Some(call),
449 _ => None,
450 }
451 }
452}
453
454impl MaybeUtilityCall<Runtime> for RuntimeCall {
455 fn maybe_utility_call(&self) -> Option<&pallet_utility::Call<Runtime>> {
457 match self {
458 RuntimeCall::Utility(call) => Some(call),
459 _ => None,
460 }
461 }
462}
463
464impl MaybeNestedCall<Runtime> for RuntimeCall {
465 fn maybe_nested_call(&self) -> Option<Vec<&RuntimeCallFor<Runtime>>> {
470 let calls = self.maybe_nested_utility_calls();
476 if calls.is_some() {
477 return calls;
478 }
479
480 let calls = self.maybe_nested_multisig_calls();
481 if calls.is_some() {
482 return calls;
483 }
484
485 None
486 }
487}
488
489impl pallet_sudo::Config for Runtime {
490 type RuntimeEvent = RuntimeEvent;
491 type RuntimeCall = RuntimeCall;
492 type WeightInfo = weights::pallet_sudo::WeightInfo<Runtime>;
493}
494
495pub type CouncilCollective = pallet_collective::Instance1;
496
497macro_rules! impl_get_council_democracy_field_block_number {
499 ($field_type_name:ident, $field:ident) => {
500 pub struct $field_type_name;
501
502 impl Get<BlockNumber> for $field_type_name {
503 fn get() -> BlockNumber {
504 pallet_runtime_configs::CouncilDemocracyConfig::<Runtime>::get().$field
505 }
506 }
507 };
508}
509
510impl_get_council_democracy_field_block_number! {CouncilMotionDuration, council_motion_duration}
511
512parameter_types! {
513 pub MaxProposalWeight: Weight = Perbill::from_percent(50) * SubspaceBlockWeights::get().max_block;
516}
517
518pub type EnsureRootOr<O> = EitherOfDiverse<EnsureRoot<AccountId>, O>;
519pub type AllCouncil = EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 1>;
520pub type TwoThirdsCouncil = EnsureProportionAtLeast<AccountId, CouncilCollective, 2, 3>;
521pub type HalfCouncil = EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 2>;
522
523impl pallet_collective::Config<CouncilCollective> for Runtime {
525 type DefaultVote = pallet_collective::PrimeDefaultVote;
526 type MaxMembers = ConstU32<100>;
527 type MaxProposalWeight = MaxProposalWeight;
528 type MaxProposals = ConstU32<100>;
529 type MotionDuration = CouncilMotionDuration;
531 type Proposal = RuntimeCall;
532 type RuntimeEvent = RuntimeEvent;
533 type RuntimeOrigin = RuntimeOrigin;
534 type SetMembersOrigin = EnsureRootOr<AllCouncil>;
535 type WeightInfo = weights::pallet_collective::WeightInfo<Runtime>;
536 type DisapproveOrigin = TwoThirdsCouncil;
537 type KillOrigin = TwoThirdsCouncil;
538 type Consideration = ();
541}
542
543parameter_types! {
545 pub PreimageBaseDeposit: Balance = 100 * AI3;
546 pub PreimageByteDeposit: Balance = AI3;
547 pub const PreImageHoldReason: HoldIdentifierWrapper = HoldIdentifierWrapper(HoldIdentifier::Preimage);
548}
549
550impl pallet_preimage::Config for Runtime {
551 type Consideration = HoldConsideration<
552 AccountId,
553 Balances,
554 PreImageHoldReason,
555 LinearStoragePrice<PreimageBaseDeposit, PreimageByteDeposit, Balance>,
556 >;
557 type Currency = Balances;
558 type ManagerOrigin = EnsureRoot<AccountId>;
559 type RuntimeEvent = RuntimeEvent;
560 type WeightInfo = weights::pallet_preimage::WeightInfo<Runtime>;
561}
562
563parameter_types! {
564 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * SubspaceBlockWeights::get().max_block;
565 pub const NoPreimagePostponement: Option<u32> = Some(10);
567}
568
569impl pallet_scheduler::Config for Runtime {
580 type MaxScheduledPerBlock = ConstU32<50>;
581 type MaximumWeight = MaximumSchedulerWeight;
582 type OriginPrivilegeCmp = EqualPrivilegeOnly;
583 type PalletsOrigin = OriginCaller;
584 type Preimages = Preimage;
585 type RuntimeCall = RuntimeCall;
586 type RuntimeEvent = RuntimeEvent;
587 type RuntimeOrigin = RuntimeOrigin;
588 type ScheduleOrigin = EnsureRoot<AccountId>;
589 type WeightInfo = weights::pallet_scheduler::WeightInfo<Runtime>;
590}
591
592type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
593
594pub struct DemocracySlash;
595impl OnUnbalanced<NegativeImbalance> for DemocracySlash {
596 fn on_nonzero_unbalanced(slashed: NegativeImbalance) {
597 Balances::resolve_creating(&TreasuryAccount::get(), slashed);
598 }
599}
600
601impl_get_council_democracy_field_block_number! {CooloffPeriod, democracy_cooloff_period}
602impl_get_council_democracy_field_block_number! {EnactmentPeriod, democracy_enactment_period}
603impl_get_council_democracy_field_block_number! {FastTrackVotingPeriod, democracy_fast_track_voting_period}
604impl_get_council_democracy_field_block_number! {LaunchPeriod, democracy_launch_period}
605impl_get_council_democracy_field_block_number! {VoteLockingPeriod, democracy_vote_locking_period}
606impl_get_council_democracy_field_block_number! {VotingPeriod, democracy_voting_period}
607
608impl pallet_democracy::Config for Runtime {
610 type BlacklistOrigin = EnsureRoot<AccountId>;
611 type CancelProposalOrigin = EnsureRoot<AccountId>;
613 type CancellationOrigin = EnsureRootOr<TwoThirdsCouncil>;
615 type CooloffPeriod = CooloffPeriod;
618 type Currency = Balances;
619 type EnactmentPeriod = EnactmentPeriod;
622 type ExternalDefaultOrigin = AllCouncil;
626 type ExternalMajorityOrigin = HalfCouncil;
630 type ExternalOrigin = HalfCouncil;
633 type FastTrackOrigin = EnsureRootOr<HalfCouncil>;
636 type FastTrackVotingPeriod = FastTrackVotingPeriod;
638 type InstantAllowed = ConstBool<true>;
639 type InstantOrigin = EnsureRootOr<AllCouncil>;
640 type LaunchPeriod = LaunchPeriod;
642 type MaxBlacklisted = ConstU32<100>;
643 type MaxDeposits = ConstU32<100>;
644 type MaxProposals = ConstU32<100>;
645 type MaxVotes = ConstU32<100>;
646 type MinimumDeposit = ConstU128<{ 1000 * AI3 }>;
649 type PalletsOrigin = OriginCaller;
650 type Preimages = Preimage;
651 type RuntimeEvent = RuntimeEvent;
652 type Scheduler = Scheduler;
653 type Slash = DemocracySlash;
655 type SubmitOrigin = EnsureMember<AccountId, CouncilCollective>;
658 type VetoOrigin = EnsureMember<AccountId, CouncilCollective>;
661 type VoteLockingPeriod = VoteLockingPeriod;
662 type VotingPeriod = VotingPeriod;
664 type WeightInfo = pallet_democracy::weights::SubstrateWeight<Runtime>;
665}
666
667parameter_types! {
668 pub const SelfChainId: ChainId = ChainId::Consensus;
669}
670
671pub struct OnXDMRewards;
672
673impl sp_messenger::OnXDMRewards<Balance> for OnXDMRewards {
674 fn on_xdm_rewards(reward: Balance) {
675 if let Some(block_author) = Subspace::find_block_reward_address() {
676 let _ = Balances::deposit_creating(&block_author, reward);
677 }
678 }
679
680 fn on_chain_protocol_fees(chain_id: ChainId, fees: Balance) {
681 if let ChainId::Domain(domain_id) = chain_id {
684 Domains::reward_domain_operators(domain_id, fees)
685 }
686 }
687}
688
689pub struct MmrProofVerifier;
690
691impl sp_subspace_mmr::MmrProofVerifier<mmr::Hash, NumberFor<Block>, Hash> for MmrProofVerifier {
692 fn verify_proof_and_extract_leaf(
693 mmr_leaf_proof: ConsensusChainMmrLeafProof<NumberFor<Block>, Hash, mmr::Hash>,
694 ) -> Option<mmr::Leaf> {
695 let mmr_root = SubspaceMmr::mmr_root_hash(mmr_leaf_proof.consensus_block_number)?;
696 Self::verify_proof_stateless(mmr_root, mmr_leaf_proof)
697 }
698
699 fn verify_proof_stateless(
700 mmr_root: mmr::Hash,
701 mmr_leaf_proof: ConsensusChainMmrLeafProof<NumberFor<Block>, Hash, mmr::Hash>,
702 ) -> Option<mmr::Leaf> {
703 let ConsensusChainMmrLeafProof {
704 opaque_mmr_leaf,
705 proof,
706 ..
707 } = mmr_leaf_proof;
708
709 pallet_mmr::verify_leaves_proof::<mmr::Hashing, _>(
710 mmr_root,
711 vec![mmr::DataOrHash::Data(
712 EncodableOpaqueLeaf(opaque_mmr_leaf.0.clone()).into_opaque_leaf(),
713 )],
714 proof,
715 )
716 .ok()?;
717
718 let leaf: mmr::Leaf = opaque_mmr_leaf.into_opaque_leaf().try_decode()?;
719
720 Some(leaf)
721 }
722}
723
724pub struct StorageKeys;
725
726impl sp_messenger::StorageKeys for StorageKeys {
727 fn confirmed_domain_block_storage_key(domain_id: DomainId) -> Option<Vec<u8>> {
728 Some(Domains::confirmed_domain_block_storage_key(domain_id))
729 }
730
731 fn outbox_storage_key(chain_id: ChainId, message_key: MessageKey) -> Option<Vec<u8>> {
732 get_storage_key(StorageKeyRequest::OutboxStorageKey {
733 chain_id,
734 message_key,
735 })
736 }
737
738 fn inbox_responses_storage_key(chain_id: ChainId, message_key: MessageKey) -> Option<Vec<u8>> {
739 get_storage_key(StorageKeyRequest::InboxResponseStorageKey {
740 chain_id,
741 message_key,
742 })
743 }
744}
745
746parameter_types! {
747 pub const ChannelReserveFee: Balance = 100 * AI3;
749 pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
750 pub const MaxOutgoingMessages: u32 = MAX_OUTGOING_MESSAGES;
751}
752
753const_assert!(MaxOutgoingMessages::get() >= 1);
755
756pub struct DomainRegistration;
757impl sp_messenger::DomainRegistration for DomainRegistration {
758 fn is_domain_registered(domain_id: DomainId) -> bool {
759 Domains::is_domain_registered(domain_id)
760 }
761}
762
763impl pallet_messenger::Config for Runtime {
764 type RuntimeEvent = RuntimeEvent;
765 type SelfChainId = SelfChainId;
766
767 fn get_endpoint_handler(endpoint: &Endpoint) -> Option<Box<dyn EndpointHandlerT<MessageId>>> {
768 if endpoint == &Endpoint::Id(TransporterEndpointId::get()) {
769 Some(Box::new(EndpointHandler(PhantomData::<Runtime>)))
770 } else {
771 None
772 }
773 }
774
775 type Currency = Balances;
776 type WeightInfo = weights::pallet_messenger::WeightInfo<Runtime>;
777 type WeightToFee = ConstantMultiplier<Balance, TransactionWeightFee>;
778 type AdjustedWeightToFee = XdmAdjustedWeightToFee<Runtime>;
779 type FeeMultiplier = XdmFeeMultipler;
780 type OnXDMRewards = OnXDMRewards;
781 type MmrHash = mmr::Hash;
782 type MmrProofVerifier = MmrProofVerifier;
783 #[cfg(feature = "runtime-benchmarks")]
784 type StorageKeys = sp_messenger::BenchmarkStorageKeys;
785 #[cfg(not(feature = "runtime-benchmarks"))]
786 type StorageKeys = StorageKeys;
787 type DomainOwner = Domains;
788 type HoldIdentifier = HoldIdentifierWrapper;
789 type ChannelReserveFee = ChannelReserveFee;
790 type ChannelInitReservePortion = ChannelInitReservePortion;
791 type DomainRegistration = DomainRegistration;
792 type MaxOutgoingMessages = MaxOutgoingMessages;
793 type MessengerOrigin = pallet_messenger::EnsureMessengerOrigin;
794 type NoteChainTransfer = Transporter;
795 type ExtensionWeightInfo = pallet_messenger::extensions::weights::SubstrateWeight<
796 Runtime,
797 (),
800 weights::pallet_messenger_from_domains_extension::WeightInfo<Runtime>,
801 >;
802}
803
804impl<C> frame_system::offchain::CreateTransactionBase<C> for Runtime
805where
806 RuntimeCall: From<C>,
807{
808 type Extrinsic = UncheckedExtrinsic;
809 type RuntimeCall = RuntimeCall;
810}
811
812impl<C> frame_system::offchain::CreateInherent<C> for Runtime
813where
814 RuntimeCall: From<C>,
815{
816 fn create_inherent(call: Self::RuntimeCall) -> Self::Extrinsic {
817 UncheckedExtrinsic::new_bare(call)
818 }
819}
820
821impl<C> subspace_runtime_primitives::CreateUnsigned<C> for Runtime
822where
823 RuntimeCall: From<C>,
824{
825 fn create_unsigned(call: Self::RuntimeCall) -> Self::Extrinsic {
826 create_unsigned_general_extrinsic(call)
827 }
828}
829
830parameter_types! {
831 pub const TransporterEndpointId: EndpointId = 1;
832 pub const MinimumTransfer: Balance = AI3;
833}
834
835impl pallet_transporter::Config for Runtime {
836 type RuntimeEvent = RuntimeEvent;
837 type SelfChainId = SelfChainId;
838 type SelfEndpointId = TransporterEndpointId;
839 type Currency = Balances;
840 type Sender = Messenger;
841 type AccountIdConverter = AccountIdConverter;
842 type WeightInfo = weights::pallet_transporter::WeightInfo<Runtime>;
843 type MinimumTransfer = MinimumTransfer;
844}
845
846pub struct BlockTreePruningDepth;
847impl Get<BlockNumber> for BlockTreePruningDepth {
848 fn get() -> BlockNumber {
849 pallet_runtime_configs::DomainBlockPruningDepth::<Runtime>::get()
850 }
851}
852
853pub struct StakeWithdrawalLockingPeriod;
854impl Get<BlockNumber> for StakeWithdrawalLockingPeriod {
855 fn get() -> BlockNumber {
856 pallet_runtime_configs::StakingWithdrawalPeriod::<Runtime>::get()
857 }
858}
859
860parameter_types! {
861 pub const MaximumReceiptDrift: BlockNumber = 128;
862 pub const InitialDomainTxRange: u64 = INITIAL_DOMAIN_TX_RANGE;
863 pub const DomainTxRangeAdjustmentInterval: u64 = TX_RANGE_ADJUSTMENT_INTERVAL_BLOCKS;
864 pub const MinOperatorStake: Balance = 100 * AI3;
867 pub const MinNominatorStake: Balance = AI3;
870 pub MaxDomainBlockSize: u32 = NORMAL_DISPATCH_RATIO * MAX_BLOCK_LENGTH;
872 pub MaxDomainBlockWeight: Weight = maximum_domain_block_weight();
874 pub const DomainInstantiationDeposit: Balance = 100 * AI3;
875 pub const MaxDomainNameLength: u32 = 32;
876 pub const StakeEpochDuration: DomainNumber = 100;
879 pub TreasuryAccount: AccountId = PalletId(*b"treasury").into_account_truncating();
880 pub const MaxPendingStakingOperation: u32 = 512;
881 pub const DomainsPalletId: PalletId = PalletId(*b"domains_");
882 pub const MaxInitialDomainAccounts: u32 = 10;
883 pub const MinInitialDomainAccountBalance: Balance = AI3;
884 pub const BundleLongevity: u32 = 5;
885 pub const WithdrawalLimit: u32 = 32;
886 pub const CurrentBundleAndExecutionReceiptVersion: BundleAndExecutionReceiptVersion = BundleAndExecutionReceiptVersion{
887 bundle_version: BundleVersion::V0,
888 execution_receipt_version: ExecutionReceiptVersion::V0,
889 };
890 pub const OperatorActivationDelayInEpochs: EpochIndex = 5;
892}
893
894const_assert!(BlockSlotCount::get() >= 2 && BlockSlotCount::get() > BundleLongevity::get());
897
898const_assert!(BlockHashCount::get() > BlockSlotCount::get());
901
902const_assert!(MinOperatorStake::get() >= MinNominatorStake::get());
904
905pub struct BlockSlot;
906
907impl pallet_domains::BlockSlot<Runtime> for BlockSlot {
908 fn future_slot(block_number: BlockNumber) -> Option<sp_consensus_slots::Slot> {
909 let block_slots = Subspace::block_slots();
910 block_slots
911 .get(&block_number)
912 .map(|slot| *slot + Slot::from(BlockAuthoringDelay::get()))
913 }
914
915 fn slot_produced_after(to_check: sp_consensus_slots::Slot) -> Option<BlockNumber> {
916 let block_slots = Subspace::block_slots();
917 for (block_number, slot) in block_slots.into_iter().rev() {
918 if to_check > slot {
919 return Some(block_number);
920 }
921 }
922 None
923 }
924}
925
926pub struct OnChainRewards;
927
928impl sp_domains::OnChainRewards<Balance> for OnChainRewards {
929 fn on_chain_rewards(chain_id: ChainId, reward: Balance) {
930 match chain_id {
931 ChainId::Consensus => {
932 if let Some(block_author) = Subspace::find_block_reward_address() {
933 let _ = Balances::deposit_creating(&block_author, reward);
934 }
935 }
936 ChainId::Domain(domain_id) => Domains::reward_domain_operators(domain_id, reward),
937 }
938 }
939}
940
941impl pallet_domains::Config for Runtime {
942 type RuntimeEvent = RuntimeEvent;
943 type DomainOrigin = pallet_domains::EnsureDomainOrigin;
944 type DomainHash = DomainHash;
945 type Balance = Balance;
946 type DomainHeader = sp_runtime::generic::Header<DomainNumber, BlakeTwo256>;
947 type ConfirmationDepthK = ConfirmationDepthK;
948 type Currency = Balances;
949 type Share = Balance;
950 type HoldIdentifier = HoldIdentifierWrapper;
951 type BlockTreePruningDepth = BlockTreePruningDepth;
952 type ConsensusSlotProbability = SlotProbability;
953 type MaxDomainBlockSize = MaxDomainBlockSize;
954 type MaxDomainBlockWeight = MaxDomainBlockWeight;
955 type MaxDomainNameLength = MaxDomainNameLength;
956 type DomainInstantiationDeposit = DomainInstantiationDeposit;
957 type WeightInfo = weights::pallet_domains::WeightInfo<Runtime>;
958 type InitialDomainTxRange = InitialDomainTxRange;
959 type DomainTxRangeAdjustmentInterval = DomainTxRangeAdjustmentInterval;
960 type MinOperatorStake = MinOperatorStake;
961 type MinNominatorStake = MinNominatorStake;
962 type StakeWithdrawalLockingPeriod = StakeWithdrawalLockingPeriod;
963 type StakeEpochDuration = StakeEpochDuration;
964 type TreasuryAccount = TreasuryAccount;
965 type MaxPendingStakingOperation = MaxPendingStakingOperation;
966 type Randomness = Subspace;
967 type PalletId = DomainsPalletId;
968 type StorageFee = TransactionFees;
969 type BlockTimestamp = pallet_timestamp::Pallet<Runtime>;
970 type BlockSlot = BlockSlot;
971 type DomainsTransfersTracker = Transporter;
972 type MaxInitialDomainAccounts = MaxInitialDomainAccounts;
973 type MinInitialDomainAccountBalance = MinInitialDomainAccountBalance;
974 type BundleLongevity = BundleLongevity;
975 type DomainBundleSubmitted = Messenger;
976 type OnDomainInstantiated = Messenger;
977 type MmrHash = mmr::Hash;
978 type MmrProofVerifier = MmrProofVerifier;
979 type FraudProofStorageKeyProvider = StorageKeyProvider;
980 type OnChainRewards = OnChainRewards;
981 type WithdrawalLimit = WithdrawalLimit;
982 type CurrentBundleAndExecutionReceiptVersion = CurrentBundleAndExecutionReceiptVersion;
983 type OperatorActivationDelayInEpochs = OperatorActivationDelayInEpochs;
984}
985
986parameter_types! {
987 pub const AvgBlockspaceUsageNumBlocks: BlockNumber = 100;
988 pub const ProposerTaxOnVotes: (u32, u32) = (1, 10);
989}
990
991impl pallet_rewards::Config for Runtime {
992 type RuntimeEvent = RuntimeEvent;
993 type Currency = Balances;
994 type AvgBlockspaceUsageNumBlocks = AvgBlockspaceUsageNumBlocks;
995 type TransactionByteFee = TransactionByteFee;
996 type MaxRewardPoints = ConstU32<20>;
997 type ProposerTaxOnVotes = ProposerTaxOnVotes;
998 type RewardsEnabled = Subspace;
999 type FindBlockRewardAddress = Subspace;
1000 type FindVotingRewardAddresses = Subspace;
1001 type WeightInfo = weights::pallet_rewards::WeightInfo<Runtime>;
1002 type OnReward = ();
1003}
1004
1005impl pallet_runtime_configs::Config for Runtime {
1006 type WeightInfo = weights::pallet_runtime_configs::WeightInfo<Runtime>;
1007}
1008
1009impl pallet_domains::extensions::DomainsCheck for Runtime {
1010 fn is_domains_enabled() -> bool {
1011 RuntimeConfigs::enable_domains()
1012 }
1013}
1014
1015mod mmr {
1016 use super::Runtime;
1017 pub use pallet_mmr::primitives::*;
1018
1019 pub type Leaf = <<Runtime as pallet_mmr::Config>::LeafData as LeafDataProvider>::LeafData;
1020 pub type Hashing = <Runtime as pallet_mmr::Config>::Hashing;
1021 pub type Hash = <Hashing as sp_runtime::traits::Hash>::Output;
1022}
1023
1024pub struct BlockHashProvider;
1025
1026impl pallet_mmr::BlockHashProvider<BlockNumber, Hash> for BlockHashProvider {
1027 fn block_hash(block_number: BlockNumber) -> Hash {
1028 consensus_block_hash(block_number).expect("Hash must exist for a given block number.")
1029 }
1030}
1031
1032impl pallet_mmr::Config for Runtime {
1033 const INDEXING_PREFIX: &'static [u8] = mmr::INDEXING_PREFIX;
1034 type Hashing = Keccak256;
1035 type LeafData = SubspaceMmr;
1036 type OnNewRoot = SubspaceMmr;
1037 type BlockHashProvider = BlockHashProvider;
1038 type WeightInfo = weights::pallet_mmr::WeightInfo<Runtime>;
1039 #[cfg(feature = "runtime-benchmarks")]
1040 type BenchmarkHelper = ();
1041}
1042
1043parameter_types! {
1044 pub const MmrRootHashCount: u32 = 1024;
1045}
1046
1047impl pallet_subspace_mmr::Config for Runtime {
1048 type MmrRootHash = mmr::Hash;
1049 type MmrRootHashCount = MmrRootHashCount;
1050}
1051
1052parameter_types! {
1053 pub const MaxSignatories: u32 = 100;
1054}
1055
1056macro_rules! deposit {
1057 ($name:ident, $item_fee:expr, $items:expr, $bytes:expr) => {
1058 pub struct $name;
1059
1060 impl Get<Balance> for $name {
1061 fn get() -> Balance {
1062 $item_fee.saturating_mul($items.into()).saturating_add(
1063 TransactionFees::transaction_byte_fee().saturating_mul($bytes.into()),
1064 )
1065 }
1066 }
1067 };
1068}
1069
1070deposit!(DepositBaseFee, 20 * AI3, 1u32, 88u32);
1073
1074deposit!(DepositFactor, 0u128, 0u32, 32u32);
1076
1077impl pallet_multisig::Config for Runtime {
1078 type RuntimeEvent = RuntimeEvent;
1079 type RuntimeCall = RuntimeCall;
1080 type Currency = Balances;
1081 type DepositBase = DepositBaseFee;
1082 type DepositFactor = DepositFactor;
1083 type MaxSignatories = MaxSignatories;
1084 type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
1085}
1086
1087construct_runtime!(
1088 pub struct Runtime {
1089 System: frame_system = 0,
1090 Timestamp: pallet_timestamp = 1,
1091
1092 Subspace: pallet_subspace = 2,
1093 Rewards: pallet_rewards = 4,
1094
1095 Balances: pallet_balances = 5,
1096 TransactionFees: pallet_transaction_fees = 6,
1097 TransactionPayment: pallet_transaction_payment = 7,
1098 Utility: pallet_utility = 8,
1099
1100 Domains: pallet_domains = 12,
1101 RuntimeConfigs: pallet_runtime_configs = 14,
1102
1103 Mmr: pallet_mmr = 30,
1104 SubspaceMmr: pallet_subspace_mmr = 31,
1105
1106 Messenger: pallet_messenger exclude_parts { Inherent } = 60,
1109 Transporter: pallet_transporter = 61,
1110
1111 Scheduler: pallet_scheduler = 81,
1113 Council: pallet_collective::<Instance1> = 82,
1114 Democracy: pallet_democracy = 83,
1115 Preimage: pallet_preimage = 84,
1116
1117 Multisig: pallet_multisig = 90,
1119
1120 Sudo: pallet_sudo = 100,
1122 }
1123);
1124
1125pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
1127pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
1129pub type Block = generic::Block<Header, UncheckedExtrinsic>;
1131
1132pub type SignedExtra = (
1134 frame_system::CheckNonZeroSender<Runtime>,
1135 frame_system::CheckSpecVersion<Runtime>,
1136 frame_system::CheckTxVersion<Runtime>,
1137 frame_system::CheckGenesis<Runtime>,
1138 frame_system::CheckMortality<Runtime>,
1139 frame_system::CheckNonce<Runtime>,
1140 frame_system::CheckWeight<Runtime>,
1141 pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
1142 BalanceTransferCheckExtension<Runtime>,
1143 pallet_subspace::extensions::SubspaceExtension<Runtime>,
1144 pallet_domains::extensions::DomainsExtension<Runtime>,
1145 pallet_messenger::extensions::MessengerExtension<Runtime>,
1146);
1147pub type UncheckedExtrinsic =
1149 generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
1150
1151pub type Executive = frame_executive::Executive<
1153 Runtime,
1154 Block,
1155 frame_system::ChainContext<Runtime>,
1156 Runtime,
1157 AllPalletsWithSystem,
1158 pallet_domains::migrations::VersionCheckedMigrateDomainsV5ToV6<Runtime>,
1159>;
1160
1161impl pallet_subspace::extensions::MaybeSubspaceCall<Runtime> for RuntimeCall {
1162 fn maybe_subspace_call(&self) -> Option<&pallet_subspace::Call<Runtime>> {
1163 match self {
1164 RuntimeCall::Subspace(call) => Some(call),
1165 _ => None,
1166 }
1167 }
1168}
1169
1170impl pallet_domains::extensions::MaybeDomainsCall<Runtime> for RuntimeCall {
1171 fn maybe_domains_call(&self) -> Option<&pallet_domains::Call<Runtime>> {
1172 match self {
1173 RuntimeCall::Domains(call) => Some(call),
1174 _ => None,
1175 }
1176 }
1177}
1178
1179impl pallet_messenger::extensions::MaybeMessengerCall<Runtime> for RuntimeCall {
1180 fn maybe_messenger_call(&self) -> Option<&pallet_messenger::Call<Runtime>> {
1181 match self {
1182 RuntimeCall::Messenger(call) => Some(call),
1183 _ => None,
1184 }
1185 }
1186}
1187
1188fn extract_segment_headers(ext: &UncheckedExtrinsic) -> Option<Vec<SegmentHeader>> {
1189 match &ext.function {
1190 RuntimeCall::Subspace(pallet_subspace::Call::store_segment_headers { segment_headers }) => {
1191 Some(segment_headers.clone())
1192 }
1193 _ => None,
1194 }
1195}
1196
1197fn is_xdm_mmr_proof_valid(ext: &ExtrinsicFor<Block>) -> Option<bool> {
1198 match &ext.function {
1199 RuntimeCall::Messenger(pallet_messenger::Call::relay_message { msg })
1200 | RuntimeCall::Messenger(pallet_messenger::Call::relay_message_response { msg }) => {
1201 let ConsensusChainMmrLeafProof {
1202 consensus_block_number,
1203 opaque_mmr_leaf,
1204 proof,
1205 ..
1206 } = msg.proof.consensus_mmr_proof();
1207
1208 let mmr_root = SubspaceMmr::mmr_root_hash(consensus_block_number)?;
1209
1210 Some(
1211 pallet_mmr::verify_leaves_proof::<mmr::Hashing, _>(
1212 mmr_root,
1213 vec![mmr::DataOrHash::Data(
1214 EncodableOpaqueLeaf(opaque_mmr_leaf.0.clone()).into_opaque_leaf(),
1215 )],
1216 proof,
1217 )
1218 .is_ok(),
1219 )
1220 }
1221 _ => None,
1222 }
1223}
1224
1225fn create_unsigned_general_extrinsic(call: RuntimeCall) -> UncheckedExtrinsic {
1226 let extra: SignedExtra = (
1227 frame_system::CheckNonZeroSender::<Runtime>::new(),
1228 frame_system::CheckSpecVersion::<Runtime>::new(),
1229 frame_system::CheckTxVersion::<Runtime>::new(),
1230 frame_system::CheckGenesis::<Runtime>::new(),
1231 frame_system::CheckMortality::<Runtime>::from(generic::Era::Immortal),
1232 frame_system::CheckNonce::<Runtime>::from(0u32.into()),
1235 frame_system::CheckWeight::<Runtime>::new(),
1236 pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(0u128),
1239 BalanceTransferCheckExtension::<Runtime>::default(),
1240 pallet_subspace::extensions::SubspaceExtension::<Runtime>::new(),
1241 pallet_domains::extensions::DomainsExtension::<Runtime>::new(),
1242 pallet_messenger::extensions::MessengerExtension::<Runtime>::new(),
1243 );
1244
1245 UncheckedExtrinsic::new_transaction(call, extra)
1246}
1247
1248struct RewardAddress([u8; 32]);
1249
1250impl From<PublicKey> for RewardAddress {
1251 #[inline]
1252 fn from(public_key: PublicKey) -> Self {
1253 Self(*public_key)
1254 }
1255}
1256
1257impl From<RewardAddress> for AccountId32 {
1258 #[inline]
1259 fn from(reward_address: RewardAddress) -> Self {
1260 reward_address.0.into()
1261 }
1262}
1263
1264pub struct StorageKeyProvider;
1265impl FraudProofStorageKeyProvider<NumberFor<Block>> for StorageKeyProvider {
1266 fn storage_key(req: FraudProofStorageKeyRequest<NumberFor<Block>>) -> Vec<u8> {
1267 match req {
1268 FraudProofStorageKeyRequest::InvalidInherentExtrinsicData => {
1269 pallet_domains::BlockInherentExtrinsicData::<Runtime>::hashed_key().to_vec()
1270 }
1271 FraudProofStorageKeyRequest::SuccessfulBundles(domain_id) => {
1272 pallet_domains::SuccessfulBundles::<Runtime>::hashed_key_for(domain_id)
1273 }
1274 FraudProofStorageKeyRequest::DomainAllowlistUpdates(domain_id) => {
1275 Messenger::domain_allow_list_update_storage_key(domain_id)
1276 }
1277 FraudProofStorageKeyRequest::DomainRuntimeUpgrades => {
1278 pallet_domains::DomainRuntimeUpgrades::<Runtime>::hashed_key().to_vec()
1279 }
1280 FraudProofStorageKeyRequest::RuntimeRegistry(runtime_id) => {
1281 pallet_domains::RuntimeRegistry::<Runtime>::hashed_key_for(runtime_id)
1282 }
1283 FraudProofStorageKeyRequest::DomainSudoCall(domain_id) => {
1284 pallet_domains::DomainSudoCalls::<Runtime>::hashed_key_for(domain_id)
1285 }
1286 FraudProofStorageKeyRequest::EvmDomainContractCreationAllowedByCall(domain_id) => {
1287 pallet_domains::EvmDomainContractCreationAllowedByCalls::<Runtime>::hashed_key_for(
1288 domain_id,
1289 )
1290 }
1291 FraudProofStorageKeyRequest::MmrRoot(block_number) => {
1292 pallet_subspace_mmr::MmrRootHashes::<Runtime>::hashed_key_for(block_number)
1293 }
1294 }
1295 }
1296}
1297
1298#[cfg(feature = "runtime-benchmarks")]
1299mod benches {
1300 frame_benchmarking::define_benchmarks!(
1301 [frame_benchmarking, BaselineBench::<Runtime>]
1302 [frame_system, SystemBench::<Runtime>]
1303 [pallet_timestamp, Timestamp]
1304 [pallet_subspace, Subspace]
1305 [pallet_subspace_extension, SubspaceExtensionBench::<Runtime>]
1306 [pallet_rewards, Rewards]
1307 [pallet_balances, Balances]
1308 [balance_transfer_check_extension, BalanceTransferCheckBench::<Runtime>]
1309 [pallet_transaction_payment, TransactionPayment]
1311 [pallet_utility, Utility]
1312 [pallet_domains, Domains]
1313 [pallet_runtime_configs, RuntimeConfigs]
1314 [pallet_mmr, Mmr]
1315 [pallet_messenger, Messenger]
1317 [pallet_messenger_from_domains_extension, MessengerFromDomainsExtensionBench::<Runtime>]
1318 [pallet_transporter, Transporter]
1319 [pallet_scheduler, Scheduler]
1320 [pallet_collective, Council]
1321 [pallet_democracy, Democracy]
1322 [pallet_preimage, Preimage]
1323 [pallet_multisig, Multisig]
1324 [pallet_sudo, Sudo]
1325 );
1326}
1327
1328#[cfg(feature = "runtime-benchmarks")]
1329impl frame_system_benchmarking::Config for Runtime {}
1330
1331#[cfg(feature = "runtime-benchmarks")]
1332impl frame_benchmarking::baseline::Config for Runtime {}
1333
1334impl_runtime_apis! {
1335 impl sp_api::Core<Block> for Runtime {
1336 fn version() -> RuntimeVersion {
1337 VERSION
1338 }
1339
1340 fn execute_block(block: Block) {
1341 Executive::execute_block(block);
1342 }
1343
1344 fn initialize_block(header: &HeaderFor<Block>) -> ExtrinsicInclusionMode {
1345 Executive::initialize_block(header)
1346 }
1347 }
1348
1349 impl sp_api::Metadata<Block> for Runtime {
1350 fn metadata() -> OpaqueMetadata {
1351 OpaqueMetadata::new(Runtime::metadata().into())
1352 }
1353
1354 fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
1355 Runtime::metadata_at_version(version)
1356 }
1357
1358 fn metadata_versions() -> Vec<u32> {
1359 Runtime::metadata_versions()
1360 }
1361 }
1362
1363 impl sp_block_builder::BlockBuilder<Block> for Runtime {
1364 fn apply_extrinsic(extrinsic: ExtrinsicFor<Block>) -> ApplyExtrinsicResult {
1365 Executive::apply_extrinsic(extrinsic)
1366 }
1367
1368 fn finalize_block() -> HeaderFor<Block> {
1369 Executive::finalize_block()
1370 }
1371
1372 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<ExtrinsicFor<Block>> {
1373 data.create_extrinsics()
1374 }
1375
1376 fn check_inherents(
1377 block: Block,
1378 data: sp_inherents::InherentData,
1379 ) -> sp_inherents::CheckInherentsResult {
1380 data.check_extrinsics(&block)
1381 }
1382 }
1383
1384 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
1385 fn validate_transaction(
1386 source: TransactionSource,
1387 tx: ExtrinsicFor<Block>,
1388 block_hash: BlockHashFor<Block>,
1389 ) -> TransactionValidity {
1390 Executive::validate_transaction(source, tx, block_hash)
1391 }
1392 }
1393
1394 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
1395 fn offchain_worker(header: &HeaderFor<Block>) {
1396 Executive::offchain_worker(header)
1397 }
1398 }
1399
1400 impl sp_objects::ObjectsApi<Block> for Runtime {
1401 fn extract_block_object_mapping(block: Block) -> BlockObjectMapping {
1402 extract_block_object_mapping(block)
1403 }
1404 }
1405
1406 impl sp_consensus_subspace::SubspaceApi<Block, PublicKey> for Runtime {
1407 fn pot_parameters() -> PotParameters {
1408 Subspace::pot_parameters()
1409 }
1410
1411 fn solution_ranges() -> SolutionRanges {
1412 Subspace::solution_ranges()
1413 }
1414
1415 fn submit_vote_extrinsic(
1416 signed_vote: SignedVote<NumberFor<Block>, BlockHashFor<Block>, PublicKey>,
1417 ) {
1418 let SignedVote { vote, signature } = signed_vote;
1419 let Vote::V0 {
1420 height,
1421 parent_hash,
1422 slot,
1423 solution,
1424 proof_of_time,
1425 future_proof_of_time,
1426 } = vote;
1427
1428 Subspace::submit_vote(SignedVote {
1429 vote: Vote::V0 {
1430 height,
1431 parent_hash,
1432 slot,
1433 solution: solution.into_reward_address_format::<RewardAddress, AccountId32>(),
1434 proof_of_time,
1435 future_proof_of_time,
1436 },
1437 signature,
1438 })
1439 }
1440
1441 fn history_size() -> HistorySize {
1442 <pallet_subspace::Pallet<Runtime>>::history_size()
1443 }
1444
1445 fn max_pieces_in_sector() -> u16 {
1446 MAX_PIECES_IN_SECTOR
1447 }
1448
1449 fn segment_commitment(segment_index: SegmentIndex) -> Option<SegmentCommitment> {
1450 Subspace::segment_commitment(segment_index)
1451 }
1452
1453 fn extract_segment_headers(ext: &ExtrinsicFor<Block>) -> Option<Vec<SegmentHeader >> {
1454 extract_segment_headers(ext)
1455 }
1456
1457 fn is_inherent(ext: &ExtrinsicFor<Block>) -> bool {
1458 match &ext.function {
1459 RuntimeCall::Subspace(call) => Subspace::is_inherent(call),
1460 RuntimeCall::Timestamp(call) => Timestamp::is_inherent(call),
1461 _ => false,
1462 }
1463 }
1464
1465 fn root_plot_public_key() -> Option<PublicKey> {
1466 Subspace::root_plot_public_key()
1467 }
1468
1469 fn should_adjust_solution_range() -> bool {
1470 Subspace::should_adjust_solution_range()
1471 }
1472
1473 fn chain_constants() -> ChainConstants {
1474 ChainConstants::V0 {
1475 confirmation_depth_k: ConfirmationDepthK::get(),
1476 block_authoring_delay: Slot::from(BlockAuthoringDelay::get()),
1477 era_duration: EraDuration::get(),
1478 slot_probability: SlotProbability::get(),
1479 slot_duration: SlotDuration::from_millis(SLOT_DURATION),
1480 recent_segments: RecentSegments::get(),
1481 recent_history_fraction: RecentHistoryFraction::get(),
1482 min_sector_lifetime: MinSectorLifetime::get(),
1483 }
1484 }
1485
1486 fn block_weight() -> Weight {
1487 System::block_weight().total()
1488 }
1489 }
1490
1491 impl sp_domains::DomainsApi<Block, DomainHeader> for Runtime {
1492 fn submit_bundle_unsigned(
1493 opaque_bundle: sp_domains::bundle::OpaqueBundle<NumberFor<Block>, BlockHashFor<Block>, DomainHeader, Balance>,
1494 ) {
1495 Domains::submit_bundle_unsigned(opaque_bundle)
1496 }
1497
1498 fn submit_receipt_unsigned(
1499 singleton_receipt: SealedSingletonReceipt<NumberFor<Block>, BlockHashFor<Block>, DomainHeader, Balance>,
1500 ) {
1501 Domains::submit_receipt_unsigned(singleton_receipt)
1502 }
1503
1504 fn extract_successful_bundles(
1505 domain_id: DomainId,
1506 extrinsics: Vec<ExtrinsicFor<Block>>,
1507 ) -> sp_domains::bundle::OpaqueBundles<Block, DomainHeader, Balance> {
1508 crate::domains::extract_successful_bundles(domain_id, extrinsics)
1509 }
1510
1511 fn extrinsics_shuffling_seed() -> Randomness {
1512 Randomness::from(Domains::extrinsics_shuffling_seed().to_fixed_bytes())
1513 }
1514
1515 fn domain_runtime_code(domain_id: DomainId) -> Option<Vec<u8>> {
1516 Domains::domain_runtime_code(domain_id)
1517 }
1518
1519 fn runtime_id(domain_id: DomainId) -> Option<sp_domains::RuntimeId> {
1520 Domains::runtime_id(domain_id)
1521 }
1522
1523 fn runtime_upgrades() -> Vec<sp_domains::RuntimeId> {
1524 Domains::runtime_upgrades()
1525 }
1526
1527 fn domain_instance_data(domain_id: DomainId) -> Option<(DomainInstanceData, NumberFor<Block>)> {
1528 Domains::domain_instance_data(domain_id)
1529 }
1530
1531 fn domain_timestamp() -> Moment {
1532 Domains::timestamp()
1533 }
1534
1535 fn consensus_transaction_byte_fee() -> Balance {
1536 Domains::consensus_transaction_byte_fee()
1537 }
1538
1539 fn domain_tx_range(domain_id: DomainId) -> U256 {
1540 Domains::domain_tx_range(domain_id)
1541 }
1542
1543 fn genesis_state_root(domain_id: DomainId) -> Option<H256> {
1544 Domains::domain_genesis_block_execution_receipt(domain_id)
1545 .map(|er| *er.final_state_root())
1546 }
1547
1548 fn head_receipt_number(domain_id: DomainId) -> DomainNumber {
1549 Domains::head_receipt_number(domain_id)
1550 }
1551
1552 fn oldest_unconfirmed_receipt_number(domain_id: DomainId) -> Option<DomainNumber> {
1553 Domains::oldest_unconfirmed_receipt_number(domain_id)
1554 }
1555
1556 fn domain_bundle_limit(domain_id: DomainId) -> Option<sp_domains::DomainBundleLimit> {
1557 Domains::domain_bundle_limit(domain_id).ok().flatten()
1558 }
1559
1560 fn non_empty_er_exists(domain_id: DomainId) -> bool {
1561 Domains::non_empty_er_exists(domain_id)
1562 }
1563
1564 fn domain_best_number(domain_id: DomainId) -> Option<DomainNumber> {
1565 Domains::domain_best_number(domain_id).ok()
1566 }
1567
1568 fn execution_receipt(receipt_hash: DomainHash) -> Option<ExecutionReceiptFor<DomainHeader, Block, Balance>> {
1569 Domains::execution_receipt(receipt_hash)
1570 }
1571
1572 fn domain_operators(domain_id: DomainId) -> Option<(BTreeMap<OperatorId, Balance>, Vec<OperatorId>)> {
1573 Domains::domain_staking_summary(domain_id).map(|summary| {
1574 let next_operators = summary.next_operators.into_iter().collect();
1575 (summary.current_operators, next_operators)
1576 })
1577 }
1578
1579 fn receipt_hash(domain_id: DomainId, domain_number: DomainNumber) -> Option<DomainHash> {
1580 Domains::receipt_hash(domain_id, domain_number)
1581 }
1582
1583 fn latest_confirmed_domain_block(domain_id: DomainId) -> Option<(DomainNumber, DomainHash)>{
1584 Domains::latest_confirmed_domain_block(domain_id)
1585 }
1586
1587 fn is_bad_er_pending_to_prune(domain_id: DomainId, receipt_hash: DomainHash) -> bool {
1588 Domains::execution_receipt(receipt_hash).map(
1589 |er| Domains::is_bad_er_pending_to_prune(domain_id, *er.domain_block_number())
1590 )
1591 .unwrap_or(false)
1592 }
1593
1594 fn storage_fund_account_balance(operator_id: OperatorId) -> Balance {
1595 Domains::storage_fund_account_balance(operator_id)
1596 }
1597
1598 fn is_domain_runtime_upgraded_since(domain_id: DomainId, at: NumberFor<Block>) -> Option<bool> {
1599 Domains::is_domain_runtime_upgraded_since(domain_id, at)
1600 }
1601
1602 fn domain_sudo_call(domain_id: DomainId) -> Option<Vec<u8>> {
1603 Domains::domain_sudo_call(domain_id)
1604 }
1605
1606 fn evm_domain_contract_creation_allowed_by_call(domain_id: DomainId) -> Option<PermissionedActionAllowedBy<EthereumAccountId>> {
1607 Domains::evm_domain_contract_creation_allowed_by_call(domain_id)
1608 }
1609
1610 fn last_confirmed_domain_block_receipt(domain_id: DomainId) -> Option<ExecutionReceiptFor<DomainHeader, Block, Balance>>{
1611 Domains::latest_confirmed_domain_execution_receipt(domain_id)
1612 }
1613
1614 fn current_bundle_and_execution_receipt_version() -> BundleAndExecutionReceiptVersion {
1615 Domains::current_bundle_and_execution_receipt_version()
1616 }
1617
1618 fn genesis_execution_receipt(domain_id: DomainId) -> Option<ExecutionReceiptFor<DomainHeader, Block, Balance>> {
1619 Domains::domain_genesis_block_execution_receipt(domain_id)
1620 }
1621
1622 fn nominator_position(
1623 operator_id: OperatorId,
1624 nominator_account: sp_runtime::AccountId32,
1625 ) -> Option<sp_domains::NominatorPosition<Balance, DomainNumber, Balance>> {
1626 Domains::nominator_position(operator_id, nominator_account)
1627 }
1628
1629 fn block_pruning_depth() -> NumberFor<Block> {
1630 BlockTreePruningDepth::get()
1631 }
1632 }
1633
1634 impl sp_domains::BundleProducerElectionApi<Block, Balance> for Runtime {
1635 fn bundle_producer_election_params(domain_id: DomainId) -> Option<BundleProducerElectionParams<Balance>> {
1636 Domains::bundle_producer_election_params(domain_id)
1637 }
1638
1639 fn operator(operator_id: OperatorId) -> Option<(OperatorPublicKey, Balance)> {
1640 Domains::operator(operator_id)
1641 }
1642 }
1643
1644 impl sp_session::SessionKeys<Block> for Runtime {
1645 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
1646 SessionKeys::generate(seed)
1647 }
1648
1649 fn decode_session_keys(
1650 encoded: Vec<u8>,
1651 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
1652 SessionKeys::decode_into_raw_public_keys(&encoded)
1653 }
1654 }
1655
1656 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
1657 fn account_nonce(account: AccountId) -> Nonce {
1658 *System::account_nonce(account)
1659 }
1660 }
1661
1662 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
1663 fn query_info(
1664 uxt: ExtrinsicFor<Block>,
1665 len: u32,
1666 ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
1667 TransactionPayment::query_info(uxt, len)
1668 }
1669 fn query_fee_details(
1670 uxt: ExtrinsicFor<Block>,
1671 len: u32,
1672 ) -> pallet_transaction_payment::FeeDetails<Balance> {
1673 TransactionPayment::query_fee_details(uxt, len)
1674 }
1675 fn query_weight_to_fee(weight: Weight) -> Balance {
1676 TransactionPayment::weight_to_fee(weight)
1677 }
1678 fn query_length_to_fee(length: u32) -> Balance {
1679 TransactionPayment::length_to_fee(length)
1680 }
1681 }
1682
1683 impl sp_messenger::MessengerApi<Block, BlockNumber, BlockHashFor<Block>> for Runtime {
1684 fn is_xdm_mmr_proof_valid(
1685 ext: &ExtrinsicFor<Block>
1686 ) -> Option<bool> {
1687 is_xdm_mmr_proof_valid(ext)
1688 }
1689
1690 fn extract_xdm_mmr_proof(ext: &ExtrinsicFor<Block>) -> Option<ConsensusChainMmrLeafProof<BlockNumber, BlockHashFor<Block>, sp_core::H256>> {
1691 match &ext.function {
1692 RuntimeCall::Messenger(pallet_messenger::Call::relay_message { msg })
1693 | RuntimeCall::Messenger(pallet_messenger::Call::relay_message_response { msg }) => {
1694 Some(msg.proof.consensus_mmr_proof())
1695 }
1696 _ => None,
1697 }
1698 }
1699
1700 fn batch_extract_xdm_mmr_proof(extrinsics: &Vec<ExtrinsicFor<Block>>) -> BTreeMap<u32, ConsensusChainMmrLeafProof<BlockNumber, BlockHashFor<Block>, sp_core::H256>> {
1701 let mut mmr_proofs = BTreeMap::new();
1702 for (index, ext) in extrinsics.iter().enumerate() {
1703 match &ext.function {
1704 RuntimeCall::Messenger(pallet_messenger::Call::relay_message { msg })
1705 | RuntimeCall::Messenger(pallet_messenger::Call::relay_message_response { msg }) => {
1706 mmr_proofs.insert(index as u32, msg.proof.consensus_mmr_proof());
1707 }
1708 _ => {},
1709 }
1710 }
1711 mmr_proofs
1712 }
1713
1714 fn confirmed_domain_block_storage_key(domain_id: DomainId) -> Vec<u8> {
1715 Domains::confirmed_domain_block_storage_key(domain_id)
1716 }
1717
1718 fn outbox_storage_key(message_key: MessageKey) -> Vec<u8> {
1719 Messenger::outbox_storage_key(message_key)
1720 }
1721
1722 fn inbox_response_storage_key(message_key: MessageKey) -> Vec<u8> {
1723 Messenger::inbox_response_storage_key(message_key)
1724 }
1725
1726 fn domain_chains_allowlist_update(domain_id: DomainId) -> Option<DomainAllowlistUpdates>{
1727 Messenger::domain_chains_allowlist_update(domain_id)
1728 }
1729
1730 fn xdm_id(ext: &ExtrinsicFor<Block>) -> Option<XdmId> {
1731 match &ext.function {
1732 RuntimeCall::Messenger(pallet_messenger::Call::relay_message { msg })=> {
1733 Some(XdmId::RelayMessage((msg.src_chain_id, msg.channel_id, msg.nonce)))
1734 }
1735 RuntimeCall::Messenger(pallet_messenger::Call::relay_message_response { msg }) => {
1736 Some(XdmId::RelayResponseMessage((msg.src_chain_id, msg.channel_id, msg.nonce)))
1737 }
1738 _ => None,
1739 }
1740 }
1741
1742 fn channel_nonce(chain_id: ChainId, channel_id: ChannelId) -> Option<ChannelNonce> {
1743 Messenger::channel_nonce(chain_id, channel_id)
1744 }
1745 }
1746
1747 impl sp_messenger::RelayerApi<Block, BlockNumber, BlockNumber, BlockHashFor<Block>> for Runtime {
1748 fn outbox_message_unsigned(msg: CrossDomainMessage<NumberFor<Block>, BlockHashFor<Block>, BlockHashFor<Block>>) -> Option<ExtrinsicFor<Block>> {
1749 Messenger::outbox_message_unsigned(msg)
1750 }
1751
1752 fn inbox_response_message_unsigned(msg: CrossDomainMessage<NumberFor<Block>, BlockHashFor<Block>, BlockHashFor<Block>>) -> Option<ExtrinsicFor<Block>> {
1753 Messenger::inbox_response_message_unsigned(msg)
1754 }
1755
1756 fn updated_channels() -> BTreeSet<(ChainId, ChannelId)> {
1757 Messenger::updated_channels()
1758 }
1759
1760 fn channel_storage_key(chain_id: ChainId, channel_id: ChannelId) -> Vec<u8> {
1761 Messenger::channel_storage_key(chain_id, channel_id)
1762 }
1763
1764 fn open_channels() -> BTreeSet<(ChainId, ChannelId)> {
1765 Messenger::open_channels()
1766 }
1767
1768 fn block_messages_with_query(query: BlockMessagesQuery) -> MessagesWithStorageKey {
1769 Messenger::get_block_messages(query)
1770 }
1771
1772 fn channels_and_state() -> Vec<(ChainId, ChannelId, ChannelStateWithNonce)> {
1773 Messenger::channels_and_states()
1774 }
1775
1776 fn first_outbox_message_nonce_to_relay(dst_chain_id: ChainId, channel_id: ChannelId, from_nonce: XdmNonce) -> Option<XdmNonce> {
1777 Messenger::first_outbox_message_nonce_to_relay(dst_chain_id, channel_id, from_nonce)
1778 }
1779
1780 fn first_inbox_message_response_nonce_to_relay(dst_chain_id: ChainId, channel_id: ChannelId, from_nonce: XdmNonce) -> Option<XdmNonce> {
1781 Messenger::first_inbox_message_response_nonce_to_relay(dst_chain_id, channel_id, from_nonce)
1782 }
1783 }
1784
1785 impl sp_domains_fraud_proof::FraudProofApi<Block, DomainHeader> for Runtime {
1786 fn submit_fraud_proof_unsigned(fraud_proof: FraudProof<NumberFor<Block>, BlockHashFor<Block>, DomainHeader, H256>) {
1787 Domains::submit_fraud_proof_unsigned(fraud_proof)
1788 }
1789
1790 fn fraud_proof_storage_key(req: FraudProofStorageKeyRequest<NumberFor<Block>>) -> Vec<u8> {
1791 <StorageKeyProvider as FraudProofStorageKeyProvider<NumberFor<Block>>>::storage_key(req)
1792 }
1793 }
1794
1795 impl mmr::MmrApi<Block, mmr::Hash, BlockNumber> for Runtime {
1796 fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
1797 Ok(Mmr::mmr_root())
1798 }
1799
1800 fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
1801 Ok(Mmr::mmr_leaves())
1802 }
1803
1804 fn generate_proof(
1805 block_numbers: Vec<BlockNumber>,
1806 best_known_block_number: Option<BlockNumber>,
1807 ) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::LeafProof<mmr::Hash>), mmr::Error> {
1808 Mmr::generate_proof(block_numbers, best_known_block_number).map(
1809 |(leaves, proof)| {
1810 (
1811 leaves
1812 .into_iter()
1813 .map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf))
1814 .collect(),
1815 proof,
1816 )
1817 },
1818 )
1819 }
1820
1821 fn verify_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::LeafProof<mmr::Hash>)
1822 -> Result<(), mmr::Error>
1823 {
1824 let leaves = leaves.into_iter().map(|leaf|
1825 leaf.into_opaque_leaf()
1826 .try_decode()
1827 .ok_or(mmr::Error::Verify)).collect::<Result<Vec<mmr::Leaf>, mmr::Error>>()?;
1828 Mmr::verify_leaves(leaves, proof)
1829 }
1830
1831 fn verify_proof_stateless(
1832 root: mmr::Hash,
1833 leaves: Vec<mmr::EncodableOpaqueLeaf>,
1834 proof: mmr::LeafProof<mmr::Hash>
1835 ) -> Result<(), mmr::Error> {
1836 let nodes = leaves.into_iter().map(|leaf|mmr::DataOrHash::Data(leaf.into_opaque_leaf())).collect();
1837 pallet_mmr::verify_leaves_proof::<mmr::Hashing, _>(root, nodes, proof)
1838 }
1839 }
1840
1841 impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
1842 fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
1843 build_state::<RuntimeGenesisConfig>(config)
1844 }
1845
1846 fn get_preset(_id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
1847 get_preset::<RuntimeGenesisConfig>(&None, |_| None)
1849 }
1850
1851 fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
1852 vec![]
1853 }
1854 }
1855
1856 #[cfg(feature = "runtime-benchmarks")]
1857 impl frame_benchmarking::Benchmark<Block> for Runtime {
1858 fn benchmark_metadata(extra: bool) -> (
1859 Vec<frame_benchmarking::BenchmarkList>,
1860 Vec<frame_support::traits::StorageInfo>,
1861 ) {
1862 use frame_benchmarking::{baseline, Benchmarking, BenchmarkList};
1863 use frame_support::traits::StorageInfoTrait;
1864 use frame_system_benchmarking::Pallet as SystemBench;
1865 use baseline::Pallet as BaselineBench;
1866 use pallet_subspace::extensions::benchmarking::Pallet as SubspaceExtensionBench;
1867 use pallet_messenger::extensions::benchmarking_from_domains::Pallet as MessengerFromDomainsExtensionBench;
1868 use subspace_runtime_primitives::extension::benchmarking::Pallet as BalanceTransferCheckBench;
1869
1870 let mut list = Vec::<BenchmarkList>::new();
1871 list_benchmarks!(list, extra);
1872
1873 let storage_info = AllPalletsWithSystem::storage_info();
1874
1875 (list, storage_info)
1876 }
1877
1878 fn dispatch_benchmark(
1879 config: frame_benchmarking::BenchmarkConfig
1880 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {
1881 use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch};
1882 use sp_core::storage::TrackedStorageKey;
1883
1884 use frame_system_benchmarking::Pallet as SystemBench;
1885 use baseline::Pallet as BaselineBench;
1886 use pallet_subspace::extensions::benchmarking::Pallet as SubspaceExtensionBench;
1887 use pallet_messenger::extensions::benchmarking_from_domains::Pallet as MessengerFromDomainsExtensionBench;
1888 use subspace_runtime_primitives::extension::benchmarking::Pallet as BalanceTransferCheckBench;
1889
1890 use frame_support::traits::WhitelistedStorageKeys;
1891 let whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();
1892
1893 let mut batches = Vec::<BenchmarkBatch>::new();
1894 let params = (&config, &whitelist);
1895 add_benchmarks!(params, batches);
1896
1897 Ok(batches)
1898 }
1899 }
1900}
1901
1902#[cfg(test)]
1903mod tests {
1904 use crate::{Runtime, SubspaceBlockWeights as BlockWeights};
1905 use pallet_domains::bundle_storage_fund::AccountType;
1906 use sp_domains::OperatorId;
1907 use sp_runtime::traits::AccountIdConversion;
1908 use subspace_runtime_primitives::tests_utils::FeeMultiplierUtils;
1909
1910 #[test]
1911 fn multiplier_can_grow_from_zero() {
1912 FeeMultiplierUtils::<Runtime, BlockWeights>::multiplier_can_grow_from_zero()
1913 }
1914
1915 #[test]
1916 fn test_bundle_storage_fund_account_uniqueness() {
1917 let _: <Runtime as frame_system::Config>::AccountId = <Runtime as pallet_domains::Config>::PalletId::get()
1918 .try_into_sub_account((AccountType::StorageFund, OperatorId::MAX))
1919 .expect(
1920 "The `AccountId` type must be large enough to fit the seed of the bundle storage fund account",
1921 );
1922 }
1923}