Skip to content

Commit 5929fae

Browse files
author
Samuel Dare
committed
Merge remote-tracking branch 'origin/devnet-ready' into feat/root-weights-proxy
2 parents ab0a240 + 12140e4 commit 5929fae

File tree

16 files changed

+242
-134
lines changed

16 files changed

+242
-134
lines changed

.dockerignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.devcontainer
22
.github
33
.vscode
4-
!scripts/init.sh
5-
target
4+
target/
5+
.dockerignore
6+
Dockerfile

.github/workflows/docker.yml

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,42 @@
11
name: Publish Docker Image
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
tags:
8-
- '*'
9-
pull_request:
10-
branches:
11-
- main
12-
workflow_dispatch:
4+
release:
5+
types: [published]
136

147
permissions:
15-
contents: read
16-
packages: write
17-
actions: read
18-
security-events: write
8+
contents: read
9+
packages: write
10+
actions: read
11+
security-events: write
1912

2013
jobs:
2114
publish:
2215
runs-on: SubtensorCI
23-
16+
2417
steps:
2518
- name: Checkout code
2619
uses: actions/checkout@v4
27-
20+
2821
- name: Set up QEMU
2922
uses: docker/setup-qemu-action@v2
30-
23+
3124
- name: Set up Docker Buildx
3225
uses: docker/setup-buildx-action@v2
33-
26+
3427
- name: Login to GHCR
3528
uses: docker/login-action@v2
3629
with:
3730
registry: ghcr.io
3831
username: ${{ github.actor }}
3932
password: ${{ secrets.GITHUB_TOKEN }}
40-
33+
4134
- name: Extract metadata (tags, labels) for Docker
4235
id: meta
4336
uses: docker/metadata-action@v4
4437
with:
4538
images: ghcr.io/${{ github.repository }}
46-
39+
4740
- name: Build and push Docker image
4841
uses: docker/build-push-action@v4
4942
with:
@@ -52,4 +45,4 @@ jobs:
5245
tags: |
5346
${{ steps.meta.outputs.tags }}
5447
ghcr.io/${{ github.repository }}:latest
55-
labels: ${{ steps.meta.outputs.labels }}
48+
labels: ${{ steps.meta.outputs.labels }}

Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,12 @@ codegen-units = 1
167167

168168
[features]
169169
default = []
170-
try-runtime = ["node-subtensor/try-runtime", "node-subtensor-runtime/try-runtime"]
171-
runtime-benchmarks = ["node-subtensor/runtime-benchmarks", "node-subtensor-runtime/runtime-benchmarks"]
170+
try-runtime = [
171+
"node-subtensor/try-runtime",
172+
"node-subtensor-runtime/try-runtime",
173+
]
174+
runtime-benchmarks = [
175+
"node-subtensor/runtime-benchmarks",
176+
"node-subtensor-runtime/runtime-benchmarks",
177+
]
178+
metadata-hash = ["node-subtensor-runtime/metadata-hash"]

Dockerfile

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,44 @@
1-
21
ARG BASE_IMAGE=ubuntu:20.04
32

4-
FROM $BASE_IMAGE as builder
3+
FROM $BASE_IMAGE AS builder
54
SHELL ["/bin/bash", "-c"]
65

7-
# This is being set so that no interactive components are allowed when updating.
6+
# Set noninteractive mode for apt-get
87
ARG DEBIAN_FRONTEND=noninteractive
98

109
LABEL ai.opentensor.image.authors="[email protected]" \
1110
ai.opentensor.image.vendor="Opentensor Foundation" \
1211
ai.opentensor.image.title="opentensor/subtensor" \
1312
ai.opentensor.image.description="Opentensor Subtensor Blockchain" \
14-
ai.opentensor.image.revision="${VCS_REF}" \
15-
ai.opentensor.image.created="${BUILD_DATE}" \
1613
ai.opentensor.image.documentation="https://docs.bittensor.com"
1714

