-
Notifications
You must be signed in to change notification settings - Fork 319
Subnet Protocol Alpha Accounting #2645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devnet-ready
Are you sure you want to change the base?
Changes from all commits
bbb22e8
8344515
311fcc5
9b91b4b
ea9ed53
695a6d8
bb33770
de0e9f2
20b8401
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -473,7 +473,11 @@ impl<T: Config> Pallet<T> { | |
| // - track hotkeys to clear pool totals. | ||
| let mut keys_to_remove: Vec<(T::AccountId, T::AccountId)> = Vec::new(); | ||
| let mut stakers: Vec<(T::AccountId, T::AccountId, u128)> = Vec::new(); | ||
| let mut total_alpha_value_u128: u128 = 0; | ||
| let protocol_alpha_value_u128: u128 = SubnetAlphaIn::<T>::get(netuid) | ||
| .saturating_add(SubnetProtocolAlpha::<T>::get(netuid)) | ||
| .to_u64() as u128; | ||
|
Comment on lines
+476
to
+478
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MEDIUM] Update dissolve weights for protocol-alpha storage This adds a new |
||
| let mut total_alpha_value_u128: u128 = protocol_alpha_value_u128; | ||
| let mut protocol_tao_share = TaoBalance::ZERO; | ||
|
|
||
| let hotkeys_in_subnet: Vec<T::AccountId> = TotalHotkeyAlpha::<T>::iter_keys() | ||
| .filter(|(_, this_netuid)| *this_netuid == netuid) | ||
|
|
@@ -517,16 +521,18 @@ impl<T: Config> Pallet<T> { | |
|
|
||
| // 6) Pro‑rata distribution of the pot by α value (largest‑remainder), | ||
| // **credited directly to each staker's COLDKEY free balance**. | ||
| if pot_u64 > 0 && total_alpha_value_u128 > 0 && !stakers.is_empty() { | ||
| if pot_u64 > 0 && total_alpha_value_u128 > 0 { | ||
| struct Portion<A, C> { | ||
| _hot: A, | ||
| cold: C, | ||
| is_protocol: bool, | ||
| share: u64, // TAO to credit to coldkey balance | ||
| rem: u128, // remainder for largest‑remainder method | ||
| } | ||
|
|
||
| let pot_u128: u128 = pot_u64 as u128; | ||
| let mut portions: Vec<Portion<_, _>> = Vec::with_capacity(stakers.len()); | ||
| let mut portions: Vec<Portion<_, _>> = | ||
| Vec::with_capacity(stakers.len().saturating_add(1)); | ||
| let mut distributed: u128 = 0; | ||
|
|
||
| for (hot, cold, alpha_val) in &stakers { | ||
|
|
@@ -539,6 +545,22 @@ impl<T: Config> Pallet<T> { | |
| portions.push(Portion { | ||
| _hot: hot.clone(), | ||
| cold: cold.clone(), | ||
| is_protocol: false, | ||
| share: share_u64, | ||
| rem, | ||
| }); | ||
| } | ||
|
|
||
| if protocol_alpha_value_u128 > 0 { | ||
| let prod: u128 = pot_u128.saturating_mul(protocol_alpha_value_u128); | ||
| let share_u128: u128 = prod.checked_div(total_alpha_value_u128).unwrap_or_default(); | ||
| let share_u64: u64 = share_u128.min(u128::from(u64::MAX)) as u64; | ||
| distributed = distributed.saturating_add(u128::from(share_u64)); | ||
| let rem: u128 = prod.checked_rem(total_alpha_value_u128).unwrap_or_default(); | ||
| portions.push(Portion { | ||
| _hot: owner_coldkey.clone(), | ||
| cold: owner_coldkey.clone(), | ||
| is_protocol: true, | ||
| share: share_u64, | ||
| rem, | ||
| }); | ||
|
|
@@ -555,7 +577,9 @@ impl<T: Config> Pallet<T> { | |
|
|
||
| // Credit each share directly to coldkey free balance. | ||
| for p in portions { | ||
| if p.share > 0 { | ||
| if p.is_protocol { | ||
| protocol_tao_share = protocol_tao_share.saturating_add(p.share.into()); | ||
| } else if p.share > 0 { | ||
| // Cannot fail the whole transaction if this transfer fails | ||
| let _ = Self::transfer_tao_from_subnet(netuid, &p.cold, p.share.into()); | ||
| } | ||
|
|
@@ -578,6 +602,7 @@ impl<T: Config> Pallet<T> { | |
| SubnetAlphaIn::<T>::remove(netuid); | ||
| SubnetAlphaInProvided::<T>::remove(netuid); | ||
| SubnetAlphaOut::<T>::remove(netuid); | ||
| SubnetProtocolAlpha::<T>::remove(netuid); | ||
|
|
||
| // Clear the locked balance on the subnet. | ||
| Self::set_subnet_locked_balance(netuid, TaoBalance::ZERO); | ||
|
|
@@ -596,7 +621,8 @@ impl<T: Config> Pallet<T> { | |
| && let Some(subnet_account) = Self::get_subnet_account_id(netuid) | ||
| { | ||
| // Transfer maximum transferrable up to refund to owner | ||
| let transferrable = Self::get_coldkey_balance(&subnet_account); | ||
| let transferrable = | ||
| Self::get_coldkey_balance(&subnet_account).saturating_sub(protocol_tao_share); | ||
| // We do our best effort to refund owner to as full amount of refund as possible, but | ||
| // we cannot fail new subnet registration, so the result is ignored. | ||
| let _ = Self::transfer_tao(&subnet_account, &owner_coldkey, refund.min(transferrable)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.