diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 03a20a5f21..6d7ede9f46 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -1682,6 +1682,18 @@ pub mod pallet { pallet_subtensor::Pallet::::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, + childkey_tax_rate: u16, + ) -> DispatchResult { + ensure_root(origin)?; + pallet_subtensor::Pallet::::set_childkey_tax_rate(childkey_tax_rate)?; + Ok(()) + } } } diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 73fc928e90..5572ba681d 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -743,6 +743,7 @@ impl Pallet { // 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)); @@ -817,6 +818,14 @@ impl Pallet { // 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. diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index ef41b07c78..9b35c7e266 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -1482,6 +1482,14 @@ pub mod pallet { pub type ImmuneOwnerUidsLimit = StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultImmuneOwnerUidsLimit>; + #[pallet::type_value] + /// Default value for childkey tax rate, 18% + pub fn DefaultChildkeyTaxRate() -> u16 { + 11_796 + } + #[pallet::storage] + pub type ChildkeyTaxRate = StorageValue<_, u16, ValueQuery, DefaultChildkeyTaxRate>; + /// ======================================= /// ==== Subnetwork Consensus Storage ==== /// ======================================= diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 46b4aaf92b..d40cee3223 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -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, netuids: Vec>, diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index f64962f094..b46a3e4a10 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -829,4 +829,26 @@ impl Pallet { ImmuneOwnerUidsLimit::::insert(netuid, limit); Ok(()) } + + /// Get the childkey tax rate + /// + /// # Returns + /// - `u16` - The childkey tax rate. + pub fn get_childkey_tax_rate() -> u16 { + ChildkeyTaxRate::::get() + } + + /// Set the childkey tax rate + /// + /// # Arguments + /// + /// * `childkey_tax_rate` - The new childkey tax rate. + /// + /// # Returns + /// - `Ok(())` on success. + /// - `Err(Error::::InvalidValue)` if `childkey_tax_rate` is outside `[0, 100]`. + pub fn set_childkey_tax_rate(childkey_tax_rate: u16) -> DispatchResult { + ChildkeyTaxRate::::set(childkey_tax_rate); + Ok(()) + } } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 00cc24b411..679e5e55b2 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -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,