Skip to content

Commit

Permalink
Merge devnet-ready to feat/rao-devnet-ready
Browse files Browse the repository at this point in the history
  • Loading branch information
gztensor committed Oct 31, 2024
2 parents d4196f8 + 2ad1381 commit 7bceea7
Show file tree
Hide file tree
Showing 27 changed files with 3,727 additions and 628 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/cargo-audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: cargo audit
on:
pull_request:
types:
- labeled
- unlabeled
- synchronize
concurrency:
group: cargo-audit-${{ github.ref }}
cancel-in-progress: true

jobs:
cargo-audit:
name: cargo audit
runs-on: SubtensorCI
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-cargo-audit') }}
steps:
- name: Check-out repositoroy under $GITHUB_WORKSPACE
uses: actions/checkout@v4

- 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 Stable
uses: actions-rs/[email protected]
with:
toolchain: stable
components: rustfmt, clippy
profile: minimal

- name: Utilize Shared Rust Cache
uses: Swatinem/[email protected]
with:
key: ubuntu-latest-${{ env.RUST_BIN_DIR }}

- name: Install cargo-audit
run: cargo install cargo-audit

- name: cargo audit
run: cargo audit --ignore RUSTSEC-2024-0336 # rustls issue; wait for upstream to resolve this
15 changes: 0 additions & 15 deletions .github/workflows/check-devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,3 @@ jobs:
echo "network spec_version: $spec_version"
if (( $(echo "$local_spec_version <= $spec_version" | bc -l) )); then echo "$local_spec_version ≯ $spec_version ❌"; exit 1; fi
echo "$local_spec_version > $spec_version ✅"
check-devnet-migrations:
name: check devnet migrations
runs-on: ubuntu-22.04
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Run Try Runtime Checks
uses: "paritytech/[email protected]"
with:
runtime-package: "node-subtensor-runtime"
node-uri: "wss://dev.chain.opentensor.ai:443"
checks: "pre-and-post"
extra-args: "--disable-spec-version-check --no-weight-warnings"
14 changes: 0 additions & 14 deletions .github/workflows/check-finney.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,3 @@ jobs:
echo "network spec_version: $spec_version"
if (( $(echo "$local_spec_version <= $spec_version" | bc -l) )); then echo "$local_spec_version ≯ $spec_version ❌"; exit 1; fi
echo "$local_spec_version > $spec_version ✅"
check-finney-migrations:
name: check finney migrations
runs-on: SubtensorCI
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Run Try Runtime Checks
uses: "paritytech/[email protected]"
with:
runtime-package: "node-subtensor-runtime"
node-uri: "wss://entrypoint-finney.opentensor.ai:443"
checks: "pre-and-post"
extra-args: "--disable-spec-version-check --no-weight-warnings"
40 changes: 0 additions & 40 deletions .github/workflows/check-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,46 +208,6 @@ jobs:

- name: cargo clippy --workspace --all-targets --all-features -- -D warnings
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
# runs cargo audit
cargo-audit:
name: cargo audit
runs-on: SubtensorCI
strategy:
matrix:
rust-branch:
- stable
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
os:
- ubuntu-latest
# - macos-latest
steps:
- name: Check-out repositoroy under $GITHUB_WORKSPACE
uses: actions/checkout@v4

- 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/[email protected]
with:
toolchain: ${{ matrix.rust-branch }}
components: rustfmt, clippy
profile: minimal

- name: Utilize Shared Rust Cache
uses: Swatinem/[email protected]
with:
key: ${{ matrix.os }}-${{ env.RUST_BIN_DIR }}

- name: Install cargo-audit
run: cargo install cargo-audit

- name: cargo audit
run: cargo audit --ignore RUSTSEC-2024-0336 # rustls issue; wait for upstream to resolve this

# runs cargo test --workspace
cargo-test:
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/check-testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,3 @@ jobs:
echo "network spec_version: $spec_version"
if (( $(echo "$local_spec_version <= $spec_version" | bc -l) )); then echo "$local_spec_version ≯ $spec_version ❌"; exit 1; fi
echo "$local_spec_version > $spec_version ✅"
check-testnet-migrations:
name: check testnet migrations
runs-on: ubuntu-22.04
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Run Try Runtime Checks
uses: "paritytech/[email protected]"
with:
runtime-package: "node-subtensor-runtime"
node-uri: "wss://test.chain.opentensor.ai:443"
checks: "pre-and-post"
extra-args: "--disable-spec-version-check --no-weight-warnings"
54 changes: 54 additions & 0 deletions .github/workflows/try-runtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Try Runtime

on:
pull_request:
branches: [main, devnet-ready, devnet, testnet, finney]
types: [labeled, unlabeled, synchronize]

env:
CARGO_TERM_COLOR: always

jobs:
check-devnet:
name: check devnet
runs-on: SubtensorCI
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Run Try Runtime Checks
uses: "paritytech/[email protected]"
with:
runtime-package: "node-subtensor-runtime"
node-uri: "wss://dev.chain.opentensor.ai:443"
checks: "all"
extra-args: "--disable-spec-version-check --no-weight-warnings"

check-testnet:
name: check testnet
runs-on: SubtensorCI
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Run Try Runtime Checks
uses: "paritytech/[email protected]"
with:
runtime-package: "node-subtensor-runtime"
node-uri: "wss://test.chain.opentensor.ai:443"
checks: "all"
extra-args: "--disable-spec-version-check --no-weight-warnings"

