Skip to content

Commit

Permalink
add the new host functions for parachains
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege committed May 15, 2024
1 parent c4ae135 commit e96799b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
10 changes: 5 additions & 5 deletions examples/parachain/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ macro_rules! construct_async_run {
let runner = $cli.create_runner($cmd)?;
runner.async_run(|$config| {
let executor =
sc_service::new_wasm_executor::<sp_io::SubstrateHostFunctions>(&$config);
sc_service::new_wasm_executor::<crate::service::HostFunctions>(&$config);
let $components = new_partial(&$config, executor)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
Expand Down Expand Up @@ -169,7 +169,7 @@ pub fn run() -> Result<()> {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| {
let executor =
sc_service::new_wasm_executor::<sp_io::SubstrateHostFunctions>(&config);
sc_service::new_wasm_executor::<crate::service::HostFunctions>(&config);
let components = new_partial(&config, executor)?;

cmd.run(components.client.clone())
Expand All @@ -196,7 +196,7 @@ pub fn run() -> Result<()> {
},
BenchmarkCmd::Block(cmd) => runner.sync_run(|config| {
let executor =
sc_service::new_wasm_executor::<sp_io::SubstrateHostFunctions>(&config);
sc_service::new_wasm_executor::<crate::service::HostFunctions>(&config);
let partials = new_partial(&config, executor)?;
cmd.run(partials.client)
}),
Expand All @@ -211,7 +211,7 @@ pub fn run() -> Result<()> {
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {
let executor =
sc_service::new_wasm_executor::<sp_io::SubstrateHostFunctions>(&config);
sc_service::new_wasm_executor::<crate::service::HostFunctions>(&config);
let partials = new_partial(&config, executor)?;
let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();
Expand All @@ -234,7 +234,7 @@ pub fn run() -> Result<()> {
let runner = cli.create_runner(cmd)?;

type HostFunctionsOf<E> = ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
crate::service::HostFunctions,
<E as NativeExecutionDispatch>::ExtendHostFunctions,
>;

Expand Down
10 changes: 6 additions & 4 deletions examples/parachain/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ use sp_core::traits::CodeExecutor;
use sp_keystore::KeystorePtr;
use substrate_prometheus_endpoint::Registry;

type ParachainClient = TFullClient<Block, RuntimeApi, WasmExecutor<sp_io::SubstrateHostFunctions>>;
pub type HostFunctions =
(sp_io::SubstrateHostFunctions, cumulus_client_service::storage_proof_size::HostFunctions);

type ParachainClient = TFullClient<Block, RuntimeApi, WasmExecutor<HostFunctions>>;

type ParachainBackend = TFullBackend<Block>;

type ParachainBlockImport<E = WasmExecutor<sp_io::SubstrateHostFunctions>> =
type ParachainBlockImport<E = WasmExecutor<HostFunctions>> =
TParachainBlockImport<Block, Arc<ClientWithExecutor<E>>, ParachainBackend>;

type ClientWithExecutor<E> = TFullClient<Block, RuntimeApi, E>;
Expand Down Expand Up @@ -141,8 +144,7 @@ async fn start_node_impl(
hwbench: Option<sc_sysinfo::HwBench>,
) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient>)> {
let parachain_config = prepare_node_config(parachain_config);
let executor =
sc_service::new_wasm_executor::<sp_io::SubstrateHostFunctions>(&parachain_config);
let executor = sc_service::new_wasm_executor::<HostFunctions>(&parachain_config);
let params = new_partial(&parachain_config, executor)?;
let (block_import, mut telemetry, telemetry_worker_handle) = params.other;

Expand Down
1 change: 1 addition & 0 deletions simnode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ frame-system = { workspace = true, default-features = true }
# parachain stuff
cumulus-client-cli = { workspace = true }
cumulus-client-collator = { workspace = true }
cumulus-client-service = { workspace = true }
parachain-inherent = { workspace = true }
sproof-builder = { workspace = true }
parachain-info = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions simnode/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ use sp_wasm_interface::ExtendedHostFunctions;
/// The simnode executor type, we use the wasm executor to force the runtime use host functions
/// instead of native code for signature verification, this in turn uses our signature verification
/// overrides.
pub type Executor = WasmExecutor<
pub type Executor = WasmExecutor<(
ExtendedHostFunctions<sp_io::SubstrateHostFunctions, SignatureVerificationOverride>,
>;
cumulus_client_service::storage_proof_size::HostFunctions,
)>;

/// Creates a [`WasmExecutor`] according to [`Configuration`].
pub fn new_wasm_executor(config: &Configuration) -> Executor {
Expand Down

0 comments on commit e96799b

Please sign in to comment.