18-
# show backtraces
19-
ENV RUST_BACKTRACE 1
20-
21-
# Necessary libraries for Rust execution
15+
# Set up Rust environment
16+
ENV RUST_BACKTRACE=1
2217
RUN apt-get update && \
2318
apt-get install -y curl build-essential protobuf-compiler clang git && \
2419
rm -rf /var/lib/apt/lists/*
2520

26-
# Install cargo and Rust
2721
RUN set -o pipefail && curl https://sh.rustup.rs -sSf | sh -s -- -y
2822
ENV PATH="/root/.cargo/bin:${PATH}"
23+
RUN rustup update stable
24+
RUN rustup target add wasm32-unknown-unknown --toolchain stable
2925

30-
RUN mkdir -p /subtensor && \
31-
mkdir /subtensor/scripts
32-
33-
# Scripts
34-
COPY ./scripts/init.sh /subtensor/scripts/
35-
36-
# Capture dependencies
37-
COPY Cargo.lock Cargo.toml /subtensor/
26+
# Copy entire repository
27+
COPY . /build
28+
WORKDIR /build
3829

39-
# Specs
40-
COPY ./snapshot.json /subtensor/snapshot.json
41-
COPY ./raw_spec_testfinney.json /subtensor/raw_spec_testfinney.json
42-
COPY ./raw_spec_finney.json /subtensor/raw_spec_finney.json
30+
# Build the project
31+
RUN cargo build -p node-subtensor --profile production --features="runtime-benchmarks metadata-hash" --locked
4332

44-
# Copy our sources
45-
COPY ./node /subtensor/node
46-
COPY ./pallets /subtensor/pallets
47-
COPY ./runtime /subtensor/runtime
48-
COPY ./support /subtensor/support
33+
# Verify the binary was produced
34+
RUN test -e /build/target/production/node-subtensor
4935

50-
# Copy our toolchain
51-
COPY rust-toolchain.toml /subtensor/
52-
RUN /subtensor/scripts/init.sh
53-
54-
# Cargo build
55-
WORKDIR /subtensor
56-
RUN cargo build --profile production --features runtime-benchmarks --locked
5736
EXPOSE 30333 9933 9944
5837

59-
6038
FROM $BASE_IMAGE AS subtensor
6139

62-
COPY --from=builder /subtensor/snapshot.json /
63-
COPY --from=builder /subtensor/raw_spec_testfinney.json /
64-
COPY --from=builder /subtensor/raw_spec_finney.json /
65-
COPY --from=builder /subtensor/target/production/node-subtensor /usr/local/bin
40+
# Copy all chainspec files
41+
COPY --from=builder /build/*.json /
42+
43+
# Copy final binary
44+
COPY --from=builder /build/target/production/node-subtensor /usr/local/bin

node/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ runtime-benchmarks = [
9292
"frame-system/runtime-benchmarks",
9393
"sc-service/runtime-benchmarks",
9494
"sp-runtime/runtime-benchmarks",
95-
"pallet-commitments/runtime-benchmarks"
95+
"pallet-commitments/runtime-benchmarks",
9696
]
9797
pow-faucet = []
9898

@@ -103,5 +103,7 @@ try-runtime = [
103103
"frame-system/try-runtime",
104104
"pallet-transaction-payment/try-runtime",
105105
"sp-runtime/try-runtime",
106-
"pallet-commitments/try-runtime"
106+
"pallet-commitments/try-runtime",
107107
]
108+
109+
metadata-hash = ["node-subtensor-runtime/metadata-hash"]

pallets/admin-utils/tests/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ fn test_sudo_get_set_alpha() {
12431243
DispatchError::BadOrigin
12441244
);
12451245

1246-
assert_ok!(SubtensorModule::register_network(signer.clone(), None));
1246+
assert_ok!(SubtensorModule::register_network(signer.clone()));
12471247

12481248
assert_ok!(AdminUtils::sudo_set_alpha_values(
12491249
signer.clone(),

pallets/subtensor/rpc/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ pub trait SubtensorCustomApi<BlockHash> {
4646
fn get_subnet_info(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
4747
#[method(name = "subnetInfo_getSubnetsInfo")]
4848
fn get_subnets_info(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
49+
#[method(name = "subnetInfo_getSubnetInfo_v2")]
50+
fn get_subnet_info_v2(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
51+
#[method(name = "subnetInfo_getSubnetsInf_v2")]
52+
fn get_subnets_info_v2(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
4953
#[method(name = "subnetInfo_getSubnetHyperparams")]
5054
fn get_subnet_hyperparams(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
5155

@@ -215,6 +219,26 @@ where
215219
.map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into())
216220
}
217221

222+
fn get_subnet_info_v2(
223+
&self,
224+
netuid: u16,
225+
at: Option<<Block as BlockT>::Hash>,
226+
) -> RpcResult<Vec<u8>> {
227+
let api = self.client.runtime_api();
228+
let at = at.unwrap_or_else(|| self.client.info().best_hash);
229+
230+
api.get_subnet_info_v2(at, netuid)
231+
.map_err(|e| Error::RuntimeError(format!("Unable to get subnet info: {:?}", e)).into())
232+
}
233+
234+
fn get_subnets_info_v2(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
235+
let api = self.client.runtime_api();
236+
let at = at.unwrap_or_else(|| self.client.info().best_hash);
237+
238+
api.get_subnets_info_v2(at)
239+
.map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into())
240+
}
241+
218242
fn get_network_lock_cost(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<u64> {
219243
let api = self.client.runtime_api();
220244
let at = at.unwrap_or_else(|| self.client.info().best_hash);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ sp_api::decl_runtime_apis! {
2121
pub trait SubnetInfoRuntimeApi {
2222
fn get_subnet_info(netuid: u16) -> Vec<u8>;
2323
fn get_subnets_info() -> Vec<u8>;
24+
fn get_subnet_info_v2(netuid: u16) -> Vec<u8>;
25+
fn get_subnets_info_v2() -> Vec<u8>;
2426
fn get_subnet_hyperparams(netuid: u16) -> Vec<u8>;
2527
}
2628

pallets/subtensor/src/benchmarks.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ benchmarks! {
299299
let amount: u64 = 1;
300300
let amount_to_be_staked = 100_000_000_000_000u64;
301301
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked);
302-
}: register_network(RawOrigin::Signed(coldkey), None)
302+
}: register_network(RawOrigin::Signed(coldkey))
303303

304304
benchmark_dissolve_network {
305305
let seed : u32 = 1;
@@ -311,8 +311,8 @@ benchmarks! {
311311
let amount: u64 = 1;
312312
let amount_to_be_staked = 100_000_000_000_000u64;
313313
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked);
314-
assert_ok!(Subtensor::<T>::register_network(RawOrigin::Signed(coldkey.clone()).into(), None));
315-
}: dissolve_network(RawOrigin::Signed(coldkey), 1)
314+
assert_ok!(Subtensor::<T>::register_network(RawOrigin::Signed(coldkey.clone()).into()));
315+
}: dissolve_network(RawOrigin::Root, coldkey.clone(), 1)
316316

317317

318318
// swap_hotkey {
@@ -519,6 +519,6 @@ reveal_weights {
519519
Identities::<T>::insert(&old_coldkey, identity);
520520

521521
// Benchmark setup complete, now execute the extrinsic
522-
}: swap_coldkey(RawOrigin::Signed(old_coldkey.clone()), old_coldkey.clone(), new_coldkey.clone())
522+
}: swap_coldkey(RawOrigin::Root, old_coldkey.clone(), new_coldkey.clone())
523523

524524
}

pallets/subtensor/src/coinbase/root.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ impl<T: Config> Pallet<T> {
891891
.into())
892892
}
893893

894-
/// Facilitates user registration of a new subnetwork.
894+
/// Facilitates user registration of a new subnetwork with subnet identity.
895895
///
896896
/// # Args:
897897
/// * `origin` (`T::RuntimeOrigin`): The calling origin. Must be signed.
@@ -1126,20 +1126,19 @@ impl<T: Config> Pallet<T> {
11261126
/// Removes a network (identified by netuid) and all associated parameters.
11271127
///
11281128
/// This function is responsible for cleaning up all the data associated with a network.
1129-
/// It ensures that all the storage values related to the network are removed, and any
1130-
/// reserved balance is returned to the network owner.
1129+
/// It ensures that all the storage values related to the network are removed, any
1130+
/// reserved balance is returned to the network owner, and the subnet identity is removed if it exists.
11311131
///
11321132
/// # Args:
11331133
/// * 'netuid': ('u16'): The unique identifier of the network to be removed.
11341134
///
11351135
/// # Note:
11361136
/// This function does not emit any events, nor does it raise any errors. It silently
11371137
/// returns if any internal checks fail.
1138-
///
11391138
pub fn remove_network(netuid: u16) {
11401139
// --- 1. Return balance to subnet owner.
1141-
let owner_coldkey = SubnetOwner::<T>::get(netuid);
1142-
let reserved_amount = Self::get_subnet_locked_balance(netuid);
1140+
let owner_coldkey: T::AccountId = SubnetOwner::<T>::get(netuid);
1141+
let reserved_amount: u64 = Self::get_subnet_locked_balance(netuid);
11431142

11441143
// --- 2. Remove network count.
11451144
SubnetworkN::<T>::remove(netuid);
@@ -1150,13 +1149,13 @@ impl<T: Config> Pallet<T> {
11501149
// --- 4. Remove netuid from added networks.
11511150
NetworksAdded::<T>::remove(netuid);
11521151

1153-
// --- 6. Decrement the network counter.
1154-
TotalNetworks::<T>::mutate(|n| *n = n.saturating_sub(1));
1152+
// --- 5. Decrement the network counter.
1153+
TotalNetworks::<T>::mutate(|n: &mut u16| *n = n.saturating_sub(1));
11551154

1156-
// --- 7. Remove various network-related storages.
1155+
// --- 6. Remove various network-related storages.
11571156
NetworkRegisteredAt::<T>::remove(netuid);
11581157

1159-
// --- 8. Remove incentive mechanism memory.
1158+
// --- 7. Remove incentive mechanism memory.
11601159
let _ = Uids::<T>::clear_prefix(netuid, u32::MAX, None);
11611160
let _ = Keys::<T>::clear_prefix(netuid, u32::MAX, None);
11621161
let _ = Bonds::<T>::clear_prefix(netuid, u32::MAX, None);
@@ -1171,7 +1170,7 @@ impl<T: Config> Pallet<T> {
11711170
)
11721171
{
11731172
// Create a new vector to hold modified weights.
1174-
let mut modified_weights = weights_i.clone();
1173+
let mut modified_weights: Vec<(u16, u16)> = weights_i.clone();
11751174
// Iterate over each weight entry to potentially update it.
11761175
for (subnet_id, weight) in modified_weights.iter_mut() {
11771176
if subnet_id == &netuid {
@@ -1213,6 +1212,12 @@ impl<T: Config> Pallet<T> {
12131212
Self::add_balance_to_coldkey_account(&owner_coldkey, reserved_amount);
12141213
Self::set_subnet_locked_balance(netuid, 0);
12151214
SubnetOwner::<T>::remove(netuid);
1215+
1216+
// --- 13. Remove subnet identity if it exists.
1217+
if SubnetIdentities::<T>::contains_key(netuid) {
1218+
SubnetIdentities::<T>::remove(netuid);
1219+
Self::deposit_event(Event::SubnetIdentityRemoved(netuid));
1220+
}
12161221
}
12171222

12181223
#[allow(clippy::arithmetic_side_effects)]

0 commit comments

Comments
 (0)