sp_domains_fraud_proof/
runtime_interface.rs1#[cfg(not(feature = "std"))]
2extern crate alloc;
3
4#[cfg(feature = "std")]
5use crate::FraudProofExtension;
6use crate::{
7 DomainInherentExtrinsic, DomainInherentExtrinsicData, DomainStorageKeyRequest,
8 StatelessDomainRuntimeCall,
9};
10#[cfg(not(feature = "std"))]
11use alloc::vec::Vec;
12use domain_runtime_primitives::BlockNumber;
13use sp_core::H256;
14#[cfg(feature = "std")]
15use sp_externalities::ExternalitiesExt;
16use sp_runtime::OpaqueExtrinsic;
17use sp_runtime_interface::pass_by::{
18 AllocateAndReturnByCodec, PassFatPointerAndDecode, PassFatPointerAndRead,
19 PassPointerAndReadCopy,
20};
21use sp_runtime_interface::runtime_interface;
22use sp_weights::Weight;
23
24#[runtime_interface]
26pub trait FraudProofRuntimeInterface {
27 fn derive_bundle_digest(
29 &mut self,
30 domain_runtime_code: PassFatPointerAndDecode<Vec<u8>>,
31 bundle_body: PassFatPointerAndDecode<Vec<OpaqueExtrinsic>>,
32 ) -> AllocateAndReturnByCodec<Option<H256>> {
33 self.extension::<FraudProofExtension>()
34 .expect("No `FraudProofExtension` associated for the current context!")
35 .derive_bundle_digest(domain_runtime_code, bundle_body)
36 }
37
38 fn execution_proof_check(
40 &mut self,
41 domain_block_id: PassFatPointerAndDecode<(BlockNumber, H256)>,
42 pre_state_root: PassPointerAndReadCopy<H256, 32>,
43 encoded_proof: PassFatPointerAndDecode<Vec<u8>>,
44 execution_method: PassFatPointerAndRead<&str>,
45 call_data: PassFatPointerAndRead<&[u8]>,
46 domain_runtime_code: PassFatPointerAndDecode<Vec<u8>>,
47 ) -> AllocateAndReturnByCodec<Option<Vec<u8>>> {
48 self.extension::<FraudProofExtension>()
49 .expect("No `FraudProofExtension` associated for the current context!")
50 .execution_proof_check(
51 domain_block_id,
52 pre_state_root,
53 encoded_proof,
54 execution_method,
55 call_data,
56 domain_runtime_code,
57 )
58 }
59
60 fn check_extrinsics_in_single_context(
61 &mut self,
62 domain_runtime_code: PassFatPointerAndDecode<Vec<u8>>,
63 domain_block_id: PassFatPointerAndDecode<(BlockNumber, H256)>,
64 domain_block_state_root: PassPointerAndReadCopy<H256, 32>,
65 bundle_extrinsics: PassFatPointerAndDecode<Vec<OpaqueExtrinsic>>,
66 encoded_proof: PassFatPointerAndDecode<Vec<u8>>,
67 ) -> AllocateAndReturnByCodec<Option<Option<u32>>> {
68 self.extension::<FraudProofExtension>()
69 .expect("No `FraudProofExtension` associated for the current context!")
70 .check_extrinsics_in_single_context(
71 domain_runtime_code,
72 domain_block_id,
73 domain_block_state_root,
74 bundle_extrinsics,
75 encoded_proof,
76 )
77 }
78
79 fn construct_domain_inherent_extrinsic(
80 &mut self,
81 domain_runtime_code: PassFatPointerAndDecode<Vec<u8>>,
82 domain_inherent_extrinsic_data: PassFatPointerAndDecode<DomainInherentExtrinsicData>,
83 ) -> AllocateAndReturnByCodec<Option<DomainInherentExtrinsic>> {
84 self.extension::<FraudProofExtension>()
85 .expect("No `FraudProofExtension` associated for the current context!")
86 .construct_domain_inherent_extrinsic(
87 domain_runtime_code,
88 domain_inherent_extrinsic_data,
89 )
90 }
91
92 fn domain_storage_key(
93 &mut self,
94 domain_runtime_code: PassFatPointerAndDecode<Vec<u8>>,
95 req: PassFatPointerAndDecode<DomainStorageKeyRequest>,
96 ) -> AllocateAndReturnByCodec<Option<Vec<u8>>> {
97 self.extension::<FraudProofExtension>()
98 .expect("No `FraudProofExtension` associated for the current context!")
99 .domain_storage_key(domain_runtime_code, req)
100 }
101
102 fn domain_runtime_call(
103 &mut self,
104 domain_runtime_code: PassFatPointerAndDecode<Vec<u8>>,
105 call: PassFatPointerAndDecode<StatelessDomainRuntimeCall>,
106 ) -> AllocateAndReturnByCodec<Option<bool>> {
107 self.extension::<FraudProofExtension>()
108 .expect("No `FraudProofExtension` associated for the current context!")
109 .domain_runtime_call(domain_runtime_code, call)
110 }
111
112 fn bundle_weight(
113 &mut self,
114 domain_runtime_code: PassFatPointerAndDecode<Vec<u8>>,
115 bundle_body: PassFatPointerAndDecode<Vec<OpaqueExtrinsic>>,
116 ) -> AllocateAndReturnByCodec<Option<Weight>> {
117 self.extension::<FraudProofExtension>()
118 .expect("No `FraudProofExtension` associated for the current context!")
119 .bundle_weight(domain_runtime_code, bundle_body)
120 }
121
122 fn extract_xdm_mmr_proof(
123 &mut self,
124 domain_runtime_code: PassFatPointerAndDecode<Vec<u8>>,
125 opaque_extrinsic: PassFatPointerAndDecode<Vec<u8>>,
126 ) -> AllocateAndReturnByCodec<Option<Option<Vec<u8>>>> {
127 self.extension::<FraudProofExtension>()
128 .expect("No `FraudProofExtension` associated for the current context!")
129 .extract_xdm_mmr_proof(domain_runtime_code, opaque_extrinsic)
130 }
131}