difftreelog
feat estimate multiple extrinsics PoV
in: master
3 files changed
client/rpc/src/pov_estimate.rsdiffbeforeafterboth--- a/client/rpc/src/pov_estimate.rs
+++ b/client/rpc/src/pov_estimate.rs
@@ -122,7 +122,11 @@
#[async_trait]
pub trait PovEstimateApi<BlockHash> {
#[method(name = "unique_estimateExtrinsicPoV")]
- fn estimate_extrinsic_pov(&self, encoded_xt: Bytes, at: Option<BlockHash>) -> Result<PovInfo>;
+ fn estimate_extrinsic_pov(
+ &self,
+ encoded_xts: Vec<Bytes>,
+ at: Option<BlockHash>,
+ ) -> Result<PovInfo>;
}
#[allow(deprecated)]
@@ -135,7 +139,7 @@
{
fn estimate_extrinsic_pov(
&self,
- encoded_xt: Bytes,
+ encoded_xts: Vec<Bytes>,
at: Option<<Block as BlockT>::Hash>,
) -> Result<PovInfo> {
self.deny_unsafe.check_if_safe()?;
@@ -151,20 +155,20 @@
RuntimeId::Unique => execute_extrinsic_in_sandbox::<Block, UniqueRuntimeExecutor>(
state,
&self.exec_params,
- encoded_xt,
+ encoded_xts,
),
#[cfg(feature = "quartz-runtime")]
RuntimeId::Quartz => execute_extrinsic_in_sandbox::<Block, QuartzRuntimeExecutor>(
state,
&self.exec_params,
- encoded_xt,
+ encoded_xts,
),
RuntimeId::Opal => execute_extrinsic_in_sandbox::<Block, OpalRuntimeExecutor>(
state,
&self.exec_params,
- encoded_xt,
+ encoded_xts,
),
runtime_id => Err(anyhow!("unknown runtime id {:?}", runtime_id).into()),
@@ -188,7 +192,7 @@
fn execute_extrinsic_in_sandbox<Block, D>(
state: StateOf<Block>,
exec_params: &ExecutorParams,
- encoded_xt: Bytes,
+ encoded_xts: Vec<Bytes>,
) -> Result<PovInfo>
where
Block: BlockT,
@@ -216,23 +220,29 @@
);
let execution = ExecutionStrategy::NativeElseWasm;
- let encoded_bytes = encoded_xt.encode();
+ let mut results = Vec::new();
+
+ for encoded_xt in encoded_xts {
+ let encoded_bytes = encoded_xt.encode();
+
+ let xt_result = StateMachine::new(
+ &proving_backend,
+ &mut changes,
+ &executor,
+ "PovEstimateApi_pov_estimate",
+ encoded_bytes.as_slice(),
+ full_extensions(),
+ &runtime_code,
+ sp_core::testing::TaskExecutor::new(),
+ )
+ .execute(execution.into())
+ .map_err(|e| anyhow!("failed to execute the extrinsic {:?}", e))?;
- let xt_result = StateMachine::new(
- &proving_backend,
- &mut changes,
- &executor,
- "PovEstimateApi_pov_estimate",
- encoded_bytes.as_slice(),
- full_extensions(),
- &runtime_code,
- sp_core::testing::TaskExecutor::new(),
- )
- .execute(execution.into())
- .map_err(|e| anyhow!("failed to execute the extrinsic {:?}", e))?;
+ let xt_result = Decode::decode(&mut &*xt_result)
+ .map_err(|e| anyhow!("failed to decode the extrinsic result {:?}", e))?;
- let xt_result = Decode::decode(&mut &*xt_result)
- .map_err(|e| anyhow!("failed to decode the extrinsic result {:?}", e))?;
+ results.push(xt_result);
+ }
let proof = proving_backend
.extract_proof()
@@ -252,6 +262,6 @@
proof_size: proof_size as u64,
compact_proof_size: compact_proof_size as u64,
compressed_proof_size: compressed_proof_size as u64,
- result: xt_result,
+ results,
})
}
primitives/pov-estimate-rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/pov-estimate-rpc/src/lib.rs
+++ b/primitives/pov-estimate-rpc/src/lib.rs
@@ -17,6 +17,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
use scale_info::TypeInfo;
+use sp_std::vec::Vec;
#[cfg(feature = "std")]
use serde::Serialize;
@@ -30,7 +31,7 @@
pub proof_size: u64,
pub compact_proof_size: u64,
pub compressed_proof_size: u64,
- pub result: ApplyExtrinsicResult,
+ pub results: Vec<ApplyExtrinsicResult>,
}
sp_api::decl_runtime_apis! {
tests/src/interfaces/unique/definitions.tsdiffbeforeafterboth175 [collectionParam, tokenParam],175 [collectionParam, tokenParam],176 'Option<u128>',176 'Option<u128>',177 ),177 ),178<<<<<<< HEAD179<<<<<<< HEAD180 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 types198 'UpPovEstimateRpcPovInfo',199>>>>>>> fix: update polkadot types and definitions200 ),201 },183 },202};184};203185