Skip to content

Commit

Permalink
Merge branch 'main' into refactor/hotkey_swap
Browse files Browse the repository at this point in the history
  • Loading branch information
distributedstatemachine committed Jul 2, 2024
2 parents 5ad3567 + ce6793d commit 3b1d766
Show file tree
Hide file tree
Showing 67 changed files with 104,876 additions and 256,240 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/update-chainspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Update Chainspecs

concurrency:
group: update-chainspec-${{ github.ref }}
cancel-in-progress: true

on:
push:
branches: [main, testnet, staging, staging-ready]

workflow_dispatch:
inputs:
verbose:
description: "Output more information when triggered manually"
required: false
default: ""

env:
CARGO_TERM_COLOR: always
VERBOSE: ${{ github.events.input.verbose }}

jobs:
update-chainspecs:
runs-on: SubtensorCI
permissions:
contents: write

strategy:
matrix:
rust-branch:
- nightly-2024-03-05
rust-target:
- x86_64-unknown-linux-gnu
os:
- ubuntu-latest
include:
- os: ubuntu-latest
env:
RELEASE_NAME: development
RUSTV: ${{ matrix.rust-branch }}
RUST_BACKTRACE: full
RUST_BIN_DIR: target/${{ matrix.rust-target }}
TARGET: ${{ matrix.rust-target }}
steps:
- name: Check-out repository under $GITHUB_WORKSPACE
uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get update &&
sudo apt-get install -y clang curl libssl-dev llvm libudev-dev protobuf-compiler
- name: Install Rust ${{ matrix.rust-branch }}
uses: actions-rs/toolchain@v1.0.6
with:
toolchain: ${{ matrix.rust-branch }}
components: rustfmt, clippy
profile: minimal

- name: Utilize Shared Rust Cache
uses: Swatinem/rust-cache@v2.2.1
with:
key: ${{ matrix.os }}-${{ env.RUST_BIN_DIR }}

- name: Build chainspecs
run: ./scripts/build_all_chainspecs.sh

