sp_domains_fraud_proof/
runtime_interface.rs

1#[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::runtime_interface;
18use sp_weights::Weight;
19
20/// Domain fraud proof related runtime interface
21#[runtime_interface]
22pub trait FraudProofRuntimeInterface {
23    /// Derive the bundle digest for the given bundle body.
24    fn derive_bundle_digest(
25        &mut self,
26        domain_runtime_code: Vec<u8>,
27        bundle_body: Vec<OpaqueExtrinsic>,
28    ) -> Option<H256> {
29        self.extension::<FraudProofExtension>()
30            .expect("No `FraudProofExtension` associated for the current context!")
31            .derive_bundle_digest(domain_runtime_code, bundle_body)
32    }
33
34    /// Check the execution proof with also included domain block id.
35    fn execution_proof_check(
36        &mut self,
37        domain_block_id: (BlockNumber, H256),
38        pre_state_root: H256,
39        encoded_proof: Vec<u8>,
40        execution_method: &str,
41        call_data: &[u8],
42        domain_runtime_code: Vec<u8>,
43    ) -> Option<Vec<u8>> {
44        self.extension::<FraudProofExtension>()
45            .expect("No `FraudProofExtension` associated for the current context!")
46            .execution_proof_check(
47                domain_block_id,
48                pre_state_root,
49                encoded_proof,
50                execution_method,
51                call_data,
52                domain_runtime_code,
53            )
54    }
55
56    fn check_extrinsics_in_single_context(
57        &mut self,
58        domain_runtime_code: Vec<u8>,
59        domain_block_id: (BlockNumber, H256),
60        domain_block_state_root: H256,
61        bundle_extrinsics: Vec<OpaqueExtrinsic>,
62        encoded_proof: Vec<u8>,
63    ) -> Option<Option<u32>> {
64        self.extension::<FraudProofExtension>()
65            .expect("No `FraudProofExtension` associated for the current context!")
66            .check_extrinsics_in_single_context(
67                domain_runtime_code,
68                domain_block_id,
69                domain_block_state_root,
70                bundle_extrinsics,
71                encoded_proof,
72            )
73    }
74
75    fn construct_domain_inherent_extrinsic(
76        &mut self,
77        domain_runtime_code: Vec<u8>,
78        domain_inherent_extrinsic_data: DomainInherentExtrinsicData,
79    ) -> Option<DomainInherentExtrinsic> {
80        self.extension::<FraudProofExtension>()
81            .expect("No `FraudProofExtension` associated for the current context!")
82            .construct_domain_inherent_extrinsic(
83                domain_runtime_code,
84                domain_inherent_extrinsic_data,
85            )
86    }
87
88    fn domain_storage_key(
89        &mut self,
90        domain_runtime_code: Vec<u8>,
91        req: DomainStorageKeyRequest,
92    ) -> Option<Vec<u8>> {
93        self.extension::<FraudProofExtension>()
94            .expect("No `FraudProofExtension` associated for the current context!")
95            .domain_storage_key(domain_runtime_code, req)
96    }
97
98    fn domain_runtime_call(
99        &mut self,
100        domain_runtime_code: Vec<u8>,
101        call: StatelessDomainRuntimeCall,
102    ) -> Option<bool> {
103        self.extension::<FraudProofExtension>()
104            .expect("No `FraudProofExtension` associated for the current context!")
105            .domain_runtime_call(domain_runtime_code, call)
106    }
107
108    fn bundle_weight(
109        &mut self,
110        domain_runtime_code: Vec<u8>,
111        bundle_body: Vec<OpaqueExtrinsic>,
112    ) -> Option<Weight> {
113        self.extension::<FraudProofExtension>()
114            .expect("No `FraudProofExtension` associated for the current context!")
115            .bundle_weight(domain_runtime_code, bundle_body)
116    }
117
118    fn extract_xdm_mmr_proof(
119        &mut self,
120        domain_runtime_code: Vec<u8>,
121        opaque_extrinsic: Vec<u8>,
122    ) -> Option<Option<Vec<u8>>> {
123        self.extension::<FraudProofExtension>()
124            .expect("No `FraudProofExtension` associated for the current context!")
125            .extract_xdm_mmr_proof(domain_runtime_code, opaque_extrinsic)
126    }
127}