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

Commit

Permalink
Add some modifications for cirrus development (paritytech#143)
Browse files Browse the repository at this point in the history
* Separate out subspace-primitives from subspace-runtime

* Introduce `NewFull` struct in subspace-node

Also expose the `service` module in public.

* Make subspace-node a library
  • Loading branch information
liuchengxu authored Nov 22, 2021
1 parent bc48573 commit ff9c6f9
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 106 deletions.
47 changes: 18 additions & 29 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ env:
jobs:
cargo-fmt:
runs-on: ubuntu-20.04
strategy:
matrix:
rust:
- nightly

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Rust toolchain
uses: actions-rs/toolchain@v1
# TODO: Below can be removed when https://github.com/actions-rs/toolchain/issues/126 is resolved
with:
toolchain: ${{ matrix.rust }}
toolchain: nightly
target: wasm32-unknown-unknown
override: true
components: rustfmt, clippy
Expand All @@ -33,9 +30,7 @@ jobs:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ matrix.rust }}-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: cargo fmt
uses: actions-rs/cargo@v1
Expand All @@ -50,8 +45,6 @@ jobs:
- ubuntu-20.04
- macos-11
- windows-2019
rust:
- nightly

runs-on: ${{ matrix.os }}

Expand All @@ -61,8 +54,9 @@ jobs:

- name: Rust toolchain
uses: actions-rs/toolchain@v1
# TODO: Below can be removed when https://github.com/actions-rs/toolchain/issues/126 is resolved
with:
toolchain: ${{ matrix.rust }}
toolchain: nightly
target: wasm32-unknown-unknown
override: true
components: rustfmt, clippy
Expand All @@ -85,21 +79,19 @@ jobs:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ matrix.os }}-cargo-${{ matrix.rust }}-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ matrix.os }}-cargo-
key: ${{ matrix.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: cargo clippy (Linux or Windows with CUDA)
uses: actions-rs/cargo@v1
uses: actions-rs/clippy-check@v1
with:
command: clippy
token: ${{ secrets.GITHUB_TOKEN }}
args: --features=subspace-farmer/cuda -- -D warnings
if: runner.os != 'macOS'

- name: cargo clippy (macOS)
uses: actions-rs/cargo@v1
uses: actions-rs/clippy-check@v1
with:
command: clippy
token: ${{ secrets.GITHUB_TOKEN }}
args: -- -D warnings
if: runner.os == 'macOS'

Expand All @@ -110,8 +102,6 @@ jobs:
- ubuntu-20.04
- macos-11
- windows-2019
rust:
- nightly

runs-on: ${{ matrix.os }}

Expand All @@ -121,8 +111,9 @@ jobs:

- name: Rust toolchain
uses: actions-rs/toolchain@v1
# TODO: Below can be removed when https://github.com/actions-rs/toolchain/issues/126 is resolved
with:
toolchain: ${{ matrix.rust }}
toolchain: nightly
target: wasm32-unknown-unknown
override: true
components: rustfmt, clippy
Expand All @@ -137,27 +128,25 @@ jobs:
id: cuda-toolkit
with:
cuda: '11.2.2'
if: runner.os != 'macOS'
if: runner.os == 'Linux'

- name: Configure cache
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ matrix.os }}-cargo-${{ matrix.rust }}-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ matrix.os }}-cargo-
key: ${{ matrix.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: cargo test (Linux or Windows with CUDA)
- name: cargo test (Linux with CUDA)
uses: actions-rs/cargo@v1
with:
command: test
args: --features=subspace-farmer/cuda
if: runner.os != 'macOS'
if: runner.os == 'Linux'

- name: cargo test (macOS)
- name: cargo test (macOS or Windows)
uses: actions-rs/cargo@v1
with:
command: test
if: runner.os == 'macOS'
if: runner.os == 'macOS' || runner.os == 'Windows'
4 changes: 2 additions & 2 deletions .github/workflows/rustdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
- name: Build Documentation
run: cargo doc --all --no-deps --lib
env:
RUSTC_BOOTSTRAP: 1
RUSTDOCFLAGS: "-Z unstable-options --enable-index-page"
RUSTC_BOOTSTRAP: 1
RUSTDOCFLAGS: "-Z unstable-options --enable-index-page"

- name: Deploy Docs
uses: JamesIves/github-pages-deploy-action@releases/v3
Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/subspace-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ include = [
"/README.md"
]

[[bin]]
name = "subspace-node"
path = "bin/main.rs"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

Expand All @@ -32,6 +36,7 @@ sc-consensus-subspace-rpc = { version = "0.1.0", path = "../sc-consensus-subspac
sc-consensus-slots = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "26d69bcbe26f6b463e9374e1b1c54c3067fb6131" }
sc-consensus-uncles = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "26d69bcbe26f6b463e9374e1b1c54c3067fb6131" }
sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "26d69bcbe26f6b463e9374e1b1c54c3067fb6131", features = ["wasmtime"] }
sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "26d69bcbe26f6b463e9374e1b1c54c3067fb6131" }
sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "26d69bcbe26f6b463e9374e1b1c54c3067fb6131" }
sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "26d69bcbe26f6b463e9374e1b1c54c3067fb6131" }
sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "26d69bcbe26f6b463e9374e1b1c54c3067fb6131", features = ["wasmtime"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@

#![warn(missing_docs)]

mod chain_spec;
#[macro_use]
mod service;
mod cli;
mod command;
mod rpc;

fn main() -> sc_cli::Result<()> {
command::run()
subspace_node::run()
}
34 changes: 24 additions & 10 deletions crates/subspace-node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use sc_cli::RunCmd;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
pub struct Cli {
#[structopt(subcommand)]
pub subcommand: Option<Subcommand>,
//! Subspace CLI library.

#[structopt(flatten)]
pub run: RunCmd,
}
use structopt::StructOpt;

/// Utilities for working with a node.
#[derive(Debug, StructOpt)]
pub enum Subcommand {
/// Key management cli utilities
Key(sc_cli::KeySubcommand),

/// Build a chain specification.
BuildSpec(sc_cli::BuildSpecCmd),

Expand All @@ -55,3 +49,23 @@ pub enum Subcommand {
#[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
}

/// Command used to run a Subspace node.
#[derive(Debug, StructOpt)]
pub struct RunCmd {
/// Base command to run a node.
#[structopt(flatten)]
pub base: sc_cli::RunCmd,
}

/// Subspace Cli.
#[derive(Debug, StructOpt)]
pub struct Cli {
/// Various utility commands.
#[structopt(subcommand)]
pub subcommand: Option<Subcommand>,

/// Run a node.
#[structopt(flatten)]
pub run: RunCmd,
}
6 changes: 4 additions & 2 deletions crates/subspace-node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ pub fn run() -> sc_cli::Result<()> {
}
}
None => {
let runner = cli.create_runner(&cli.run)?;
let runner = cli.create_runner(&cli.run.base)?;
runner.run_node_until_exit(|config| async move {
service::new_full(config).map_err(sc_cli::Error::Service)
service::new_full(config)
.map(|full| full.task_manager)
.map_err(sc_cli::Error::Service)
})
}
}
Expand Down
28 changes: 28 additions & 0 deletions crates/subspace-node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2021 Subspace Labs, Inc.
// SPDX-License-Identifier: GPL-3.0-or-later

