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

Commit

Permalink
fix: Add missing host functions to ChainSpec (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
code0xff authored Feb 2, 2024
1 parent 2f7b897 commit 68cef43
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 27 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ sp-std = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release
sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
sp-transaction-pool = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
sp-version = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
sp-wasm-interface = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0" }
substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0" }
Expand Down
2 changes: 2 additions & 0 deletions template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ sp-block-builder = { workspace = true }
sp-core = { workspace = true }
sp-consensus-aura = { workspace = true }
sp-consensus-grandpa = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-session = { workspace = true }
sp-timestamp = { workspace = true }
sp-transaction-pool = { workspace = true }
sp-wasm-interface = { workspace = true }
substrate-frame-rpc-system = { workspace = true }

# Horizon
Expand Down
13 changes: 5 additions & 8 deletions template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use horizon_template_runtime::{AccountId, RuntimeGenesisConfig, Signature, WASM_BINARY};
use sc_chain_spec::NoExtension;
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_consensus_grandpa::AuthorityId as GrandpaId;
Expand All @@ -27,7 +28,8 @@ use sp_runtime::traits::{IdentifyAccount, Verify};
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";

/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig>;
pub type ChainSpec =
sc_service::GenericChainSpec<RuntimeGenesisConfig, NoExtension, hp_io::crypto::HostFunctions>;

/// Generate a crypto pair from seed.
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
Expand Down Expand Up @@ -107,15 +109,10 @@ fn testnet_genesis(
_enable_println: bool,
) -> serde_json::Value {
serde_json::json!({
// Configure endowed accounts with initial balance of (1 << 52) - (1 << 50).
"balances": {
"balances": endowed_accounts
.iter()
.cloned()
.map(|k| (k, (1u64 << 52) - (1u64 << 50)))
.collect::<Vec<_>>(),
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::<Vec<_>>(),
},
"cosmos_accounts": {
"cosmosAccounts": {
"accounts": endowed_accounts.iter().cloned().map(|k| k.clone()).collect::<Vec<_>>(),
},
"aura": {
Expand Down
26 changes: 7 additions & 19 deletions template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,18 @@ use horizon_template_runtime::{self, opaque::Block, RuntimeApi};
use sc_client_api::{Backend, BlockBackend};
use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams};
use sc_consensus_grandpa::SharedVoterState;
pub use sc_executor::NativeElseWasmExecutor;
use sc_executor::WasmExecutor;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager, WarpSyncParams};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use std::{sync::Arc, time::Duration};

// Our native executor instance.
pub struct ExecutorDispatch;

impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
type ExtendHostFunctions = hp_io::crypto::HostFunctions;

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
horizon_template_runtime::api::dispatch(method, data)
}

fn native_version() -> sc_executor::NativeVersion {
horizon_template_runtime::native_version()
}
}

pub(crate) type FullClient =
sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
pub(crate) type FullClient = sc_service::TFullClient<
Block,
RuntimeApi,
WasmExecutor<(sp_io::SubstrateHostFunctions, hp_io::crypto::HostFunctions)>,
>;
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;

Expand Down Expand Up @@ -85,7 +73,7 @@ pub fn new_partial(
})
.transpose()?;

let executor = sc_service::new_native_or_wasm_executor(config);
let executor = sc_service::new_wasm_executor(config);

let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
Expand Down

0 comments on commit 68cef43

Please sign in to comment.