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
20 changes: 19 additions & 1 deletion pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ pub mod pallet {
/// Subnets to keep alpha emissions (swap everything else).
subnets: BTreeSet<NetUid>,
},
/// Delegate choice to subnet.
Delegated,
}

/// Default minimum root claim amount.
Expand All @@ -354,7 +356,12 @@ pub mod pallet {
/// This is set by the user. Either swap to TAO or keep as alpha.
#[pallet::type_value]
pub fn DefaultRootClaimType<T: Config>() -> RootClaimTypeEnum {
RootClaimTypeEnum::default()
RootClaimTypeEnum::Delegated
}
/// Default value for delegate claim type storage
#[pallet::type_value]
pub fn DefaultValidatorClaimType<T: Config>() -> RootClaimTypeEnum {
RootClaimTypeEnum::Keep
}

/// Default number of root claims per claim call.
Expand Down Expand Up @@ -2252,6 +2259,17 @@ pub mod pallet {
ValueQuery,
DefaultRootClaimType<T>,
>;
#[pallet::storage] // -- MAP ( hotkey, netuid ) --> delegate_claim_type enum
pub type ValidatorClaimType<T: Config> = StorageDoubleMap<
_,
Blake2_128Concat,
T::AccountId,
Identity,
NetUid,
RootClaimTypeEnum,
ValueQuery,
DefaultValidatorClaimType<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
33 changes: 33 additions & 0 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2431,5 +2431,38 @@ 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_validator_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, &hotkey),
Error::<T>::NonAssociatedColdKey
);

// Ensure the delegate claim type is not Delegated.
ensure!(
!matches!(new_claim_type, RootClaimTypeEnum::Delegated),
Error::<T>::InvalidRootClaimType
);

ValidatorClaimType::<T>::insert(hotkey.clone(), netuid, new_claim_type.clone());
Self::deposit_event(Event::ValidatorClaimTypeSet {
hotkey: hotkey.clone(),
root_claim_type: new_claim_type,
});
Ok(())
}
}
}
2 changes: 2 additions & 0 deletions pallets/subtensor/src/macros/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,7 @@ mod errors {
InvalidRootClaimThreshold,
/// Exceeded subnet limit number or zero.
InvalidSubnetNumber,
/// Delegates cant set delegated as claim type
InvalidRootClaimType,
}
}
10 changes: 10 additions & 0 deletions pallets/subtensor/src/macros/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,16 @@ mod events {
root_claim_type: RootClaimTypeEnum,
},

/// Root claim type for a coldkey has been set.
/// Parameters:
/// (coldkey, u8)
ValidatorClaimTypeSet {
/// delegate hotkey
hotkey: T::AccountId,
/// root claim type enum
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 @@ -157,10 +157,21 @@ impl<T: Config> Pallet<T> {
return; // no-op
}

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

let swap = match actual_root_claim {
RootClaimTypeEnum::Swap => true,
RootClaimTypeEnum::Keep => false,
RootClaimTypeEnum::KeepSubnets { subnets } => !subnets.contains(&netuid),
RootClaimTypeEnum::Delegated => {
// Should not reach here. Added for completeness.
log::error!("Delegated root_claim_type should have been switched. Skipping.");
return;
}
};

if swap {
Expand All @@ -179,6 +190,9 @@ impl<T: Config> Pallet<T> {
}
};

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

Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
hotkey,
coldkey,
Expand All @@ -194,7 +208,7 @@ impl<T: Config> Pallet<T> {
} else
/* 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,
Expand Down
Loading
Loading