difftreelog
fix PoV estimate RPC
in: master
8 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -12843,6 +12843,7 @@
"sp-blockchain",
"sp-core",
"sp-externalities",
+ "sp-keystore",
"sp-rpc",
"sp-runtime",
"sp-state-machine",
Cargo.tomldiffbeforeafterboth--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,7 +11,7 @@
'runtime/unique',
'runtime/tests',
]
-default-members = ['node/*', 'runtime/opal']
+default-members = ['node/*', 'client/*', 'runtime/opal']
package.version = "0.9.36"
[profile.release]
client/rpc/Cargo.tomldiffbeforeafterboth--- a/client/rpc/Cargo.toml
+++ b/client/rpc/Cargo.toml
@@ -25,6 +25,7 @@
sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-blockchain = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
+sp-keystore = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-rpc = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
pallet-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.rsdiffbeforeafterboth--- a/node/cli/src/service.rs
+++ b/node/cli/src/service.rs
@@ -67,6 +67,8 @@
use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};
use up_common::types::opaque::*;
+
+#[cfg(feature = "pov-estimate")]
use crate::chain_spec::RuntimeIdentification;
// RMRK
@@ -517,8 +519,12 @@
.for_each(|()| futures::future::ready(())),
);
+ #[cfg(feature = "pov-estimate")]
let rpc_backend = backend.clone();
+
+ #[cfg(feature = "pov-estimate")]
let runtime_id = parachain_config.chain_spec.runtime_id();
+
let rpc_builder = Box::new(move |deny_unsafe, subscription_task_executor| {
let full_deps = unique_rpc::FullDeps {
#[cfg(feature = "pov-estimate")]
@@ -1058,8 +1064,13 @@
let rpc_pool = transaction_pool.clone();
let rpc_network = network.clone();
let rpc_frontier_backend = frontier_backend.clone();
+
+ #[cfg(feature = "pov-estimate")]
let rpc_backend = backend.clone();
+
+ #[cfg(feature = "pov-estimate")]
let runtime_id = config.chain_spec.runtime_id();
+
let rpc_builder = Box::new(move |deny_unsafe, subscription_executor| {
let full_deps = unique_rpc::FullDeps {
#[cfg(feature = "pov-estimate")]
node/rpc/src/lib.rsdiffbeforeafterboth--- a/node/rpc/src/lib.rs
+++ b/node/rpc/src/lib.rs
@@ -48,6 +48,7 @@
RmrkPartType, RmrkTheme,
};
+#[cfg(feature = "pov-estimate")]
type FullBackend = sc_service::TFullBackend<Block>;
/// Extra dependencies for GRANDPA
@@ -84,7 +85,7 @@
pub deny_unsafe: DenyUnsafe,
/// EthFilterApi pool.
pub filter_pool: Option<FilterPool>,
-
+
#[cfg(feature = "pov-estimate")]
pub runtime_id: RuntimeId,
/// Executor params for PoV estimating
@@ -271,7 +272,16 @@
io.merge(Rmrk::new(client.clone()).into_rpc())?;
#[cfg(feature = "pov-estimate")]
- io.merge(PovEstimate::new(client.clone(), backend, deny_unsafe, exec_params, runtime_id).into_rpc())?;
+ io.merge(
+ PovEstimate::new(
+ client.clone(),
+ backend,
+ deny_unsafe,
+ exec_params,
+ runtime_id,
+ )
+ .into_rpc(),
+ )?;
if let Some(filter_pool) = filter_pool {
io.merge(
primitives/pov-estimate-rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/pov-estimate-rpc/src/lib.rs
+++ b/primitives/pov-estimate-rpc/src/lib.rs
@@ -16,24 +16,25 @@
#![cfg_attr(not(feature = "std"), no_std)]
-use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::Serialize;
use sp_runtime::ApplyExtrinsicResult;
+use sp_core::Bytes;
#[cfg_attr(feature = "std", derive(Serialize))]
-#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
+#[derive(Debug, TypeInfo)]
pub struct PovInfo {
- pub proof_size: u64,
- pub compact_proof_size: u64,
- pub compressed_proof_size: u64,
+ pub proof_size: u64,
+ pub compact_proof_size: u64,
+ pub compressed_proof_size: u64,
+ pub result: ApplyExtrinsicResult,
}
sp_api::decl_runtime_apis! {
- pub trait PovEstimateApi {
- fn pov_estimate(uxt: Block::Extrinsic) -> ApplyExtrinsicResult;
- }
+ pub trait PovEstimateApi {
+ fn pov_estimate(uxt: Bytes) -> ApplyExtrinsicResult;
+ }
}
runtime/common/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/runtime_apis.rs
+++ b/runtime/common/runtime_apis.rs
@@ -35,11 +35,11 @@
) => {
use sp_std::prelude::*;
use sp_api::impl_runtime_apis;
- use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};
+ use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160, Bytes};
use sp_runtime::{
Permill,
traits::Block as BlockT,
- transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError, InvalidTransaction},
+ transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, DispatchError,
};
use fp_rpc::TransactionStatus;
@@ -780,12 +780,24 @@
impl up_pov_estimate_rpc::PovEstimateApi<Block> for Runtime {
#[allow(unused_variables)]
- fn pov_estimate(uxt: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
+ fn pov_estimate(uxt: Bytes) -> ApplyExtrinsicResult {
#[cfg(feature = "pov-estimate")]
- return Executive::apply_extrinsic(uxt);
+ {
+ use codec::Decode;
+
+ let uxt_decode = <<Block as BlockT>::Extrinsic as Decode>::decode(&mut &*uxt)
+ .map_err(|_| DispatchError::Other("failed to decode the extrinsic"));
+
+ let uxt = match uxt_decode {
+ Ok(uxt) => uxt,
+ Err(err) => return Ok(err.into()),
+ };
+
+ Executive::apply_extrinsic(uxt)
+ }
#[cfg(not(feature = "pov-estimate"))]
- return Err(TransactionValidityError::Invalid(InvalidTransaction::Call))
+ return Ok(unsupported!());
}
}