Skip to main content

subspace_fake_runtime_api/
lib.rs

1//! Provides "fake" runtime API implementation as a workaround for compile-time checks.
2
3use domain_runtime_primitives::opaque::Header as DomainHeader;
4use domain_runtime_primitives::{
5    BlockNumber as DomainNumber, EthereumAccountId, Hash as DomainHash,
6};
7use frame_support::weights::Weight;
8use sp_consensus_subspace::{ChainConstants, PotParameters, SignedVote, SolutionRanges};
9use sp_core::crypto::KeyTypeId;
10use sp_core::{H256, OpaqueMetadata};
11use sp_domains::bundle_producer_election::BundleProducerElectionParams;
12use sp_domains::execution_receipt::{ExecutionReceiptFor, SealedSingletonReceipt};
13use sp_domains::{
14    BundleAndExecutionReceiptVersion, DomainAllowlistUpdates, DomainId, DomainInstanceData,
15    NominatorPosition, OperatorId, OperatorPublicKey, PermissionedActionAllowedBy,
16};
17use sp_domains_fraud_proof::fraud_proof::FraudProof;
18use sp_domains_fraud_proof::storage_proof::FraudProofStorageKeyRequest;
19use sp_messenger::messages::{
20    BlockMessagesQuery, ChainId, ChannelId, ChannelStateWithNonce, CrossDomainMessage, MessageKey,
21    MessagesWithStorageKey, Nonce as XdmNonce,
22};
23use sp_messenger::{ChannelNonce, XdmId};
24use sp_runtime::traits::NumberFor;
25use sp_runtime::transaction_validity::{TransactionSource, TransactionValidity};
26use sp_runtime::{ApplyExtrinsicResult, ExtrinsicInclusionMode};
27use sp_subspace_mmr::ConsensusChainMmrLeafProof;
28use sp_version::RuntimeVersion;
29use std::collections::btree_map::BTreeMap;
30use std::collections::btree_set::BTreeSet;
31use subspace_core_primitives::objects::BlockObjectMapping;
32use subspace_core_primitives::segments::{
33    HistorySize, SegmentCommitment, SegmentHeader, SegmentIndex,
34};
35use subspace_core_primitives::{PublicKey, Randomness, U256};
36use subspace_runtime_primitives::opaque::Block;
37use subspace_runtime_primitives::{
38    AccountId, Balance, BlockHashFor, BlockNumber, ExtrinsicFor, HeaderFor, Moment, Nonce,
39};
40
41mod mmr {
42    pub use pallet_mmr::primitives::*;
43    use sp_core::H256;
44    // Full type for this is actually `<<Runtime as pallet_mmr::Config>::Hashing as sp_runtime::traits::Hash>::Output`
45    // but since we don't really want to impl pallet for the fake runtime, we just use the `Keccak256::Output = H256`
46    pub type Hash = H256;
47}
48
49struct Runtime;
50
51sp_api::impl_runtime_apis! {
52    impl sp_api::Core<Block> for Runtime {
53        fn version() -> RuntimeVersion {
54            unreachable!()
55        }
56
57        fn execute_block(_block: <Block as sp_runtime::traits::Block>::LazyBlock) {
58            unreachable!()
59        }
60
61        fn initialize_block(_header: &HeaderFor<Block>) -> ExtrinsicInclusionMode {
62            unreachable!()
63        }
64    }
65
66    impl sp_api::Metadata<Block> for Runtime {
67        fn metadata() -> OpaqueMetadata {
68            unreachable!()
69        }
70
71        fn metadata_at_version(_version: u32) -> Option<OpaqueMetadata> {
72            unreachable!()
73        }
74
75        fn metadata_versions() -> Vec<u32> {
76            unreachable!()
77        }
78    }
79
80    impl sp_block_builder::BlockBuilder<Block> for Runtime {
81        fn apply_extrinsic(_extrinsic: ExtrinsicFor<Block>) -> ApplyExtrinsicResult {
82            unreachable!()
83        }
84
85        fn finalize_block() -> HeaderFor<Block> {
86            unreachable!()
87        }
88
89        fn inherent_extrinsics(_data: sp_inherents::InherentData) -> Vec<ExtrinsicFor<Block>> {
90            unreachable!()
91        }
92
93        fn check_inherents(
94            _block: <Block as sp_runtime::traits::Block>::LazyBlock,
95            _data: sp_inherents::InherentData,
96        ) -> sp_inherents::CheckInherentsResult {
97            unreachable!()
98        }
99    }
100
101    impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
102        fn validate_transaction(
103            _source: TransactionSource,
104            _tx: ExtrinsicFor<Block>,
105            _block_hash: BlockHashFor<Block>,
106        ) -> TransactionValidity {
107            unreachable!()
108        }
109    }
110
111    impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
112        fn offchain_worker(_header: &HeaderFor<Block>) {
113            unreachable!()
114        }
115    }
116
117    impl sp_objects::ObjectsApi<Block> for Runtime {
118        fn extract_block_object_mapping(_block: Block) -> BlockObjectMapping {
119            unreachable!()
120        }
121    }
122
123    impl sp_consensus_subspace::SubspaceApi<Block, PublicKey> for Runtime {
124        fn pot_parameters() -> PotParameters {
125            unreachable!()
126        }
127
128        fn solution_ranges() -> SolutionRanges {
129            unreachable!()
130        }
131
132        fn submit_vote_extrinsic(
133            _signed_vote: SignedVote<NumberFor<Block>, BlockHashFor<Block>, PublicKey>,
134        ) {
135            unreachable!()
136        }
137
138        fn history_size() -> HistorySize {
139            unreachable!()
140        }
141
142        fn max_pieces_in_sector() -> u16 {
143            unreachable!()
144        }
145
146        fn segment_commitment(_segment_index: SegmentIndex) -> Option<SegmentCommitment> {
147            unreachable!()
148        }
149
150        fn extract_segment_headers(_ext: &ExtrinsicFor<Block>) -> Option<Vec<SegmentHeader >> {
151            unreachable!()
152        }
153
154        fn is_inherent(_ext: &ExtrinsicFor<Block>) -> bool {
155            unreachable!()
156        }
157
158        fn root_plot_public_key() -> Option<PublicKey> {
159            unreachable!()
160        }
161
162        fn should_adjust_solution_range() -> bool {
163            unreachable!()
164        }
165
166        fn chain_constants() -> ChainConstants {
167            unreachable!()
168        }
169
170        fn block_weight() -> Weight {
171            unreachable!()
172        }
173    }
174
175    impl sp_domains::DomainsApi<Block, DomainHeader> for Runtime {
176        fn submit_bundle_unsigned(
177            _opaque_bundle: sp_domains::bundle::OpaqueBundle<NumberFor<Block>, BlockHashFor<Block>, DomainHeader, Balance>,
178        ) {
179            unreachable!()
180        }
181
182        fn submit_receipt_unsigned(
183            _singleton_receipt: SealedSingletonReceipt<NumberFor<Block>, BlockHashFor<Block>, DomainHeader, Balance>,
184        ) {
185            unreachable!()
186        }
187
188        fn extract_successful_bundles(
189            _domain_id: DomainId,
190            _extrinsics: Vec<ExtrinsicFor<Block>>,
191        ) -> sp_domains::bundle::OpaqueBundles<Block, DomainHeader, Balance> {
192            unreachable!()
193        }
194
195        fn extrinsics_shuffling_seed() -> Randomness {
196            unreachable!()
197        }
198
199        fn domain_runtime_code(_domain_id: DomainId) -> Option<Vec<u8>> {
200            unreachable!()
201        }
202
203        fn runtime_id(_domain_id: DomainId) -> Option<sp_domains::RuntimeId> {
204            unreachable!()
205        }
206
207        fn runtime_upgrades() -> Vec<sp_domains::RuntimeId> {
208            unreachable!()
209        }
210
211        fn domain_instance_data(_domain_id: DomainId) -> Option<(DomainInstanceData, NumberFor<Block>)> {
212            unreachable!()
213        }
214
215        fn domain_timestamp() -> Moment {
216            unreachable!()
217        }
218
219        fn consensus_transaction_byte_fee() -> Balance {
220            unreachable!()
221        }
222
223        fn domain_tx_range(_domain_id: DomainId) -> U256 {
224            unreachable!()
225        }
226
227        fn genesis_state_root(_domain_id: DomainId) -> Option<H256> {
228            unreachable!()
229        }
230
231        fn head_receipt_number(_domain_id: DomainId) -> DomainNumber {
232            unreachable!()
233        }
234
235        fn oldest_unconfirmed_receipt_number(_domain_id: DomainId) -> Option<DomainNumber> {
236            unreachable!()
237        }
238
239        fn domain_bundle_limit(_domain_id: DomainId) -> Option<sp_domains::DomainBundleLimit> {
240            unreachable!()
241        }
242
243        fn non_empty_er_exists(_domain_id: DomainId) -> bool {
244            unreachable!()
245        }
246
247        fn domain_best_number(_domain_id: DomainId) -> Option<DomainNumber> {
248            unreachable!()
249        }
250
251        fn execution_receipt(_receipt_hash: DomainHash) -> Option<ExecutionReceiptFor<DomainHeader, Block, Balance>> {
252            unreachable!()
253        }
254
255        fn domain_operators(_domain_id: DomainId) -> Option<(BTreeMap<OperatorId, Balance>, Vec<OperatorId>)> {
256            unreachable!()
257        }
258
259        fn receipt_hash(_domain_id: DomainId, _domain_number: DomainNumber) -> Option<DomainHash> {
260            unreachable!()
261        }
262
263        fn latest_confirmed_domain_block(_domain_id: DomainId) -> Option<(DomainNumber, DomainHash)>{
264            unreachable!()
265        }
266
267        fn is_bad_er_pending_to_prune(_domain_id: DomainId, _receipt_hash: DomainHash) -> bool {
268            unreachable!()
269        }
270
271        fn storage_fund_account_balance(_operator_id: OperatorId) -> Balance {
272            unreachable!()
273        }
274
275        fn is_domain_runtime_upgraded_since(_domain_id: DomainId, _at: NumberFor<Block>) -> Option<bool> {
276            unreachable!()
277        }
278
279        fn domain_sudo_call(_domain_id: DomainId) -> Option<Vec<u8>> {
280            unreachable!()
281        }
282
283        fn evm_domain_contract_creation_allowed_by_call(_domain_id: DomainId) -> Option<PermissionedActionAllowedBy<EthereumAccountId>>{
284            unreachable!()
285        }
286
287        fn last_confirmed_domain_block_receipt(_domain_id: DomainId) -> Option<ExecutionReceiptFor<DomainHeader, Block, Balance>> {
288            unreachable!()
289        }
290
291        fn current_bundle_and_execution_receipt_version() -> BundleAndExecutionReceiptVersion {
292            unreachable!()
293        }
294
295        fn genesis_execution_receipt(_domain_id: DomainId) -> Option<ExecutionReceiptFor<DomainHeader, Block, Balance>> {
296            unreachable!()
297        }
298
299        fn nominator_position(
300            _operator_id: OperatorId,
301            _nominator_account: sp_runtime::AccountId32,
302        ) -> Option<NominatorPosition<Balance, DomainNumber, Balance>> {
303            unreachable!()
304        }
305
306        fn block_pruning_depth() -> NumberFor<Block> {
307            unreachable!()
308        }
309    }
310
311    impl sp_domains::BundleProducerElectionApi<Block, Balance> for Runtime {
312        fn bundle_producer_election_params(_domain_id: DomainId) -> Option<BundleProducerElectionParams<Balance>> {
313            unreachable!()
314        }
315
316        fn operator(_operator_id: OperatorId) -> Option<(OperatorPublicKey, Balance)> {
317            unreachable!()
318        }
319    }
320
321    impl sp_session::SessionKeys<Block> for Runtime {
322        fn generate_session_keys(
323            _owner: Vec<u8>,
324            _seed: Option<Vec<u8>>,
325        ) -> sp_session::OpaqueGeneratedSessionKeys {
326            unreachable!()
327        }
328
329        fn decode_session_keys(
330            _encoded: Vec<u8>,
331        ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
332            unreachable!()
333        }
334    }
335
336    impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
337        fn account_nonce(_account: AccountId) -> Nonce {
338            unreachable!()
339        }
340    }
341
342    impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
343        fn query_info(
344            _uxt: ExtrinsicFor<Block>,
345            _len: u32,
346        ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
347            unreachable!()
348        }
349        fn query_fee_details(
350            _uxt: ExtrinsicFor<Block>,
351            _len: u32,
352        ) -> pallet_transaction_payment::FeeDetails<Balance> {
353            unreachable!()
354        }
355        fn query_weight_to_fee(_weight: Weight) -> Balance {
356            unreachable!()
357        }
358        fn query_length_to_fee(_length: u32) -> Balance {
359            unreachable!()
360        }
361    }
362
363    impl sp_messenger::MessengerApi<Block, BlockNumber, BlockHashFor<Block>> for Runtime {
364        fn is_xdm_mmr_proof_valid(
365            _ext: &ExtrinsicFor<Block>
366        ) -> Option<bool> {
367            unreachable!()
368        }
369
370        fn extract_xdm_mmr_proof(_ext: &ExtrinsicFor<Block>) -> Option<ConsensusChainMmrLeafProof<BlockNumber, BlockHashFor<Block>, sp_core::H256>> {
371            unreachable!()
372        }
373
374        fn batch_extract_xdm_mmr_proof(_extrinsics: &Vec<ExtrinsicFor<Block>>) -> BTreeMap<u32, ConsensusChainMmrLeafProof<BlockNumber, BlockHashFor<Block>, sp_core::H256>> {
375            unreachable!()
376        }
377
378        fn confirmed_domain_block_storage_key(_domain_id: DomainId) -> Vec<u8> {
379            unreachable!()
380        }
381
382        fn outbox_storage_key(_message_key: MessageKey) -> Vec<u8> {
383            unreachable!()
384        }
385
386        fn inbox_response_storage_key(_message_key: MessageKey) -> Vec<u8> {
387            unreachable!()
388        }
389
390        fn domain_chains_allowlist_update(_domain_id: DomainId) -> Option<DomainAllowlistUpdates>{
391            unreachable!()
392        }
393
394        fn xdm_id(_ext: &ExtrinsicFor<Block>) -> Option<XdmId> {
395            unreachable!()
396        }
397
398        fn channel_nonce(_chain_id: ChainId, _channel_id: ChannelId) -> Option<ChannelNonce> {
399            unreachable!()
400        }
401    }
402
403    impl sp_messenger::RelayerApi<Block, BlockNumber, BlockNumber, BlockHashFor<Block>> for Runtime {
404        fn outbox_message_unsigned(_msg: CrossDomainMessage<NumberFor<Block>, BlockHashFor<Block>, BlockHashFor<Block>>) -> Option<ExtrinsicFor<Block>> {
405            unreachable!()
406        }
407
408        fn inbox_response_message_unsigned(_msg: CrossDomainMessage<NumberFor<Block>, BlockHashFor<Block>, BlockHashFor<Block>>) -> Option<ExtrinsicFor<Block>> {
409            unreachable!()
410        }
411
412        fn updated_channels() -> BTreeSet<(ChainId, ChannelId)> {
413            unreachable!()
414        }
415
416        fn channel_storage_key(_chain_id: ChainId, _channel_id: ChannelId) -> Vec<u8> {
417            unreachable!()
418        }
419
420        fn open_channels() -> BTreeSet<(ChainId, ChannelId)> {
421            unreachable!()
422        }
423
424        fn block_messages_with_query(_: BlockMessagesQuery) -> MessagesWithStorageKey {
425            unreachable!()
426        }
427
428        fn channels_and_state() -> Vec<(ChainId, ChannelId, ChannelStateWithNonce)> {
429            unreachable!()
430        }
431
432        fn first_outbox_message_nonce_to_relay(_: ChainId, _: ChannelId, _: XdmNonce) -> Option<XdmNonce> {
433            unreachable!()
434        }
435
436        fn first_inbox_message_response_nonce_to_relay(_: ChainId, _: ChannelId, _: XdmNonce) -> Option<XdmNonce> {
437            unreachable!()
438        }
439    }
440
441    impl sp_domains_fraud_proof::FraudProofApi<Block, DomainHeader> for Runtime {
442        fn submit_fraud_proof_unsigned(_fraud_proof: FraudProof<NumberFor<Block>, BlockHashFor<Block>, DomainHeader, H256>) {
443            unreachable!()
444        }
445
446        fn fraud_proof_storage_key(_req: FraudProofStorageKeyRequest<NumberFor<Block>>) -> Vec<u8> {
447            unreachable!()
448        }
449    }
450
451    impl mmr::MmrApi<Block, mmr::Hash, BlockNumber> for Runtime {
452        fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
453            unreachable!()
454        }
455
456        fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
457            unreachable!()
458        }
459
460        fn generate_proof(
461            _block_numbers: Vec<BlockNumber>,
462            _best_known_block_number: Option<BlockNumber>,
463        ) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::LeafProof<mmr::Hash>), mmr::Error> {
464            unreachable!()
465        }
466
467        fn generate_ancestry_proof(
468            _prev_block_number: BlockNumber,
469            _best_known_block_number: Option<BlockNumber>,
470        ) -> Result<mmr::AncestryProof<mmr::Hash>, mmr::Error> {
471            unreachable!()
472        }
473
474        fn verify_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::LeafProof<mmr::Hash>)
475            -> Result<(), mmr::Error>
476        {
477            unreachable!()
478        }
479
480        fn verify_proof_stateless(
481            _root: mmr::Hash,
482            _leaves: Vec<mmr::EncodableOpaqueLeaf>,
483            _proof: mmr::LeafProof<mmr::Hash>
484        ) -> Result<(), mmr::Error> {
485            unreachable!()
486        }
487    }
488
489    impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
490        fn build_state(_config: Vec<u8>) -> sp_genesis_builder::Result {
491            unreachable!()
492        }
493
494        fn get_preset(_id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
495            unreachable!()
496        }
497
498        fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
499            unreachable!()
500        }
501    }
502}