- uses: stefanzweifel/git-auto-commit-action@v5
name: Commit any updated chainspecs
with:
commit_message: Update chainspecs
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ members = [
resolver = "2"

[workspace.lints.clippy]
indexing-slicing = "deny"
arithmetic-side-effects = "deny"
type_complexity = "allow"
unwrap-used = "deny"

[workspace.dependencies]
cargo-husky = { version = "1", default-features = false }
Expand Down
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ COPY Cargo.lock Cargo.toml /subtensor/

# Specs
COPY ./snapshot.json /subtensor/snapshot.json
COPY ./raw_spec.json /subtensor/raw_spec.json
COPY ./raw_testspec.json /subtensor/raw_testspec.json
COPY ./raw_spec_testfinney.json /subtensor/raw_spec_testfinney.json
COPY ./raw_spec_finney.json /subtensor/raw_spec_finney.json

# Copy our sources
COPY ./node /subtensor/node
Expand All @@ -52,13 +52,13 @@ RUN /subtensor/scripts/init.sh

# Cargo build
WORKDIR /subtensor
RUN cargo build --release --features runtime-benchmarks --locked
RUN cargo build --profile production --features runtime-benchmarks --locked
EXPOSE 30333 9933 9944


FROM $BASE_IMAGE AS subtensor

COPY --from=builder /subtensor/snapshot.json /
COPY --from=builder /subtensor/raw_spec.json /
COPY --from=builder /subtensor/raw_testspec.json /
COPY --from=builder /subtensor/target/release/node-subtensor /usr/local/bin
COPY --from=builder /subtensor/raw_spec_testfinney.json /
COPY --from=builder /subtensor/raw_spec_finney.json /
COPY --from=builder /subtensor/target/production/node-subtensor /usr/local/bin
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.8'
version: "3.8"

volumes:
mainnet-lite-volume:
Expand Down Expand Up @@ -38,7 +38,7 @@ services:
- |
node-subtensor \
--base-path /tmp/blockchain \
--chain raw_spec.json \
--chain raw_spec_finney.json \
--rpc-external --rpc-cors all \
--no-mdns \
--in-peers 500 --out-peers 500 \
Expand All @@ -56,7 +56,7 @@ services:
- |
node-subtensor \
--base-path /tmp/blockchain \
--chain raw_spec.json \
--chain raw_spec_finney.json \
--rpc-external --rpc-cors all \
--no-mdns \
--in-peers 500 --out-peers 500 \
Expand All @@ -74,7 +74,7 @@ services:
- |
node-subtensor \
--base-path /tmp/blockchain \
--chain raw_testspec.json \
--chain raw_spec_testfinney.json \
--rpc-external --rpc-cors all \
--no-mdns \
--in-peers 500 --out-peers 500 \
Expand All @@ -94,7 +94,7 @@ services:
- |
node-subtensor \
--base-path /tmp/blockchain \
--chain raw_testspec.json \
--chain raw_spec_testfinney.json \
--rpc-external --rpc-cors all \
--no-mdns \
--in-peers 500 --out-peers 500 \
Expand Down
11 changes: 6 additions & 5 deletions docs/running-subtensor-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ rm -rf /tmp/blockchain
Install subtensor by compiling with `cargo`:

```bash
cargo build --release --features=runtime-benchmarks
cargo build --profile production --features=runtime-benchmarks
```

## Run the subtensor node
Expand All @@ -174,32 +174,33 @@ You can now run the public subtensor node either as a lite node or as an archive
To run a lite node connected to the mainchain, execute the below command (note the `--sync=warp` flag which runs the subtensor node in lite mode):

```bash title="With --sync=warp setting, for lite node"
./target/release/node-subtensor --chain raw_spec.json --base-path /tmp/blockchain --sync=warp --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /ip4/13.58.175.193/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
./target/production/node-subtensor --chain raw_spec.json --base-path /tmp/blockchain --sync=warp --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /ip4/13.58.175.193/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
```

### Archive node on mainchain

To run an archive node connected to the mainchain, execute the below command (note the `--sync=full` which syncs the node to the full chain and `--pruning archive` flags, which disables the node's automatic pruning of older historical data):

```bash title="With --sync=full and --pruning archive setting, for archive node"
./target/release/node-subtensor --chain raw_spec.json --base-path /tmp/blockchain --sync=full --pruning archive --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /ip4/13.58.175.193/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
./target/production/node-subtensor --chain raw_spec.json --base-path /tmp/blockchain --sync=full --pruning archive --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /ip4/13.58.175.193/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
```

### Lite node on testchain

To run a lite node connected to the testchain, execute the below command:

```bash title="With bootnodes set to testnet and --sync=warp setting, for lite node."
./target/release/node-subtensor --chain raw_testspec.json --base-path /tmp/blockchain --sync=warp --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
./target/production/node-subtensor --chain raw_testspec.json --base-path /tmp/blockchain --sync=warp --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
```

### Archive node on testchain

To run an archive node connected to the testchain, execute the below command:

```bash title="With bootnodes set to testnet and --sync=full and --pruning archive setting, for archive node"
./target/release/node-subtensor --chain raw_testspec.json --base-path /tmp/blockchain --sync=full --pruning archive --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
./target/production/node-subtensor --chain raw_testspec.json --base-path /tmp/blockchain --sync=full --pruning archive --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
```

## Running on cloud

We have not tested these installation scripts on any cloud service. In addition, if you are using Runpod cloud service, then note that this service is already [containerized](https://docs.runpod.io/pods/overview). Hence, the only option available to you is to compile from the source, as described in the above [Method 2: Using Source Code](#method-2-using-source-code) section. Note that these scripts have not been tested on Runpod.
6 changes: 3 additions & 3 deletions docs/rust-setup.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
title: Installation
---

This guide is for reference only, please check the latest information on getting starting with Substrate
This guide is for reference only, please check the latest information on getting starting with Substrate
[here](https://docs.substrate.io/main-docs/install/).

This page will guide you through the **2 steps** needed to prepare a computer for **Substrate** development.
Expand Down Expand Up @@ -207,7 +206,7 @@ Use the `WASM_BUILD_TOOLCHAIN` environment variable to specify the Rust nightly
project should use for Wasm compilation:

```bash
WASM_BUILD_TOOLCHAIN=nightly-<yyyy-MM-dd> cargo build --release
WASM_BUILD_TOOLCHAIN=nightly-<yyyy-MM-dd> cargo build --profile production
```

> Note that this only builds _the runtime_ with the specified nightly. The rest of project will be
Expand All @@ -223,3 +222,4 @@ rustup uninstall nightly
rustup install nightly-<yyyy-MM-dd>
rustup target add wasm32-unknown-unknown --toolchain nightly-<yyyy-MM-dd>
```

103,931 changes: 0 additions & 103,931 deletions finney_plain_spec.json

This file was deleted.

6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export RUST_BACKTRACE := "full"
export SKIP_WASM_BUILD := "1"
export RUST_BIN_DIR := "target/x86_64-unknown-linux-gnu"
export TARGET := "x86_64-unknown-linux-gnu"
export RUSTV := "nightly-2024-03-05"
export RUSTV := "stable"
export RELEASE_NAME := "development"

fmt:
Expand All @@ -25,13 +25,13 @@ benchmarks:

clippy:
@echo "Running cargo clippy..."
cargo +{{RUSTV}} clippy -- -D clippy::panic \
cargo +{{RUSTV}} clippy --workspace --all-targets -- -D \
-D clippy::todo \
-D clippy::unimplemented

clippy-fix:
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
cargo +{{RUSTV}} clippy --fix --allow-dirty -- -A clippy::panic \
cargo +{{RUSTV}} clippy --fix --allow-dirty --workspace --all-targets -- -A \
-A clippy::todo \
-A clippy::unimplemented
fix:
Expand Down
18 changes: 13 additions & 5 deletions node/src/chain_spec/finney.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;

pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
let path: PathBuf = std::path::PathBuf::from("./snapshot.json");
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
let wasm_binary = WASM_BINARY.ok_or("Development wasm not available".to_string())?;

// We mmap the file into memory first, as this is *a lot* faster than using
// `serde_json::from_reader`. See https://github.com/serde-rs/json/issues/160
Expand Down Expand Up @@ -53,14 +53,16 @@ pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
let key_account = sp_runtime::AccountId32::from(key);

processed_balances.push((key_account, *amount));
balances_issuance += *amount;
balances_issuance = balances_issuance
.checked_add(*amount)
.ok_or("Balances issuance overflowed".to_string())?;
}

// Give front-ends necessary data to present to users
let mut properties = sc_service::Properties::new();
properties.insert("tokenSymbol".into(), "TAO".into());
properties.insert("tokenDecimals".into(), 9.into());
properties.insert("ss58Format".into(), 13116.into());
properties.insert("ss58Format".into(), 42.into());

Ok(ChainSpec::builder(
wasm_binary,
Expand All @@ -70,8 +72,14 @@ pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
},
)
.with_name("Bittensor")
.with_protocol_id("bittensor")
.with_id("bittensor")
.with_chain_type(ChainType::Live)
.with_boot_nodes(vec![
"/dns/bootnode.finney.chain.opentensor.ai/tcp/30333/ws/p2p/12D3KooWRwbMb85RWnT8DSXSYMWQtuDwh4LJzndoRrTDotTR5gDC"
.parse()
.unwrap(),
])
.with_genesis_config_patch(finney_genesis(
// Initial PoA authorities (Validators)
// aura | grandpa
Expand Down Expand Up @@ -191,9 +199,9 @@ fn finney_genesis(
.collect::<Vec<_>>(),
},
"sudo": { "key": Some(<AccountId32 as Ss58Codec>::from_ss58check("5FCM3DBXWiGcwYYQtT8z4ZD93TqYpYxjaAfgv6aMStV1FTCT").unwrap()) },
"subtensor_module": {
"subtensorModule": {
"stakes": stakes,
"balances_issuance": balances_issuance,
"balancesIssuance": balances_issuance,
}
})
}
3 changes: 2 additions & 1 deletion node/src/chain_spec/localnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn localnet_config() -> Result<ChainSpec, String> {
let mut properties = sc_service::Properties::new();
properties.insert("tokenSymbol".into(), "TAO".into());
properties.insert("tokenDecimals".into(), 9.into());
properties.insert("ss58Format".into(), 13116.into());
properties.insert("ss58Format".into(), 42.into());

Ok(ChainSpec::builder(
wasm_binary,
Expand All @@ -26,6 +26,7 @@ pub fn localnet_config() -> Result<ChainSpec, String> {
},
)
.with_name("Bittensor")
.with_protocol_id("bittensor")
.with_id("bittensor")
.with_chain_type(ChainType::Development)
.with_genesis_config_patch(localnet_genesis(
Expand Down
14 changes: 11 additions & 3 deletions node/src/chain_spec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
};

let old_state: ColdkeyHotkeys =
json::from_slice(&bytes).map_err(|e| format!("Error parsing genesis file: {}", e))?;
json::from_slice(&bytes).map_err(|e| format!("Error parsing genesis file: {e}"))?;

let mut processed_stakes: Vec<(
sp_runtime::AccountId32,
Expand Down Expand Up @@ -53,14 +53,16 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
let key_account = sp_runtime::AccountId32::from(key);

processed_balances.push((key_account, *amount));
balances_issuance += *amount;
balances_issuance = balances_issuance
.checked_add(*amount)
.ok_or("Balances issuance overflowed".to_string())?;
}

// Give front-ends necessary data to present to users
let mut properties = sc_service::Properties::new();
properties.insert("tokenSymbol".into(), "TAO".into());
properties.insert("tokenDecimals".into(), 9.into());
properties.insert("ss58Format".into(), 13116.into());
properties.insert("ss58Format".into(), 42.into());

Ok(ChainSpec::builder(
wasm_binary,
Expand All @@ -70,6 +72,12 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
},
)
.with_name("Bittensor")
.with_boot_nodes(vec![
"/dns/bootnode.test.chain.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr"
.parse()
.unwrap(),
])
.with_protocol_id("bittensor")
.with_id("bittensor")
.with_chain_type(ChainType::Development)
.with_genesis_config_patch(testnet_genesis(
Expand Down
Loading

0 comments on commit 3b1d766

Please sign in to comment.