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
12 changes: 12 additions & 0 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,18 @@ pub mod pallet {
pallet_subtensor::Pallet::<T>::set_owner_immune_neuron_limit(netuid, immune_neurons)?;
Ok(())
}

/// Sets the childkey tax rate
#[pallet::call_index(73)]
#[pallet::weight(Weight::from_parts(15_000_000, 0))]
pub fn sudo_set_childkey_tax_rate(
origin: OriginFor<T>,
childkey_tax_rate: u16,
) -> DispatchResult {
ensure_root(origin)?;
pallet_subtensor::Pallet::<T>::set_childkey_tax_rate(childkey_tax_rate)?;
Ok(())
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ impl<T: Config> Pallet<T> {
// Calculate the hotkey's share of the validator emission based on its childkey take
let validating_emission: U96F32 = U96F32::saturating_from_num(dividends);
let mut remaining_emission: U96F32 = validating_emission;

let childkey_take_proportion: U96F32 =
U96F32::saturating_from_num(Self::get_childkey_take(hotkey, netuid))
.safe_div(U96F32::saturating_from_num(u16::MAX));
Expand Down Expand Up @@ -817,6 +818,14 @@ impl<T: Config> Pallet<T> {
// Remove this emission from the remaining emission.
remaining_emission = remaining_emission.saturating_sub(parent_emission);

let parent_emission_tax = parent_emission
.saturating_mul(U96F32::saturating_from_num(Self::get_childkey_tax_rate()))
.safe_div(U96F32::saturating_from_num(u16::MAX));
log::debug!("Parent emission tax: {parent_emission_tax:?} for hotkey {hotkey:?}");

parent_emission = parent_emission.saturating_sub(parent_emission_tax);
log::debug!("Parent emission after tax: {parent_emission:?} for hotkey {hotkey:?}");

// Get the childkey take for this parent.
let child_emission_take: U96F32 = if parent_owner == childkey_owner {
// The parent is from the same coldkey, so we don't remove any childkey take.
Expand Down
8 changes: 8 additions & 0 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,14 @@ pub mod pallet {
pub type ImmuneOwnerUidsLimit<T> =
StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultImmuneOwnerUidsLimit<T>>;

#[pallet::type_value]
/// Default value for childkey tax rate, 18%
pub fn DefaultChildkeyTaxRate<T: Config>() -> u16 {
11_796
}
#[pallet::storage]
pub type ChildkeyTaxRate<T> = StorageValue<_, u16, ValueQuery, DefaultChildkeyTaxRate<T>>;

/// =======================================
/// ==== Subnetwork Consensus Storage ====
/// =======================================
Expand Down
6 changes: 3 additions & 3 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ mod dispatches {
/// - On failure for each failed item in the batch.
///
#[pallet::call_index(80)]
#[pallet::weight((Weight::from_parts(19_330_000, 0)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(0_u64)), DispatchClass::Normal, Pays::No))]
#[pallet::weight((Weight::from_parts(94_830_000, 0)
.saturating_add(T::DbWeight::get().reads(14_u64))
.saturating_add(T::DbWeight::get().writes(2_u64)), DispatchClass::Normal, Pays::No))]
pub fn batch_set_weights(
origin: OriginFor<T>,
netuids: Vec<Compact<NetUid>>,
Expand Down
22 changes: 22 additions & 0 deletions pallets/subtensor/src/utils/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,4 +829,26 @@ impl<T: Config> Pallet<T> {
ImmuneOwnerUidsLimit::<T>::insert(netuid, limit);
Ok(())
}

/// Get the childkey tax rate
///
/// # Returns
/// - `u16` - The childkey tax rate.
pub fn get_childkey_tax_rate() -> u16 {
ChildkeyTaxRate::<T>::get()
}

/// Set the childkey tax rate
///
/// # Arguments
///
/// * `childkey_tax_rate` - The new childkey tax rate.
///
/// # Returns
/// - `Ok(())` on success.
/// - `Err(Error::<T>::InvalidValue)` if `childkey_tax_rate` is outside `[0, 100]`.
pub fn set_childkey_tax_rate(childkey_tax_rate: u16) -> DispatchResult {
ChildkeyTaxRate::<T>::set(childkey_tax_rate);
Ok(())
}
}
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,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: 307,
spec_version: 308,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
Loading