check-finney:
name: check finney
runs-on: SubtensorCI
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Run Try Runtime Checks
uses: "paritytech/[email protected]"
with:
runtime-package: "node-subtensor-runtime"
node-uri: "wss://archive.chain.opentensor.ai:443"
checks: "all"
extra-args: "--disable-spec-version-check --no-weight-warnings"
4 changes: 2 additions & 2 deletions pallets/admin-utils/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@ mod benchmarks {
}

#[benchmark]
fn sudo_set_commit_reveal_weights_interval() {
fn sudo_set_commit_reveal_weights_periods() {
pallet_subtensor::Pallet::<T>::init_new_network(
1u16, /*netuid*/
1u16, /*sudo_tempo*/
);

#[extrinsic_call]
_(RawOrigin::Root, 1u16/*netuid*/, 3u64/*interval*/)/*set_commit_reveal_weights_interval()*/;
_(RawOrigin::Root, 1u16/*netuid*/, 3u64/*interval*/)/*set_commit_reveal_weights_periods()*/;
}

#[benchmark]
Expand Down
65 changes: 39 additions & 26 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,32 +960,6 @@ pub mod pallet {
Ok(())
}

/// The extrinsic sets the commit/reveal interval for a subnet.
/// It is only callable by the root account or subnet owner.
/// The extrinsic will call the Subtensor pallet to set the interval.
#[pallet::call_index(48)]
#[pallet::weight(T::WeightInfo::sudo_set_commit_reveal_weights_interval())]
pub fn sudo_set_commit_reveal_weights_interval(
origin: OriginFor<T>,
netuid: u16,
interval: u64,
) -> DispatchResult {
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;

ensure!(
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
Error::<T>::SubnetDoesNotExist
);

pallet_subtensor::Pallet::<T>::set_commit_reveal_weights_interval(netuid, interval);
log::debug!(
"SetWeightCommitInterval( netuid: {:?}, interval: {:?} ) ",
netuid,
interval
);
Ok(())
}

/// The extrinsic enabled/disables commit/reaveal for a given subnet.
/// It is only callable by the root account or subnet owner.
/// The extrinsic will call the Subtensor pallet to set the value.
Expand Down Expand Up @@ -1161,6 +1135,45 @@ pub mod pallet {

Ok(())
}

/// Sets the commit-reveal weights periods for a specific subnet.
///
/// This extrinsic allows the subnet owner or root account to set the duration (in epochs) during which committed weights must be revealed.
/// The commit-reveal mechanism ensures that users commit weights in advance and reveal them only within a specified period.
///
/// # Arguments
/// * `origin` - The origin of the call, which must be the subnet owner or the root account.
/// * `netuid` - The unique identifier of the subnet for which the periods are being set.
/// * `periods` - The number of epochs that define the commit-reveal period.
///
/// # Errors
/// * `BadOrigin` - If the caller is neither the subnet owner nor the root account.
/// * `SubnetDoesNotExist` - If the specified subnet does not exist.
///
/// # Weight
/// Weight is handled by the `#[pallet::weight]` attribute.
#[pallet::call_index(56)]
#[pallet::weight(T::WeightInfo::sudo_set_commit_reveal_weights_periods())]
pub fn sudo_set_commit_reveal_weights_periods(
origin: OriginFor<T>,
netuid: u16,
periods: u64,
) -> DispatchResult {
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;

ensure!(
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
Error::<T>::SubnetDoesNotExist
);

pallet_subtensor::Pallet::<T>::set_reveal_period(netuid, periods);
log::debug!(
"SetWeightCommitPeriods( netuid: {:?}, periods: {:?} ) ",
netuid,
periods
);
Ok(())
}
}
}

Expand Down
24 changes: 12 additions & 12 deletions pallets/admin-utils/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub trait WeightInfo {
fn sudo_set_min_burn() -> Weight;
fn sudo_set_network_registration_allowed() -> Weight;
fn sudo_set_tempo() -> Weight;
fn sudo_set_commit_reveal_weights_interval() -> Weight;
fn sudo_set_commit_reveal_weights_periods() -> Weight;
fn sudo_set_commit_reveal_weights_enabled() -> Weight;
}

Expand Down Expand Up @@ -413,12 +413,12 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
fn sudo_set_commit_reveal_weights_interval() -> Weight {
fn sudo_set_commit_reveal_weights_periods() -> Weight {
// Proof Size summary in bytes:
// Measured: `1111`
// Estimated: `4697`
// Minimum execution time: 46_450_000 picoseconds.
Weight::from_parts(47_279_000, 4697)
// Measured: `456`
// Estimated: `3921`
// Minimum execution time: 19_070_000 picoseconds.
Weight::from_parts(19_380_000, 456)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
Expand Down Expand Up @@ -781,17 +781,17 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
fn sudo_set_commit_reveal_weights_interval() -> Weight {
fn sudo_set_commit_reveal_weights_periods() -> Weight {
// -- Extrinsic Time --
// Model:
// Time ~= 20.42
// µs
// Time ~= 19.38
// µs
// Reads = 1
// Writes = 1
// Recorded proof Size = 456
Weight::from_parts(20_420_000, 456)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
Weight::from_parts(19_380_000, 456)
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
fn sudo_set_commit_reveal_weights_enabled() -> Weight {
// -- Extrinsic Time --
Expand Down
Loading

0 comments on commit 7bceea7

Please sign in to comment.