Skip to content

Commit ba81fe3

Browse files
A0-4208: Hide NativeExecutionDispatch behind feature flags (#1675)
# Description Hide implementation of `NativeExecutionDispatch` for the `ExecutorDispatch` behind `local-debugging`. `NativeExecutionDispatch` is needed for debugging locally, as well as for `runtime-benchmarks`. Pehaps it's not needed for `try-runtime`, but it's subject to the next PRs. ## Type of change Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) # Checklist: https://github.com/Cardinal-Cryptography/aleph-node/actions/runs/8628234269 https://github.com/Cardinal-Cryptography/aleph-node/actions/runs/8615033603
1 parent cd41f54 commit ba81fe3

File tree

6 files changed

+73
-20
lines changed

6 files changed

+73
-20
lines changed

.github/workflows/nightly-check-node-features-build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
# This workflow checks node build with various features
3-
name: Feature-gated builds
3+
name: Nightly feature-gated builds
44
on:
55
workflow_dispatch:
66
schedule:
@@ -32,6 +32,9 @@ jobs:
3232
- name: aleph-node with runtime-benchmarks
3333
run: cargo check --profile production -p aleph-node --features runtime-benchmarks --locked
3434

35+
- name: aleph-node with local-debugging
36+
run: cargo check --profile dev -p aleph-node --features local-debugging --locked
37+
3538
slack-notification:
3639
name: Slack notification
3740
runs-on: ubuntu-20.04

BUILD.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ If `cargo build --release` does not succeed but throws an error mentioning `Rust
104104

105105
After a successful build the binary can be found in `target/release/aleph-node`.
106106

107+
### Local debugging
108+
109+
If you'd like to use Rust debugger with aleph-node binary, built it with `local-debugging` feature:
110+
```
111+
cargo check --profile dev -p aleph-node --features local-debugging --locked
112+
```
107113

108114
[nix]: https://nixos.org/download.html
109115
[rustup]: https://rustup.rs/

bin/node/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,4 @@ runtime-benchmarks = [
101101
only_legacy = [
102102
"finality-aleph/only_legacy"
103103
]
104+
local-debugging = []

bin/node/src/executor.rs

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,64 @@
1-
//! `CodeExecutor` specialization which uses natively compiled runtime when the WASM to be
2-
//! executed is equivalent to the natively compiled code.
1+
//! This module declares an `AlephExecutor` which is either a
2+
//! * `WasmExecutor`, for production and test build (when no local debugging is required)
3+
//! * `NativeElseWasmExecutor` for `try-runtime`, `runtime-benchmarks` and local debugging builds
34
4-
use sc_executor::NativeElseWasmExecutor;
5+
use sc_service::Configuration;
56

6-
// Declare an instance of the native executor named `ExecutorDispatch`. Include the wasm binary as the equivalent wasm code.
7-
pub struct ExecutorDispatch;
7+
#[cfg(not(any(
8+
feature = "runtime-benchmarks",
9+
feature = "local-debugging",
10+
feature = "try-runtime"
11+
)))]
12+
pub mod aleph_executor {
13+
use sc_executor::WasmExecutor;
14+
15+
use super::Configuration;
816

9-
impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
10-
#[cfg(feature = "runtime-benchmarks")]
1117
type ExtendHostFunctions = (
18+
sp_io::SubstrateHostFunctions,
1219
aleph_runtime_interfaces::snark_verifier::HostFunctions,
13-
frame_benchmarking::benchmarking::HostFunctions,
1420
);
15-
#[cfg(not(feature = "runtime-benchmarks"))]
16-
type ExtendHostFunctions = (aleph_runtime_interfaces::snark_verifier::HostFunctions,);
21+
pub type Executor = WasmExecutor<ExtendHostFunctions>;
22+
23+
pub fn get_executor(config: &Configuration) -> Executor {
24+
sc_service::new_wasm_executor(config)
25+
}
26+
}
27+
28+
#[cfg(any(
29+
feature = "runtime-benchmarks",
30+
feature = "local-debugging",
31+
feature = "try-runtime"
32+
))]
33+
pub mod aleph_executor {
34+
use sc_executor::NativeElseWasmExecutor;
35+
36+
use super::Configuration;
1737

18-
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
19-
aleph_runtime::api::dispatch(method, data)
38+
pub struct ExecutorDispatch;
39+
40+
impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
41+
#[cfg(feature = "runtime-benchmarks")]
42+
type ExtendHostFunctions = (
43+
aleph_runtime_interfaces::snark_verifier::HostFunctions,
44+
frame_benchmarking::benchmarking::HostFunctions,
45+
);
46+
47+
#[cfg(not(feature = "runtime-benchmarks"))]
48+
type ExtendHostFunctions = (aleph_runtime_interfaces::snark_verifier::HostFunctions,);
49+
50+
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
51+
aleph_runtime::api::dispatch(method, data)
52+
}
53+
54+
fn native_version() -> sc_executor::NativeVersion {
55+
aleph_runtime::native_version()
56+
}
2057
}
2158

22-
fn native_version() -> sc_executor::NativeVersion {
23-
aleph_runtime::native_version()
59+
pub type Executor = NativeElseWasmExecutor<ExecutorDispatch>;
60+
61+
pub fn get_executor(config: &Configuration) -> Executor {
62+
sc_service::new_native_or_wasm_executor(config)
2463
}
2564
}
26-
27-
pub type AlephExecutor = NativeElseWasmExecutor<ExecutorDispatch>;

bin/node/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ mod rpc;
99
mod service;
1010

1111
pub use cli::{Cli, Subcommand};
12-
pub use executor::ExecutorDispatch;
12+
#[cfg(any(
13+
feature = "runtime-benchmarks",
14+
feature = "local-debugging",
15+
feature = "try-runtime"
16+
))]
17+
pub use executor::aleph_executor::ExecutorDispatch;
1318
pub use service::{new_authority, new_partial};

bin/node/src/service.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ use sp_consensus_aura::{sr25519::AuthorityPair as AuraPair, Slot};
3131
use crate::{
3232
aleph_cli::AlephCli,
3333
chain_spec::DEFAULT_BACKUP_FOLDER,
34-
executor::AlephExecutor,
34+
executor::aleph_executor,
3535
rpc::{create_full as create_full_rpc, FullDeps as RpcFullDeps},
3636
};
3737

38+
type AlephExecutor = aleph_executor::Executor;
3839
type FullClient = sc_service::TFullClient<Block, RuntimeApi, AlephExecutor>;
3940
type FullBackend = sc_service::TFullBackend<Block>;
4041
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
@@ -103,7 +104,7 @@ pub fn new_partial(config: &Configuration) -> Result<ServiceComponents, ServiceE
103104
})
104105
.transpose()?;
105106

106-
let executor = sc_service::new_native_or_wasm_executor(config);
107+
let executor = aleph_executor::get_executor(config);
107108

108109
let (client, backend, keystore_container, task_manager) =
109110
sc_service::new_full_parts::<Block, RuntimeApi, AlephExecutor>(

0 commit comments

Comments
 (0)