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) {
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,
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(_seed: Option<Vec<u8>>) -> Vec<u8> {
323            unreachable!()
324        }
325
326        fn decode_session_keys(
327            _encoded: Vec<u8>,
328        ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
329            unreachable!()
330        }
331    }
332
333    impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
334        fn account_nonce(_account: AccountId) -> Nonce {
335            unreachable!()
336        }
337    }
338
339    impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
340        fn query_info(
341            _uxt: ExtrinsicFor<Block>,
342            _len: u32,
343        ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
344            unreachable!()
345        }
346        fn query_fee_details(
347            _uxt: ExtrinsicFor<Block>,
348            _len: u32,
349        ) -> pallet_transaction_payment::FeeDetails<Balance> {
350            unreachable!()
351        }
352        fn query_weight_to_fee(_weight: Weight) -> Balance {
353            unreachable!()
354        }
355        fn query_length_to_fee(_length: u32) -> Balance {
356            unreachable!()
357        }
358    }
359
360    impl sp_messenger::MessengerApi<Block, BlockNumber, BlockHashFor<Block>> for Runtime {
361        fn is_xdm_mmr_proof_valid(
362            _ext: &ExtrinsicFor<Block>
363        ) -> Option<bool> {
364            unreachable!()
365        }
366
367        fn extract_xdm_mmr_proof(_ext: &ExtrinsicFor<Block>) -> Option<ConsensusChainMmrLeafProof<BlockNumber, BlockHashFor<Block>, sp_core::H256>> {
368            unreachable!()
369        }
370
371        fn batch_extract_xdm_mmr_proof(_extrinsics: &Vec<ExtrinsicFor<Block>>) -> BTreeMap<u32, ConsensusChainMmrLeafProof<BlockNumber, BlockHashFor<Block>, sp_core::H256>> {
372            unreachable!()
373        }
374
375        fn confirmed_domain_block_storage_key(_domain_id: DomainId) -> Vec<u8> {
376            unreachable!()
377        }
378
379        fn outbox_storage_key(_message_key: MessageKey) -> Vec<u8> {
380            unreachable!()
381        }
382
383        fn inbox_response_storage_key(_message_key: MessageKey) -> Vec<u8> {
384            unreachable!()
385        }
386
387        fn domain_chains_allowlist_update(_domain_id: DomainId) -> Option<DomainAllowlistUpdates>{
388            unreachable!()
389        }
390
391        fn xdm_id(_ext: &ExtrinsicFor<Block>) -> Option<XdmId> {
392            unreachable!()
393        }
394
395        fn channel_nonce(_chain_id: ChainId, _channel_id: ChannelId) -> Option<ChannelNonce> {
396            unreachable!()
397        }
398    }
399
400    impl sp_messenger::RelayerApi<Block, BlockNumber, BlockNumber, BlockHashFor<Block>> for Runtime {
401        fn outbox_message_unsigned(_msg: CrossDomainMessage<NumberFor<Block>, BlockHashFor<Block>, BlockHashFor<Block>>) -> Option<ExtrinsicFor<Block>> {
402            unreachable!()
403        }
404
405        fn inbox_response_message_unsigned(_msg: CrossDomainMessage<NumberFor<Block>, BlockHashFor<Block>, BlockHashFor<Block>>) -> Option<ExtrinsicFor<Block>> {
406            unreachable!()
407        }
408
409        fn updated_channels() -> BTreeSet<(ChainId, ChannelId)> {
410            unreachable!()
411        }
412
413        fn channel_storage_key(_chain_id: ChainId, _channel_id: ChannelId) -> Vec<u8> {
414            unreachable!()
415        }
416
417        fn open_channels() -> BTreeSet<(ChainId, ChannelId)> {
418            unreachable!()
419        }
420
421        fn block_messages_with_query(_: BlockMessagesQuery) -> MessagesWithStorageKey {
422            unreachable!()
423        }
424
425        fn channels_and_state() -> Vec<(ChainId, ChannelId, ChannelStateWithNonce)> {
426            unreachable!()
427        }
428
429        fn first_outbox_message_nonce_to_relay(_: ChainId, _: ChannelId, _: XdmNonce) -> Option<XdmNonce> {
430            unreachable!()
431        }
432
433        fn first_inbox_message_response_nonce_to_relay(_: ChainId, _: ChannelId, _: XdmNonce) -> Option<XdmNonce> {
434            unreachable!()
435        }
436    }
437
438    impl sp_domains_fraud_proof::FraudProofApi<Block, DomainHeader> for Runtime {
439        fn submit_fraud_proof_unsigned(_fraud_proof: FraudProof<NumberFor<Block>, BlockHashFor<Block>, DomainHeader, H256>) {
440            unreachable!()
441        }
442
443        fn fraud_proof_storage_key(_req: FraudProofStorageKeyRequest<NumberFor<Block>>) -> Vec<u8> {
444            unreachable!()
445        }
446    }
447
448    impl mmr::MmrApi<Block, mmr::Hash, BlockNumber> for Runtime {
449        fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
450            unreachable!()
451        }
452
453        fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
454            unreachable!()
455        }
456
457        fn generate_proof(
458            _block_numbers: Vec<BlockNumber>,
459            _best_known_block_number: Option<BlockNumber>,
460        ) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::LeafProof<mmr::Hash>), mmr::Error> {
461            unreachable!()
462        }
463
464        fn verify_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::LeafProof<mmr::Hash>)
465            -> Result<(), mmr::Error>
466        {
467            unreachable!()
468        }
469
470        fn verify_proof_stateless(
471            _root: mmr::Hash,
472            _leaves: Vec<mmr::EncodableOpaqueLeaf>,
473            _proof: mmr::LeafProof<mmr::Hash>
474        ) -> Result<(), mmr::Error> {
475            unreachable!()
476        }
477    }
478
479    impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
480        fn build_state(_config: Vec<u8>) -> sp_genesis_builder::Result {
481            unreachable!()
482        }
483
484        fn get_preset(_id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
485            unreachable!()
486        }
487
488        fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
489            unreachable!()
490        }
491    }
492}