Skip to content

Commit aa0f7d7

Browse files
authored
Merge pull request #1421 from opentensor/devnet
testnet deploy 3/17/2025
2 parents 82bba03 + 8ad06c1 commit aa0f7d7

File tree

23 files changed

+1564
-320
lines changed

23 files changed

+1564
-320
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build Localnet Docker Image
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
build:
8+
runs-on: SubtensorCI
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Set up QEMU
15+
uses: docker/setup-qemu-action@v2
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v2
19+
20+
- name: Build Docker Image
21+
run: docker build -f Dockerfile-localnet -t localnet .
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Publish Localnet Docker Image
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
branch-or-tag:
9+
description: "Branch or tag to use for the Docker image tag and ref to checkout (optional)"
10+
required: false
11+
default: ""
12+
push:
13+
branches:
14+
- devnet-ready
15+
16+
permissions:
17+
contents: read
18+
packages: write
19+
actions: read
20+
security-events: write
21+
22+
jobs:
23+
publish:
24+
runs-on: SubtensorCI
25+
26+
steps:
27+
- name: Determine Docker tag and ref
28+
id: tag
29+
run: |
30+
branch_or_tag="${{ github.event.inputs.branch-or-tag || github.ref_name }}"
31+
echo "Determined branch or tag: $branch_or_tag"
32+
echo "tag=$branch_or_tag" >> $GITHUB_ENV
33+
echo "ref=$branch_or_tag" >> $GITHUB_ENV
34+
35+
# Check if this is a tagged release (not devnet-ready/devnet/testnet)
36+
if [[ "$branch_or_tag" != "devnet-ready" ]]; then
37+
echo "latest_tag=true" >> $GITHUB_ENV
38+
else
39+
echo "latest_tag=false" >> $GITHUB_ENV
40+
fi
41+
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
with:
45+
ref: ${{ env.ref }}
46+
47+
- name: Set up QEMU
48+
uses: docker/setup-qemu-action@v2
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v2
52+
53+
- name: Login to GHCR
54+
uses: docker/login-action@v2
55+
with:
56+
registry: ghcr.io
57+
username: ${{ github.actor }}
58+
password: ${{ secrets.GITHUB_TOKEN }}
59+
60+
- name: Build and push Docker image
61+
uses: docker/build-push-action@v4
62+
with:
63+
context: .
64+
file: Dockerfile-localnet
65+
push: true
66+
platforms: linux/amd64,linux/arm64
67+
tags: |
68+
ghcr.io/${{ github.repository }}-localnet:${{ env.tag }}
69+
${{ env.latest_tag == 'true' && format('ghcr.io/{0}-localnet:latest', github.repository) || '' }}

.github/workflows/docker.yml

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ permissions:
2222
security-events: write
2323

2424
jobs:
25-
publish:
25+
publish-x86:
2626
runs-on: SubtensorCI
2727

2828
steps:
@@ -64,7 +64,53 @@ jobs:
6464
with:
6565
context: .
6666
push: true
67-
platforms: linux/amd64,linux/arm64
67+
platforms: linux/amd64
68+
tags: |
69+
ghcr.io/${{ github.repository }}:${{ env.tag }}
70+
${{ env.latest_tag == 'true' && format('ghcr.io/{0}:latest', github.repository) || '' }}
71+
publish-arm:
72+
runs-on: SubtensorCI
73+
74+
steps:
75+
- name: Determine Docker tag and ref
76+
id: tag
77+
run: |
78+
branch_or_tag="${{ github.event.inputs.branch-or-tag || github.ref_name }}"
79+
echo "Determined branch or tag: $branch_or_tag"
80+
echo "tag=$branch_or_tag" >> $GITHUB_ENV
81+
echo "ref=$branch_or_tag" >> $GITHUB_ENV
82+
83+
# Check if this is a tagged release (not devnet-ready/devnet/testnet)
84+
if [[ "${{ github.event_name }}" == "release" && "$branch_or_tag" != "devnet-ready" && "$branch_or_tag" != "devnet" && "$branch_or_tag" != "testnet" ]]; then
85+
echo "latest_tag=true" >> $GITHUB_ENV
86+
else
87+
echo "latest_tag=false" >> $GITHUB_ENV
88+
fi
89+
90+
- name: Checkout code
91+
uses: actions/checkout@v4
92+
with:
93+
ref: ${{ env.ref }}
94+
95+
- name: Set up QEMU
96+
uses: docker/setup-qemu-action@v2
97+
98+
- name: Set up Docker Buildx
99+
uses: docker/setup-buildx-action@v2
100+
101+
- name: Login to GHCR
102+
uses: docker/login-action@v2
103+
with:
104+
registry: ghcr.io
105+
username: ${{ github.actor }}
106+
password: ${{ secrets.GITHUB_TOKEN }}
107+
108+
- name: Build and push Docker image
109+
uses: docker/build-push-action@v4
110+
with:
111+
context: .
112+
push: true
113+
platforms: linux/arm64
68114
tags: |
69115
ghcr.io/${{ github.repository }}:${{ env.tag }}
70116
${{ env.latest_tag == 'true' && format('ghcr.io/{0}:latest', github.repository) || '' }}

