git.delta.rocks / unique-network / refs/commits / 254f58fefc7b

difftreelog

feat estimate multiple extrinsics PoV

Daniel Shiposha2022-11-23parent: #cff7f42.patch.diff
in: master

3 files changed

modifiedclient/rpc/src/pov_estimate.rsdiffbeforeafterboth
122#[async_trait]122#[async_trait]
123pub trait PovEstimateApi<BlockHash> {123pub trait PovEstimateApi<BlockHash> {
124 #[method(name = "unique_estimateExtrinsicPoV")]124 #[method(name = "unique_estimateExtrinsicPoV")]
125 fn estimate_extrinsic_pov(&self, encoded_xt: Bytes, at: Option<BlockHash>) -> Result<PovInfo>;125 fn estimate_extrinsic_pov(
126 &self,
127 encoded_xts: Vec<Bytes>,
128 at: Option<BlockHash>,
129 ) -> Result<PovInfo>;
126}130}
127131
135{139{
136 fn estimate_extrinsic_pov(140 fn estimate_extrinsic_pov(
137 &self,141 &self,
138 encoded_xt: Bytes,142 encoded_xts: Vec<Bytes>,
139 at: Option<<Block as BlockT>::Hash>,143 at: Option<<Block as BlockT>::Hash>,
140 ) -> Result<PovInfo> {144 ) -> Result<PovInfo> {
141 self.deny_unsafe.check_if_safe()?;145 self.deny_unsafe.check_if_safe()?;
151 RuntimeId::Unique => execute_extrinsic_in_sandbox::<Block, UniqueRuntimeExecutor>(155 RuntimeId::Unique => execute_extrinsic_in_sandbox::<Block, UniqueRuntimeExecutor>(
152 state,156 state,
153 &self.exec_params,157 &self.exec_params,
154 encoded_xt,158 encoded_xts,
155 ),159 ),
156160
157 #[cfg(feature = "quartz-runtime")]161 #[cfg(feature = "quartz-runtime")]
158 RuntimeId::Quartz => execute_extrinsic_in_sandbox::<Block, QuartzRuntimeExecutor>(162 RuntimeId::Quartz => execute_extrinsic_in_sandbox::<Block, QuartzRuntimeExecutor>(
159 state,163 state,
160 &self.exec_params,164 &self.exec_params,
161 encoded_xt,165 encoded_xts,
162 ),166 ),
163167
164 RuntimeId::Opal => execute_extrinsic_in_sandbox::<Block, OpalRuntimeExecutor>(168 RuntimeId::Opal => execute_extrinsic_in_sandbox::<Block, OpalRuntimeExecutor>(
165 state,169 state,
166 &self.exec_params,170 &self.exec_params,
167 encoded_xt,171 encoded_xts,
168 ),172 ),
169173
170 runtime_id => Err(anyhow!("unknown runtime id {:?}", runtime_id).into()),174 runtime_id => Err(anyhow!("unknown runtime id {:?}", runtime_id).into()),
188fn execute_extrinsic_in_sandbox<Block, D>(192fn execute_extrinsic_in_sandbox<Block, D>(
189 state: StateOf<Block>,193 state: StateOf<Block>,
190 exec_params: &ExecutorParams,194 exec_params: &ExecutorParams,
191 encoded_xt: Bytes,195 encoded_xts: Vec<Bytes>,
192) -> Result<PovInfo>196) -> Result<PovInfo>
193where197where
194 Block: BlockT,198 Block: BlockT,
216 );220 );
217 let execution = ExecutionStrategy::NativeElseWasm;221 let execution = ExecutionStrategy::NativeElseWasm;
218222
223 let mut results = Vec::new();
224
225 for encoded_xt in encoded_xts {
219 let encoded_bytes = encoded_xt.encode();226 let encoded_bytes = encoded_xt.encode();
220227
221 let xt_result = StateMachine::new(228 let xt_result = StateMachine::new(
234 let xt_result = Decode::decode(&mut &*xt_result)241 let xt_result = Decode::decode(&mut &*xt_result)
235 .map_err(|e| anyhow!("failed to decode the extrinsic result {:?}", e))?;242 .map_err(|e| anyhow!("failed to decode the extrinsic result {:?}", e))?;
243
244 results.push(xt_result);
245 }
236246
237 let proof = proving_backend247 let proof = proving_backend
238 .extract_proof()248 .extract_proof()
252 proof_size: proof_size as u64,262 proof_size: proof_size as u64,
253 compact_proof_size: compact_proof_size as u64,263 compact_proof_size: compact_proof_size as u64,
254 compressed_proof_size: compressed_proof_size as u64,264 compressed_proof_size: compressed_proof_size as u64,
255 result: xt_result,265 results,
256 })266 })
257}267}
258268
modifiedprimitives/pov-estimate-rpc/src/lib.rsdiffbeforeafterboth
17#![cfg_attr(not(feature = "std"), no_std)]17#![cfg_attr(not(feature = "std"), no_std)]
1818
19use scale_info::TypeInfo;19use scale_info::TypeInfo;
20use sp_std::vec::Vec;
2021
21#[cfg(feature = "std")]22#[cfg(feature = "std")]
22use serde::Serialize;23use serde::Serialize;
30 pub proof_size: u64,31 pub proof_size: u64,
31 pub compact_proof_size: u64,32 pub compact_proof_size: u64,
32 pub compressed_proof_size: u64,33 pub compressed_proof_size: u64,
33 pub result: ApplyExtrinsicResult,34 pub results: Vec<ApplyExtrinsicResult>,
34}35}
3536
36sp_api::decl_runtime_apis! {37sp_api::decl_runtime_apis! {
modifiedtests/src/interfaces/unique/definitions.tsdiffbeforeafterboth
175 [collectionParam, tokenParam],175 [collectionParam, tokenParam],
176 'Option<u128>',176 'Option<u128>',
177 ),177 ),
178<<<<<<< HEAD
179<<<<<<< HEAD
180 allowanceForAll: fun(178 allowanceForAll: fun(
181 'Tells whether the given `owner` approves the `operator`.',179 'Tells whether the given `owner` approves the `operator`.',
182 [collectionParam, crossAccountParam('owner'), crossAccountParam('operator')],180 [collectionParam, crossAccountParam('owner'), crossAccountParam('operator')],
183 'Option<bool>',181 'Option<bool>',
184=======
185 povEstimate: fun(
186 'Estimate PoV size',
187 [{name: 'encodedXt', type: 'Vec<u8>'}],
188=======
189 estimateExtrinsicPoV: fun(
190 'Estimate PoV size of an encoded extrinsic',
191 [{name: 'encodedXt', type: 'Bytes'}],
192 'UpPovEstimateRpcPovInfo',
193 ),182 ),
194 estimateCallPoV: fun(
195 'Estimate PoV size of an encoded call',
196 [{name: 'encodedCall', type: 'Bytes'}],
197>>>>>>> chore: regenerate types
198 'UpPovEstimateRpcPovInfo',
199>>>>>>> fix: update polkadot types and definitions
200 ),
201 },183 },
202};184};
203185