Skip to content

Commit

Permalink
Merge pull request #527 from opentensor/hotfix/set-root-weights
Browse files Browse the repository at this point in the history
hotfix/set-root-weights
  • Loading branch information
distributedstatemachine committed Jun 14, 2024
2 parents 703bdbd + 87e47c5 commit b4ca34b
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 84 deletions.
59 changes: 5 additions & 54 deletions .github/workflows/check-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
strategy:
matrix:
rust-branch:
- nightly-2024-03-05
- stable
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
Expand Down Expand Up @@ -119,55 +119,7 @@ jobs:
strategy:
matrix:
rust-branch:
- nightly-2024-03-05
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
os:
- ubuntu-latest
# - macos-latest
include:
- os: ubuntu-latest
# - os: macos-latest
env:
RELEASE_NAME: development
# RUSTFLAGS: -A warnings
RUSTV: ${{ matrix.rust-branch }}
RUST_BACKTRACE: full
RUST_BIN_DIR: target/${{ matrix.rust-target }}
SKIP_WASM_BUILD: 1
TARGET: ${{ matrix.rust-target }}
steps:
- name: Check-out repository under $GITHUB_WORKSPACE
uses: actions/checkout@v2

- 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/toolchain@v1.0.6
with:
toolchain: ${{ matrix.rust-branch }}
components: rustfmt, clippy
profile: minimal

- name: Utilize Shared Rust Cache
uses: Swatinem/rust-cache@v2.2.1
with:
key: ${{ matrix.os }}-${{ env.RUST_BIN_DIR }}

- name: cargo clippy --workspace --all-targets --all-features -- -D warnings
run: cargo clippy --workspace --all-targets --all-features -- -D warnings

cargo-clippy-all-features:
name: cargo clippy --all-features
runs-on: SubtensorCI
strategy:
matrix:
rust-branch:
- nightly-2024-03-05
- stable
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
Expand Down Expand Up @@ -208,15 +160,14 @@ jobs:

- name: cargo clippy --workspace --all-targets --all-features -- -D warnings
run: cargo clippy --workspace --all-targets --all-features -- -D warnings

# runs cargo test --workspace
cargo-test:
name: cargo test
runs-on: SubtensorCI
strategy:
matrix:
rust-branch:
- nightly-2024-03-05
- stable
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
Expand Down Expand Up @@ -265,7 +216,7 @@ jobs:
strategy:
matrix:
rust-branch:
- nightly-2024-03-05
- stable
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
Expand Down Expand Up @@ -314,7 +265,7 @@ jobs:
strategy:
matrix:
rust-branch:
- nightly-2024-03-05
- stable
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
Expand Down
4 changes: 2 additions & 2 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct FullDeps<C, P, B> {
/// Grandpa block import setup.
pub grandpa: GrandpaDeps<B>,
/// Backend used by the node.
pub backend: Arc<B>,
pub _backend: Arc<B>,
}

/// Instantiate all full RPC extensions.
Expand Down Expand Up @@ -74,7 +74,7 @@ where
pool,
deny_unsafe,
grandpa,
backend: _,
_backend: _,
} = deps;

// Custom RPC methods for Paratensor
Expand Down
2 changes: 1 addition & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
subscription_executor: subscription_executor.clone(),
finality_provider: finality_proof_provider.clone(),
},
backend: rpc_backend.clone(),
_backend: rpc_backend.clone(),
};
crate::rpc::create_full(deps).map_err(Into::into)
},
Expand Down
1 change: 0 additions & 1 deletion pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub use weights::WeightInfo;
use sp_runtime::DispatchError;
use sp_runtime::{traits::Member, RuntimeAppPublic};

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

#[deny(missing_docs)]
Expand Down
6 changes: 2 additions & 4 deletions pallets/commitments/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#![cfg_attr(not(feature = "std"), no_std)]

mod benchmarking;
#[cfg(test)]
mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

pub mod types;
pub mod weights;

Expand Down Expand Up @@ -234,7 +232,7 @@ where
pub fn get_priority_vanilla() -> u64 {
// Return high priority so that every extrinsic except set_weights function will
// have a higher priority than the set_weights call
u64::max_value()
u64::MAX
}
}

