-
Notifications
You must be signed in to change notification settings - Fork 258
Delegate set claim type #2224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
unconst
wants to merge
28
commits into
devnet-ready
Choose a base branch
from
delegate_set_claim_type
base: devnet-ready
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+510
−7
Open
Delegate set claim type #2224
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
2c68387
delegates can set the claim type for all their delegates
6c50312
record flow
12b7af2
ran fmt
badae21
claim type
03908e3
fixes
13b2ee1
fmt
2f70212
Keep default
d12bcfc
add tests fix errors
857e59e
commit Cargo.lock
sam0x17 ad3a0d1
fix
sam0x17 f743b87
Merge remote-tracking branch 'origin/devnet-ready' into delegate_set_…
sam0x17 26c9a3e
bump spec version
sam0x17 665b72f
bump spec version
sam0x17 eaf07dc
Merge remote-tracking branch 'origin/devnet-ready' into delegate_set_…
sam0x17 43896e2
Merge branch 'root-claim-upgrade2' into delegate_set_claim_type
shamil-gadelshin 9b34a03
Fix set_validator_claim_type
shamil-gadelshin c991786
Merge branch 'devnet-ready' into _delegate_set_claim_type
shamil-gadelshin d536c5f
Merge branch 'devnet-ready' into delegate_set_claim_type
shamil-gadelshin 7ab6ade
Add SubnetTaoFlow test.
shamil-gadelshin c7c6747
Merge branch 'devnet-ready' into delegate_set_claim_type
shamil-gadelshin e55109d
Modify ValidatorClaimTypeSet event
shamil-gadelshin 7b53c20
Bump spec version.
shamil-gadelshin 897a623
Merge branch 'devnet-ready' into delegate_set_claim_type
shamil-gadelshin 75f6845
Merge remote-tracking branch 'origin/devnet-ready' into delegate_set_…
sam0x17 6c38494
Merge remote-tracking branch 'origin/devnet-ready' into delegate_set_…
sam0x17 709676c
Add tao outflow root_prop multiplier
shamil-gadelshin fa61d93
Add test for calculate_tao_outflow()
shamil-gadelshin ef8e46d
Fix set_validator_claim_type
shamil-gadelshin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ use super::*; | |
| use frame_support::weights::Weight; | ||
| use sp_core::Get; | ||
| use sp_std::collections::btree_set::BTreeSet; | ||
| use substrate_fixed::types::I96F32; | ||
| use substrate_fixed::types::{I96F32, U96F32}; | ||
| use subtensor_swap_interface::SwapHandler; | ||
|
|
||
| impl<T: Config> Pallet<T> { | ||
|
|
@@ -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 { | ||
|
|
@@ -179,6 +190,12 @@ impl<T: Config> Pallet<T> { | |
| } | ||
| }; | ||
|
|
||
| let recorded_tao_outflow = | ||
| Self::calculate_tao_outflow(netuid, owed_tao.amount_paid_out); | ||
|
|
||
| // Importantly measures swap as flow. | ||
| Self::record_tao_outflow(netuid, recorded_tao_outflow.into()); | ||
|
|
||
| Self::increase_stake_for_hotkey_and_coldkey_on_subnet( | ||
| hotkey, | ||
| coldkey, | ||
|
|
@@ -194,7 +211,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, | ||
|
|
@@ -209,6 +226,35 @@ impl<T: Config> Pallet<T> { | |
| }); | ||
| } | ||
|
|
||
| // Calculates root proportion for subnet, uses "1 / root_prop" (with 10 as an upper bound) as | ||
| // a multiplier for provided Tao amount. | ||
| pub(crate) fn calculate_tao_outflow(netuid: NetUid, amount: TaoCurrency) -> TaoCurrency { | ||
| let root_tao: U96F32 = U96F32::saturating_from_num(SubnetTAO::<T>::get(NetUid::ROOT)); | ||
| let tao_weight: U96F32 = root_tao.saturating_mul(Self::get_tao_weight()); | ||
| let alpha_issuance: U96F32 = U96F32::saturating_from_num(Self::get_alpha_issuance(netuid)); | ||
| let root_proportion: U96F32 = tao_weight | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have this code in multiple places in code and need to consolidate it. Let it be a tech debt for now :( |
||
| .checked_div(tao_weight.saturating_add(alpha_issuance)) | ||
| .unwrap_or(U96F32::saturating_from_num(0)); | ||
|
|
||
| let root_prop_multiplier = { | ||
| let root_prop_multiplier = U96F32::saturating_from_num(1) | ||
| .checked_div(root_proportion) | ||
| .unwrap_or(U96F32::saturating_from_num(0.0)); | ||
| let upper_bound = U96F32::saturating_from_num(10); | ||
|
|
||
| if root_prop_multiplier < upper_bound { | ||
| root_prop_multiplier | ||
| } else { | ||
| upper_bound | ||
| } | ||
| }; | ||
|
|
||
| let tao = U96F32::saturating_from_num(amount.to_u64()); | ||
| let recorded_tao_outflow: u64 = tao.saturating_mul(root_prop_multiplier).to_num(); | ||
|
|
||
| recorded_tao_outflow.into() | ||
| } | ||
|
|
||
| fn root_claim_on_subnet_weight(_root_claim_type: RootClaimTypeEnum) -> Weight { | ||
| Weight::from_parts(60_000_000, 6987) | ||
| .saturating_add(T::DbWeight::get().reads(7_u64)) | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.