Skip to content

Commit 6b86ebf

Browse files
authored
Merge pull request #1484 from opentensor/testnet
mainnet deploy 4/10/2025
2 parents 719a6f5 + 1df522d commit 6b86ebf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4132
-850
lines changed

.github/workflows/docker.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ jobs:
6666
push: true
6767
platforms: linux/amd64
6868
tags: |
69-
ghcr.io/${{ github.repository }}:${{ env.tag }}
70-
${{ env.latest_tag == 'true' && format('ghcr.io/{0}:latest', github.repository) || '' }}
69+
ghcr.io/${{ github.repository }}:${{ env.tag }}-amd64
70+
${{ env.latest_tag == 'true' && format('ghcr.io/{0}:latest-amd64', github.repository) || '' }}
7171
publish-arm:
7272
runs-on: SubtensorCI
7373

@@ -112,5 +112,5 @@ jobs:
112112
push: true
113113
platforms: linux/arm64
114114
tags: |
115-
ghcr.io/${{ github.repository }}:${{ env.tag }}
116-
${{ env.latest_tag == 'true' && format('ghcr.io/{0}:latest', github.repository) || '' }}
115+
ghcr.io/${{ github.repository }}:${{ env.tag }}-arm64
116+
${{ env.latest_tag == 'true' && format('ghcr.io/{0}:latest-arm64', github.repository) || '' }}

Cargo.lock

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ futures = "0.3.30"
6767
hex = { version = "0.4", default-features = false }
6868
hex-literal = "0.4.1"
6969
jsonrpsee = { version = "0.24.4", default-features = false }
70+
libsecp256k1 = { version = "0.7.2", default-features = false }
7071
log = { version = "0.4.21", default-features = false }
7172
memmap2 = "0.9.4"
7273
ndarray = { version = "0.15.6", default-features = false }

Dockerfile

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,62 @@
1-
ARG BASE_IMAGE=ubuntu:latest
2-
3-
FROM $BASE_IMAGE AS builder
4-
SHELL ["/bin/bash", "-c"]
5-
6-
# Set noninteractive mode for apt-get
7-
ARG DEBIAN_FRONTEND=noninteractive
1+
ARG BASE_IMAGE=rust:1.83
2+
FROM $BASE_IMAGE AS base_builder
83

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

