Skip to content

Commit 1eda4d4

Browse files
author
Samuel Dare
committed
hotfix: return total stake on subnet taking into consideration childkeys
1 parent 4f3f151 commit 1eda4d4

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

pallets/subtensor/src/epoch/run_epoch.rs

+33
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,39 @@ impl<T: Config> Pallet<T> {
8686
finalized_stake
8787
}
8888

89+
/// Calculates the total stake for a hotkey across all subnets.
90+
///
91+
/// This function iterates through all subnets and accumulates the stake
92+
/// for the given hotkey on each subnet.
93+
///
94+
/// # Arguments
95+
///
96+
/// * `hotkey` - The AccountId of the hotkey to calculate the total stake for.
97+
///
98+
/// # Returns
99+
///
100+
/// * `u64` - The total stake for the hotkey across all subnets.
101+
///
102+
103+
pub fn get_total_stake_for_hotkey_on_subnets(hotkey: &T::AccountId) -> u64 {
104+
// Get the list of all subnets
105+
let subnet_list: Vec<u16> = Self::get_all_subnet_netuids();
106+
107+
// Initialize the total stake
108+
let mut total_stake: u64 = 0;
109+
110+
// Iterate through all subnets and accumulate the stake
111+
for netuid in subnet_list {
112+
// Get the stake for the hotkey on this subnet
113+
let subnet_stake: u64 = Self::get_stake_for_hotkey_on_subnet(hotkey, netuid);
114+
115+
// Add the subnet stake to the total stake using saturating addition
116+
total_stake = total_stake.saturating_add(subnet_stake);
117+
}
118+
119+
// Return the total stake
120+
total_stake
121+
}
89122
/// Calculates reward consensus and returns the emissions for uids/hotkeys in a given `netuid`.
90123
/// (Dense version used only for testing purposes.)
91124
#[allow(clippy::indexing_slicing)]

pallets/subtensor/src/rpc_info/delegate_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<T: Config> Pallet<T> {
6060
let owner = Self::get_owning_coldkey_for_hotkey(&delegate.clone());
6161
let take: Compact<u16> = <Delegates<T>>::get(delegate.clone()).into();
6262

63-
let total_stake: U64F64 = Self::get_total_stake_for_hotkey(&delegate.clone()).into();
63+
let total_stake: U64F64 = Self::get_total_stake_for_hotkey_on_subnets(&delegate.clone()).into();
6464

6565
let return_per_1000: U64F64 = if total_stake > U64F64::from_num(0) {
6666
emissions_per_day

0 commit comments

Comments
 (0)