-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Adds new execution strategy nativeElseWasm #1546
Conversation
core/cli/src/lib.rs
Outdated
@@ -237,6 +237,7 @@ where | |||
"both" => service::ExecutionStrategy::Both, | |||
"native" => service::ExecutionStrategy::NativeWhenPossible, | |||
"wasm" => service::ExecutionStrategy::AlwaysWasm, | |||
"nativeElseWasm" => service::ExecutionStrategy::NativeElseWasm, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should stick to all lowercase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not use the block_construction
execution strategy while constructing blocks or the syncing
execution strategy while syncing. You need to make use of them.
The pr also needs to be resolved.
bf49528
to
6ba8ef8
Compare
I believe block constructions is fixed by now. Need to re-check syncing. |
we keep |
important bits of logic look good. |
Will need another merge |
0d4e57c
to
32d5681
Compare
@@ -19,6 +19,7 @@ | |||
#![cfg_attr(not(feature = "std"), no_std)] | |||
|
|||
use substrate_client::decl_runtime_apis; | |||
use substrate_client::runtime_api::ExecutionContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The macro should not enforce the user to include any stuff that is used internally. Please use ExecutionContext
by absolute path as we do it for other types as well.
TraitItem::Method(method) => { | ||
let mut new_method = method.clone(); | ||
new_method.sig.ident = Ident::new(&format!("{}_with_context", &method.sig.ident), Span::call_site()); | ||
new_method.sig.decl.inputs.push(context_arg.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we put the context
argument after BlockId
?
@@ -250,7 +250,9 @@ fn generate_block_and_block_id_ty( | |||
let block = quote!( <#runtime as #crate_::runtime_api::#trait_>::#assoc_type ); | |||
let block_id = quote!( #crate_::runtime_api::BlockId<#block> ); | |||
|
|||
(block, block_id) | |||
let ts = (block, block_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some left over debug stuff.
let mut execution_context = parse_quote!( ExecutionContext::Other ); | ||
let mut call_generator_name = input.sig.ident.to_string(); | ||
|
||
let with_context_str = "_with_context"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing all this string parsing here, I would propose to drop generate_impl_with_context()
and these modifications.
Switch to use fold_impl_item
. Iterate manual over all methods and call the function that generates the method once with the original impl_item_method
and a second time where you just replace the name and add the corresponding function argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, makes much more sense 👍 .
ee931a6
to
5a6b489
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far. Just some last nits + fix failing tests.
@@ -339,8 +339,9 @@ impl<'a> ToClientSideDecl<'a> { | |||
|
|||
items.into_iter().for_each(|i| match i { | |||
TraitItem::Method(method) => { | |||
let (fn_decl, fn_impl) = self.fold_trait_item_method(method); | |||
let (fn_decl, fn_impl, fn_decl_ctx) = self.fold_trait_item_method(method.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let (fn_decl, fn_impl, fn_decl_ctx) = self.fold_trait_item_method(method.clone()); | |
let (fn_decl, fn_impl, fn_decl_ctx) = self.fold_trait_item_method(method); |
@@ -726,6 +742,8 @@ pub fn decl_runtime_apis_impl(input: proc_macro::TokenStream) -> proc_macro::Tok | |||
let runtime_decls = generate_runtime_decls(&api_decls); | |||
let client_side_decls = generate_client_side_decls(&api_decls); | |||
|
|||
// println!("generating this declaration:\n\n{}\n\n", quote!( #client_side_decls )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left over debug stuff.
core/sr-api-macros/src/utils.rs
Outdated
@@ -15,7 +15,8 @@ | |||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>. | |||
|
|||
use proc_macro2::{TokenStream, Span}; | |||
use syn::{Result, Ident, FnDecl, parse_quote, Type, Pat, spanned::Spanned, FnArg, Error}; | |||
use syn::{Result, Ident, FnDecl, parse_quote, Type, Pat, spanned::Spanned, | |||
FnArg, Error}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this line break.
let runtime_api = client.runtime_api(); | ||
let block_id = BlockId::Number(client.info().unwrap().chain.best_number); | ||
|
||
#[allow(deprecated)] | ||
let res = runtime_api.function_signature_changed_before_version_2(&block_id).unwrap(); | ||
assert_eq!(&res, &[1, 2]); | ||
} | ||
|
||
#[test] | ||
#[should_panic] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide an expected message, see above for an example. (So we make sure that the panic is the one we expect).
node/runtime/src/lib.rs
Outdated
@@ -54,6 +54,7 @@ use substrate_primitives::OpaqueMetadata; | |||
|
|||
#[cfg(any(feature = "std", test))] | |||
pub use runtime_primitives::BuildStorage; | |||
pub use runtime_primitives::ExecutionContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be required here.
node/runtime/src/lib.rs
Outdated
@@ -65,8 +66,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { | |||
spec_name: create_runtime_str!("node"), | |||
impl_name: create_runtime_str!("substrate-node"), | |||
authoring_version: 10, | |||
spec_version: 26, | |||
impl_version: 26, | |||
spec_version: 27, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to increase the spec_version
. impl_version
should be enough. CI will still report an issue, but that is okay for the runtime check.
@@ -80,7 +80,8 @@ where | |||
{ | |||
type Error = ClientError; | |||
|
|||
fn call(&self, id: &BlockId<Block>, method: &str, call_data: &[u8]) -> ClientResult<Vec<u8>> { | |||
fn call(&self, id: &BlockId<Block>, method: &str, call_data: &[u8], strategy: ExecutionStrategy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn call(&self, id: &BlockId<Block>, method: &str, call_data: &[u8], strategy: ExecutionStrategy) | |
fn call(&self, id: &BlockId<Block>, method: &str, call_data: &[u8], _: ExecutionStrategy) |
3544003
to
6407f81
Compare
* fix: adds new execution strategy nativeElseWasm and replace nativeWhenPossible with it * feat: adds cmd line params for execution strategies * fix: uses of cmd line execution strategies * chore: remove white spaces * chore: remove println * chore: remove whitespace * fix: generating functions with context * feat: add function to generate with_context declarations * fix: add implementation for with_context function calls * fix: add execution context to call_api_at function * fix: making use of context to select strategy for block_builder * chore: cleaning up * fix: merging issues * fix tests * add wasm files * chore: small doc for context fields * chore: delete redundant docs * fix: use full path for ExecutionContext * fix: add context functions from inside fold_item_impl * chore: remove clone * fix: moving generative function to utils, remove unused imports * fix: add missing full path for ExecutionContext * fix: merge issues * update wasm files * fix: update to keep up with changes in master * chore: remove unused functions, clean up * fix test * fix grumbles * fix: add more tests * fix: some refactorings * feat: add execution strategy to call * chore: small improvements * fix: add message to panic * fix tests
PR for issue #1395.