mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 14:17:56 +00:00
Name all the tasks! (#6726)
* Remove any implementation of `Spawn` or `Executor` from our task executors * Fix compilation * Rename `SpawnBlockingExecutor` * Update primitives/core/src/traits.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fix tests Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -33,7 +33,7 @@ use sp_core::{
|
||||
};
|
||||
use log::warn;
|
||||
use codec::Encode;
|
||||
use sp_externalities::Extensions;
|
||||
use sp_externalities::{Extensions, Extension};
|
||||
|
||||
/// Simple Map-based Externalities impl.
|
||||
#[derive(Debug)]
|
||||
@@ -53,17 +53,6 @@ impl BasicExternalities {
|
||||
Self::new(Storage::default())
|
||||
}
|
||||
|
||||
/// New basic extternalities with tasks executor.
|
||||
pub fn with_tasks_executor() -> Self {
|
||||
let mut extensions = Extensions::default();
|
||||
extensions.register(sp_core::traits::TaskExecutorExt(sp_core::tasks::executor()));
|
||||
|
||||
Self {
|
||||
inner: Storage::default(),
|
||||
extensions,
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert key/value
|
||||
pub fn insert(&mut self, k: StorageKey, v: StorageValue) -> Option<StorageValue> {
|
||||
self.inner.top.insert(k, v)
|
||||
@@ -107,6 +96,11 @@ impl BasicExternalities {
|
||||
pub fn extensions(&mut self) -> &mut Extensions {
|
||||
&mut self.extensions
|
||||
}
|
||||
|
||||
/// Register an extension.
|
||||
pub fn register_extension(&mut self, ext: impl Extension) {
|
||||
self.extensions.register(ext);
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for BasicExternalities {
|
||||
|
||||
@@ -26,7 +26,7 @@ use codec::{Decode, Encode, Codec};
|
||||
use sp_core::{
|
||||
offchain::storage::OffchainOverlayedChanges,
|
||||
storage::ChildInfo, NativeOrEncoded, NeverNativeValue, hexdisplay::HexDisplay,
|
||||
traits::{CodeExecutor, CallInWasmExt, RuntimeCode},
|
||||
traits::{CodeExecutor, CallInWasmExt, RuntimeCode, SpawnNamed},
|
||||
};
|
||||
use sp_externalities::Extensions;
|
||||
|
||||
@@ -77,7 +77,6 @@ pub use trie_backend::TrieBackend;
|
||||
pub use error::{Error, ExecutionError};
|
||||
pub use in_memory_backend::new_in_mem;
|
||||
pub use stats::{UsageInfo, UsageUnit, StateMachineStats};
|
||||
pub use sp_core::traits::CloneableSpawn;
|
||||
|
||||
const PROOF_CLOSE_TRANSACTION: &str = "\
|
||||
Closing a transaction that was started in this function. Client initiated transactions
|
||||
@@ -233,7 +232,7 @@ impl<'a, B, H, N, Exec> StateMachine<'a, B, H, N, Exec> where
|
||||
call_data: &'a [u8],
|
||||
mut extensions: Extensions,
|
||||
runtime_code: &'a RuntimeCode,
|
||||
spawn_handle: Box<dyn CloneableSpawn>,
|
||||
spawn_handle: impl SpawnNamed + Send + 'static,
|
||||
) -> Self {
|
||||
extensions.register(CallInWasmExt::new(exec.clone()));
|
||||
extensions.register(sp_core::traits::TaskExecutorExt::new(spawn_handle));
|
||||
@@ -463,11 +462,11 @@ impl<'a, B, H, N, Exec> StateMachine<'a, B, H, N, Exec> where
|
||||
}
|
||||
|
||||
/// Prove execution using the given state backend, overlayed changes, and call executor.
|
||||
pub fn prove_execution<B, H, N, Exec>(
|
||||
pub fn prove_execution<B, H, N, Exec, Spawn>(
|
||||
mut backend: B,
|
||||
overlay: &mut OverlayedChanges,
|
||||
exec: &Exec,
|
||||
spawn_handle: Box<dyn CloneableSpawn>,
|
||||
spawn_handle: Spawn,
|
||||
method: &str,
|
||||
call_data: &[u8],
|
||||
runtime_code: &RuntimeCode,
|
||||
@@ -478,10 +477,11 @@ where
|
||||
H::Out: Ord + 'static + codec::Codec,
|
||||
Exec: CodeExecutor + Clone + 'static,
|
||||
N: crate::changes_trie::BlockNumber,
|
||||
Spawn: SpawnNamed + Send + 'static,
|
||||
{
|
||||
let trie_backend = backend.as_trie_backend()
|
||||
.ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box<dyn Error>)?;
|
||||
prove_execution_on_trie_backend::<_, _, N, _>(
|
||||
prove_execution_on_trie_backend::<_, _, N, _, _>(
|
||||
trie_backend,
|
||||
overlay,
|
||||
exec,
|
||||
@@ -501,11 +501,11 @@ where
|
||||
///
|
||||
/// Note: changes to code will be in place if this call is made again. For running partial
|
||||
/// blocks (e.g. a transaction at a time), ensure a different method is used.
|
||||
pub fn prove_execution_on_trie_backend<S, H, N, Exec>(
|
||||
pub fn prove_execution_on_trie_backend<S, H, N, Exec, Spawn>(
|
||||
trie_backend: &TrieBackend<S, H>,
|
||||
overlay: &mut OverlayedChanges,
|
||||
exec: &Exec,
|
||||
spawn_handle: Box<dyn CloneableSpawn>,
|
||||
spawn_handle: Spawn,
|
||||
method: &str,
|
||||
call_data: &[u8],
|
||||
runtime_code: &RuntimeCode,
|
||||
@@ -516,6 +516,7 @@ where
|
||||
H::Out: Ord + 'static + codec::Codec,
|
||||
Exec: CodeExecutor + 'static + Clone,
|
||||
N: crate::changes_trie::BlockNumber,
|
||||
Spawn: SpawnNamed + Send + 'static,
|
||||
{
|
||||
let mut offchain_overlay = OffchainOverlayedChanges::default();
|
||||
let proving_backend = proving_backend::ProvingBackend::new(trie_backend);
|
||||
@@ -541,12 +542,12 @@ where
|
||||
}
|
||||
|
||||
/// Check execution proof, generated by `prove_execution` call.
|
||||
pub fn execution_proof_check<H, N, Exec>(
|
||||
pub fn execution_proof_check<H, N, Exec, Spawn>(
|
||||
root: H::Out,
|
||||
proof: StorageProof,
|
||||
overlay: &mut OverlayedChanges,
|
||||
exec: &Exec,
|
||||
spawn_handle: Box<dyn CloneableSpawn>,
|
||||
spawn_handle: Spawn,
|
||||
method: &str,
|
||||
call_data: &[u8],
|
||||
runtime_code: &RuntimeCode,
|
||||
@@ -556,9 +557,10 @@ where
|
||||
Exec: CodeExecutor + Clone + 'static,
|
||||
H::Out: Ord + 'static + codec::Codec,
|
||||
N: crate::changes_trie::BlockNumber,
|
||||
Spawn: SpawnNamed + Send + 'static,
|
||||
{
|
||||
let trie_backend = create_proof_check_backend::<H>(root.into(), proof)?;
|
||||
execution_proof_check_on_trie_backend::<_, N, _>(
|
||||
execution_proof_check_on_trie_backend::<_, N, _, _>(
|
||||
&trie_backend,
|
||||
overlay,
|
||||
exec,
|
||||
@@ -570,11 +572,11 @@ where
|
||||
}
|
||||
|
||||
/// Check execution proof on proving backend, generated by `prove_execution` call.
|
||||
pub fn execution_proof_check_on_trie_backend<H, N, Exec>(
|
||||
pub fn execution_proof_check_on_trie_backend<H, N, Exec, Spawn>(
|
||||
trie_backend: &TrieBackend<MemoryDB<H>, H>,
|
||||
overlay: &mut OverlayedChanges,
|
||||
exec: &Exec,
|
||||
spawn_handle: Box<dyn CloneableSpawn>,
|
||||
spawn_handle: Spawn,
|
||||
method: &str,
|
||||
call_data: &[u8],
|
||||
runtime_code: &RuntimeCode,
|
||||
@@ -584,6 +586,7 @@ where
|
||||
H::Out: Ord + 'static + codec::Codec,
|
||||
Exec: CodeExecutor + Clone + 'static,
|
||||
N: crate::changes_trie::BlockNumber,
|
||||
Spawn: SpawnNamed + Send + 'static,
|
||||
{
|
||||
let mut offchain_overlay = OffchainOverlayedChanges::default();
|
||||
let mut sm = StateMachine::<_, H, N, Exec>::new(
|
||||
@@ -765,7 +768,9 @@ mod tests {
|
||||
use super::*;
|
||||
use super::ext::Ext;
|
||||
use super::changes_trie::Configuration as ChangesTrieConfig;
|
||||
use sp_core::{map, traits::{Externalities, RuntimeCode}};
|
||||
use sp_core::{
|
||||
map, traits::{Externalities, RuntimeCode}, testing::TaskExecutor,
|
||||
};
|
||||
use sp_runtime::traits::BlakeTwo256;
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -859,7 +864,7 @@ mod tests {
|
||||
&[],
|
||||
Default::default(),
|
||||
&wasm_code,
|
||||
sp_core::tasks::executor(),
|
||||
TaskExecutor::new(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@@ -891,7 +896,7 @@ mod tests {
|
||||
&[],
|
||||
Default::default(),
|
||||
&wasm_code,
|
||||
sp_core::tasks::executor(),
|
||||
TaskExecutor::new(),
|
||||
);
|
||||
|
||||
assert_eq!(state_machine.execute(ExecutionStrategy::NativeElseWasm).unwrap(), vec![66]);
|
||||
@@ -920,7 +925,7 @@ mod tests {
|
||||
&[],
|
||||
Default::default(),
|
||||
&wasm_code,
|
||||
sp_core::tasks::executor(),
|
||||
TaskExecutor::new(),
|
||||
);
|
||||
|
||||
assert!(
|
||||
@@ -947,23 +952,23 @@ mod tests {
|
||||
// fetch execution proof from 'remote' full node
|
||||
let remote_backend = trie_backend::tests::test_trie();
|
||||
let remote_root = remote_backend.storage_root(std::iter::empty()).0;
|
||||
let (remote_result, remote_proof) = prove_execution::<_, _, u64, _>(
|
||||
let (remote_result, remote_proof) = prove_execution::<_, _, u64, _, _>(
|
||||
remote_backend,
|
||||
&mut Default::default(),
|
||||
&executor,
|
||||
sp_core::tasks::executor(),
|
||||
TaskExecutor::new(),
|
||||
"test",
|
||||
&[],
|
||||
&RuntimeCode::empty(),
|
||||
).unwrap();
|
||||
|
||||
// check proof locally
|
||||
let local_result = execution_proof_check::<BlakeTwo256, u64, _>(
|
||||
let local_result = execution_proof_check::<BlakeTwo256, u64, _, _>(
|
||||
remote_root,
|
||||
remote_proof,
|
||||
&mut Default::default(),
|
||||
&executor,
|
||||
sp_core::tasks::executor(),
|
||||
TaskExecutor::new(),
|
||||
"test",
|
||||
&[],
|
||||
&RuntimeCode::empty(),
|
||||
|
||||
@@ -39,6 +39,8 @@ use sp_core::{
|
||||
well_known_keys::{CHANGES_TRIE_CONFIG, CODE, HEAP_PAGES, is_child_storage_key},
|
||||
Storage,
|
||||
},
|
||||
traits::TaskExecutorExt,
|
||||
testing::TaskExecutor,
|
||||
};
|
||||
use codec::Encode;
|
||||
use sp_externalities::{Extensions, Extension};
|
||||
@@ -109,8 +111,7 @@ impl<H: Hasher, N: ChangesTrieBlockNumber> TestExternalities<H, N>
|
||||
let offchain_overlay = OffchainOverlayedChanges::enabled();
|
||||
|
||||
let mut extensions = Extensions::default();
|
||||
extensions.register(sp_core::traits::TaskExecutorExt(sp_core::tasks::executor()));
|
||||
|
||||
extensions.register(TaskExecutorExt::new(TaskExecutor::new()));
|
||||
|
||||
let offchain_db = TestPersistentOffchainDB::new();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user