Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macos docker builds and add compose file for local subtensor #1122

Open
wants to merge 4 commits into
base: devnet-ready
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 39 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,64 @@
ARG BASE_IMAGE=ubuntu:24.04
ARG BASE_IMAGE=rust:1.83

FROM $BASE_IMAGE AS builder
SHELL ["/bin/bash", "-c"]

# Set noninteractive mode for apt-get
ARG DEBIAN_FRONTEND=noninteractive
FROM $BASE_IMAGE AS base_builder

LABEL ai.opentensor.image.authors="[email protected]" \
ai.opentensor.image.vendor="Opentensor Foundation" \
ai.opentensor.image.title="opentensor/subtensor" \
ai.opentensor.image.description="Opentensor Subtensor Blockchain" \
ai.opentensor.image.documentation="https://docs.bittensor.com"

# Set up Rust environment
ENV RUST_BACKTRACE=1
RUN apt-get update && \
apt-get install -y curl build-essential protobuf-compiler clang git pkg-config libssl-dev && \
rm -rf /var/lib/apt/lists/*

RUN set -o pipefail && curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup update stable
RUN rustup target add wasm32-unknown-unknown --toolchain stable


# Set up Rust environment
ENV RUST_BACKTRACE=1
RUN apt-get update && apt-get install -y protobuf-compiler curl clang git
RUN rm -rf /var/lib/apt/lists/*

# Copy entire repository
COPY . /build
WORKDIR /build


#
# Image for building prod
#
FROM base_builder as prod_builder
# Build the project
RUN cargo build -p node-subtensor --profile production --features="metadata-hash" --locked

# Verify the binary was produced
RUN test -e /build/target/production/node-subtensor

EXPOSE 30333 9933 9944

#
# Final prod image
#
FROM $BASE_IMAGE AS subtensor

# Copy all chainspec files
COPY --from=builder /build/chainspecs/*.json /
COPY --from=prod_builder /build/*.json /
# Copy final binary
COPY --from=prod_builder /build/target/production/node-subtensor /usr/local/bin


#
# Image for building local
#
FROM base_builder as local_builder
# Build the project
RUN cargo build --workspace --profile release --features="pow-faucet"
# Verify the binary was produced
RUN test -e /build/target/release/node-subtensor
EXPOSE 30333 9933 9944


#
# Final local image
#
FROM $BASE_IMAGE AS subtensor-local
# Copy all chainspec files
COPY --from=local_builder /build/*.json /
# Copy final binary
COPY --from=builder /build/target/production/node-subtensor /usr/local/bin
COPY --from=local_builder /build/target/release/node-subtensor /usr/local/bin
RUN "node-subtensor" build-spec --disable-default-bootnode --raw --chain local > /localnet.json
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Requirements:

---

## For Subnet Development
## For Subnet Development

If you are developing and testing subnet incentive mechanism, you will need to run a local subtensor node. Follow the detailed step-by-step instructions provided in the [**Subtensor Nodes** section in Bittensor Developer Documentation](https://docs.bittensor.com/subtensor-nodes).

Expand Down Expand Up @@ -216,7 +216,7 @@ If you want to see the multi-node consensus algorithm in action, refer to our
A Substrate project such as this consists of a number of components that are spread across a few
directories.

### Node Capabilities
### Node Capabilities

A blockchain node is an application that allows users to participate in a blockchain network.
Substrate-based blockchain nodes expose a number of capabilities:
Expand All @@ -232,7 +232,7 @@ Substrate-based blockchain nodes expose a number of capabilities:

**Directory structure**

There are several files in the [`node`](./node/) directory. Make a note of the following important files:
There are several files in the [`node`](./node/) directory. Make a note of the following important files:

- [`chain_spec.rs`](./node/src/chain_spec.rs): A
[chain specification](https://docs.substrate.io/main-docs/build/chain-spec/) is a
Expand Down
74 changes: 74 additions & 0 deletions docker-compose.localnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
volumes:
subtensor-alice:
subtensor-bob:

services:
common: &common
image: ghcr.io/opentensor/subtensor:latest-local
cpu_count: 4
mem_limit: 40000000000
memswap_limit: 80000000000
environment:
- CARGO_HOME=/var/www/node-subtensor/.cargo

alice:
<<: *common
container_name: subtensor-alice
build:
context: .
dockerfile: Dockerfile
target: subtensor-local
ports:
- "9944:9944"
- "30334:30334"
expose:
- 9944
- 30334
volumes:
- subtensor-alice:/tmp/blockchain
command:
- /bin/bash
- -c
- |
node-subtensor \
--base-path /tmp/blockchain \
--chain localnet.json \
--rpc-external \
--rpc-methods=unsafe \
--alice \
--port 30334 \
--rpc-port 9944 \
--validator \
--rpc-cors=all \
--allow-private-ipv4 \
--discover-local \
--unsafe-force-node-key-generation

bob:
<<: *common
container_name: subtensor-bob
expose:
- 9945
- 30335
ports:
- "9945:9945"
- "30335:30335"
volumes:
- subtensor-bob:/tmp/blockchain
command:
- /bin/bash
- -c
- |
node-subtensor \
--base-path /tmp/blockchain \
--chain localnet.json \
--bob \
--rpc-methods=unsafe \
--rpc-external \
--port 30335 \
--rpc-port 9945 \
--validator \
--rpc-cors=all \
--allow-private-ipv4 \
--discover-local \
--unsafe-force-node-key-generation
31 changes: 30 additions & 1 deletion docs/running-subtensor-locally.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# Running subtensor node locally

See the [**Subtensor Nodes** section in Bittensor Developer Documentation](https://docs.bittensor.com/subtensor-nodes).
For General information on running Subtensors, see
[**Subtensor Nodes** section in Bittensor Developer Documentation](https://docs.bittensor.com/subtensor-nodes).

### Running a localnet subtensor node

Running a localnet in docker compose is the easiest way to quickly iterate on
chain state, like building on the evm.

1. install docker and docker compose, along with cloning this repository.

1. build the images from source on the desired branch using
`docker compose -f docker-compose.localnet.yml build`. Note this will take
quite a while.

1. Run the docker compose file via
`docker compose -f docker-compose.localnet.yml up -d`

Now you should have a full local validator running. To test your connection, you
can use the following script to check `//Alice`'s balance. Alice is a sudo
account in localnet.

```py
# pip install substrate-interface
from substrateinterface import Keypair, SubstrateInterface

substrate = SubstrateInterface(url="ws://127.0.0.1:9945")
hotkey = Keypair.create_from_uri('//Alice')
result = substrate.query("System", "Account", [hotkey.ss58_address])
print(result.value)
```