10+
RUN rustup update stable
11+
RUN rustup target add wasm32-unknown-unknown --toolchain stable
12+
13+
1514
# Set up Rust environment
1615
ENV RUST_BACKTRACE=1
17-
RUN apt-get update && \
18-
apt-get install -y curl build-essential protobuf-compiler clang git pkg-config libssl-dev && \
19-
rm -rf /var/lib/apt/lists/*
16+
RUN apt-get update && apt-get install -y curl build-essential protobuf-compiler clang git pkg-config libssl-dev
17+
RUN rm -rf /var/lib/apt/lists/*
2018

2119
# Copy entire repository
2220
COPY . /build
2321
WORKDIR /build
2422

25-
# Install Rust
26-
RUN set -o pipefail && curl https://sh.rustup.rs -sSf | sh -s -- -y
27-
ENV PATH="/root/.cargo/bin:${PATH}"
28-
RUN rustup toolchain install
29-
RUN rustup target add wasm32-unknown-unknown
30-
23+
#
24+
# Image for building prod
25+
#
26+
FROM base_builder AS prod_builder
3127
# Build the project
3228
RUN cargo build -p node-subtensor --profile production --features="metadata-hash" --locked
33-
34-
# Slim down image
35-
RUN rm -rf /root/.cargo
36-
3729
# Verify the binary was produced
3830
RUN test -e /build/target/production/node-subtensor
39-
4031
EXPOSE 30333 9933 9944
4132

33+
#
34+
# Final prod image
35+
#
4236
FROM $BASE_IMAGE AS subtensor
43-
4437
# Copy all chainspec files
45-
COPY --from=builder /build/chainspecs/*.json /
38+
COPY --from=prod_builder /build/*.json /
39+
# Copy final binary
40+
COPY --from=prod_builder /build/target/production/node-subtensor /usr/local/bin
41+
42+
43+
#
44+
# Image for building local
45+
#
46+
FROM base_builder AS local_builder
47+
# Build the project
48+
RUN cargo build --workspace --profile release --features="pow-faucet"
49+
# Verify the binary was produced
50+
RUN test -e /build/target/release/node-subtensor
51+
EXPOSE 30333 9933 9944
4652

53+
54+
#
55+
# Final local image
56+
#
57+
FROM $BASE_IMAGE AS subtensor-local
58+
# Copy all chainspec files
59+
COPY --from=local_builder /build/*.json /
4760
# Copy final binary
48-
COPY --from=builder /build/target/production/node-subtensor /usr/local/bin
61+
COPY --from=local_builder /build/target/release/node-subtensor /usr/local/bin
62+
RUN "node-subtensor" build-spec --disable-default-bootnode --raw --chain local > /localnet.json

docker-compose.localnet.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
volumes:
2+
subtensor-alice:
3+
subtensor-bob:
4+
5+
services:
6+
common: &common
7+
image: ghcr.io/opentensor/subtensor:latest-local
8+
cpu_count: 4
9+
mem_limit: 40000000000
10+
memswap_limit: 80000000000
11+
environment:
12+
- CARGO_HOME=/var/www/node-subtensor/.cargo
13+
14+
alice:
15+
<<: *common
16+
container_name: subtensor-alice
17+
build:
18+
context: .
19+
dockerfile: Dockerfile
20+
target: subtensor-local
21+
ports:
22+
- "9944:9944"
23+
- "30334:30334"
24+
expose:
25+
- 9944
26+
- 30334
27+
volumes:
28+
- subtensor-alice:/tmp/blockchain
29+
command:
30+
- /bin/bash
31+
- -c
32+
- |
33+
node-subtensor \
34+
--base-path /tmp/blockchain \
35+
--chain localnet.json \
36+
--rpc-external \
37+
--rpc-methods=unsafe \
38+
--alice \
39+
--port 30334 \
40+
--rpc-port 9944 \
41+
--validator \
42+
--rpc-cors=all \
43+
--allow-private-ipv4 \
44+
--discover-local \
45+
--unsafe-force-node-key-generation
46+
47+
bob:
48+
<<: *common
49+
container_name: subtensor-bob
50+
expose:
51+
- 9945
52+
- 30335
53+
ports:
54+
- "9945:9945"
55+
- "30335:30335"
56+
volumes:
57+
- subtensor-bob:/tmp/blockchain
58+
command:
59+
- /bin/bash
60+
- -c
61+
- |
62+
node-subtensor \
63+
--base-path /tmp/blockchain \
64+
--chain localnet.json \
65+
--bob \
66+
--rpc-methods=unsafe \
67+
--rpc-external \
68+
--port 30335 \
69+
--rpc-port 9945 \
70+
--validator \
71+
--rpc-cors=all \
72+
--allow-private-ipv4 \
73+
--discover-local \
74+
--unsafe-force-node-key-generation

docs/running-subtensor-locally.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
11
# Running subtensor node locally
22

3-
See the [**Subtensor Nodes** section in Bittensor Developer Documentation](https://docs.bittensor.com/subtensor-nodes).
3+
For General information on running Subtensors, see
4+
[**Subtensor Nodes** section in Bittensor Developer Documentation](https://docs.bittensor.com/subtensor-nodes).
5+
6+
### Running a localnet subtensor node
7+
8+
Running a localnet in docker compose is the easiest way to quickly iterate on
9+
chain state, like building on the evm.
10+
11+
1. install docker and docker compose, along with cloning this repository.
12+
13+
1. build the images from source on the desired branch using
14+
`docker compose -f docker-compose.localnet.yml build`. Note this will take
15+
quite a while.
16+
17+
1. Run the docker compose file via
18+
`docker compose -f docker-compose.localnet.yml up -d`
19+
20+
Now you should have a full local validator running. To test your connection, you
21+
can use the following script to check `//Alice`'s balance. Alice is a sudo
22+
account in localnet.
23+
24+
```py
25+
# pip install substrate-interface
26+
from substrateinterface import Keypair, SubstrateInterface
27+
28+
substrate = SubstrateInterface(url="ws://127.0.0.1:9945")
29+
hotkey = Keypair.create_from_uri('//Alice')
30+
result = substrate.query("System", "Account", [hotkey.ss58_address])
31+
print(result.value)
32+
```

evm-tests/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const ETH_LOCAL_URL = 'http://localhost:9944'
22
export const SUB_LOCAL_URL = 'ws://localhost:9944'
33
export const SS58_PREFIX = 42;
44
// set the tx timeout as 2 second when eable the fast-blocks feature.
5-
export const TX_TIMEOUT = 2000;
5+
export const TX_TIMEOUT = 3000;
66

77
export const IED25519VERIFY_ADDRESS = "0x0000000000000000000000000000000000000402";
88
export const IEd25519VerifyABI = [

evm-tests/src/contracts/staking.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,30 @@ export const IStakingV2ABI = [
137137
"stateMutability": "payable",
138138
"type": "function"
139139
},
140+
{
141+
"inputs": [
142+
{
143+
"internalType": "bytes32",
144+
"name": "hotkey",
145+
"type": "bytes32"
146+
},
147+
{
148+
"internalType": "uint256",
149+
"name": "netuid",
150+
"type": "uint256"
151+
}
152+
],
153+
"name": "getAlphaStakedValidators",
154+
"outputs": [
155+
{
156+
"internalType": "uint256[]",
157+
"name": "",
158+
"type": "uint256[]"
159+
}
160+
],
161+
"stateMutability": "view",
162+
"type": "function"
163+
},
140164
{
141165
"inputs": [
142166
{
@@ -166,6 +190,30 @@ export const IStakingV2ABI = [
166190
"stateMutability": "view",
167191
"type": "function"
168192
},
193+
{
194+
"inputs": [
195+
{
196+
"internalType": "bytes32",
197+
"name": "hotkey",
198+
"type": "bytes32"
199+
},
200+
{
201+
"internalType": "uint256",
202+
"name": "netuid",
203+
"type": "uint256"
204+
}
205+
],
206+
"name": "getTotalAlphaStaked",
207+
"outputs": [
208+
{
209+
"internalType": "uint256",
210+
"name": "",
211+
"type": "uint256"
212+
}
213+
],
214+
"stateMutability": "view",
215+
"type": "function"
216+
},
169217
{
170218
"inputs": [
171219
{

0 commit comments

Comments
 (0)