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
+9 -56
View File
@@ -40,17 +40,14 @@ use kitchensink_runtime::{
};
use node_primitives::Block;
use sc_block_builder::BlockBuilderProvider;
use sc_client_api::{
execution_extensions::{ExecutionExtensions, ExecutionStrategies},
ExecutionStrategy,
};
use sc_client_api::execution_extensions::ExecutionExtensions;
use sc_client_db::PruningMode;
use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, ImportedAux};
use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod, WasmtimeInstantiationStrategy};
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_consensus::BlockOrigin;
use sp_core::{blake2_256, ed25519, sr25519, traits::SpawnNamed, ExecutionContext, Pair, Public};
use sp_core::{blake2_256, ed25519, sr25519, traits::SpawnNamed, Pair, Public};
use sp_inherents::InherentData;
use sp_runtime::{
traits::{Block as BlockT, IdentifyAccount, Verify},
@@ -354,7 +351,7 @@ impl BenchDb {
dir.path().to_string_lossy(),
);
let (_client, _backend, _task_executor) =
Self::bench_client(database_type, dir.path(), Profile::Native, &keyring);
Self::bench_client(database_type, dir.path(), &keyring);
let directory_guard = Guard(dir);
BenchDb { keyring, directory_guard, database_type }
@@ -380,7 +377,6 @@ impl BenchDb {
fn bench_client(
database_type: DatabaseType,
dir: &std::path::Path,
profile: Profile,
keyring: &BenchKeyring,
) -> (Client, std::sync::Arc<Backend>, TaskExecutor) {
let db_config = sc_client_db::DatabaseSettings {
@@ -415,12 +411,7 @@ impl BenchDb {
genesis_block_builder,
None,
None,
ExecutionExtensions::new(
profile.into_execution_strategies(),
None,
None,
Arc::new(executor),
),
ExecutionExtensions::new(None, Arc::new(executor)),
Box::new(task_executor.clone()),
None,
None,
@@ -444,11 +435,7 @@ impl BenchDb {
client
.runtime_api()
.inherent_extrinsics_with_context(
client.chain_info().genesis_hash,
ExecutionContext::BlockConstruction,
inherent_data,
)
.inherent_extrinsics(client.chain_info().genesis_hash, inherent_data)
.expect("Get inherents failed")
}
@@ -459,12 +446,8 @@ impl BenchDb {
/// Get cliet for this database operations.
pub fn client(&mut self) -> Client {
let (client, _backend, _task_executor) = Self::bench_client(
self.database_type,
self.directory_guard.path(),
Profile::Wasm,
&self.keyring,
);
let (client, _backend, _task_executor) =
Self::bench_client(self.database_type, self.directory_guard.path(), &self.keyring);
client
}
@@ -507,10 +490,10 @@ impl BenchDb {
}
/// Clone this database and create context for testing/benchmarking.
pub fn create_context(&self, profile: Profile) -> BenchContext {
pub fn create_context(&self) -> BenchContext {
let BenchDb { directory_guard, keyring, database_type } = self.clone();
let (client, backend, task_executor) =
Self::bench_client(database_type, directory_guard.path(), profile, &keyring);
Self::bench_client(database_type, directory_guard.path(), &keyring);
BenchContext {
client: Arc::new(client),
@@ -611,36 +594,6 @@ impl BenchKeyring {
}
}
/// Profile for exetion strategies.
#[derive(Clone, Copy, Debug)]
pub enum Profile {
/// As native as possible.
Native,
/// As wasm as possible.
Wasm,
}
impl Profile {
fn into_execution_strategies(self) -> ExecutionStrategies {
match self {
Profile::Wasm => ExecutionStrategies {
syncing: ExecutionStrategy::AlwaysWasm,
importing: ExecutionStrategy::AlwaysWasm,
block_construction: ExecutionStrategy::AlwaysWasm,
offchain_worker: ExecutionStrategy::AlwaysWasm,
other: ExecutionStrategy::AlwaysWasm,
},
Profile::Native => ExecutionStrategies {
syncing: ExecutionStrategy::NativeElseWasm,
importing: ExecutionStrategy::NativeElseWasm,
block_construction: ExecutionStrategy::NativeElseWasm,
offchain_worker: ExecutionStrategy::NativeElseWasm,
other: ExecutionStrategy::NativeElseWasm,
},
}
}
}
struct Guard(tempfile::TempDir);
impl Guard {