Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
2f7ea4b
Add root claim infrastructure
shamil-gadelshin Sep 9, 2025
c579597
Alter coinbase.rs
shamil-gadelshin Sep 12, 2025
6c614fe
Alter tests
shamil-gadelshin Sep 12, 2025
e04c8e9
Remove comments
shamil-gadelshin Sep 12, 2025
f607993
Change TaoDividendsPerSubnet -> AlphaDividendsPerSubnet
shamil-gadelshin Sep 12, 2025
8877c40
Fix: PendingAlphaSwapped only needs to increase for non-subsidized su…
gztensor Sep 12, 2025
e7605df
Update tests
shamil-gadelshin Sep 16, 2025
c48a9c4
Update coinbase.rs
shamil-gadelshin Sep 16, 2025
9fa484a
Cargo fmt
shamil-gadelshin Sep 16, 2025
7f5dba4
Remove TaoDividendsPerSubnet
shamil-gadelshin Sep 16, 2025
28e2f74
Remove PendingAlphaSwapped
shamil-gadelshin Sep 16, 2025
eb32237
Rename RootDebt -> RootClaimed
shamil-gadelshin Sep 16, 2025
2e613b0
Fix RootClaimable map
shamil-gadelshin Sep 17, 2025
b125673
Add root claim tests.
shamil-gadelshin Sep 17, 2025
0151f49
Add basic test with drain_emissions
shamil-gadelshin Sep 17, 2025
83b2b36
Update tests.
shamil-gadelshin Sep 17, 2025
c482f2f
Update tests
shamil-gadelshin Sep 18, 2025
55c1b1d
Simplify tests
shamil-gadelshin Sep 18, 2025
a11d7a9
Add disproportional stake test
shamil-gadelshin Sep 19, 2025
e3cc8e1
Add test with removed stake.
shamil-gadelshin Sep 19, 2025
dd44dd8
Fix existing tests
shamil-gadelshin Sep 19, 2025
0b13d2e
Update tests
shamil-gadelshin Sep 22, 2025
8d1140d
Fix swap claim root
shamil-gadelshin Sep 22, 2025
65bb4f0
Add basic run_coinbase test
shamil-gadelshin Sep 24, 2025
1accdfa
Fix block indices to claim
shamil-gadelshin Sep 25, 2025
c09bcb3
Optimize RootClaimable
shamil-gadelshin Sep 26, 2025
fc161b3
Update benchmarks
shamil-gadelshin Sep 29, 2025
b39d51c
Add coldkey to the new map.
shamil-gadelshin Sep 30, 2025
57bcae3
Add root staking maps migration.
shamil-gadelshin Sep 30, 2025
cc7a1df
Add run_coinbase test for root claim.
shamil-gadelshin Oct 2, 2025
78e45af
Refactor root claim code.
shamil-gadelshin Oct 3, 2025
dcaa3f7
Merge branch 'devnet-ready' into root-claim2
shamil-gadelshin Oct 3, 2025
d0b2dac
Fix merge issues
shamil-gadelshin Oct 3, 2025
0f82356
Remove obsolete code
shamil-gadelshin Oct 3, 2025
239df82
Fix typo
shamil-gadelshin Oct 3, 2025
69e222b
Add sudo_set_num_root_claims extrinsic
shamil-gadelshin Oct 3, 2025
c5d9f31
Update claim_root benchmark.
shamil-gadelshin Oct 6, 2025
99345b1
Refactor code
shamil-gadelshin Oct 10, 2025
cc324ec
Add migration
shamil-gadelshin Oct 10, 2025
8d63857
Merge branch 'devnet-ready' into root-claim2
shamil-gadelshin Oct 14, 2025
1f1c7e7
Fix merge conflicts
shamil-gadelshin Oct 14, 2025
3d3ef0d
Update pallets/subtensor/src/staking/claim_root.rs
shamil-gadelshin Oct 14, 2025
ab5a274
Handle case for stake mismatch.
shamil-gadelshin Oct 14, 2025
db3a0f0
Add proxy type.
shamil-gadelshin Oct 15, 2025
c213dd0
Add swap_coldkey support for root claim
shamil-gadelshin Oct 16, 2025
d6203c0
Add swap_hotkey support for root claim
shamil-gadelshin Oct 16, 2025
7a2ebae
Remove PendingRootDivs map
shamil-gadelshin Oct 17, 2025
b0e346e
Claim all during network deregistration.
shamil-gadelshin Oct 17, 2025
d68d3aa
Modify default claim root key number
shamil-gadelshin Oct 17, 2025
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
1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ pub enum ProxyType {
SudoUncheckedSetCode,
SwapHotkey,
SubnetLeaseBeneficiary, // Used to operate the leased subnet
RootClaim,
}

