mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 19:11:04 +00:00
Remove native call (#12201)
* Remove native call With the recent introduction of staging runtime apis the native call wasn't supported anymore. This removes the entire support for this as it is not used anymore. * FMT * Fix benchmarks * FIX ui tests
This commit is contained in:
@@ -18,13 +18,11 @@
|
||||
|
||||
//! A method call executor interface.
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use sc_executor::{RuntimeVersion, RuntimeVersionOf};
|
||||
use sp_core::NativeOrEncoded;
|
||||
use sp_externalities::Extensions;
|
||||
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
|
||||
use sp_state_machine::{ExecutionManager, ExecutionStrategy, OverlayedChanges, StorageProof};
|
||||
use std::{cell::RefCell, panic::UnwindSafe, result};
|
||||
use std::cell::RefCell;
|
||||
|
||||
use crate::execution_extensions::ExecutionExtensions;
|
||||
use sp_api::{ProofRecorder, StorageTransactionCache};
|
||||
@@ -68,11 +66,9 @@ pub trait CallExecutor<B: BlockT>: RuntimeVersionOf {
|
||||
/// of the execution context.
|
||||
fn contextual_call<
|
||||
EM: Fn(
|
||||
Result<NativeOrEncoded<R>, Self::Error>,
|
||||
Result<NativeOrEncoded<R>, Self::Error>,
|
||||
) -> Result<NativeOrEncoded<R>, Self::Error>,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, sp_api::ApiError> + UnwindSafe,
|
||||
Result<Vec<u8>, Self::Error>,
|
||||
Result<Vec<u8>, Self::Error>,
|
||||
) -> Result<Vec<u8>, Self::Error>,
|
||||
>(
|
||||
&self,
|
||||
at: &BlockId<B>,
|
||||
@@ -85,10 +81,9 @@ pub trait CallExecutor<B: BlockT>: RuntimeVersionOf {
|
||||
>,
|
||||
>,
|
||||
execution_manager: ExecutionManager<EM>,
|
||||
native_call: Option<NC>,
|
||||
proof_recorder: &Option<ProofRecorder<B>>,
|
||||
extensions: Option<Extensions>,
|
||||
) -> sp_blockchain::Result<NativeOrEncoded<R>>
|
||||
) -> sp_blockchain::Result<Vec<u8>>
|
||||
where
|
||||
ExecutionManager<EM>: Clone;
|
||||
|
||||
|
||||
@@ -201,11 +201,11 @@ impl<Block: traits::Block> ExecutionExtensions<Block> {
|
||||
///
|
||||
/// Based on the execution context and capabilities it produces
|
||||
/// the right manager and extensions object to support desired set of APIs.
|
||||
pub fn manager_and_extensions<E: std::fmt::Debug, R: codec::Codec>(
|
||||
pub fn manager_and_extensions<E: std::fmt::Debug>(
|
||||
&self,
|
||||
at: &BlockId<Block>,
|
||||
context: ExecutionContext,
|
||||
) -> (ExecutionManager<DefaultHandler<R, E>>, Extensions) {
|
||||
) -> (ExecutionManager<DefaultHandler<E>>, Extensions) {
|
||||
let manager = match context {
|
||||
ExecutionContext::BlockConstruction => self.strategies.block_construction.get_manager(),
|
||||
ExecutionContext::Syncing => self.strategies.syncing.get_manager(),
|
||||
|
||||
@@ -27,22 +27,18 @@ use std::{
|
||||
marker::PhantomData,
|
||||
panic::{AssertUnwindSafe, UnwindSafe},
|
||||
path::PathBuf,
|
||||
result,
|
||||
sync::{
|
||||
atomic::{AtomicU64, Ordering},
|
||||
mpsc, Arc,
|
||||
},
|
||||
};
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use codec::Encode;
|
||||
use sc_executor_common::{
|
||||
runtime_blob::RuntimeBlob,
|
||||
wasm_runtime::{AllocationStats, InvokeMethod, WasmInstance, WasmModule},
|
||||
};
|
||||
use sp_core::{
|
||||
traits::{CodeExecutor, Externalities, RuntimeCode, RuntimeSpawn, RuntimeSpawnExt},
|
||||
NativeOrEncoded,
|
||||
};
|
||||
use sp_core::traits::{CodeExecutor, Externalities, RuntimeCode, RuntimeSpawn, RuntimeSpawnExt};
|
||||
use sp_externalities::ExternalitiesExt as _;
|
||||
use sp_tasks::new_async_externalities;
|
||||
use sp_version::{GetNativeVersion, NativeVersion, RuntimeVersion};
|
||||
@@ -339,18 +335,14 @@ where
|
||||
{
|
||||
type Error = Error;
|
||||
|
||||
fn call<
|
||||
R: Decode + Encode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, Box<dyn std::error::Error + Send + Sync>> + UnwindSafe,
|
||||
>(
|
||||
fn call(
|
||||
&self,
|
||||
ext: &mut dyn Externalities,
|
||||
runtime_code: &RuntimeCode,
|
||||
method: &str,
|
||||
data: &[u8],
|
||||
_use_native: bool,
|
||||
_native_call: Option<NC>,
|
||||
) -> (Result<NativeOrEncoded<R>>, bool) {
|
||||
) -> (Result<Vec<u8>>, bool) {
|
||||
tracing::trace!(
|
||||
target: "executor",
|
||||
%method,
|
||||
@@ -363,7 +355,7 @@ where
|
||||
|module, mut instance, _onchain_version, mut ext| {
|
||||
with_externalities_safe(&mut **ext, move || {
|
||||
preregister_builtin_ext(module.clone());
|
||||
instance.call_export(method, data).map(NativeOrEncoded::Encoded)
|
||||
instance.call_export(method, data)
|
||||
})
|
||||
},
|
||||
);
|
||||
@@ -594,18 +586,14 @@ fn preregister_builtin_ext(module: Arc<dyn WasmModule>) {
|
||||
impl<D: NativeExecutionDispatch + 'static> CodeExecutor for NativeElseWasmExecutor<D> {
|
||||
type Error = Error;
|
||||
|
||||
fn call<
|
||||
R: Decode + Encode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, Box<dyn std::error::Error + Send + Sync>> + UnwindSafe,
|
||||
>(
|
||||
fn call(
|
||||
&self,
|
||||
ext: &mut dyn Externalities,
|
||||
runtime_code: &RuntimeCode,
|
||||
method: &str,
|
||||
data: &[u8],
|
||||
use_native: bool,
|
||||
native_call: Option<NC>,
|
||||
) -> (Result<NativeOrEncoded<R>>, bool) {
|
||||
) -> (Result<Vec<u8>>, bool) {
|
||||
tracing::trace!(
|
||||
target: "executor",
|
||||
function = %method,
|
||||
@@ -623,49 +611,31 @@ impl<D: NativeExecutionDispatch + 'static> CodeExecutor for NativeElseWasmExecut
|
||||
let can_call_with =
|
||||
onchain_version.can_call_with(&self.native_version.runtime_version);
|
||||
|
||||
match (use_native, can_call_with, native_call) {
|
||||
(_, false, _) | (false, _, _) => {
|
||||
if !can_call_with {
|
||||
tracing::trace!(
|
||||
target: "executor",
|
||||
native = %self.native_version.runtime_version,
|
||||
chain = %onchain_version,
|
||||
"Request for native execution failed",
|
||||
);
|
||||
}
|
||||
if use_native && can_call_with {
|
||||
tracing::trace!(
|
||||
target: "executor",
|
||||
native = %self.native_version.runtime_version,
|
||||
chain = %onchain_version,
|
||||
"Request for native execution succeeded",
|
||||
);
|
||||
|
||||
with_externalities_safe(&mut **ext, move || {
|
||||
preregister_builtin_ext(module.clone());
|
||||
instance.call_export(method, data).map(NativeOrEncoded::Encoded)
|
||||
})
|
||||
},
|
||||
(true, true, Some(call)) => {
|
||||
used_native = true;
|
||||
Ok(with_externalities_safe(&mut **ext, move || D::dispatch(method, data))?
|
||||
.ok_or_else(|| Error::MethodNotFound(method.to_owned())))
|
||||
} else {
|
||||
if !can_call_with {
|
||||
tracing::trace!(
|
||||
target: "executor",
|
||||
native = %self.native_version.runtime_version,
|
||||
chain = %onchain_version,
|
||||
"Request for native execution with native call succeeded"
|
||||
"Request for native execution failed",
|
||||
);
|
||||
}
|
||||
|
||||
used_native = true;
|
||||
let res = with_externalities_safe(&mut **ext, move || (call)())
|
||||
.and_then(|r| r.map(NativeOrEncoded::Native).map_err(Error::ApiError));
|
||||
|
||||
Ok(res)
|
||||
},
|
||||
_ => {
|
||||
tracing::trace!(
|
||||
target: "executor",
|
||||
native = %self.native_version.runtime_version,
|
||||
chain = %onchain_version,
|
||||
"Request for native execution succeeded",
|
||||
);
|
||||
|
||||
used_native = true;
|
||||
Ok(with_externalities_safe(&mut **ext, move || D::dispatch(method, data))?
|
||||
.map(NativeOrEncoded::Encoded)
|
||||
.ok_or_else(|| Error::MethodNotFound(method.to_owned())))
|
||||
},
|
||||
with_externalities_safe(&mut **ext, move || {
|
||||
preregister_builtin_ext(module.clone());
|
||||
instance.call_export(method, data)
|
||||
})
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -17,21 +17,17 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use super::{client::ClientConfig, wasm_override::WasmOverride, wasm_substitutes::WasmSubstitutes};
|
||||
use codec::{Decode, Encode};
|
||||
use sc_client_api::{backend, call_executor::CallExecutor, HeaderBackend};
|
||||
use sc_executor::{RuntimeVersion, RuntimeVersionOf};
|
||||
use sp_api::{ProofRecorder, StorageTransactionCache};
|
||||
use sp_core::{
|
||||
traits::{CodeExecutor, RuntimeCode, SpawnNamed},
|
||||
NativeOrEncoded, NeverNativeValue,
|
||||
};
|
||||
use sp_core::traits::{CodeExecutor, RuntimeCode, SpawnNamed};
|
||||
use sp_externalities::Extensions;
|
||||
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
|
||||
use sp_state_machine::{
|
||||
backend::AsTrieBackend, ExecutionManager, ExecutionStrategy, Ext, OverlayedChanges,
|
||||
StateMachine, StorageProof,
|
||||
};
|
||||
use std::{cell::RefCell, panic::UnwindSafe, result, sync::Arc};
|
||||
use std::{cell::RefCell, sync::Arc};
|
||||
|
||||
/// Call executor that executes methods locally, querying all required
|
||||
/// data from local backend.
|
||||
@@ -162,7 +158,7 @@ where
|
||||
sp_blockchain::Error::UnknownBlock(format!("Could not find block hash for {:?}", at))
|
||||
})?;
|
||||
|
||||
let return_data = StateMachine::new(
|
||||
let mut sm = StateMachine::new(
|
||||
&state,
|
||||
&mut changes,
|
||||
&self.executor,
|
||||
@@ -172,22 +168,17 @@ where
|
||||
&runtime_code,
|
||||
self.spawn_handle.clone(),
|
||||
)
|
||||
.set_parent_hash(at_hash)
|
||||
.execute_using_consensus_failure_handler::<_, NeverNativeValue, fn() -> _>(
|
||||
strategy.get_manager(),
|
||||
None,
|
||||
)?;
|
||||
.set_parent_hash(at_hash);
|
||||
|
||||
Ok(return_data.into_encoded())
|
||||
sm.execute_using_consensus_failure_handler(strategy.get_manager())
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
fn contextual_call<
|
||||
EM: Fn(
|
||||
Result<NativeOrEncoded<R>, Self::Error>,
|
||||
Result<NativeOrEncoded<R>, Self::Error>,
|
||||
) -> Result<NativeOrEncoded<R>, Self::Error>,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, sp_api::ApiError> + UnwindSafe,
|
||||
Result<Vec<u8>, Self::Error>,
|
||||
Result<Vec<u8>, Self::Error>,
|
||||
) -> Result<Vec<u8>, Self::Error>,
|
||||
>(
|
||||
&self,
|
||||
at: &BlockId<Block>,
|
||||
@@ -196,10 +187,9 @@ where
|
||||
changes: &RefCell<OverlayedChanges>,
|
||||
storage_transaction_cache: Option<&RefCell<StorageTransactionCache<Block, B::State>>>,
|
||||
execution_manager: ExecutionManager<EM>,
|
||||
native_call: Option<NC>,
|
||||
recorder: &Option<ProofRecorder<Block>>,
|
||||
extensions: Option<Extensions>,
|
||||
) -> Result<NativeOrEncoded<R>, sp_blockchain::Error>
|
||||
) -> Result<Vec<u8>, sp_blockchain::Error>
|
||||
where
|
||||
ExecutionManager<EM>: Clone,
|
||||
{
|
||||
@@ -242,10 +232,7 @@ where
|
||||
)
|
||||
.with_storage_transaction_cache(storage_transaction_cache.as_deref_mut())
|
||||
.set_parent_hash(at_hash);
|
||||
state_machine.execute_using_consensus_failure_handler(
|
||||
execution_manager,
|
||||
native_call.map(|n| || (n)().map_err(|e| Box::new(e) as Box<_>)),
|
||||
)
|
||||
state_machine.execute_using_consensus_failure_handler(execution_manager)
|
||||
},
|
||||
None => {
|
||||
let mut state_machine = StateMachine::new(
|
||||
@@ -260,10 +247,7 @@ where
|
||||
)
|
||||
.with_storage_transaction_cache(storage_transaction_cache.as_deref_mut())
|
||||
.set_parent_hash(at_hash);
|
||||
state_machine.execute_using_consensus_failure_handler(
|
||||
execution_manager,
|
||||
native_call.map(|n| || (n)().map_err(|e| Box::new(e) as Box<_>)),
|
||||
)
|
||||
state_machine.execute_using_consensus_failure_handler(execution_manager)
|
||||
},
|
||||
}
|
||||
.map_err(Into::into)
|
||||
|
||||
@@ -22,7 +22,6 @@ use super::{
|
||||
block_rules::{BlockRules, LookupResult as BlockLookupResult},
|
||||
genesis,
|
||||
};
|
||||
use codec::{Decode, Encode};
|
||||
use log::{info, trace, warn};
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use prometheus_endpoint::Registry;
|
||||
@@ -59,12 +58,9 @@ use sp_blockchain::{
|
||||
use sp_consensus::{BlockOrigin, BlockStatus, Error as ConsensusError};
|
||||
|
||||
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedSender};
|
||||
use sp_core::{
|
||||
storage::{
|
||||
well_known_keys, ChildInfo, ChildType, PrefixedStorageKey, Storage, StorageChild,
|
||||
StorageData, StorageKey,
|
||||
},
|
||||
NativeOrEncoded,
|
||||
use sp_core::storage::{
|
||||
well_known_keys, ChildInfo, ChildType, PrefixedStorageKey, Storage, StorageChild, StorageData,
|
||||
StorageKey,
|
||||
};
|
||||
#[cfg(feature = "test-helpers")]
|
||||
use sp_keystore::SyncCryptoStorePtr;
|
||||
@@ -85,9 +81,7 @@ use sp_trie::{CompactProof, StorageProof};
|
||||
use std::{
|
||||
collections::{hash_map::DefaultHasher, HashMap, HashSet},
|
||||
marker::PhantomData,
|
||||
panic::UnwindSafe,
|
||||
path::PathBuf,
|
||||
result,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
@@ -1659,27 +1653,23 @@ where
|
||||
{
|
||||
type StateBackend = B::State;
|
||||
|
||||
fn call_api_at<
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, sp_api::ApiError> + UnwindSafe,
|
||||
>(
|
||||
fn call_api_at(
|
||||
&self,
|
||||
params: CallApiAtParams<Block, NC, B::State>,
|
||||
) -> Result<NativeOrEncoded<R>, sp_api::ApiError> {
|
||||
params: CallApiAtParams<Block, B::State>,
|
||||
) -> Result<Vec<u8>, sp_api::ApiError> {
|
||||
let at = params.at;
|
||||
|
||||
let (manager, extensions) =
|
||||
self.execution_extensions.manager_and_extensions(at, params.context);
|
||||
|
||||
self.executor
|
||||
.contextual_call::<fn(_, _) -> _, _, _>(
|
||||
.contextual_call(
|
||||
at,
|
||||
params.function,
|
||||
¶ms.arguments,
|
||||
params.overlayed_changes,
|
||||
Some(params.storage_transaction_cache),
|
||||
manager,
|
||||
params.native_call,
|
||||
params.recorder,
|
||||
Some(extensions),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user