diff --git a/evm-tests/src/contracts/alpha.ts b/evm-tests/src/contracts/alpha.ts index ae2429804..04248f585 100644 --- a/evm-tests/src/contracts/alpha.ts +++ b/evm-tests/src/contracts/alpha.ts @@ -317,7 +317,13 @@ export const IAlphaABI = [ "type": "function" }, { - "inputs": [], + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], "name": "getCKBurn", "outputs": [ { diff --git a/evm-tests/test/alpha.precompile.test.ts b/evm-tests/test/alpha.precompile.test.ts index 1ca3c755a..e3e1a32bb 100644 --- a/evm-tests/test/alpha.precompile.test.ts +++ b/evm-tests/test/alpha.precompile.test.ts @@ -216,10 +216,10 @@ describe("Test Alpha Precompile", () => { abi: IAlphaABI, address: toViemAddress(IALPHA_ADDRESS), functionName: "getCKBurn", - args: [] + args: [subnetId] }) - const ckBurnOnChain = await api.query.SubtensorModule.CKBurn.getValue() + const ckBurnOnChain = await api.query.SubtensorModule.CKBurn.getValue(subnetId); assert.strictEqual(ckBurn, ckBurnOnChain, "CK burn should match on chain"); assert.ok(ckBurn !== undefined, "CK burn should be defined"); diff --git a/pallets/admin-utils/src/benchmarking.rs b/pallets/admin-utils/src/benchmarking.rs index b8dafc0de..d4759e334 100644 --- a/pallets/admin-utils/src/benchmarking.rs +++ b/pallets/admin-utils/src/benchmarking.rs @@ -369,5 +369,16 @@ mod benchmarks { _(RawOrigin::Root, 1u16.into()/*netuid*/, 5u16/*immune_neurons*/)/*sudo_set_owner_immune_neuron_limit()*/; } + #[benchmark] + fn sudo_set_ck_burn() { + pallet_subtensor::Pallet::::init_new_network( + 1u16.into(), /*netuid*/ + 1u16, /*sudo_tempo*/ + ); + + #[extrinsic_call] + _(RawOrigin::Root, 1u16.into()/*netuid*/, 5u64/*burn*/)/*sudo_set_ck_burn()*/; + } + //impl_benchmark_test_suite!(AdminUtils, crate::mock::new_test_ext(), crate::mock::Test); } diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 4af202132..6c770eb76 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -1815,9 +1815,13 @@ pub mod pallet { #[pallet::weight(Weight::from_parts(15_650_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] - pub fn sudo_set_ck_burn(origin: OriginFor, burn: u64) -> DispatchResult { - ensure_root(origin)?; - pallet_subtensor::Pallet::::set_ck_burn(burn); + pub fn sudo_set_ck_burn(origin: OriginFor, netuid: NetUid, burn: u64) -> DispatchResult { + pallet_subtensor::Pallet::::ensure_sn_owner_or_root_with_limits( + origin, + netuid, + &[TransactionType::OwnerHyperparamUpdate], + )?; + pallet_subtensor::Pallet::::set_ck_burn(netuid, burn); log::debug!("CKBurnSet( burn: {burn:?} ) "); Ok(()) } diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 25b1b8960..f4b853594 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -2269,3 +2269,39 @@ fn test_sudo_set_subsubnet_count() { )); }); } + +#[test] +fn test_sudo_set_ck_burn() { + new_test_ext().execute_with(|| { + let netuid = NetUid::from(1); + let to_be_set: u64 = 1000000; + + // Set up a network + add_network(netuid, 10); + + let init_value = pallet_subtensor::CKBurn::::get(netuid); + + // Test that non-root origin fails + assert_eq!( + AdminUtils::sudo_set_ck_burn( + <::RuntimeOrigin>::signed(U256::from(1)), + netuid, + to_be_set + ), + Err(DispatchError::BadOrigin) + ); + // Value should remain unchanged + assert_eq!(SubtensorModule::get_ck_burn(netuid), init_value); + + // Test that root can set the CK burn successfully + assert_ok!(AdminUtils::sudo_set_ck_burn( + <::RuntimeOrigin>::root(), + netuid, + to_be_set + )); + + // Verify the value was set correctly + let set_value = pallet_subtensor::CKBurn::::get(netuid); + assert_eq!(set_value, to_be_set); + }); +} diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 4bc6d1161..a57a21459 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -757,7 +757,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 burn_take_proportion: U96F32 = Self::get_ck_burn(); + let burn_take_proportion: U96F32 = Self::get_ck_burn(netuid); let child_take_proportion: U96F32 = U96F32::saturating_from_num(Self::get_childkey_take(hotkey, netuid)) .safe_div(U96F32::saturating_from_num(u16::MAX)); diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index dd12a9b76..ed969e20f 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -942,8 +942,14 @@ pub mod pallet { pub type TaoWeight = StorageValue<_, u64, ValueQuery, DefaultTaoWeight>; #[pallet::storage] /// --- ITEM --> CK burn - pub type CKBurn = StorageValue<_, u64, ValueQuery, DefaultCKBurn>; + pub type CKBurn = StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultCKBurn>; + + // #[pallet::storage] + // /// --- ITEM --> CK burn + // pub type CKBurnPerSubnet = + // StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultCKBurn>; #[pallet::storage] + /// --- ITEM ( default_delegate_take ) pub type MaxDelegateTake = StorageValue<_, u16, ValueQuery, DefaultDelegateTake>; #[pallet::storage] diff --git a/pallets/subtensor/src/staking/stake_utils.rs b/pallets/subtensor/src/staking/stake_utils.rs index 528289ec0..8e095f740 100644 --- a/pallets/subtensor/src/staking/stake_utils.rs +++ b/pallets/subtensor/src/staking/stake_utils.rs @@ -96,8 +96,8 @@ impl Pallet { // This ensures the result is always between 0 and 1 weight_fixed.safe_div(U96F32::saturating_from_num(u64::MAX)) } - pub fn get_ck_burn() -> U96F32 { - let stored_weight = CKBurn::::get(); + pub fn get_ck_burn(netuid: NetUid) -> U96F32 { + let stored_weight = CKBurn::::get(netuid); let weight_fixed = U96F32::saturating_from_num(stored_weight); weight_fixed.safe_div(U96F32::saturating_from_num(u64::MAX)) } @@ -123,9 +123,9 @@ impl Pallet { TaoWeight::::set(weight); } // Set the amount burned on non owned CK - pub fn set_ck_burn(weight: u64) { + pub fn set_ck_burn(netuid: NetUid, weight: u64) { // Update the ck burn value. - CKBurn::::set(weight); + CKBurn::::insert(netuid, weight); } /// Calculates the weighted combination of alpha and global tao for a single hotkey onet a subnet. diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 1208add95..7de86e264 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -2862,7 +2862,7 @@ fn test_childkey_take_drain() { // Add network, register hotkeys, and setup network parameters add_network(netuid, subnet_tempo, 0); - SubtensorModule::set_ck_burn(0); + SubtensorModule::set_ck_burn(netuid, 0); mock::setup_reserves(netuid, (stake * 10_000).into(), (stake * 10_000).into()); register_ok_neuron(netuid, child_hotkey, child_coldkey, 0); register_ok_neuron(netuid, parent_hotkey, parent_coldkey, 1); @@ -2982,7 +2982,7 @@ fn test_parent_child_chain_emission() { let subnet_owner_coldkey = U256::from(1001); let subnet_owner_hotkey = U256::from(1002); let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); - SubtensorModule::set_ck_burn(0); + SubtensorModule::set_ck_burn(netuid, 0); Tempo::::insert(netuid, 1); // Setup large LPs to prevent slippage @@ -3195,7 +3195,7 @@ fn test_parent_child_chain_epoch() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); add_network(netuid, 1, 0); - SubtensorModule::set_ck_burn(0); + SubtensorModule::set_ck_burn(netuid, 0); // Set owner cut to 0 SubtensorModule::set_subnet_owner_cut(0_u16); @@ -3340,7 +3340,7 @@ fn test_dividend_distribution_with_children() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); add_network(netuid, 1, 0); - SubtensorModule::set_ck_burn(0); + SubtensorModule::set_ck_burn(netuid, 0); mock::setup_reserves( netuid, 1_000_000_000_000_000.into(), @@ -3575,7 +3575,7 @@ fn test_dividend_distribution_with_children() { fn test_dynamic_parent_child_relationships() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - SubtensorModule::set_ck_burn(0); + SubtensorModule::set_ck_burn(netuid, 0); add_network_disable_commit_reveal(netuid, 1, 0); // Define hotkeys and coldkeys diff --git a/pallets/subtensor/src/tests/coinbase.rs b/pallets/subtensor/src/tests/coinbase.rs index c772a4ac3..be9f15ae5 100644 --- a/pallets/subtensor/src/tests/coinbase.rs +++ b/pallets/subtensor/src/tests/coinbase.rs @@ -1063,7 +1063,7 @@ fn test_drain_alpha_childkey_parentkey() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); add_network(netuid, 1, 0); - SubtensorModule::set_ck_burn(0); + SubtensorModule::set_ck_burn(netuid, 0); let parent = U256::from(1); let child = U256::from(2); let coldkey = U256::from(3); @@ -1239,7 +1239,7 @@ fn test_get_root_children_drain() { let alpha = NetUid::from(1); add_network(NetUid::ROOT, 1, 0); add_network(alpha, 1, 0); - SubtensorModule::set_ck_burn(0); + SubtensorModule::set_ck_burn(alpha, 0); // Set TAO weight to 1. SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. // Create keys. @@ -1401,7 +1401,7 @@ fn test_get_root_children_drain_half_proportion() { let alpha = NetUid::from(1); add_network(NetUid::ROOT, 1, 0); add_network(alpha, 1, 0); - SubtensorModule::set_ck_burn(0); + SubtensorModule::set_ck_burn(alpha, 0); // Set TAO weight to 1. SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. // Create keys. @@ -1579,7 +1579,7 @@ fn test_get_root_children_drain_with_half_take() { add_network(alpha, 1, 0); // Set TAO weight to 1. SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. - SubtensorModule::set_ck_burn(0); + SubtensorModule::set_ck_burn(alpha, 0); // Create keys. let cold_alice = U256::from(0); let cold_bob = U256::from(1); @@ -2787,7 +2787,7 @@ fn test_drain_alpha_childkey_parentkey_with_burn() { // Childkey take is 10% ChildkeyTake::::insert(child, netuid, u16::MAX / 10); - let burn_rate = SubtensorModule::get_ck_burn(); + let burn_rate = SubtensorModule::get_ck_burn(netuid); let parent_stake_before = SubtensorModule::get_stake_for_hotkey_on_subnet(&parent, netuid); let child_stake_before = SubtensorModule::get_stake_for_hotkey_on_subnet(&child, netuid); diff --git a/precompiles/src/alpha.rs b/precompiles/src/alpha.rs index 29f7cab56..9bff524e8 100644 --- a/precompiles/src/alpha.rs +++ b/precompiles/src/alpha.rs @@ -90,10 +90,10 @@ where Ok(U256::from(tao_weight)) } - #[precompile::public("getCKBurn()")] + #[precompile::public("getCKBurn(uint16)")] #[precompile::view] - fn get_ck_burn(_handle: &mut impl PrecompileHandle) -> EvmResult { - let ck_burn = pallet_subtensor::CKBurn::::get(); + fn get_ck_burn(_handle: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { + let ck_burn = pallet_subtensor::CKBurn::::get(NetUid::from(netuid)); Ok(U256::from(ck_burn)) } diff --git a/precompiles/src/solidity/alpha.abi b/precompiles/src/solidity/alpha.abi index 14d6eb66d..e8ae98c8e 100644 --- a/precompiles/src/solidity/alpha.abi +++ b/precompiles/src/solidity/alpha.abi @@ -315,7 +315,13 @@ "type": "function" }, { - "inputs": [], + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], "name": "getCKBurn", "outputs": [ { diff --git a/precompiles/src/solidity/alpha.sol b/precompiles/src/solidity/alpha.sol index c99252ff4..19ddc0c89 100644 --- a/precompiles/src/solidity/alpha.sol +++ b/precompiles/src/solidity/alpha.sol @@ -97,5 +97,5 @@ interface IAlpha { /// @dev Returns the CK burn rate. /// @return The CK burn rate. - function getCKBurn() external view returns (uint256); + function getCKBurn(uint16 netuid) external view returns (uint256); } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index d49d5147e..aa87c52a1 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: 316, + spec_version: 317, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,