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
@@ -138,10 +138,9 @@ impl GenesisStorageBuilder {
.build_storage()
.expect("Build storage from substrate-test-runtime GenesisConfig");
storage.top.insert(
well_known_keys::HEAP_PAGES.into(),
self.heap_pages_override.unwrap_or(16_u64).encode(),
);
if let Some(heap_pages) = self.heap_pages_override {
storage.top.insert(well_known_keys::HEAP_PAGES.into(), heap_pages.encode());
}
storage.top.extend(self.extra_storage.top.clone());
storage.children_default.extend(self.extra_storage.children_default.clone());
+31 -27
View File
@@ -845,8 +845,12 @@ pub mod storage_key_generator {
/// Generate the hashed storage keys from the raw literals. These keys are expected to be be in
/// storage with given substrate-test runtime.
pub fn generate_expected_storage_hashed_keys() -> Vec<String> {
let literals: Vec<&[u8]> = vec![b":code", b":extrinsic_index", b":heappages"];
pub fn generate_expected_storage_hashed_keys(custom_heap_pages: bool) -> Vec<String> {
let mut literals: Vec<&[u8]> = vec![b":code", b":extrinsic_index"];
if custom_heap_pages {
literals.push(b":heappages");
}
let keys: Vec<Vec<&[u8]>> = vec![
vec![b"Babe", b"Authorities"],
@@ -906,8 +910,11 @@ pub mod storage_key_generator {
/// that would be generated by `generate_expected_storage_hashed_keys`. This list is provided
/// for the debugging convenience only. Value of each hex-string is documented with the literal
/// origin.
pub fn get_expected_storage_hashed_keys() -> Vec<String> {
[
///
/// `custom_heap_pages`: Should be set to `true` when the state contains the `:heap_pages` key
/// aka when overriding the heap pages to be used by the executor.
pub fn get_expected_storage_hashed_keys(custom_heap_pages: bool) -> Vec<&'static str> {
let mut res = vec![
//System|:__STORAGE_VERSION__:
"00771836bebdd29870ff246d305c578c4e7b9012096b41c4eb3aaf947f6ea429",
//SubstrateTest|Authorities
@@ -977,20 +984,25 @@ pub mod storage_key_generator {
"3a636f6465",
// :extrinsic_index
"3a65787472696e7369635f696e646578",
// :heappages
"3a686561707061676573",
// Balances|:__STORAGE_VERSION__:
"c2261276cc9d1f8598ea4b6a74b15c2f4e7b9012096b41c4eb3aaf947f6ea429",
// Balances|TotalIssuance
"c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80",
].into_iter().map(String::from).collect::<Vec<_>>()
];
if custom_heap_pages {
// :heappages
res.push("3a686561707061676573");
}
res
}
#[test]
fn expected_keys_vec_are_matching() {
assert_eq!(
storage_key_generator::get_expected_storage_hashed_keys(),
storage_key_generator::generate_expected_storage_hashed_keys(),
storage_key_generator::get_expected_storage_hashed_keys(false),
storage_key_generator::generate_expected_storage_hashed_keys(false),
);
}
}
@@ -1001,15 +1013,14 @@ mod tests {
use codec::Encode;
use frame_support::dispatch::DispatchInfo;
use sc_block_builder::BlockBuilderProvider;
use sp_api::ProvideRuntimeApi;
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_consensus::BlockOrigin;
use sp_core::{storage::well_known_keys::HEAP_PAGES, ExecutionContext};
use sp_core::{storage::well_known_keys::HEAP_PAGES, traits::CallContext};
use sp_keyring::AccountKeyring;
use sp_runtime::{
traits::{Hash as _, SignedExtension},
transaction_validity::{InvalidTransaction, ValidTransaction},
};
use sp_state_machine::ExecutionStrategy;
use substrate_test_runtime_client::{
prelude::*, runtime::TestAPI, DefaultTestClientBuilderExt, TestClientBuilder,
};
@@ -1019,20 +1030,15 @@ mod tests {
// This tests that the on-chain `HEAP_PAGES` parameter is respected.
// Create a client devoting only 8 pages of wasm memory. This gives us ~512k of heap memory.
let mut client = TestClientBuilder::new()
.set_execution_strategy(ExecutionStrategy::AlwaysWasm)
.set_heap_pages(8)
.build();
let mut client = TestClientBuilder::new().set_heap_pages(8).build();
let best_hash = client.chain_info().best_hash;
// Try to allocate 1024k of memory on heap. This is going to fail since it is twice larger
// than the heap.
let ret = client.runtime_api().vec_with_capacity_with_context(
best_hash,
// Use `BlockImport` to ensure we use the on chain heap pages as configured above.
ExecutionContext::Importing,
1048576,
);
let mut runtime_api = client.runtime_api();
// This is currently required to allocate the 1024k of memory as configured above.
runtime_api.set_call_context(CallContext::Onchain);
let ret = runtime_api.vec_with_capacity(best_hash, 1048576);
assert!(ret.is_err());
// Create a block that sets the `:heap_pages` to 32 pages of memory which corresponds to
@@ -1054,8 +1060,7 @@ mod tests {
#[test]
fn test_storage() {
let client =
TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
let client = TestClientBuilder::new().build();
let runtime_api = client.runtime_api();
let best_hash = client.chain_info().best_hash;
@@ -1080,8 +1085,7 @@ mod tests {
let backend =
sp_state_machine::TrieBackendBuilder::<_, crate::Hashing>::new(db, root).build();
let proof = sp_state_machine::prove_read(backend, vec![b"value3"]).unwrap();
let client =
TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
let client = TestClientBuilder::new().build();
let runtime_api = client.runtime_api();
let best_hash = client.chain_info().best_hash;
@@ -1108,7 +1112,7 @@ mod tests {
.cloned()
.map(storage_key_generator::hex)
.collect::<Vec<_>>(),
storage_key_generator::get_expected_storage_hashed_keys()
storage_key_generator::get_expected_storage_hashed_keys(false)
);
}
@@ -24,7 +24,7 @@
use frame_support::{pallet_prelude::*, storage};
use sp_core::sr25519::Public;
use sp_runtime::{
traits::{BlakeTwo256, Hash},
traits::Hash,
transaction_validity::{
InvalidTransaction, TransactionSource, TransactionValidity, ValidTransaction,
},
@@ -41,7 +41,7 @@ pub mod pallet {
use crate::TransferData;
use frame_system::pallet_prelude::*;
use sp_core::storage::well_known_keys;
use sp_runtime::{transaction_validity::TransactionPriority, Perbill};
use sp_runtime::{traits::BlakeTwo256, transaction_validity::TransactionPriority, Perbill};
#[pallet::pallet]
#[pallet::without_storage_info]