Dockerfile-localnet

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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
8+
9+
LABEL ai.opentensor.image.authors="[email protected]" \
10+
ai.opentensor.image.vendor="Opentensor Foundation" \
11+
ai.opentensor.image.title="opentensor/subtensor-localnet" \
12+
ai.opentensor.image.description="Opentensor Subtensor Blockchain" \
13+
ai.opentensor.image.documentation="https://docs.bittensor.com"
14+
15+
# Set up Rust environment
16+
ENV RUST_BACKTRACE=1
17+
18+
RUN apt-get update
19+
RUN apt-get install -y curl build-essential protobuf-compiler clang git pkg-config libssl-dev llvm libudev-dev
20+
21+
# Copy entire repository
22+
COPY . /build
23+
WORKDIR /build
24+
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+
31+
## Build fast-blocks node
32+
RUN ./scripts/localnet.sh --build-only
33+
# Build non-fast-blocks
34+
RUN ./scripts/localnet.sh False --build-only
35+
36+
# Verify the binaries was produced
37+
RUN test -e /build/target/fast-blocks/release/node-subtensor
38+
RUN test -e /build/target/non-fast-blocks/release/node-subtensor
39+
40+
FROM $BASE_IMAGE AS subtensor-localnet
41+
42+
# Copy binaries
43+
COPY --from=builder /build/target/fast-blocks/release/node-subtensor target/fast-blocks/release/node-subtensor
44+
RUN chmod +x target/fast-blocks/release/node-subtensor
45+
46+
COPY --from=builder /build/target/non-fast-blocks/release/node-subtensor target/non-fast-blocks/release/node-subtensor
47+
RUN chmod +x target/non-fast-blocks/release/node-subtensor
48+
49+
COPY --from=builder /build/snapshot.json /snapshot.json
50+
51+
COPY --from=builder /build/scripts/localnet.sh scripts/localnet.sh
52+
RUN chmod +x /scripts/localnet.sh
53+
54+
## Ubdate certificates
55+
RUN apt-get update && apt-get install -y ca-certificates
56+
57+
# Do not build (just run)
58+
ENV BUILD_BINARY=0
59+
# Switch to local run with IP 0.0.0.0 within docker image
60+
ENV RUN_IN_DOCKER=1
61+
# Expose ports
62+
EXPOSE 30334 30335 9944 9945
63+
64+
ENTRYPOINT ["/scripts/localnet.sh"]
65+
CMD ["True"]

pallets/subtensor/runtime-api/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ sp_api::decl_runtime_apis! {
4646
fn get_stake_info_for_coldkey( coldkey_account: AccountId32 ) -> Vec<StakeInfo<AccountId32>>;
4747
fn get_stake_info_for_coldkeys( coldkey_accounts: Vec<AccountId32> ) -> Vec<(AccountId32, Vec<StakeInfo<AccountId32>>)>;
4848
fn get_stake_info_for_hotkey_coldkey_netuid( hotkey_account: AccountId32, coldkey_account: AccountId32, netuid: u16 ) -> Option<StakeInfo<AccountId32>>;
49+
fn get_stake_fee( origin: Option<(AccountId32, u16)>, origin_coldkey_account: AccountId32, destination: Option<(AccountId32, u16)>, destination_coldkey_account: AccountId32, amount: u64 ) -> u64;
4950
}
5051