Expand Down
1 change: 0 additions & 1 deletion pallets/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#[cfg(test)]
mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod types;
pub mod weights;
Expand Down
11 changes: 5 additions & 6 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use sp_std::marker::PhantomData;
// ============================
// ==== Benchmark Imports =====
// ============================
#[cfg(feature = "runtime-benchmarks")]
mod benchmarks;

// =========================
Expand Down Expand Up @@ -2063,7 +2062,7 @@ pub mod pallet {
let current_block_number: u64 = Self::get_current_block_as_u64();
let default_priority: u64 =
current_block_number - Self::get_last_update_for_uid(netuid, uid);
return default_priority + u32::max_value() as u64;
return default_priority + u32::MAX as u64;
}
0
}
Expand Down Expand Up @@ -2141,7 +2140,7 @@ where
pub fn get_priority_vanilla() -> u64 {
// Return high priority so that every extrinsic except set_weights function will
// have a higher priority than the set_weights call
u64::max_value()
u64::MAX
}

pub fn get_priority_set_weights(who: &T::AccountId, netuid: u16) -> u64 {
Expand Down Expand Up @@ -2219,9 +2218,9 @@ where
Err(InvalidTransaction::Call.into())
}
}
Some(Call::set_root_weights { netuid, .. }) => {
if Self::check_weights_min_stake(who) {
let priority: u64 = Self::get_priority_set_weights(who, *netuid);
Some(Call::set_root_weights { netuid, hotkey, .. }) => {
if Self::check_weights_min_stake(hotkey) {
let priority: u64 = Self::get_priority_set_weights(hotkey, *netuid);
Ok(ValidTransaction {
priority,
longevity: 1,
Expand Down
8 changes: 4 additions & 4 deletions pallets/subtensor/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,12 +1009,12 @@ impl<T: Config> Pallet<T> {
NetworkRegisteredAt::<T>::remove(netuid);

// --- 8. Remove incentive mechanism memory.
let _ = Uids::<T>::clear_prefix(netuid, u32::max_value(), None);
let _ = Keys::<T>::clear_prefix(netuid, u32::max_value(), None);
let _ = Bonds::<T>::clear_prefix(netuid, u32::max_value(), None);
let _ = Uids::<T>::clear_prefix(netuid, u32::MAX, None);
let _ = Keys::<T>::clear_prefix(netuid, u32::MAX, None);
let _ = Bonds::<T>::clear_prefix(netuid, u32::MAX, None);

// --- 8. Removes the weights for this subnet (do not remove).
let _ = Weights::<T>::clear_prefix(netuid, u32::max_value(), None);
let _ = Weights::<T>::clear_prefix(netuid, u32::MAX, None);

// --- 9. Iterate over stored weights and fill the matrix.
for (uid_i, weights_i) in
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ impl<T: Config> Pallet<T> {
return weights;
}
weights.iter_mut().for_each(|x| {
*x = (*x as u64 * u16::max_value() as u64 / sum) as u16;
*x = (*x as u64 * u16::MAX as u64 / sum) as u16;
});
weights
}
Expand Down
3 changes: 2 additions & 1 deletion pallets/subtensor/tests/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,9 @@ fn test_emission_based_on_registration_status() {
n as usize
);

let block: u64 = 0;
// drain the emission tuples for the subnet with registration on
SubtensorModule::drain_emission(next_block as u64);
SubtensorModule::drain_emission(block);
// Turn on registration for the subnet with registration off
SubtensorModule::set_network_registration_allowed(netuid_off, true);
SubtensorModule::set_network_registration_allowed(netuid_on, false);
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn normalize_weights(mut weights: Vec<u16>) -> Vec<u16> {
return weights;
}
weights.iter_mut().for_each(|x| {
*x = (*x as u64 * u16::max_value() as u64 / sum) as u16;
*x = (*x as u64 * u16::MAX as u64 / sum) as u16;
});
weights
}
Expand Down
Loading

0 comments on commit b4ca34b

Please sign in to comment.