Skip to content
Open
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
8 changes: 7 additions & 1 deletion evm-tests/src/contracts/alpha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,13 @@ export const IAlphaABI = [
"type": "function"
},
{
"inputs": [],
"inputs": [
{
"internalType": "uint16",
"name": "netuid",
"type": "uint16"
}
],
"name": "getCKBurn",
"outputs": [
{
Expand Down
4 changes: 2 additions & 2 deletions evm-tests/test/alpha.precompile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
11 changes: 11 additions & 0 deletions pallets/admin-utils/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>::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);
}
10 changes: 7 additions & 3 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1815,9 +1815,13 @@ pub mod pallet {
#[pallet::weight(Weight::from_parts(15_650_000, 0)
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(1_u64))
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)))]
pub fn sudo_set_ck_burn(origin: OriginFor<T>, burn: u64) -> DispatchResult {
ensure_root(origin)?;
pallet_subtensor::Pallet::<T>::set_ck_burn(burn);
pub fn sudo_set_ck_burn(origin: OriginFor<T>, netuid: NetUid, burn: u64) -> DispatchResult {
pallet_subtensor::Pallet::<T>::ensure_sn_owner_or_root_with_limits(
origin,
netuid,
&[TransactionType::OwnerHyperparamUpdate],
)?;
pallet_subtensor::Pallet::<T>::set_ck_burn(netuid, burn);
log::debug!("CKBurnSet( burn: {burn:?} ) ");
Ok(())
}
Expand Down
36 changes: 36 additions & 0 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Test>::get(netuid);

// Test that non-root origin fails
assert_eq!(
AdminUtils::sudo_set_ck_burn(
<<Test as Config>::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(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
to_be_set
));

// Verify the value was set correctly
let set_value = pallet_subtensor::CKBurn::<Test>::get(netuid);
assert_eq!(set_value, to_be_set);
});
}
2 changes: 1 addition & 1 deletion pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,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 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));
Expand Down
8 changes: 7 additions & 1 deletion pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,14 @@ pub mod pallet {
pub type TaoWeight<T> = StorageValue<_, u64, ValueQuery, DefaultTaoWeight<T>>;
#[pallet::storage]
/// --- ITEM --> CK burn
pub type CKBurn<T> = StorageValue<_, u64, ValueQuery, DefaultCKBurn<T>>;
pub type CKBurn<T> = StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultCKBurn<T>>;

// #[pallet::storage]
// /// --- ITEM --> CK burn
// pub type CKBurnPerSubnet<T> =
// StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultCKBurn<T>>;
#[pallet::storage]

/// --- ITEM ( default_delegate_take )
pub type MaxDelegateTake<T> = StorageValue<_, u16, ValueQuery, DefaultDelegateTake<T>>;
#[pallet::storage]
Expand Down
8 changes: 4 additions & 4 deletions pallets/subtensor/src/staking/stake_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ impl<T: Config> Pallet<T> {
// 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::<T>::get();
pub fn get_ck_burn(netuid: NetUid) -> U96F32 {
let stored_weight = CKBurn::<T>::get(netuid);
let weight_fixed = U96F32::saturating_from_num(stored_weight);
weight_fixed.safe_div(U96F32::saturating_from_num(u64::MAX))
}
Expand All @@ -123,9 +123,9 @@ impl<T: Config> Pallet<T> {
TaoWeight::<T>::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::<T>::set(weight);
CKBurn::<T>::insert(netuid, weight);
}

/// Calculates the weighted combination of alpha and global tao for a single hotkey onet a subnet.
Expand Down
10 changes: 5 additions & 5 deletions pallets/subtensor/src/tests/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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::<Test>::insert(netuid, 1);

// Setup large LPs to prevent slippage
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pallets/subtensor/src/tests/coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2787,7 +2787,7 @@ fn test_drain_alpha_childkey_parentkey_with_burn() {
// Childkey take is 10%
ChildkeyTake::<Test>::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);

Expand Down
6 changes: 3 additions & 3 deletions precompiles/src/alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<U256> {
let ck_burn = pallet_subtensor::CKBurn::<R>::get();
fn get_ck_burn(_handle: &mut impl PrecompileHandle, netuid: u16) -> EvmResult<U256> {
let ck_burn = pallet_subtensor::CKBurn::<R>::get(NetUid::from(netuid));
Ok(U256::from(ck_burn))
}

Expand Down
8 changes: 7 additions & 1 deletion precompiles/src/solidity/alpha.abi
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,13 @@
"type": "function"
},
{
"inputs": [],
"inputs": [
{
"internalType": "uint16",
"name": "netuid",
"type": "uint16"
}
],
"name": "getCKBurn",
"outputs": [
{
Expand Down
2 changes: 1 addition & 1 deletion precompiles/src/solidity/alpha.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
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: 316,
spec_version: 317,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
Loading