// This program 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.

// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.

//! Subspace Node library.

#![warn(missing_docs)]

mod chain_spec;
#[macro_use]
pub mod service;
pub mod cli;
mod command;
mod rpc;

pub use self::command::run;
39 changes: 31 additions & 8 deletions crates/subspace-node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::sync::Arc;
use subspace_runtime::opaque::BlockId;
use subspace_runtime::{self, opaque::Block, RuntimeApi};

// Our native executor instance.
/// Subspace native executor instance.
pub struct ExecutorDispatch;

impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
Expand All @@ -46,11 +46,13 @@ impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
}
}

type FullClient =
/// Subspace full client.
pub type FullClient =
sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;

/// Creates `PartialComponents` for Subspace client.
#[allow(clippy::type_complexity)]
pub fn new_partial(
config: &Configuration,
Expand Down Expand Up @@ -161,8 +163,22 @@ pub fn new_partial(
})
}

/// Full client along with some other components.
pub struct NewFull<C> {
/// Task manager.
pub task_manager: TaskManager,
/// Full client.
pub client: C,
/// Network.
pub network: Arc<sc_network::NetworkService<Block, <Block as BlockT>::Hash>>,
/// RPC handlers.
pub rpc_handlers: sc_service::RpcHandlers,
/// Full client backend.
pub backend: Arc<FullBackend>,
}

/// Builds a new service for a full client.
pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
pub fn new_full(config: Configuration) -> Result<NewFull<Arc<FullClient>>, ServiceError> {
let sc_service::PartialComponents {
client,
backend,
Expand Down Expand Up @@ -291,21 +307,28 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
})
};

let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
network,
client,
let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
network: network.clone(),
client: client.clone(),
keystore: keystore_container.sync_keystore(),
task_manager: &mut task_manager,
transaction_pool,
rpc_extensions_builder,
on_demand: None,
remote_blockchain: None,
backend,
backend: backend.clone(),
system_rpc_tx,
config,
telemetry: telemetry.as_mut(),
})?;

network_starter.start_network();
Ok(task_manager)

Ok(NewFull {
task_manager,
client,
network,
rpc_handlers,
backend,
})
}
Loading

0 comments on commit ff9c6f9

Please sign in to comment.