Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 07e3361

Browse files
committed
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
2 parents 12382d8 + 0bd9ffa commit 07e3361

File tree

25 files changed

+189
-26
lines changed

25 files changed

+189
-26
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node/testing/src/bench.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ impl BenchDb {
197197
None,
198198
None,
199199
ExecutionExtensions::new(profile.into_execution_strategies(), None),
200+
sp_core::tasks::executor(),
200201
None,
201202
).expect("Should not fail");
202203

client/api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub use light::*;
3434
pub use notifications::*;
3535
pub use proof_provider::*;
3636

37-
pub use sp_state_machine::{StorageProof, ExecutionStrategy};
37+
pub use sp_state_machine::{StorageProof, ExecutionStrategy, CloneableSpawn};
3838

3939
/// Utility methods for the client.
4040
pub mod utils {

client/db/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use std::io;
4747
use std::collections::HashMap;
4848

4949
use sc_client_api::{
50-
ForkBlocks, UsageInfo, MemoryInfo, BadBlocks, IoInfo, MemorySize,
50+
ForkBlocks, UsageInfo, MemoryInfo, BadBlocks, IoInfo, MemorySize, CloneableSpawn,
5151
execution_extensions::ExecutionExtensions,
5252
backend::{NewBlockState, PrunableStateChangesTrieStorage},
5353
};
@@ -292,6 +292,7 @@ pub fn new_client<E, Block, RA>(
292292
fork_blocks: ForkBlocks<Block>,
293293
bad_blocks: BadBlocks<Block>,
294294
execution_extensions: ExecutionExtensions<Block>,
295+
spawn_handle: Box<dyn CloneableSpawn>,
295296
prometheus_registry: Option<Registry>,
296297
) -> Result<(
297298
sc_client::Client<
@@ -309,7 +310,7 @@ pub fn new_client<E, Block, RA>(
309310
E: CodeExecutor + RuntimeInfo,
310311
{
311312
let backend = Arc::new(Backend::new(settings, CANONICALIZATION_DELAY)?);
312-
let executor = sc_client::LocalCallExecutor::new(backend.clone(), executor);
313+
let executor = sc_client::LocalCallExecutor::new(backend.clone(), executor, spawn_handle);
313314
Ok((
314315
sc_client::Client::new(
315316
backend.clone(),

client/service/src/builder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ fn new_full_parts<TBl, TRtApi, TExecDisp>(
263263
fork_blocks,
264264
bad_blocks,
265265
extensions,
266+
Box::new(tasks_builder.spawn_handle()),
266267
config.prometheus_config.as_ref().map(|config| config.registry.clone()),
267268
)?
268269
};
@@ -366,6 +367,7 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> {
366367
sc_client::light::new_fetch_checker::<_, TBl, _>(
367368
light_blockchain.clone(),
368369
executor.clone(),
370+
Box::new(tasks_builder.spawn_handle()),
369371
),
370372
);
371373
let fetcher = Arc::new(sc_network::config::OnDemand::new(fetch_checker));
@@ -375,6 +377,7 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> {
375377
backend.clone(),
376378
config.expect_chain_spec().as_storage_builder(),
377379
executor,
380+
Box::new(tasks_builder.spawn_handle()),
378381
config.prometheus_config.as_ref().map(|config| config.registry.clone()),
379382
)?);
380383

client/service/src/task_manager.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use futures::{
2626
compat::*,
2727
task::{Spawn, FutureObj, SpawnError},
2828
};
29+
use sc_client_api::CloneableSpawn;
2930

3031
/// Type alias for service task executor (usually runtime).
3132
pub type ServiceTaskExecutor = Arc<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send + Sync>;
@@ -118,6 +119,12 @@ impl Spawn for SpawnTaskHandle {
118119
}
119120
}
120121

122+
impl sc_client_api::CloneableSpawn for SpawnTaskHandle {
123+
fn clone(&self) -> Box<dyn CloneableSpawn> {
124+
Box::new(Clone::clone(self))
125+
}
126+
}
127+
121128
type Boxed01Future01 = Box<dyn futures01::Future<Item = (), Error = ()> + Send + 'static>;
122129

123130
impl futures01::future::Executor<Boxed01Future01> for SpawnTaskHandle {

client/src/call_executor.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,27 @@ use sc_executor::{RuntimeVersion, RuntimeInfo, NativeVersion};
2727
use sp_externalities::Extensions;
2828
use sp_core::{NativeOrEncoded, NeverNativeValue, traits::CodeExecutor};
2929
use sp_api::{ProofRecorder, InitializeBlock, StorageTransactionCache};
30-
use sc_client_api::{backend, call_executor::CallExecutor};
30+
use sc_client_api::{backend, call_executor::CallExecutor, CloneableSpawn};
3131

3232
/// Call executor that executes methods locally, querying all required
3333
/// data from local backend.
3434
pub struct LocalCallExecutor<B, E> {
3535
backend: Arc<B>,
3636
executor: E,
37+
spawn_handle: Box<dyn CloneableSpawn>,
3738
}
3839

3940
impl<B, E> LocalCallExecutor<B, E> {
4041
/// Creates new instance of local call executor.
4142
pub fn new(
4243
backend: Arc<B>,
4344
executor: E,
45+
spawn_handle: Box<dyn CloneableSpawn>,
4446
) -> Self {
4547
LocalCallExecutor {
4648
backend,
4749
executor,
50+
spawn_handle,
4851
}
4952
}
5053
}
@@ -54,6 +57,7 @@ impl<B, E> Clone for LocalCallExecutor<B, E> where E: Clone {
5457
LocalCallExecutor {
5558
backend: self.backend.clone(),
5659
executor: self.executor.clone(),
60+
spawn_handle: self.spawn_handle.clone(),
5761
}
5862
}
5963
}
@@ -91,6 +95,7 @@ where
9195
call_data,
9296
extensions.unwrap_or_default(),
9397
&state_runtime_code.runtime_code()?,
98+
self.spawn_handle.clone(),
9499
).execute_using_consensus_failure_handler::<_, NeverNativeValue, fn() -> _>(
95100
strategy.get_manager(),
96101
None,
@@ -164,6 +169,7 @@ where
164169
call_data,
165170
extensions.unwrap_or_default(),
166171
&runtime_code,
172+
self.spawn_handle.clone(),
167173
)
168174
// TODO: https://github.com/paritytech/substrate/issues/4455
169175
// .with_storage_transaction_cache(storage_transaction_cache.as_mut().map(|c| &mut **c))
@@ -180,6 +186,7 @@ where
180186
call_data,
181187
extensions.unwrap_or_default(),
182188
&state_runtime_code.runtime_code()?,
189+
self.spawn_handle.clone(),
183190
)
184191
.with_storage_transaction_cache(storage_transaction_cache.as_mut().map(|c| &mut **c))
185192
.execute_using_consensus_failure_handler(execution_manager, native_call)
@@ -218,6 +225,7 @@ where
218225
trie_state,
219226
overlay,
220227
&self.executor,
228+
self.spawn_handle.clone(),
221229
method,
222230
call_data,
223231
&sp_state_machine::backend::BackendRuntimeCode::new(trie_state).runtime_code()?,

client/src/client.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub use sc_client_api::{
7676
},
7777
execution_extensions::{ExecutionExtensions, ExecutionStrategies},
7878
notifications::{StorageNotifications, StorageEventStream},
79-
CallExecutor, ExecutorProvider, ProofProvider,
79+
CallExecutor, ExecutorProvider, ProofProvider, CloneableSpawn,
8080
};
8181
use sp_blockchain::Error;
8282
use prometheus_endpoint::Registry;
@@ -135,6 +135,7 @@ pub fn new_in_mem<E, Block, S, RA>(
135135
genesis_storage: &S,
136136
keystore: Option<sp_core::traits::BareCryptoStorePtr>,
137137
prometheus_registry: Option<Registry>,
138+
spawn_handle: Box<dyn CloneableSpawn>,
138139
) -> sp_blockchain::Result<Client<
139140
in_mem::Backend<Block>,
140141
LocalCallExecutor<in_mem::Backend<Block>, E>,
@@ -145,7 +146,7 @@ pub fn new_in_mem<E, Block, S, RA>(
145146
S: BuildStorage,
146147
Block: BlockT,
147148
{
148-
new_with_backend(Arc::new(in_mem::Backend::new()), executor, genesis_storage, keystore, prometheus_registry)
149+
new_with_backend(Arc::new(in_mem::Backend::new()), executor, genesis_storage, keystore, spawn_handle, prometheus_registry)
149150
}
150151

151152
/// Create a client with the explicitly provided backend.
@@ -155,6 +156,7 @@ pub fn new_with_backend<B, E, Block, S, RA>(
155156
executor: E,
156157
build_genesis_storage: &S,
157158
keystore: Option<sp_core::traits::BareCryptoStorePtr>,
159+
spawn_handle: Box<dyn CloneableSpawn>,
158160
prometheus_registry: Option<Registry>,
159161
) -> sp_blockchain::Result<Client<B, LocalCallExecutor<B, E>, Block, RA>>
160162
where
@@ -163,7 +165,7 @@ pub fn new_with_backend<B, E, Block, S, RA>(
163165
Block: BlockT,
164166
B: backend::LocalBackend<Block> + 'static,
165167
{
166-
let call_executor = LocalCallExecutor::new(backend.clone(), executor);
168+
let call_executor = LocalCallExecutor::new(backend.clone(), executor, spawn_handle);
167169
let extensions = ExecutionExtensions::new(Default::default(), keystore);
168170
Client::new(
169171
backend,
@@ -1124,7 +1126,13 @@ impl<B, E, Block, RA> ProofProvider<Block> for Client<B, E, Block, RA> where
11241126

11251127
let state = self.state_at(id)?;
11261128
let header = self.prepare_environment_block(id)?;
1127-
prove_execution(state, header, &self.executor, method, call_data).map(|(r, p)| {
1129+
prove_execution(
1130+
state,
1131+
header,
1132+
&self.executor,
1133+
method,
1134+
call_data,
1135+
).map(|(r, p)| {
11281136
(r, StorageProof::merge(vec![p, code_proof]))
11291137
})
11301138
}
@@ -3482,6 +3490,7 @@ pub(crate) mod tests {
34823490
&substrate_test_runtime_client::GenesisParameters::default().genesis_storage(),
34833491
None,
34843492
None,
3493+
sp_core::tasks::executor(),
34853494
)
34863495
.unwrap();
34873496

client/src/genesis.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ mod tests {
5454
AccountKeyring, Sr25519Keyring,
5555
};
5656
use sp_runtime::traits::BlakeTwo256;
57+
use sp_core::tasks::executor as tasks_executor;
5758
use hex_literal::*;
5859

5960
native_executor_instance!(
@@ -101,6 +102,7 @@ mod tests {
101102
&header.encode(),
102103
Default::default(),
103104
&runtime_code,
105+
tasks_executor(),
104106
).execute(
105107
ExecutionStrategy::NativeElseWasm,
106108
).unwrap();
@@ -115,6 +117,7 @@ mod tests {
115117
&tx.encode(),
116118
Default::default(),
117119
&runtime_code,
120+
tasks_executor(),
118121
).execute(
119122
ExecutionStrategy::NativeElseWasm,
120123
).unwrap();
@@ -129,6 +132,7 @@ mod tests {
129132
&[],
130133
Default::default(),
131134
&runtime_code,
135+
tasks_executor(),
132136
).execute(
133137
ExecutionStrategy::NativeElseWasm,
134138
).unwrap();
@@ -179,6 +183,7 @@ mod tests {
179183
&b1data,
180184
Default::default(),
181185
&runtime_code,
186+
tasks_executor(),
182187
).execute(
183188
ExecutionStrategy::NativeElseWasm,
184189
).unwrap();
@@ -210,6 +215,7 @@ mod tests {
210215
&b1data,
211216
Default::default(),
212217
&runtime_code,
218+
tasks_executor(),
213219
).execute(
214220
ExecutionStrategy::AlwaysWasm,
215221
).unwrap();
@@ -241,6 +247,7 @@ mod tests {
241247
&b1data,
242248
Default::default(),
243249
&runtime_code,
250+
tasks_executor(),
244251
).execute(
245252
ExecutionStrategy::NativeElseWasm,
246253
);

client/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
//! LocalCallExecutor::new(
6363
//! backend.clone(),
6464
//! NativeExecutor::<LocalExecutor>::new(WasmExecutionMethod::Interpreted, None, 8),
65+
//! sp_core::tasks::executor(),
6566
//! ),
6667
//! // This parameter provides the storage for the chain genesis.
6768
//! &<Storage>::default(),

0 commit comments

Comments
 (0)