5152
pub trait SubnetRegistrationRuntimeApi {

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ mod dispatches {
966966
) -> DispatchResultWithPostInfo {
967967
// Ensure it's called with root privileges (scheduler has root privileges)
968968
ensure_root(origin)?;
969-
log::info!("swap_coldkey: {:?} -> {:?}", old_coldkey, new_coldkey);
969+
log::debug!("swap_coldkey: {:?} -> {:?}", old_coldkey, new_coldkey);
970970

971971
Self::do_swap_coldkey(&old_coldkey, &new_coldkey, swap_cost)
972972
}
@@ -1389,40 +1389,42 @@ mod dispatches {
13891389
.saturating_add(T::DbWeight::get().reads(6))
13901390
.saturating_add(T::DbWeight::get().writes(31)), DispatchClass::Operational, Pays::Yes))]
13911391
pub fn schedule_dissolve_network(
1392-
origin: OriginFor<T>,
1393-
netuid: u16,
1392+
_origin: OriginFor<T>,
1393+
_netuid: u16,
13941394
) -> DispatchResultWithPostInfo {
1395-
let who = ensure_signed(origin)?;
1396-
1397-
let current_block: BlockNumberFor<T> = <frame_system::Pallet<T>>::block_number();
1398-
let duration: BlockNumberFor<T> = DissolveNetworkScheduleDuration::<T>::get();
1399-
let when: BlockNumberFor<T> = current_block.saturating_add(duration);
1400-
1401-
let call = Call::<T>::dissolve_network {
1402-
coldkey: who.clone(),
1403-
netuid,
1404-
};
1405-
1406-
let bound_call = T::Preimages::bound(LocalCallOf::<T>::from(call.clone()))
1407-
.map_err(|_| Error::<T>::FailedToSchedule)?;
1408-
1409-
T::Scheduler::schedule(
1410-
DispatchTime::At(when),
1411-
None,
1412-
63,
1413-
frame_system::RawOrigin::Root.into(),
1414-
bound_call,
1415-
)
1416-
.map_err(|_| Error::<T>::FailedToSchedule)?;
1417-
1418-
// Emit the SwapScheduled event
1419-
Self::deposit_event(Event::DissolveNetworkScheduled {
1420-
account: who.clone(),
1421-
netuid,
1422-
execution_block: when,
1423-
});
1424-
1425-
Ok(().into())
1395+
Err(Error::<T>::CallDisabled.into())
1396+
1397+
// let who = ensure_signed(origin)?;
1398+
1399+
// let current_block: BlockNumberFor<T> = <frame_system::Pallet<T>>::block_number();
1400+
// let duration: BlockNumberFor<T> = DissolveNetworkScheduleDuration::<T>::get();
1401+
// let when: BlockNumberFor<T> = current_block.saturating_add(duration);
1402+
1403+
// let call = Call::<T>::dissolve_network {
1404+
// coldkey: who.clone(),
1405+
// netuid,
1406+
// };
1407+
1408+
// let bound_call = T::Preimages::bound(LocalCallOf::<T>::from(call.clone()))
1409+
// .map_err(|_| Error::<T>::FailedToSchedule)?;
1410+
1411+
// T::Scheduler::schedule(
1412+
// DispatchTime::At(when),
1413+
// None,
1414+
// 63,
1415+
// frame_system::RawOrigin::Root.into(),
1416+
// bound_call,
1417+
// )
1418+
// .map_err(|_| Error::<T>::FailedToSchedule)?;
1419+
1420+
// // Emit the SwapScheduled event
1421+
// Self::deposit_event(Event::DissolveNetworkScheduled {
1422+
// account: who.clone(),
1423+
// netuid,
1424+
// execution_block: when,
1425+
// });
1426+
1427+
// Ok(().into())
14261428
}
14271429

14281430
/// ---- Set prometheus information for the neuron.

pallets/subtensor/src/macros/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,7 @@ mod errors {
193193
TransferDisallowed,
194194
/// Activity cutoff is being set too low.
195195
ActivityCutoffTooLow,
196+
/// Call is disabled
197+
CallDisabled,
196198
}
197199
}

pallets/subtensor/src/macros/hooks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ mod hooks {
8181
// Remove Stake map entries
8282
.saturating_add(migrations::migrate_remove_stake_map::migrate_remove_stake_map::<T>())
8383
// Remove unused maps entries
84-
.saturating_add(migrations::migrate_remove_unused_maps_and_values::migrate_remove_unused_maps_and_values::<T>());
84+
.saturating_add(migrations::migrate_remove_unused_maps_and_values::migrate_remove_unused_maps_and_values::<T>())
85+
// Migrate dissolve sn73
86+
.saturating_add(migrations::migrate_dissolve_sn73::migrate_dissolve_sn73::<T>());
8587
weight
8688
}
8789

0 commit comments

Comments
 (0)