Unverified Commit 3d0ee437 authored by David's avatar David Committed by GitHub
Browse files

Companion PR for 'Remove substrate-in-the-browser #9541' (#3652)



* Remove telemetry external transport member

* Make it compile

* Remove more
Co-authored-by: default avatarBastian Köcher <info@kchr.de>
parent 83d18b4e
Pipeline #153200 failed with stages
in 17 minutes and 22 seconds
This diff is collapsed.
......@@ -17,8 +17,6 @@ crate-type = ["cdylib", "rlib"]
log = "0.4.13"
thiserror = "1.0.26"
structopt = { version = "0.3.21", optional = true }
wasm-bindgen = { version = "0.2.70", optional = true }
wasm-bindgen-futures = { version = "0.4.25", optional = true }
futures = "0.3.15"
service = { package = "polkadot-service", path = "../node/service", default-features = false, optional = true }
......@@ -29,7 +27,6 @@ frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", bran
try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
browser-utils = { package = "substrate-browser-utils", git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
# this crate is used only to enable `trie-memory-tracker` feature
# see https://github.com/paritytech/substrate/pull/6745
......@@ -57,12 +54,6 @@ cli = [
# is resolved.
"service/memory-stats",
]
browser = [
"wasm-bindgen",
"wasm-bindgen-futures",
"browser-utils",
"service/light-node",
]
runtime-benchmarks = [ "service/runtime-benchmarks" ]
trie-memory-tracker = [ "sp-trie/memory-tracker" ]
full-node = [ "service/full-node" ]
......
pkg
\ No newline at end of file
# How to run this demo
```sh
cargo install wasm-pack # If necessary
wasm-pack build --target web --out-dir ./browser-demo/pkg --no-typescript --release ./.. -- --no-default-features --features "browser"
xdg-open index.html
```
#!/usr/bin/env sh
wasm-pack build --target web --out-dir ./browser-demo/pkg --no-typescript --release ./.. -- --no-default-features --features "browser"
python -m http.server 8000
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>Polkadot node</title>
<link rel="shortcut icon" href="/favicon.png" />
<script type="module">
import { start_client, default as init } from './pkg/polkadot_cli.js';
function log(msg) {
document.getElementsByTagName('body')[0].innerHTML += msg + '\n';
}
async function start() {
log('Loading WASM');
await init('./pkg/polkadot_cli_bg.wasm');
log('Successfully loaded WASM');
log('Fetching chain spec');
const chain_spec_response = await fetch("https://raw.githubusercontent.com/paritytech/polkadot/master/node/service/res/westend.json");
const chain_spec_text = await chain_spec_response.text();
// Build our client.
log('Starting client');
let client = start_client(chain_spec_text, 'info');
log('Client started');
client.rpcSubscribe('{"method":"chain_subscribeNewHead","params":[],"id":1,"jsonrpc":"2.0"}',
(r) => log("New chain head: " + r));
setInterval(() => {
client
.rpcSend('{"method":"system_networkState","params":[],"id":1,"jsonrpc":"2.0"}')
.then((r) => log("Network state: " + r));
}, 20000);
}
start();
</script>
</head>
<body style="white-space: pre"></body>
</html>
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use browser_utils::{browser_configuration, init_logging, set_console_error_panic_hook, Client};
use log::info;
use wasm_bindgen::prelude::*;
/// Starts the client.
#[wasm_bindgen]
pub fn start_client(chain_spec: String, log_level: String) -> Result<Client, JsValue> {
start_inner(chain_spec, log_level).map_err(|err| JsValue::from_str(&err.to_string()))
}
fn start_inner(
chain_spec: String,
log_directives: String,
) -> Result<Client, Box<dyn std::error::Error>> {
set_console_error_panic_hook();
init_logging(&log_directives)?;
let chain_spec = service::PolkadotChainSpec::from_json_bytes(chain_spec.as_bytes().to_vec())
.map_err(|e| format!("{:?}", e))?;
let config = browser_configuration(chain_spec)?;
info!("Polkadot browser node");
info!(" version {}", config.impl_version);
info!(" by Parity Technologies, 2017-2020");
info!("📋 Chain specification: {}", config.chain_spec.name());
info!("🏷 Node name: {}", config.network.node_name);
info!("👤 Role: {}", config.display_role());
// Create the service. This is the most heavy initialization step.
let (task_manager, rpc_handlers) =
service::build_light(config).map_err(|e| format!("{:?}", e))?;
Ok(browser_utils::start_client(task_manager, rpc_handlers))
}
......@@ -240,11 +240,6 @@ fn run_node_inner(cli: Cli, overseer_gen: impl service::OverseerGen) -> Result<(
let role = config.role.clone();
match role {
#[cfg(feature = "browser")]
Role::Light => service::build_light(config)
.map(|(task_manager, _)| task_manager)
.map_err(Into::into),
#[cfg(not(feature = "browser"))]
Role::Light => Err(Error::Other("Light client not enabled".into())),
_ => service::build_full(
config,
......@@ -338,7 +333,7 @@ pub fn run() -> Result<()> {
builder.with_colors(false);
let _ = builder.init();
#[cfg(any(target_os = "android", feature = "browser"))]
#[cfg(target_os = "android")]
{
return Err(sc_cli::Error::Input(
"PVF preparation workers are not supported under this platform".into(),
......@@ -346,7 +341,7 @@ pub fn run() -> Result<()> {
.into())
}
#[cfg(not(any(target_os = "android", feature = "browser")))]
#[cfg(not(target_os = "android"))]
{
polkadot_node_core_pvf::prepare_worker_entrypoint(&cmd.socket_path);
Ok(())
......@@ -357,7 +352,7 @@ pub fn run() -> Result<()> {
builder.with_colors(false);
let _ = builder.init();
#[cfg(any(target_os = "android", feature = "browser"))]
#[cfg(target_os = "android")]
{
return Err(sc_cli::Error::Input(
"PVF execution workers are not supported under this platform".into(),
......@@ -365,7 +360,7 @@ pub fn run() -> Result<()> {
.into())
}
#[cfg(not(any(target_os = "android", feature = "browser")))]
#[cfg(not(target_os = "android"))]
{
polkadot_node_core_pvf::execute_worker_entrypoint(&cmd.socket_path);
Ok(())
......
......@@ -18,8 +18,6 @@
#![warn(missing_docs)]
#[cfg(feature = "browser")]
mod browser;
#[cfg(feature = "cli")]
mod cli;
#[cfg(feature = "cli")]
......
......@@ -181,7 +181,6 @@ pub fn node_config(
rpc_methods: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
telemetry_external_transport: None,
default_heap_pages: None,
offchain_worker: Default::default(),
force_authoring: false,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment