Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
11 changes: 11 additions & 0 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2244,6 +2244,17 @@ pub mod pallet {
ValueQuery,
DefaultRootClaimType<T>,
>;
#[pallet::storage] // -- MAP ( hotkey, netuid ) --> delegate_claim_type enum
pub type DelegateClaimType<T: Config> = StorageMap<
_,
Blake2_128Concat,
T::AccountId,
Identity,
u16,
RootClaimTypeEnum,
ValueQuery,
DefaultRootClaimType<T>,
>;
#[pallet::storage] // --- MAP ( u64 ) --> coldkey | Maps coldkeys that have stake to an index
pub type StakingColdkeysByIndex<T: Config> =
StorageMap<_, Identity, u64, T::AccountId, OptionQuery>;
Expand Down
26 changes: 26 additions & 0 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2421,5 +2421,31 @@ mod dispatches {

Ok(())
}

/// --- Sets delegate claim type for a hotkey on a subnet.
#[pallet::call_index(125)]
#[pallet::weight((
Weight::from_parts(5_711_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)),
DispatchClass::Operational,
Pays::Yes
))]
pub fn set_delegate_claim_type(
origin: OriginFor<T>,
hotkey: T::AccountId,
netuid: NetUid,
new_claim_type: RootClaimTypeEnum,
) -> DispatchResult {
let coldkey: T::AccountId = ensure_signed(origin)?;
ensure!(
Self::coldkey_owns_hotkey(coldkey.clone(), hotkey.clone()),
Error::<T>::NonAssociatedColdKey
);
DelegateClaimType::<T>::insert((hotkey.clone(), netuid), new_claim_type.clone());
Self::deposit_event(Event::DelegateClaimTypeSet {
hotkey: hotkey.clone(),
root_claim_type: new_claim_type,
});
Ok(())
}
}
}
9 changes: 9 additions & 0 deletions pallets/subtensor/src/macros/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,15 @@ mod events {
root_claim_type: RootClaimTypeEnum,
},

/// Root claim type for a coldkey has been set.
/// Parameters:
/// (coldkey, u8)
DelegateClaimTypeSet {
/// delegate hotkey
hotkeu: T::AccountId,
root_claim_type: RootClaimTypeEnum,
},

/// Subnet lease dividends have been distributed.
SubnetLeaseDividendsDistributed {
/// The lease ID
Expand Down
18 changes: 16 additions & 2 deletions pallets/subtensor/src/staking/claim_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl<T: Config> Pallet<T> {
hotkey: &T::AccountId,
coldkey: &T::AccountId,
netuid: NetUid,
root_claim_type: RootClaimTypeEnum,
mut root_claim_type: RootClaimTypeEnum,
ignore_minimum_condition: bool,
) {
// Subtract the root claimed.
Expand Down Expand Up @@ -157,6 +157,11 @@ impl<T: Config> Pallet<T> {
return; // no-op
}

// If root_claim_type is Delegated, switch to the delegate's actual claim type.
if let RootClaimTypeEnum::Delegated = root_claim_type {
root_claim_type = DelegateClaimType::<T>::get(hotkey, netuid);
}

match root_claim_type {
// Increase stake on root
RootClaimTypeEnum::Swap => {
Expand All @@ -175,6 +180,9 @@ impl<T: Config> Pallet<T> {
}
};

// Importantly measures swap as flow.
Self::record_tao_outflow(netuid, owed_tao);

Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
hotkey,
coldkey,
Expand All @@ -189,14 +197,20 @@ impl<T: Config> Pallet<T> {
);
}
RootClaimTypeEnum::Keep => {
// Increase the stake with the alpha owned
// Increase the stake with the alpha owed
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
hotkey,
coldkey,
netuid,
owed_u64.into(),
);
}
// Add Delegated arm for completeness, but it should never reach here due to switch above.
RootClaimTypeEnum::Delegated => {
// Should not reach here. Added for completeness.
log::error!("Delegated root_claim_type should have been switched. Skipping.");
return;
}
};

// Increase root claimed by owed amount.
Expand Down
Loading