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
--- 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! {
modifiedtests/src/interfaces/unique/definitions.tsdiffbeforeafterboth
before · tests/src/interfaces/unique/definitions.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617type RpcParam = {18  name: string;19  type: string;20  isOptional?: true;21};2223const CROSS_ACCOUNT_ID_TYPE = 'PalletEvmAccountBasicCrossAccountIdRepr';2425const collectionParam = {name: 'collection', type: 'u32'};26const tokenParam = {name: 'tokenId', type: 'u32'};27const propertyKeysParam = {name: 'propertyKeys', type: 'Option<Vec<String>>', isOptional: true};28const crossAccountParam = (name = 'account') => ({name, type: CROSS_ACCOUNT_ID_TYPE});29const atParam = {name: 'at', type: 'Hash', isOptional: true};3031const fun = (description: string, params: RpcParam[], type: string) => ({32  description,33  params: [...params, atParam],34  type,35});3637export default {38  types: {},39  rpc: {40    accountTokens: fun(41      'Get tokens owned by an account in a collection',42      [collectionParam, crossAccountParam()],43      'Vec<u32>',44    ),45    collectionTokens: fun(46      'Get tokens contained within a collection',47      [collectionParam],48      'Vec<u32>',49    ),50    tokenExists: fun(51      'Check if the token exists',52      [collectionParam, tokenParam],53      'bool',54    ),5556    tokenOwner: fun(57      'Get the token owner',58      [collectionParam, tokenParam],59      `Option<${CROSS_ACCOUNT_ID_TYPE}>`,60    ),61    topmostTokenOwner: fun(62      'Get the topmost token owner in the hierarchy of a possibly nested token',63      [collectionParam, tokenParam],64      `Option<${CROSS_ACCOUNT_ID_TYPE}>`,65    ),66    tokenOwners: fun(67      'Returns 10 tokens owners in no particular order',68      [collectionParam, tokenParam],69      `Vec<${CROSS_ACCOUNT_ID_TYPE}>`,70    ),71    tokenChildren: fun(72      'Get tokens nested directly into the token',73      [collectionParam, tokenParam],74      'Vec<UpDataStructsTokenChild>',75    ),7677    collectionProperties: fun(78      'Get collection properties, optionally limited to the provided keys',79      [collectionParam, propertyKeysParam],80      'Vec<UpDataStructsProperty>',81    ),82    tokenProperties: fun(83      'Get token properties, optionally limited to the provided keys',84      [collectionParam, tokenParam, propertyKeysParam],85      'Vec<UpDataStructsProperty>',86    ),87    propertyPermissions: fun(88      'Get property permissions, optionally limited to the provided keys',89      [collectionParam, propertyKeysParam],90      'Vec<UpDataStructsPropertyKeyPermission>',91    ),9293    constMetadata: fun(94      'Get token constant metadata',95      [collectionParam, tokenParam],96      'Vec<u8>',97    ),98    variableMetadata: fun(99      'Get token variable metadata',100      [collectionParam, tokenParam],101      'Vec<u8>',102    ),103104    tokenData: fun(105      'Get token data, including properties, optionally limited to the provided keys, and total pieces for an RFT',106      [collectionParam, tokenParam, propertyKeysParam],107      'UpDataStructsTokenData',108    ),109    totalSupply: fun(110      'Get the amount of distinctive tokens present in a collection',111      [collectionParam],112      'u32',113    ),114115    accountBalance: fun(116      'Get the amount of any user tokens owned by an account',117      [collectionParam, crossAccountParam()],118      'u32',119    ),120    balance: fun(121      'Get the amount of a specific token owned by an account',122      [collectionParam, crossAccountParam(), tokenParam],123      'u128',124    ),125    allowance: fun(126      'Get the amount of currently possible sponsored transactions on a token for the fee to be taken off a sponsor',127      [collectionParam, crossAccountParam('sender'), crossAccountParam('spender'), tokenParam],128      'u128',129    ),130131    adminlist: fun(132      'Get the list of admin accounts of a collection',133      [collectionParam],134      'Vec<PalletEvmAccountBasicCrossAccountIdRepr>',135    ),136    allowlist: fun(137      'Get the list of accounts allowed to operate within a collection',138      [collectionParam],139      'Vec<PalletEvmAccountBasicCrossAccountIdRepr>',140    ),141    allowed: fun(142      'Check if a user is allowed to operate within a collection',143      [collectionParam, crossAccountParam()],144      'bool',145    ),146147    lastTokenId: fun(148      'Get the last token ID created in a collection',149      [collectionParam],150      'u32',151    ),152    collectionById: fun(153      'Get a collection by the specified ID',154      [collectionParam],155      'Option<UpDataStructsRpcCollection>',156    ),157    collectionStats: fun(158      'Get chain stats about collections',159      [],160      'UpDataStructsCollectionStats',161    ),162163    nextSponsored: fun(164      'Get the number of blocks until sponsoring a transaction is available',165      [collectionParam, crossAccountParam(), tokenParam],166      'Option<u64>',167    ),168    effectiveCollectionLimits: fun(169      'Get effective collection limits',170      [collectionParam],171      'Option<UpDataStructsCollectionLimits>',172    ),173    totalPieces: fun(174      'Get the total amount of pieces of an RFT',175      [collectionParam, tokenParam],176      'Option<u128>',177    ),178<<<<<<< HEAD179<<<<<<< HEAD180    allowanceForAll: fun(181      'Tells whether the given `owner` approves the `operator`.',182      [collectionParam, crossAccountParam('owner'), crossAccountParam('operator')],183      '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    ),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  },202};