difftreelog
fix PoV estimate RPC
in: master
8 files changed
Cargo.lockdiffbeforeafterboth12843 "sp-blockchain",12843 "sp-blockchain",12844 "sp-core",12844 "sp-core",12845 "sp-externalities",12845 "sp-externalities",12846 "sp-keystore",12846 "sp-rpc",12847 "sp-rpc",12847 "sp-runtime",12848 "sp-runtime",12848 "sp-state-machine",12849 "sp-state-machine",Cargo.tomldiffbeforeafterboth11 'runtime/unique',11 'runtime/unique',12 'runtime/tests',12 'runtime/tests',13]13]14default-members = ['node/*', 'runtime/opal']14default-members = ['node/*', 'client/*', 'runtime/opal']15package.version = "0.9.36"15package.version = "0.9.36"161617[profile.release]17[profile.release]client/rpc/Cargo.tomldiffbeforeafterboth25sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }25sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }26sp-blockchain = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }26sp-blockchain = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }27sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }27sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }28sp-keystore = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }28sp-rpc = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }29sp-rpc = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }29sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }30sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }30pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.36" }31pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.36" }client/rpc/src/pov_estimate.rsdiffbeforeafterboth161617use std::sync::Arc;17use std::sync::Arc;181819use codec::Encode;19use codec::{Encode, Decode};20use sp_externalities::Extensions;202121use up_pov_estimate_rpc::{PovEstimateApi as PovEstimateRuntimeApi};22use up_pov_estimate_rpc::{PovEstimateApi as PovEstimateRuntimeApi};22use up_common::types::opaque::RuntimeId;23use up_common::types::opaque::RuntimeId;262727use jsonrpsee::{28use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc};28 core::RpcResult as Result,29 proc_macros::rpc,30};31use anyhow::anyhow;29use anyhow::anyhow;323033use sc_client_api::backend::Backend;31use sc_client_api::backend::Backend;34use sp_blockchain::HeaderBackend;32use sp_blockchain::HeaderBackend;33use sp_core::{34 Bytes,35 offchain::{36 testing::{TestOffchainExt, TestTransactionPoolExt},37 OffchainDbExt, OffchainWorkerExt, TransactionPoolExt,38 },39 testing::TaskExecutor,40 traits::TaskExecutorExt,41};42use sp_keystore::{testing::KeyStore, KeystoreExt};35use sp_api::{AsTrieBackend, BlockId, BlockT, ProvideRuntimeApi};43use sp_api::{AsTrieBackend, BlockId, BlockT, ProvideRuntimeApi};364437use sc_executor::NativeElseWasmExecutor;45use sc_executor::NativeElseWasmExecutor;113#[rpc(server)]121#[rpc(server)]114#[async_trait]122#[async_trait]115pub trait PovEstimateApi<BlockHash> {123pub trait PovEstimateApi<BlockHash> {116 #[method(name = "unique_povEstimate")]124 #[method(name = "unique_estimateExtrinsicPoV")]117 fn pov_estimate(&self, encoded_xt: Vec<u8>, at: Option<BlockHash>) -> Result<PovInfo>;125 fn estimate_extrinsic_pov(&self, encoded_xt: Bytes, at: Option<BlockHash>) -> Result<PovInfo>;118}126}119127120#[allow(deprecated)]128#[allow(deprecated)]126 C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,133 C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,127 C::Api: PovEstimateRuntimeApi<Block>,134 C::Api: PovEstimateRuntimeApi<Block>,128{135{129 fn pov_estimate(&self, encoded_xt: Vec<u8>, at: Option<<Block as BlockT>::Hash>,) -> Result<PovInfo> {136 fn estimate_extrinsic_pov(137 &self,138 encoded_xt: Bytes,139 at: Option<<Block as BlockT>::Hash>,140 ) -> Result<PovInfo> {130 self.deny_unsafe.check_if_safe()?;141 self.deny_unsafe.check_if_safe()?;145 }172 }146}173}174175fn full_extensions() -> Extensions {176 let mut extensions = Extensions::default();177 extensions.register(TaskExecutorExt::new(TaskExecutor::new()));178 let (offchain, _offchain_state) = TestOffchainExt::new();179 let (pool, _pool_state) = TestTransactionPoolExt::new();180 extensions.register(OffchainDbExt::new(offchain.clone()));181 extensions.register(OffchainWorkerExt::new(offchain));182 extensions.register(KeystoreExt(std::sync::Arc::new(KeyStore::new())));183 extensions.register(TransactionPoolExt::new(pool));184185 extensions186}147187148fn execute_extrinsic_in_sandbox<Block, D>(state: StateOf<Block>, exec_params: &ExecutorParams, encoded_xt: Vec<u8>) -> Result<PovInfo>188fn execute_extrinsic_in_sandbox<Block, D>(189 state: StateOf<Block>,190 exec_params: &ExecutorParams,191 encoded_xt: Bytes,192) -> Result<PovInfo>149where193where150 Block: BlockT,194 Block: BlockT,170 );216 );171 let execution = ExecutionStrategy::NativeElseWasm;217 let execution = ExecutionStrategy::NativeElseWasm;218219 let encoded_bytes = encoded_xt.encode();172220173 StateMachine::new(221 let xt_result = StateMachine::new(174 &proving_backend,222 &proving_backend,175 &mut changes,223 &mut changes,176 &executor,224 &executor,177 "PovEstimateApi_pov_estimate",225 "PovEstimateApi_pov_estimate",178 encoded_xt.as_slice(),226 encoded_bytes.as_slice(),179 sp_externalities::Extensions::default(),227 full_extensions(),180 &runtime_code,228 &runtime_code,181 sp_core::testing::TaskExecutor::new(),229 sp_core::testing::TaskExecutor::new(),182 )230 )183 .execute(execution.into())231 .execute(execution.into())184 .map_err(|e| anyhow!("failed to execute the extrinsic {:?}", e))?;232 .map_err(|e| anyhow!("failed to execute the extrinsic {:?}", e))?;233234 let xt_result = Decode::decode(&mut &*xt_result)235 .map_err(|e| anyhow!("failed to decode the extrinsic result {:?}", e))?;185236186 let proof = proving_backend237 let proof = proving_backend187 .extract_proof()238 .extract_proof()201 proof_size: proof_size as u64,252 proof_size: proof_size as u64,202 compact_proof_size: compact_proof_size as u64,253 compact_proof_size: compact_proof_size as u64,203 compressed_proof_size: compressed_proof_size as u64,254 compressed_proof_size: compressed_proof_size as u64,255 result: xt_result,204 })256 })205}257}206258node/cli/src/service.rsdiffbeforeafterboth686869use up_common::types::opaque::*;69use up_common::types::opaque::*;7071#[cfg(feature = "pov-estimate")]70use crate::chain_spec::RuntimeIdentification;72use crate::chain_spec::RuntimeIdentification;717372// RMRK74// RMRK517 .for_each(|()| futures::future::ready(())),519 .for_each(|()| futures::future::ready(())),518 );520 );519521522 #[cfg(feature = "pov-estimate")]520 let rpc_backend = backend.clone();523 let rpc_backend = backend.clone();524525 #[cfg(feature = "pov-estimate")]521 let runtime_id = parachain_config.chain_spec.runtime_id();526 let runtime_id = parachain_config.chain_spec.runtime_id();527522 let rpc_builder = Box::new(move |deny_unsafe, subscription_task_executor| {528 let rpc_builder = Box::new(move |deny_unsafe, subscription_task_executor| {1059 let rpc_network = network.clone();1065 let rpc_network = network.clone();1060 let rpc_frontier_backend = frontier_backend.clone();1066 let rpc_frontier_backend = frontier_backend.clone();10671068 #[cfg(feature = "pov-estimate")]1061 let rpc_backend = backend.clone();1069 let rpc_backend = backend.clone();10701071 #[cfg(feature = "pov-estimate")]1062 let runtime_id = config.chain_spec.runtime_id();1072 let runtime_id = config.chain_spec.runtime_id();10731063 let rpc_builder = Box::new(move |deny_unsafe, subscription_executor| {1074 let rpc_builder = Box::new(move |deny_unsafe, subscription_executor| {node/rpc/src/lib.rsdiffbeforeafterboth48 RmrkPartType, RmrkTheme,48 RmrkPartType, RmrkTheme,49};49};505051#[cfg(feature = "pov-estimate")]51type FullBackend = sc_service::TFullBackend<Block>;52type FullBackend = sc_service::TFullBackend<Block>;525353/// Extra dependencies for GRANDPA54/// Extra dependencies for GRANDPAprimitives/pov-estimate-rpc/src/lib.rsdiffbeforeafterboth161617#![cfg_attr(not(feature = "std"), no_std)]17#![cfg_attr(not(feature = "std"), no_std)]181819use codec::{Decode, Encode, MaxEncodedLen};20use scale_info::TypeInfo;19use scale_info::TypeInfo;212022#[cfg(feature = "std")]21#[cfg(feature = "std")]23use serde::Serialize;22use serde::Serialize;242325use sp_runtime::ApplyExtrinsicResult;24use sp_runtime::ApplyExtrinsicResult;25use sp_core::Bytes;262627#[cfg_attr(feature = "std", derive(Serialize))]27#[cfg_attr(feature = "std", derive(Serialize))]28#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]28#[derive(Debug, TypeInfo)]29pub struct PovInfo {29pub struct PovInfo {30 pub proof_size: u64,30 pub proof_size: u64,31 pub compact_proof_size: u64,31 pub compact_proof_size: u64,32 pub compressed_proof_size: u64,32 pub compressed_proof_size: u64,33 pub result: ApplyExtrinsicResult,33}34}343535sp_api::decl_runtime_apis! {36sp_api::decl_runtime_apis! {36 pub trait PovEstimateApi {37 pub trait PovEstimateApi {37 fn pov_estimate(uxt: Block::Extrinsic) -> ApplyExtrinsicResult;38 fn pov_estimate(uxt: Bytes) -> ApplyExtrinsicResult;38 }39 }39}40}4041runtime/common/runtime_apis.rsdiffbeforeafterboth35 ) => {35 ) => {36 use sp_std::prelude::*;36 use sp_std::prelude::*;37 use sp_api::impl_runtime_apis;37 use sp_api::impl_runtime_apis;38 use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};38 use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160, Bytes};39 use sp_runtime::{39 use sp_runtime::{40 Permill,40 Permill,41 traits::Block as BlockT,41 traits::Block as BlockT,42 transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError, InvalidTransaction},42 transaction_validity::{TransactionSource, TransactionValidity},43 ApplyExtrinsicResult, DispatchError,43 ApplyExtrinsicResult, DispatchError,44 };44 };45 use fp_rpc::TransactionStatus;45 use fp_rpc::TransactionStatus;780780781 impl up_pov_estimate_rpc::PovEstimateApi<Block> for Runtime {781 impl up_pov_estimate_rpc::PovEstimateApi<Block> for Runtime {782 #[allow(unused_variables)]782 #[allow(unused_variables)]783 fn pov_estimate(uxt: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {783 fn pov_estimate(uxt: Bytes) -> ApplyExtrinsicResult {784 #[cfg(feature = "pov-estimate")]784 #[cfg(feature = "pov-estimate")]785 {786 use codec::Decode;787788 let uxt_decode = <<Block as BlockT>::Extrinsic as Decode>::decode(&mut &*uxt)789 .map_err(|_| DispatchError::Other("failed to decode the extrinsic"));790791 let uxt = match uxt_decode {792 Ok(uxt) => uxt,785 return Executive::apply_extrinsic(uxt);793 Err(err) => return Ok(err.into()),794 };795796 Executive::apply_extrinsic(uxt)797 }786798787 #[cfg(not(feature = "pov-estimate"))]799 #[cfg(not(feature = "pov-estimate"))]788 return Err(TransactionValidityError::Invalid(InvalidTransaction::Call))800 return Ok(unsupported!());789 }801 }790 }802 }791803