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
--- 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,
 	})
 }
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
--- a/tests/src/interfaces/unique/definitions.ts
+++ b/tests/src/interfaces/unique/definitions.ts
@@ -175,28 +175,10 @@
       [collectionParam, tokenParam],
       'Option<u128>',
     ),
-<<<<<<< HEAD
-<<<<<<< HEAD
     allowanceForAll: fun(
       'Tells whether the given `owner` approves the `operator`.',
       [collectionParam, crossAccountParam('owner'), crossAccountParam('operator')],
       'Option<bool>',
-=======
-    povEstimate: fun(
-      'Estimate PoV size',
-      [{name: 'encodedXt', type: 'Vec<u8>'}],
-=======
-    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
     ),
   },
 };