Removal of execution strategies (#14387)

* Start

* More work!

* Moar

* More changes

* More fixes

* More worrk

* More fixes

* More fixes to make it compile

* Adds `NoOffchainStorage`

* Pass the extensions

* Small basti making small progress

* Fix merge errors and remove `ExecutionContext`

* Move registration of `ReadRuntimeVersionExt` to `ExecutionExtension`

Instead of registering `ReadRuntimeVersionExt` in `sp-state-machine` it is moved to
`ExecutionExtension` which provides the default extensions.

* Fix compilation

* Register the global extensions inside runtime api instance

* Fixes

* Fix `generate_initial_session_keys` by passing the keystore extension

* Fix the grandpa tests

* Fix more tests

* Fix more tests

* Don't set any heap pages if there isn't an override

* Fix small fallout

* FMT

* Fix tests

* More tests

* Offchain worker custom extensions

* More fixes

* Make offchain tx pool creation reusable

Introduces an `OffchainTransactionPoolFactory` for creating offchain transactions pools that can be
registered in the runtime externalities context. This factory will be required for a later pr to
make the creation of offchain transaction pools easier.

* Fixes

* Fixes

* Set offchain transaction pool in BABE before using it in the runtime

* Add the `offchain_tx_pool` to Grandpa as well

* Fix the nodes

* Print some error when using the old warnings

* Fix merge issues

* Fix compilation

* Rename `babe_link`

* Rename to `offchain_tx_pool_factory`

* Cleanup

* FMT

* Fix benchmark name

* Fix `try-runtime`

* Remove `--execution` CLI args

* Make clippy happy

* Forward bls functions

* Fix docs

* Update UI tests

* Update client/api/src/execution_extensions.rs

Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Koute <koute@users.noreply.github.com>

* Update client/cli/src/params/import_params.rs

Co-authored-by: Koute <koute@users.noreply.github.com>

* Update client/api/src/execution_extensions.rs

Co-authored-by: Koute <koute@users.noreply.github.com>

* Pass the offchain storage to the MMR RPC

* Update client/api/src/execution_extensions.rs

Co-authored-by: Sebastian Kunert <skunert49@gmail.com>

* Review comments

* Fixes

---------

Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
Co-authored-by: Koute <koute@users.noreply.github.com>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
This commit is contained in:
Bastian Köcher
2023-07-11 16:21:38 +02:00
committed by GitHub
parent a2b01c061b
commit 5eb816d7a6
96 changed files with 1175 additions and 1499 deletions
+4 -43
View File
@@ -187,9 +187,7 @@ where
let client = {
let extensions = sc_client_api::execution_extensions::ExecutionExtensions::new(
config.execution_strategies.clone(),
Some(keystore_container.keystore()),
sc_offchain::OffchainDb::factory_from_backend(&*backend),
None,
Arc::new(executor.clone()),
);
@@ -322,19 +320,14 @@ where
/// Shared network instance implementing a set of mandatory traits.
pub trait SpawnTaskNetwork<Block: BlockT>:
sc_offchain::NetworkProvider + NetworkStateInfo + NetworkStatusProvider + Send + Sync + 'static
NetworkStateInfo + NetworkStatusProvider + Send + Sync + 'static
{
}
impl<T, Block> SpawnTaskNetwork<Block> for T
where
Block: BlockT,
T: sc_offchain::NetworkProvider
+ NetworkStateInfo
+ NetworkStatusProvider
+ Send
+ Sync
+ 'static,
T: NetworkStateInfo + NetworkStatusProvider + Send + Sync + 'static,
{
}
@@ -368,38 +361,6 @@ pub struct SpawnTasksParams<'a, TBl: BlockT, TCl, TExPool, TRpc, Backend> {
pub telemetry: Option<&'a mut Telemetry>,
}
/// Build a shared offchain workers instance.
pub fn build_offchain_workers<TBl, TCl>(
config: &Configuration,
spawn_handle: SpawnTaskHandle,
client: Arc<TCl>,
network: Arc<dyn sc_offchain::NetworkProvider + Send + Sync>,
) -> Option<Arc<sc_offchain::OffchainWorkers<TCl, TBl>>>
where
TBl: BlockT,
TCl: Send + Sync + ProvideRuntimeApi<TBl> + BlockchainEvents<TBl> + 'static,
<TCl as ProvideRuntimeApi<TBl>>::Api: sc_offchain::OffchainWorkerApi<TBl>,
{
let offchain_workers = Some(Arc::new(sc_offchain::OffchainWorkers::new(client.clone())));
// Inform the offchain worker about new imported blocks
if let Some(offchain) = offchain_workers.clone() {
spawn_handle.spawn(
"offchain-notifications",
Some("offchain-worker"),
sc_offchain::notification_future(
config.role.is_authority(),
client,
offchain,
Clone::clone(&spawn_handle),
network,
),
);
}
offchain_workers
}
/// Spawn the tasks that are required to run a node.
pub fn spawn_tasks<TBl, TBackend, TExPool, TRpc, TCl>(
params: SpawnTasksParams<TBl, TCl, TExPool, TRpc, TBackend>,
@@ -420,7 +381,6 @@ where
+ Send
+ 'static,
<TCl as ProvideRuntimeApi<TBl>>::Api: sp_api::Metadata<TBl>
+ sc_offchain::OffchainWorkerApi<TBl>
+ sp_transaction_pool::runtime_api::TaggedTransactionQueue<TBl>
+ sp_session::SessionKeys<TBl>
+ sp_api::ApiExt<TBl, StateBackend = TBackend::State>,
@@ -451,6 +411,7 @@ where
client.clone(),
chain_info.best_hash,
config.dev_key_seed.clone().map(|s| vec![s]).unwrap_or_default(),
keystore.clone(),
)
.map_err(|e| Error::Application(Box::new(e)))?;
@@ -22,14 +22,10 @@ use sc_client_api::{
};
use sc_executor::{RuntimeVersion, RuntimeVersionOf};
use sp_api::{ProofRecorder, StorageTransactionCache};
use sp_core::{
traits::{CallContext, CodeExecutor, RuntimeCode},
ExecutionContext,
};
use sp_core::traits::{CallContext, CodeExecutor, RuntimeCode};
use sp_externalities::Extensions;
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
use sp_state_machine::{
backend::AsTrieBackend, ExecutionStrategy, Ext, OverlayedChanges, StateMachine, StorageProof,
};
use sp_state_machine::{backend::AsTrieBackend, Ext, OverlayedChanges, StateMachine, StorageProof};
use std::{cell::RefCell, sync::Arc};
/// Call executor that executes methods locally, querying all required
@@ -166,7 +162,6 @@ where
at_hash: Block::Hash,
method: &str,
call_data: &[u8],
strategy: ExecutionStrategy,
context: CallContext,
) -> sp_blockchain::Result<Vec<u8>> {
let mut changes = OverlayedChanges::default();
@@ -180,11 +175,7 @@ where
let runtime_code = self.check_override(runtime_code, &state, at_hash)?.0;
let extensions = self.execution_extensions.extensions(
at_hash,
at_number,
ExecutionContext::OffchainCall(None),
);
let mut extensions = self.execution_extensions.extensions(at_hash, at_number);
let mut sm = StateMachine::new(
&state,
@@ -192,14 +183,13 @@ where
&self.executor,
method,
call_data,
extensions,
&mut extensions,
&runtime_code,
context,
)
.set_parent_hash(at_hash);
sm.execute_using_consensus_failure_handler(strategy.get_manager())
.map_err(Into::into)
sm.execute().map_err(Into::into)
}
fn contextual_call(
@@ -210,22 +200,13 @@ where
changes: &RefCell<OverlayedChanges>,
storage_transaction_cache: Option<&RefCell<StorageTransactionCache<Block, B::State>>>,
recorder: &Option<ProofRecorder<Block>>,
context: ExecutionContext,
call_context: CallContext,
extensions: &RefCell<Extensions>,
) -> Result<Vec<u8>, sp_blockchain::Error> {
let mut storage_transaction_cache = storage_transaction_cache.map(|c| c.borrow_mut());
let at_number =
self.backend.blockchain().expect_block_number_from_id(&BlockId::Hash(at_hash))?;
let state = self.backend.state_at(at_hash)?;
let call_context = match context {
ExecutionContext::OffchainCall(_) => CallContext::Offchain,
_ => CallContext::Onchain,
};
let (execution_manager, extensions) =
self.execution_extensions.manager_and_extensions(at_hash, at_number, context);
let changes = &mut *changes.borrow_mut();
// It is important to extract the runtime code here before we create the proof
@@ -236,6 +217,7 @@ where
let runtime_code =
state_runtime_code.runtime_code().map_err(sp_blockchain::Error::RuntimeCode)?;
let runtime_code = self.check_override(runtime_code, &state, at_hash)?.0;
let mut extensions = extensions.borrow_mut();
match recorder {
Some(recorder) => {
@@ -251,13 +233,13 @@ where
&self.executor,
method,
call_data,
extensions,
&mut extensions,
&runtime_code,
call_context,
)
.with_storage_transaction_cache(storage_transaction_cache.as_deref_mut())
.set_parent_hash(at_hash);
state_machine.execute_using_consensus_failure_handler(execution_manager)
state_machine.execute()
},
None => {
let mut state_machine = StateMachine::new(
@@ -266,13 +248,13 @@ where
&self.executor,
method,
call_data,
extensions,
&mut extensions,
&runtime_code,
call_context,
)
.with_storage_transaction_cache(storage_transaction_cache.as_deref_mut())
.set_parent_hash(at_hash);
state_machine.execute_using_consensus_failure_handler(execution_manager)
state_machine.execute()
},
}
.map_err(Into::into)
@@ -311,11 +293,7 @@ where
method,
call_data,
&runtime_code,
self.execution_extensions.extensions(
at_hash,
at_number,
ExecutionContext::OffchainCall(None),
),
&mut self.execution_extensions.extensions(at_hash, at_number),
)
.map_err(Into::into)
}
@@ -411,7 +389,6 @@ mod tests {
backend.clone(),
executor.clone(),
genesis_block_builder,
None,
Box::new(TaskExecutor::new()),
None,
None,
@@ -430,8 +407,6 @@ mod tests {
)
.unwrap(),
execution_extensions: Arc::new(ExecutionExtensions::new(
Default::default(),
None,
None,
Arc::new(executor.clone()),
)),
@@ -486,7 +461,6 @@ mod tests {
backend.clone(),
executor.clone(),
genesis_block_builder,
None,
Box::new(TaskExecutor::new()),
None,
None,
+20 -17
View File
@@ -62,10 +62,8 @@ use sp_core::{
well_known_keys, ChildInfo, ChildType, PrefixedStorageKey, StorageChild, StorageData,
StorageKey,
},
traits::SpawnNamed,
traits::{CallContext, SpawnNamed},
};
#[cfg(feature = "test-helpers")]
use sp_keystore::KeystorePtr;
use sp_runtime::{
generic::{BlockId, SignedBlock},
traits::{
@@ -161,7 +159,6 @@ pub fn new_in_mem<E, Block, G, RA>(
backend: Arc<in_mem::Backend<Block>>,
executor: E,
genesis_block_builder: G,
keystore: Option<KeystorePtr>,
prometheus_registry: Option<Registry>,
telemetry: Option<TelemetryHandle>,
spawn_handle: Box<dyn SpawnNamed>,
@@ -181,7 +178,6 @@ where
backend,
executor,
genesis_block_builder,
keystore,
spawn_handle,
prometheus_registry,
telemetry,
@@ -224,7 +220,6 @@ pub fn new_with_backend<B, E, Block, G, RA>(
backend: Arc<B>,
executor: E,
genesis_block_builder: G,
keystore: Option<KeystorePtr>,
spawn_handle: Box<dyn SpawnNamed>,
prometheus_registry: Option<Registry>,
telemetry: Option<TelemetryHandle>,
@@ -239,12 +234,7 @@ where
Block: BlockT,
B: backend::LocalBackend<Block> + 'static,
{
let extensions = ExecutionExtensions::new(
Default::default(),
keystore,
sc_offchain::OffchainDb::factory_from_backend(&*backend),
Arc::new(executor.clone()),
);
let extensions = ExecutionExtensions::new(None, Arc::new(executor.clone()));
let call_executor =
LocalCallExecutor::new(backend.clone(), executor, config.clone(), extensions)?;
@@ -875,12 +865,12 @@ where
// We should enact state, but don't have any storage changes, so we need to execute the
// block.
(true, None, Some(ref body)) => {
let runtime_api = self.runtime_api();
let execution_context = import_block.origin.into();
let mut runtime_api = self.runtime_api();
runtime_api.execute_block_with_context(
runtime_api.set_call_context(CallContext::Onchain);
runtime_api.execute_block(
*parent_hash,
execution_context,
Block::new(import_block.header.clone(), body.clone()),
)?;
@@ -1727,7 +1717,8 @@ where
params.overlayed_changes,
Some(params.storage_transaction_cache),
params.recorder,
params.context,
params.call_context,
params.extensions,
)
.map_err(Into::into)
}
@@ -1739,6 +1730,18 @@ where
fn state_at(&self, at: Block::Hash) -> Result<Self::StateBackend, sp_api::ApiError> {
self.state_at(at).map_err(Into::into)
}
fn initialize_extensions(
&self,
at: Block::Hash,
extensions: &mut sp_externalities::Extensions,
) -> Result<(), sp_api::ApiError> {
let block_number = self.expect_block_number_from_id(&BlockId::Hash(at))?;
extensions.merge(self.executor.execution_extensions().extensions(at, block_number));
Ok(())
}
}
/// NOTE: only use this implementation when you are sure there are NO consensus-level BlockImport
-3
View File
@@ -18,7 +18,6 @@
//! Service configuration.
pub use sc_client_api::execution_extensions::{ExecutionStrategies, ExecutionStrategy};
pub use sc_client_db::{BlocksPruning, Database, DatabaseSource, PruningMode};
pub use sc_executor::{WasmExecutionMethod, WasmtimeInstantiationStrategy};
pub use sc_network::{
@@ -81,8 +80,6 @@ pub struct Configuration {
/// over on-chain runtimes when the spec version matches. Set to `None` to
/// disable overrides (default).
pub wasm_runtime_overrides: Option<PathBuf>,
/// Execution strategies.
pub execution_strategies: ExecutionStrategies,
/// JSON-RPC server binding address.
pub rpc_addr: Option<SocketAddr>,
/// Maximum number of connections for JSON-RPC server.
+2 -2
View File
@@ -55,8 +55,8 @@ use sp_runtime::{
pub use self::{
builder::{
build_network, build_offchain_workers, new_client, new_db_backend, new_full_client,
new_full_parts, new_full_parts_with_genesis_builder, new_native_or_wasm_executor,
build_network, new_client, new_db_backend, new_full_client, new_full_parts,
new_full_parts_with_genesis_builder, new_native_or_wasm_executor, new_wasm_executor,
spawn_tasks, BuildNetworkParams, KeystoreContainer, NetworkStarter, SpawnTasksParams,
TFullBackend, TFullCallExecutor, TFullClient,
},