Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2491,9 +2491,9 @@ fn test_trim_to_max_allowed_uids() {
ValidatorPermit::<Test>::insert(netuid, bool_values.clone());
Active::<Test>::insert(netuid, bool_values);

for mecid in 0..mechanism_count.into() {
for mechid in 0..mechanism_count.into() {
let netuid_index =
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mecid));
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mechid));
Incentive::<Test>::insert(netuid_index, values.clone());
LastUpdate::<Test>::insert(netuid_index, u64_values.clone());
}
Expand Down Expand Up @@ -2548,9 +2548,9 @@ fn test_trim_to_max_allowed_uids() {
}
}

for mecid in 0..mechanism_count.into() {
for mechid in 0..mechanism_count.into() {
let netuid_index =
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mecid));
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mechid));
Weights::<Test>::insert(netuid_index, uid, weights.clone());
Bonds::<Test>::insert(netuid_index, uid, bonds.clone());
}
Expand Down Expand Up @@ -2596,9 +2596,9 @@ fn test_trim_to_max_allowed_uids() {
assert_eq!(ValidatorPermit::<Test>::get(netuid), expected_bools);
assert_eq!(StakeWeight::<Test>::get(netuid), expected_values);

for mecid in 0..mechanism_count.into() {
for mechid in 0..mechanism_count.into() {
let netuid_index =
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mecid));
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mechid));
assert_eq!(Incentive::<Test>::get(netuid_index), expected_values);
assert_eq!(LastUpdate::<Test>::get(netuid_index), expected_u64_values);
}
Expand All @@ -2608,9 +2608,9 @@ fn test_trim_to_max_allowed_uids() {
assert!(!Keys::<Test>::contains_key(netuid, uid));
assert!(!BlockAtRegistration::<Test>::contains_key(netuid, uid));
assert!(!AssociatedEvmAddress::<Test>::contains_key(netuid, uid));
for mecid in 0..mechanism_count.into() {
for mechid in 0..mechanism_count.into() {
let netuid_index =
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mecid));
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mechid));
assert!(!Weights::<Test>::contains_key(netuid_index, uid));
assert!(!Bonds::<Test>::contains_key(netuid_index, uid));
}
Expand Down Expand Up @@ -2643,9 +2643,9 @@ fn test_trim_to_max_allowed_uids() {

// Ensure trimmed uids weights and bonds connections have been trimmed correctly
for uid in 0..new_max_n {
for mecid in 0..mechanism_count.into() {
for mechid in 0..mechanism_count.into() {
let netuid_index =
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mecid));
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mechid));
assert!(
Weights::<Test>::get(netuid_index, uid)
.iter()
Expand Down
12 changes: 6 additions & 6 deletions pallets/subtensor/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub trait SubtensorCustomApi<BlockHash> {
fn get_mechagraph(
&self,
netuid: NetUid,
mecid: MechId,
mechid: MechId,
at: Option<BlockHash>,
) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getSubnetState")]
Expand All @@ -103,7 +103,7 @@ pub trait SubtensorCustomApi<BlockHash> {
fn get_selective_mechagraph(
&self,
netuid: NetUid,
mecid: MechId,
mechid: MechId,
metagraph_index: Vec<u16>,
at: Option<BlockHash>,
) -> RpcResult<Vec<u8>>;
Expand Down Expand Up @@ -391,12 +391,12 @@ where
fn get_mechagraph(
&self,
netuid: NetUid,
mecid: MechId,
mechid: MechId,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<Vec<u8>> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);
match api.get_mechagraph(at, netuid, mecid) {
match api.get_mechagraph(at, netuid, mechid) {
Ok(result) => Ok(result.encode()),
Err(e) => Err(Error::RuntimeError(format!(
"Unable to get dynamic subnets info: {e:?}"
Expand Down Expand Up @@ -502,14 +502,14 @@ where
fn get_selective_mechagraph(
&self,
netuid: NetUid,
mecid: MechId,
mechid: MechId,
metagraph_index: Vec<u16>,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<Vec<u8>> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);

match api.get_selective_mechagraph(at, netuid, mecid, metagraph_index) {
match api.get_selective_mechagraph(at, netuid, mechid, metagraph_index) {
Ok(result) => Ok(result.encode()),
Err(e) => {
Err(Error::RuntimeError(format!("Unable to get selective metagraph: {e:?}")).into())
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sp_api::decl_runtime_apis! {
fn get_all_metagraphs() -> Vec<Option<Metagraph<AccountId32>>>;
fn get_metagraph(netuid: NetUid) -> Option<Metagraph<AccountId32>>;
fn get_all_mechagraphs() -> Vec<Option<Metagraph<AccountId32>>>;
fn get_mechagraph(netuid: NetUid, mecid: MechId) -> Option<Metagraph<AccountId32>>;
fn get_mechagraph(netuid: NetUid, mechid: MechId) -> Option<Metagraph<AccountId32>>;
fn get_dynamic_info(netuid: NetUid) -> Option<DynamicInfo<AccountId32>>;
fn get_subnet_state(netuid: NetUid) -> Option<SubnetState<AccountId32>>;
fn get_selective_metagraph(netuid: NetUid, metagraph_indexes: Vec<u16>) -> Option<SelectiveMetagraph<AccountId32>>;
Expand Down
6 changes: 3 additions & 3 deletions pallets/subtensor/src/coinbase/reveal_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ impl<T: Config> Pallet<T> {

// All mechanisms share the same epoch, so the reveal_period/reveal_epoch are also the same
// Reveal for all mechanisms
for mecid in 0..MechanismCountCurrent::<T>::get(netuid).into() {
let netuid_index = Self::get_mechanism_storage_index(netuid, mecid.into());
for mechid in 0..MechanismCountCurrent::<T>::get(netuid).into() {
let netuid_index = Self::get_mechanism_storage_index(netuid, mechid.into());

// Clean expired commits
for (epoch, _) in TimelockedWeightCommits::<T>::iter_prefix(netuid_index) {
Expand Down Expand Up @@ -180,7 +180,7 @@ impl<T: Config> Pallet<T> {
if let Err(e) = Self::do_set_mechanism_weights(
T::RuntimeOrigin::signed(who.clone()),
netuid,
MechId::from(mecid),
MechId::from(mechid),
uids,
values,
version_key,
Expand Down
26 changes: 13 additions & 13 deletions pallets/subtensor/src/epoch/run_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ impl<T: Config> Pallet<T> {
/// Persists per-mechanism epoch output in state
pub fn persist_mechanism_epoch_terms(
netuid: NetUid,
mecid: MechId,
mechid: MechId,
output: &BTreeMap<T::AccountId, EpochTerms>,
) {
let netuid_index = Self::get_mechanism_storage_index(netuid, mecid);
let netuid_index = Self::get_mechanism_storage_index(netuid, mechid);
let mut terms_sorted: sp_std::vec::Vec<&EpochTerms> = output.values().collect();
terms_sorted.sort_unstable_by_key(|t| t.uid);

Expand Down Expand Up @@ -145,11 +145,11 @@ impl<T: Config> Pallet<T> {
#[allow(clippy::indexing_slicing)]
pub fn epoch_dense_mechanism(
netuid: NetUid,
mecid: MechId,
mechid: MechId,
rao_emission: AlphaCurrency,
) -> Vec<(T::AccountId, AlphaCurrency, AlphaCurrency)> {
// Calculate netuid storage index
let netuid_index = Self::get_mechanism_storage_index(netuid, mecid);
let netuid_index = Self::get_mechanism_storage_index(netuid, mechid);

// Get subnetwork size.
let n: u16 = Self::get_subnetwork_n(netuid);
Expand Down Expand Up @@ -558,11 +558,11 @@ impl<T: Config> Pallet<T> {
///
pub fn epoch_mechanism(
netuid: NetUid,
mecid: MechId,
mechid: MechId,
rao_emission: AlphaCurrency,
) -> EpochOutput<T> {
// Calculate netuid storage index
let netuid_index = Self::get_mechanism_storage_index(netuid, mecid);
let netuid_index = Self::get_mechanism_storage_index(netuid, mechid);

// Initialize output keys (neuron hotkeys) and UIDs
let mut terms_map: BTreeMap<T::AccountId, EpochTerms> = Keys::<T>::iter_prefix(netuid)
Expand Down Expand Up @@ -1061,7 +1061,7 @@ impl<T: Config> Pallet<T> {

/// Output unnormalized sparse weights, input weights are assumed to be row max-upscaled in u16.
pub fn get_weights_sparse(netuid_index: NetUidStorageIndex) -> Vec<Vec<(u16, I32F32)>> {
let (netuid, _) = Self::get_netuid_and_subid(netuid_index).unwrap_or_default();
let (netuid, _) = Self::get_netuid_and_mechid(netuid_index).unwrap_or_default();
let n = Self::get_subnetwork_n(netuid) as usize;
let mut weights: Vec<Vec<(u16, I32F32)>> = vec![vec![]; n];
for (uid_i, weights_i) in
Expand All @@ -1080,7 +1080,7 @@ impl<T: Config> Pallet<T> {

/// Output unnormalized weights in [n, n] matrix, input weights are assumed to be row max-upscaled in u16.
pub fn get_weights(netuid_index: NetUidStorageIndex) -> Vec<Vec<I32F32>> {
let (netuid, _) = Self::get_netuid_and_subid(netuid_index).unwrap_or_default();
let (netuid, _) = Self::get_netuid_and_mechid(netuid_index).unwrap_or_default();
let n = Self::get_subnetwork_n(netuid) as usize;
let mut weights: Vec<Vec<I32F32>> = vec![vec![I32F32::saturating_from_num(0.0); n]; n];
for (uid_i, weights_vec) in
Expand All @@ -1103,7 +1103,7 @@ impl<T: Config> Pallet<T> {

/// Output unnormalized sparse bonds, input bonds are assumed to be column max-upscaled in u16.
pub fn get_bonds_sparse(netuid_index: NetUidStorageIndex) -> Vec<Vec<(u16, I32F32)>> {
let (netuid, _) = Self::get_netuid_and_subid(netuid_index).unwrap_or_default();
let (netuid, _) = Self::get_netuid_and_mechid(netuid_index).unwrap_or_default();
let n = Self::get_subnetwork_n(netuid) as usize;
let mut bonds: Vec<Vec<(u16, I32F32)>> = vec![vec![]; n];
for (uid_i, bonds_vec) in
Expand All @@ -1126,7 +1126,7 @@ impl<T: Config> Pallet<T> {

/// Output unnormalized bonds in [n, n] matrix, input bonds are assumed to be column max-upscaled in u16.
pub fn get_bonds(netuid_index: NetUidStorageIndex) -> Vec<Vec<I32F32>> {
let (netuid, _) = Self::get_netuid_and_subid(netuid_index).unwrap_or_default();
let (netuid, _) = Self::get_netuid_and_mechid(netuid_index).unwrap_or_default();
let n: usize = Self::get_subnetwork_n(netuid) as usize;
let mut bonds: Vec<Vec<I32F32>> = vec![vec![I32F32::saturating_from_num(0.0); n]; n];
for (uid_i, bonds_vec) in
Expand Down Expand Up @@ -1188,7 +1188,7 @@ impl<T: Config> Pallet<T> {
bonds: &[Vec<(u16, I32F32)>],
netuid_index: NetUidStorageIndex,
) -> Vec<Vec<(u16, I32F32)>> {
let (netuid, _) = Self::get_netuid_and_subid(netuid_index).unwrap_or_default();
let (netuid, _) = Self::get_netuid_and_mechid(netuid_index).unwrap_or_default();

// Retrieve the bonds moving average for the given network ID and scale it down.
let bonds_moving_average: I64F64 =
Expand Down Expand Up @@ -1301,7 +1301,7 @@ impl<T: Config> Pallet<T> {
bonds: &[Vec<(u16, I32F32)>],
consensus: &[I32F32],
) -> Vec<Vec<(u16, I32F32)>> {
let (netuid, _) = Self::get_netuid_and_subid(netuid_index).unwrap_or_default();
let (netuid, _) = Self::get_netuid_and_mechid(netuid_index).unwrap_or_default();

// Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values.
if LiquidAlphaOn::<T>::get(netuid)
Expand Down Expand Up @@ -1537,7 +1537,7 @@ impl<T: Config> Pallet<T> {
netuid_index: NetUidStorageIndex,
account_id: &T::AccountId,
) -> Result<(), DispatchError> {
let (netuid, _) = Self::get_netuid_and_subid(netuid_index).unwrap_or_default();
let (netuid, _) = Self::get_netuid_and_mechid(netuid_index).unwrap_or_default();

// check bonds reset enabled for this subnet
let bonds_reset_enabled: bool = Self::get_bonds_reset(netuid);
Expand Down
30 changes: 15 additions & 15 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod dispatches {
/// * `netuid` (u16):
/// - The network uid we are setting these weights on.
///
/// * `mecid` (`u8`):
/// * `mechid` (`u8`):
/// - The u8 mechnism identifier.
///
/// * `dests` (Vec<u16>):
Expand Down Expand Up @@ -168,15 +168,15 @@ mod dispatches {
pub fn set_mechanism_weights(
origin: OriginFor<T>,
netuid: NetUid,
mecid: MechId,
mechid: MechId,
dests: Vec<u16>,
weights: Vec<u16>,
version_key: u64,
) -> DispatchResult {
if Self::get_commit_reveal_weights_enabled(netuid) {
Err(Error::<T>::CommitRevealEnabled.into())
} else {
Self::do_set_mechanism_weights(origin, netuid, mecid, dests, weights, version_key)
Self::do_set_mechanism_weights(origin, netuid, mechid, dests, weights, version_key)
}
}

Expand Down Expand Up @@ -258,7 +258,7 @@ mod dispatches {
/// * `netuid` (`u16`):
/// - The u16 network identifier.
///
/// * `mecid` (`u8`):
/// * `mechid` (`u8`):
/// - The u8 mechanism identifier.
///
/// * `commit_hash` (`H256`):
Expand All @@ -278,10 +278,10 @@ mod dispatches {
pub fn commit_mechanism_weights(
origin: T::RuntimeOrigin,
netuid: NetUid,
mecid: MechId,
mechid: MechId,
commit_hash: H256,
) -> DispatchResult {
Self::do_commit_mechanism_weights(origin, netuid, mecid, commit_hash)
Self::do_commit_mechanism_weights(origin, netuid, mechid, commit_hash)
}

/// --- Allows a hotkey to commit weight hashes for multiple netuids as a batch.
Expand Down Expand Up @@ -379,7 +379,7 @@ mod dispatches {
/// * `netuid` (`u16`):
/// - The u16 network identifier.
///
/// * `mecid` (`u8`):
/// * `mechid` (`u8`):
/// - The u8 mechanism identifier.
///
/// * `uids` (`Vec<u16>`):
Expand Down Expand Up @@ -417,7 +417,7 @@ mod dispatches {
pub fn reveal_mechanism_weights(
origin: T::RuntimeOrigin,
netuid: NetUid,
mecid: MechId,
mechid: MechId,
uids: Vec<u16>,
values: Vec<u16>,
salt: Vec<u16>,
Expand All @@ -426,7 +426,7 @@ mod dispatches {
Self::do_reveal_mechanism_weights(
origin,
netuid,
mecid,
mechid,
uids,
values,
salt,
Expand Down Expand Up @@ -485,7 +485,7 @@ mod dispatches {
/// * `netuid` (`u16`):
/// - The u16 network identifier.
///
/// * `mecid` (`u8`):
/// * `mechid` (`u8`):
/// - The u8 mechanism identifier.
///
/// * `commit` (`Vec<u8>`):
Expand Down Expand Up @@ -515,14 +515,14 @@ mod dispatches {
pub fn commit_crv3_mechanism_weights(
origin: T::RuntimeOrigin,
netuid: NetUid,
mecid: MechId,
mechid: MechId,
commit: BoundedVec<u8, ConstU32<MAX_CRV3_COMMIT_SIZE_BYTES>>,
reveal_round: u64,
) -> DispatchResult {
Self::do_commit_timelocked_mechanism_weights(
origin,
netuid,
mecid,
mechid,
commit,
reveal_round,
4,
Expand Down Expand Up @@ -2264,7 +2264,7 @@ mod dispatches {
/// * `netuid` (`u16`):
/// - The u16 network identifier.
///
/// * `mecid` (`u8`):
/// * `mechid` (`u8`):
/// - The u8 mechanism identifier.
///
/// * `commit` (`Vec<u8>`):
Expand All @@ -2289,15 +2289,15 @@ mod dispatches {
pub fn commit_timelocked_mechanism_weights(
origin: T::RuntimeOrigin,
netuid: NetUid,
mecid: MechId,
mechid: MechId,
commit: BoundedVec<u8, ConstU32<MAX_CRV3_COMMIT_SIZE_BYTES>>,
reveal_round: u64,
commit_reveal_version: u16,
) -> DispatchResult {
Self::do_commit_timelocked_mechanism_weights(
origin,
netuid,
mecid,
mechid,
commit,
reveal_round,
commit_reveal_version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn migrate_crv3_commits_add_block<T: Config>() -> Weight {
for (netuid_index, epoch, old_q) in CRV3WeightCommits::<T>::drain() {
total_weight = total_weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));

let (netuid, _) = Pallet::<T>::get_netuid_and_subid(netuid_index).unwrap_or_default();
let (netuid, _) = Pallet::<T>::get_netuid_and_mechid(netuid_index).unwrap_or_default();
let commit_block = Pallet::<T>::get_first_block_of_epoch(netuid, epoch);

// convert VecDeque<(who,cipher,rnd)> → VecDeque<(who,cb,cipher,rnd)>
Expand Down
Loading