From 254f58fefc7b4cdb72d01d56e45bbed3f082bdb7 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Wed, 23 Nov 2022 19:30:26 +0000 Subject: [PATCH] feat: estimate multiple extrinsics PoV --- --- a/client/rpc/src/pov_estimate.rs +++ b/client/rpc/src/pov_estimate.rs @@ -122,7 +122,11 @@ #[async_trait] pub trait PovEstimateApi { #[method(name = "unique_estimateExtrinsicPoV")] - fn estimate_extrinsic_pov(&self, encoded_xt: Bytes, at: Option) -> Result; + fn estimate_extrinsic_pov( + &self, + encoded_xts: Vec, + at: Option, + ) -> Result; } #[allow(deprecated)] @@ -135,7 +139,7 @@ { fn estimate_extrinsic_pov( &self, - encoded_xt: Bytes, + encoded_xts: Vec, at: Option<::Hash>, ) -> Result { self.deny_unsafe.check_if_safe()?; @@ -151,20 +155,20 @@ RuntimeId::Unique => execute_extrinsic_in_sandbox::( state, &self.exec_params, - encoded_xt, + encoded_xts, ), #[cfg(feature = "quartz-runtime")] RuntimeId::Quartz => execute_extrinsic_in_sandbox::( state, &self.exec_params, - encoded_xt, + encoded_xts, ), RuntimeId::Opal => execute_extrinsic_in_sandbox::( 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( state: StateOf, exec_params: &ExecutorParams, - encoded_xt: Bytes, + encoded_xts: Vec, ) -> Result 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, }) } --- 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, } sp_api::decl_runtime_apis! { --- a/tests/src/interfaces/unique/definitions.ts +++ b/tests/src/interfaces/unique/definitions.ts @@ -175,28 +175,10 @@ [collectionParam, tokenParam], 'Option', ), -<<<<<<< HEAD -<<<<<<< HEAD allowanceForAll: fun( 'Tells whether the given `owner` approves the `operator`.', [collectionParam, crossAccountParam('owner'), crossAccountParam('operator')], 'Option', -======= - povEstimate: fun( - 'Estimate PoV size', - [{name: 'encodedXt', type: 'Vec'}], -======= - estimateExtrinsicPoV: fun( - 'Estimate PoV size of an encoded extrinsic', - [{name: 'encodedXt', type: 'Bytes'}], - 'UpPovEstimateRpcPovInfo', - ), - estimateCallPoV: fun( - 'Estimate PoV size of an encoded call', - [{name: 'encodedCall', type: 'Bytes'}], ->>>>>>> chore: regenerate types - 'UpPovEstimateRpcPovInfo', ->>>>>>> fix: update polkadot types and definitions ), }, }; -- gitstuff