Skip to content

Commit

Permalink
chore: fix uid unwrap and bump to 1.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
saiintbrisson committed Apr 22, 2024
1 parent e8be329 commit f5a2aa5
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "node-subspace"
version = "1.5.1"
version = "1.5.2"
description = "A fresh FRAME-based Substrate node, ready for hacking."
authors = ["Substrate DevHub <https://github.com/substrate-developer-hub>"]
homepage = "https://substrate.io/"
Expand Down
2 changes: 1 addition & 1 deletion pallets/subspace/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-subspace"
version = "1.5.1"
version = "1.5.2"
description = "FRAME pallet for runtime logic of Subspace Blockchain."
authors = ["Commune Nucleus Team"]
homepage = "https://commune.com"
Expand Down
1 change: 0 additions & 1 deletion pallets/subspace/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ impl<T: Config> Pallet<T> {
pub fn get_module_stats(netuid: u16, key: &T::AccountId) -> ModuleStats<T> {
let uid = Uids::<T>::get(netuid, key).unwrap_or(u16::MAX);

let key = Self::get_key_for_uid(netuid, uid);
let emission = Self::get_emission_for_uid(netuid, uid);
let incentive = Self::get_incentive_for_uid(netuid, uid);
let dividends = Self::get_dividends_for_uid(netuid, uid);
Expand Down
13 changes: 8 additions & 5 deletions pallets/subspace/src/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ impl<T: Config> Pallet<T> {

// Returs the key under the network uid as a Result. Ok if the uid is taken.
//
pub fn get_key_for_uid(netuid: u16, module_uid: u16) -> T::AccountId {
Keys::<T>::try_get(netuid, module_uid).unwrap()
pub fn get_key_for_uid(netuid: u16, module_uid: u16) -> Option<T::AccountId> {
Keys::<T>::try_get(netuid, module_uid).ok()
}

// Returns the uid of the key in the network as a Result. Ok if the key has a slot.
Expand All @@ -640,7 +640,10 @@ impl<T: Config> Pallet<T> {
/// Returns the stake of the uid on network or 0 if it doesnt exist.
#[cfg(debug_assertions)]
pub fn get_stake_for_uid(netuid: u16, module_uid: u16) -> u64 {
Self::get_stake_for_key(netuid, &Self::get_key_for_uid(netuid, module_uid))
let Some(key) = Self::get_key_for_uid(netuid, module_uid) else {
return 0;
};
Self::get_stake_for_key(netuid, &key)
}

pub fn get_stake_for_key(netuid: u16, key: &T::AccountId) -> u64 {
Expand Down Expand Up @@ -796,15 +799,15 @@ impl<T: Config> Pallet<T> {
pub fn get_keys(netuid: u16) -> Vec<T::AccountId> {
let uids: Vec<u16> = Self::get_uids(netuid);
let keys: Vec<T::AccountId> =
uids.iter().map(|uid| Self::get_key_for_uid(netuid, *uid)).collect();
uids.iter().map(|uid| Self::get_key_for_uid(netuid, *uid).unwrap()).collect();
keys
}

pub fn get_uid_key_tuples(netuid: u16) -> Vec<(u16, T::AccountId)> {
let n = Self::get_subnet_n(netuid);
let mut uid_key_tuples = Vec::<(u16, T::AccountId)>::new();
for uid in 0..n {
let key = Self::get_key_for_uid(netuid, uid);
let key = Self::get_key_for_uid(netuid, uid).unwrap();
uid_key_tuples.push((uid, key));
}
uid_key_tuples
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "node-subspace-runtime"
version = "1.5.1"
version = "1.5.2"
description = "A Substrate node for commune-ai"
authors = [
"Sal Vivona <https://github.com/salvivona>",
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 106,
spec_version: 107,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down

0 comments on commit f5a2aa5

Please sign in to comment.