-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Make runtime api calls native when possible #1302
Conversation
344d4f0
to
0ef307a
Compare
@arkpar could you take a look? |
@@ -89,7 +89,7 @@ where | |||
extrinsics: &mut Vec<Block::Extrinsic> | |||
) -> error::Result<()> where T: BlockBuilderApi<Block, InherentData> { | |||
api.map_api_result(|api| { | |||
match api.apply_extrinsic(block_id, &xt)? { | |||
match api.apply_extrinsic(block_id, xt.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.
Why does it have to take it by value now? Some extrinsics, such as setting the code, may be expensive to 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.
Unfortunately, the implementation of apply_extrinsics
requires to get the extrinsics by value. If we could change the implementation of apply_extrinsics
to take them by reference, we could omit the clone here.
@@ -77,7 +82,8 @@ where | |||
initialised_block: &mut Option<BlockId<B>>, | |||
prepare_environment_block: PB, | |||
manager: ExecutionManager<EM>, | |||
) -> error::Result<Vec<u8>> where ExecutionManager<EM>: Clone; | |||
native_call: Option<NC>, | |||
) -> error::Result<NativeOrEncoded<R>> where ExecutionManager<EM>: 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.
Can both call_data
and native_call
be used at the same time? Would it make more sense to use an enum here and all the similar functions?
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.
If we call first into native and then into wasm, we need both. I already thought about it. I did not came to a quick solution. I think in another iteration of this code, we could provide some interface, to just create call_data
, when it is really needed.
0ef307a
to
fdd2371
Compare
@arkpar any other grumbles? |
fdd2371
to
aafec17
Compare
For all that came here because they need to update their code: |
* Add simple benchmark for the runtime api * Make the executor support native calls * Some documentation * Hide behind `feature = "std"` * Rework the native calls * Make all tests compile again * Make every parameter using the Block serialized/deserialized in the native call * Forward `UnwindSafe` requirement * Remove debug stuff * Add some documentation * Fixes warnings * Fixes errors after master rebase * Fixes compilation after master rebase * Fixes compilation after rebase
Ensure new slot is fully processed in `MockPrimaryNode`
This pull request implements support for making real native calls, without using the dispatch function in the native runtime.
The dispatch function is not removed, because for stuff like RPC it is still used.
The native call also does not drop encode/decode completely. For parameters/return values that are generic over the
Block
, will be encoded/decoded before calling the native function. This is a requirement, as the block differs between the node and the runtime.There are still some optimizations, like don't encode all parameters, even if we only call the native function. Currently this needs to be done, as the state machine decides if it calls both wasm/native or just native or just wasm.
Fixes: #294