impl Default for ProxyType {
Expand Down
1 change: 0 additions & 1 deletion pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2663,7 +2663,6 @@ fn test_trim_to_max_allowed_uids() {
assert!(!AlphaDividendsPerSubnet::<Test>::contains_key(
netuid, hotkey
));
assert!(!TaoDividendsPerSubnet::<Test>::contains_key(netuid, hotkey));
assert!(!Axons::<Test>::contains_key(netuid, hotkey));
assert!(!NeuronCertificates::<Test>::contains_key(netuid, hotkey));
assert!(!Prometheus::<Test>::contains_key(netuid, hotkey));
Expand Down
79 changes: 79 additions & 0 deletions pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1577,4 +1577,83 @@ mod pallet_benchmarks {
#[extrinsic_call]
_(RawOrigin::Signed(coldkey.clone()), netuid, hotkey.clone());
}
#[benchmark]
fn set_root_claim_type() {
let coldkey: T::AccountId = whitelisted_caller();

#[extrinsic_call]
_(RawOrigin::Signed(coldkey.clone()), RootClaimTypeEnum::Keep);
}

#[benchmark]
fn claim_root() {
let coldkey: T::AccountId = whitelisted_caller();
let hotkey: T::AccountId = account("A", 0, 1);

let netuid = Subtensor::<T>::get_next_netuid();

let lock_cost = Subtensor::<T>::get_network_lock_cost();
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey, lock_cost.into());

assert_ok!(Subtensor::<T>::register_network(
RawOrigin::Signed(coldkey.clone()).into(),
hotkey.clone()
));

SubtokenEnabled::<T>::insert(netuid, true);
Subtensor::<T>::set_network_pow_registration_allowed(netuid, true);
NetworkRegistrationAllowed::<T>::insert(netuid, true);
FirstEmissionBlockNumber::<T>::insert(netuid, 0);

SubnetMechanism::<T>::insert(netuid, 1);
SubnetworkN::<T>::insert(netuid, 1);
Subtensor::<T>::set_tao_weight(u64::MAX); // Set TAO weight to 1.0

let root_stake = 100_000_000u64;
Subtensor::<T>::increase_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey,
&coldkey,
NetUid::ROOT,
root_stake.into(),
);

let initial_total_hotkey_alpha = 100_000_000u64;
Subtensor::<T>::increase_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey,
&coldkey,
netuid,
initial_total_hotkey_alpha.into(),
);

let pending_root_alpha = 10_000_000u64;
Subtensor::<T>::drain_pending_emission(
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
AlphaCurrency::ZERO,
);

let initial_stake =
Subtensor::<T>::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey, &coldkey, netuid);

assert_ok!(Subtensor::<T>::set_root_claim_type(
RawOrigin::Signed(coldkey.clone()).into(),
RootClaimTypeEnum::Keep
),);

#[extrinsic_call]
_(RawOrigin::Signed(coldkey.clone()));

// Verification
let new_stake =
Subtensor::<T>::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey, &coldkey, netuid);

assert!(new_stake > initial_stake);
}

