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

Adds new execution strategy nativeElseWasm #1546

Merged
merged 35 commits into from
Feb 11, 2019

Conversation

marcio-diaz
Copy link
Contributor

PR for issue #1395.

@marcio-diaz marcio-diaz added the A3-in_progress Pull request is in progress. No review needed at this stage. label Jan 24, 2019
@@ -237,6 +237,7 @@ where
"both" => service::ExecutionStrategy::Both,
"native" => service::ExecutionStrategy::NativeWhenPossible,
"wasm" => service::ExecutionStrategy::AlwaysWasm,
"nativeElseWasm" => service::ExecutionStrategy::NativeElseWasm,
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup

@marcio-diaz marcio-diaz added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Jan 26, 2019
bkchr
bkchr previously requested changes Jan 28, 2019
Copy link
Member

@bkchr bkchr left a 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.

@bkchr bkchr added A3-needsresolving A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Jan 28, 2019
@marcio-diaz marcio-diaz force-pushed the mar-improve-execution-strategies branch 2 times, most recently from bf49528 to 6ba8ef8 Compare January 31, 2019 18:52
@marcio-diaz
Copy link
Contributor Author

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.

I believe block constructions is fixed by now. Need to re-check syncing.

@gavofyork
Copy link
Member

we keep Cargo.lock :)

@gavofyork
Copy link
Member

important bits of logic look good.

@marcio-diaz marcio-diaz added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. A3-needsresolving labels Feb 1, 2019
@gavofyork
Copy link
Member

Will need another merge

@gavofyork gavofyork added A3-needsresolving and removed A0-please_review Pull request needs code review. labels Feb 1, 2019
@marcio-diaz marcio-diaz force-pushed the mar-improve-execution-strategies branch from 0d4e57c to 32d5681 Compare February 1, 2019 14:36
@marcio-diaz marcio-diaz added A0-please_review Pull request needs code review. and removed A3-needsresolving labels Feb 1, 2019
bkchr
bkchr previously requested changes Feb 1, 2019
@@ -19,6 +19,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

use substrate_client::decl_runtime_apis;
use substrate_client::runtime_api::ExecutionContext;
Copy link
Member

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());
Copy link
Member

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);
Copy link
Member

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";
Copy link
Member

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.

Copy link
Contributor Author

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 👍 .

@gavofyork gavofyork added A5-grumble and removed A0-please_review Pull request needs code review. labels Feb 3, 2019
@marcio-diaz marcio-diaz added A0-please_review Pull request needs code review. and removed A5-grumble labels Feb 5, 2019
@marcio-diaz marcio-diaz force-pushed the mar-improve-execution-strategies branch from ee931a6 to 5a6b489 Compare February 10, 2019 15:20
Copy link
Member

@bkchr bkchr left a 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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 ));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left over debug stuff.

@@ -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};
Copy link
Member

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.

core/sr-api-macros/tests/runtime_calls.rs Show resolved Hide resolved
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]
Copy link
Member

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).

@@ -54,6 +54,7 @@ use substrate_primitives::OpaqueMetadata;

#[cfg(any(feature = "std", test))]
pub use runtime_primitives::BuildStorage;
pub use runtime_primitives::ExecutionContext;
Copy link
Member

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.

@@ -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,
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

@marcio-diaz marcio-diaz force-pushed the mar-improve-execution-strategies branch from 3544003 to 6407f81 Compare February 11, 2019 10:31
@marcio-diaz marcio-diaz merged commit 5f4ebb4 into master Feb 11, 2019
@bkchr bkchr deleted the mar-improve-execution-strategies branch February 11, 2019 14:26
MTDK1 pushed a commit to bdevux/substrate that referenced this pull request Apr 12, 2019
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants