Skip to content

Commit

Permalink
Initial subspace-gateway binary which does nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Oct 16, 2024
1 parent f1428ed commit e9876a3
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ The structure of this repository is the following:
- `crates` contains Subspace-specific Rust crates used to build node and farmer, most are following Substrate naming conventions
- `subspace-node` is an implementation of the node for Subspace protocol
- `subspace-farmer` is a CLI farmer app
- `subspace-gateway` is a Subspace Distributed Storage Network gateway
- `domains` contains client and runtime code for decoupled execution and domains
- `shared` contains low-level primitives used by the node, farmer, and other applications

## How to run

Please refer to [farming.md](/docs/farming.md) on how to run farmer.
Please refer to [farming.md](/docs/farming.md) on how to run farmer.

If you are looking to farm offline, or build from source for development purposes please refer to [development.md](/docs/development.md).
36 changes: 36 additions & 0 deletions crates/subspace-gateway/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "subspace-gateway"
version = "0.1.0"
authors = ["Teor <[email protected]>"]
description = "A Subspace Network data gateway."
edition = "2021"
license = "GPL-3.0-or-later"
build = "build.rs"
homepage = "https://subspace.network"
repository = "https://github.com/autonomys/subspace"
include = [
"/src",
"/build.rs",
"/Cargo.toml",
"/README.md"
]

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

[dependencies]
anyhow = "1.0.89"
clap = { version = "4.5.18", features = ["derive"] }
fdlimit = "0.3.0"
futures = "0.3.30"
mimalloc = "0.1.43"
sc-cli = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42", default-features = false }
sc-service = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42", default-features = false }
supports-color = "3.0.1"
thiserror = "1.0.64"
tokio = { version = "1.40.0", features = ["macros"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

[build-dependencies]
substrate-build-script-utils = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42" }
74 changes: 74 additions & 0 deletions crates/subspace-gateway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Subspace Gateway

Data Gateway implementation for Subspace Network Blockchain using [Substrate](https://docs.substrate.io/) framework.

## Getting Started

Follow these steps to get started with the Subspace Gateway :hammer_and_wrench:

## Running

It is recommended to follow general farming instructions that explain how to run both farmer and node together.

## Build from source

A Rust toolchain is required to compile this repository, but there are some extra dependencies for the gateway.

`protoc` is required for `libp2p`.

### Ubuntu

LLVM/Clang and `make` are necessary:
```bash
sudo apt-get install llvm clang cmake make protobuf-compiler
```

### macOS

1. Install via Homebrew:

```bash
brew install llvm cmake make protobuf
```

2. Add `llvm` to your `~/.zshrc` or `~/.bashrc`:

```bash
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
```

3. Activate the changes:

```bash
source ~/.zshrc
```

4. Verify that `llvm` is installed:

```bash
llvm-config --version
```

### Build

Then build the node using Cargo:
```
cargo build --profile production --bin subspace-gateway
target/production/subspace-gateway --version
```

#### Start the gateway

Start a gateway connected to a single node development chain:
```bash
target/production/subspace-gateway run \
--dev
```

### Embedded Docs

Once the project has been built, the following command can be used to explore all parameters and subcommands:

```bash
target/production/subspace-gateway --help
```
23 changes: 23 additions & 0 deletions crates/subspace-gateway/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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/>.

use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};

fn main() {
generate_cargo_keys();

rerun_if_git_head_changed();
}
74 changes: 74 additions & 0 deletions crates/subspace-gateway/src/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (C) 2024 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/>.

pub(crate) mod run;

use crate::commands::run::RunOptions;
use clap::Parser;
use tracing::level_filters::LevelFilter;
use tracing::{debug, warn};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{fmt, EnvFilter, Layer};

/// Commands for working with a gateway.
#[derive(Debug, Parser)]
#[clap(about, version)]
pub enum Command {
/// Run data gateway
Run(RunOptions),
// TODO: subcommand to run various benchmarks
}

pub(super) fn init_logger() {
// TODO: Workaround for https://github.com/tokio-rs/tracing/issues/2214, also on
// Windows terminal doesn't support the same colors as bash does
let enable_color = if cfg!(windows) {
false
} else {
supports_color::on(supports_color::Stream::Stderr).is_some()
};
tracing_subscriber::registry()
.with(
fmt::layer().with_ansi(enable_color).with_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
),
)
.init();
}

pub(super) fn raise_fd_limit() {
match fdlimit::raise_fd_limit() {
Ok(fdlimit::Outcome::LimitRaised { from, to }) => {
debug!(
"Increased file descriptor limit from previous (most likely soft) limit {} to \
new (most likely hard) limit {}",
from, to
);
}
Ok(fdlimit::Outcome::Unsupported) => {
// Unsupported platform (a platform other than Linux or macOS)
}
Err(error) => {
warn!(
"Failed to increase file descriptor limit for the process due to an error: {}.",
error
);
}
}
}
78 changes: 78 additions & 0 deletions crates/subspace-gateway/src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (C) 2024 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/>.

use clap::Parser;
use futures::FutureExt;
use sc_cli::Signals;
use sc_service::TaskManager;
use std::{env, future};
use tracing::{info, info_span};

/// Options for running a node
#[derive(Debug, Parser)]
pub struct RunOptions {
#[clap(flatten)]
gateway: GatewayOptions,
}

/// Options for running a gateway
#[derive(Debug, Parser)]
pub(super) struct GatewayOptions {
/// Set a chain specification.
#[arg(long)]
chain: Option<String>,

/// Enable development mode.
#[arg(long, verbatim_doc_comment)]
dev: bool,
}

/// Default run command for gateway
pub async fn run(run_options: RunOptions) -> anyhow::Result<()> {
let signals = Signals::capture()?;

// TODO: create config from run_options instead
let RunOptions {
gateway: GatewayOptions { chain, dev: _ },
} = run_options;

info!("Subspace Gateway");
info!("✌️ version {}", env!("SUBSTRATE_CLI_IMPL_VERSION"));
info!("❤️ by {}", env!("CARGO_PKG_AUTHORS"));
info!(
"📋 Chain specification: {}",
// TODO: the config will handle this
chain.unwrap_or("unimplemented".to_string())
);

let mut task_manager: TaskManager = {
let span = info_span!("gateway");
let _enter = span.enter();

// TODO: create a gateway service here
let gateway_fut = future::ready(Err("gateway is not yet implemented"));

gateway_fut.await.map_err(|error| {
sc_service::Error::Other(format!("Failed to build a subspace gateway: {error:?}"))
})?
};

signals
.run_until_signal(task_manager.future().fuse())
.await?;

Ok(())
}
Loading

0 comments on commit e9876a3

Please sign in to comment.