#[benchmark]
fn sudo_set_num_root_claims() {
#[extrinsic_call]
_(RawOrigin::Root, 100);
}
}
8 changes: 7 additions & 1 deletion pallets/subtensor/src/coinbase/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
/// Executes the necessary operations for each block.
pub fn block_step() -> Result<(), &'static str> {
let block_number: u64 = Self::get_current_block_as_u64();
log::debug!("block_step for block: {block_number:?} ");
let last_block_hash: T::Hash = <frame_system::Pallet<T>>::parent_hash();

// --- 1. Adjust difficulties.
Self::adjust_registration_terms_for_networks();
// --- 2. Get the current coinbase emission.
Expand All @@ -21,6 +22,11 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
Self::run_coinbase(block_emission);
// --- 4. Set pending children on the epoch; but only after the coinbase has been run.
Self::try_set_pending_children(block_number);
// --- 5. Run auto-claim root divs.
Self::run_auto_claim_root_divs(last_block_hash);
// --- 6. Populate root coldkey maps.
Self::populate_root_coldkey_staking_maps();

// Return ok.
Ok(())
}
Expand Down
15 changes: 8 additions & 7 deletions pallets/subtensor/src/coinbase/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,22 +366,24 @@ impl<T: Config> Pallet<T> {
/// * 'NotSubnetOwner': If the caller does not own the specified subnet.
///
pub fn do_dissolve_network(netuid: NetUid) -> dispatch::DispatchResult {
// 1. --- The network exists?
// --- The network exists?
ensure!(
Self::if_subnet_exist(netuid) && netuid != NetUid::ROOT,
Error::<T>::SubnetNotExists
);

// 2. --- Perform the cleanup before removing the network.
Self::finalize_all_subnet_root_dividends(netuid);

// --- Perform the cleanup before removing the network.
T::SwapInterface::dissolve_all_liquidity_providers(netuid)?;
Self::destroy_alpha_in_out_stakes(netuid)?;
T::SwapInterface::clear_protocol_liquidity(netuid)?;
T::CommitmentsInterface::purge_netuid(netuid);

// 3. --- Remove the network
// --- Remove the network
Self::remove_network(netuid);

// 4. --- Emit the NetworkRemoved event
// --- Emit the NetworkRemoved event
log::info!("NetworkRemoved( netuid:{netuid:?} )");
Self::deposit_event(Event::NetworkRemoved(netuid));

Expand Down Expand Up @@ -476,8 +478,7 @@ impl<T: Config> Pallet<T> {
// --- 15. Mechanism step / emissions bookkeeping.
FirstEmissionBlockNumber::<T>::remove(netuid);
PendingEmission::<T>::remove(netuid);
PendingRootDivs::<T>::remove(netuid);
PendingAlphaSwapped::<T>::remove(netuid);
PendingRootAlphaDivs::<T>::remove(netuid);
PendingOwnerCut::<T>::remove(netuid);
BlocksSinceLastStep::<T>::remove(netuid);
LastMechansimStepBlock::<T>::remove(netuid);
Expand Down Expand Up @@ -510,6 +511,7 @@ impl<T: Config> Pallet<T> {
RAORecycledForRegistration::<T>::remove(netuid);
MaxRegistrationsPerBlock::<T>::remove(netuid);
WeightsVersionKey::<T>::remove(netuid);
PendingRootAlphaDivs::<T>::remove(netuid);

// --- 17. Subtoken / feature flags.
LiquidAlphaOn::<T>::remove(netuid);
Expand All @@ -528,7 +530,6 @@ impl<T: Config> Pallet<T> {
let _ = NeuronCertificates::<T>::clear_prefix(netuid, u32::MAX, None);
let _ = Prometheus::<T>::clear_prefix(netuid, u32::MAX, None);
let _ = AlphaDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
let _ = TaoDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
let _ = PendingChildKeys::<T>::clear_prefix(netuid, u32::MAX, None);
let _ = AssociatedEvmAddress::<T>::clear_prefix(netuid, u32::MAX, None);

Expand Down
Loading
Loading