Skip to content
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

Backport/dev registrations unstake all #468

Closed
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
cd08289
fix: reject registrations only after 3 times target
camfairchild Apr 29, 2024
d0043b5
upped spec version
shibshib Apr 29, 2024
a164a80
Merge pull request #377 from camfairchild/fix/fix-reg-rejection-limit
shibshib Apr 29, 2024
0e88691
Revert "fix: reject registrations only after 3 times target"
distributedstatemachine Apr 29, 2024
3bdcdd8
Merge pull request #378 from opentensor/revert-377-fix/fix-reg-reject…
distributedstatemachine Apr 29, 2024
57aeaf5
fixes hotregs
shibshib Apr 29, 2024
2c75c50
revert accidental change hotreg
shibshib Apr 29, 2024
2971ae0
Fix hotregs hotpatch rebased off of main
shibshib Apr 29, 2024
981e6af
Fixed cargo fmt issue
shibshib Apr 29, 2024
3e97cb2
Fixed test_registration_rate_limit_exceeded test
shibshib Apr 29, 2024
f4869d9
fix cargo fmt
sam0x17 Apr 29, 2024
e2dd8c5
Merge pull request #379 from opentensor/fix_hotregs_shib
sam0x17 Apr 30, 2024
849fad7
fix: allow unstaking entire balance
orriin Apr 30, 2024
562a0fa
fix: bump spec version
orriin Apr 30, 2024
9b1c533
Merge pull request #382 from opentensor/hotfix/unstake-entire-balance
orriin Apr 30, 2024
e02b57e
hotfix: const adjustment
orriin Apr 30, 2024
534ed79
Merge pull request #383 from opentensor/hotfix/const-adjustment
orriin Apr 30, 2024
6be147d
Change minimum take to 18%
gztensor May 6, 2024
9682e70
Merge pull request #399 from opentensor/feat/set-narrow-take-limit-bo…
sam0x17 May 7, 2024
e4d9220
Added reserved nodes to docker compose to ensure sync with validator
shibshib May 10, 2024
d9217e9
fix: bump testnet spec version
orriin May 10, 2024
da21fb6
Merge pull request #406 from opentensor/reserved_test_nodes
sam0x17 May 10, 2024
f6169aa
Merge pull request #407 from opentensor/fix/bump-testnet-spec-version
sam0x17 May 13, 2024
88cd41e
Merge remote-tracking branch 'origin/testnet' into try-finney-deploy-…
sam0x17 May 20, 2024
1048858
Merge remote-tracking branch 'origin/testnet' into try-finney-deploy-…
sam0x17 May 20, 2024
083f3d2
Merge branch 'try-finney-deploy-5-20-2024' of github.com:opentensor/s…
May 21, 2024
54578ab
chore: bump finney spec version
May 21, 2024
3ddd88a
chore: bump spec version
May 21, 2024
65d8367
Merge pull request #442 from opentensor/try-finney-deploy-5-20-2024
distributedstatemachine May 21, 2024
56f6c02
feat: min take 9%
May 22, 2024
c0e3078
chore: fmt
May 22, 2024
5bdb80d
fix: admin-utils tests
May 22, 2024
29814dc
chore: fmt
May 22, 2024
7a09392
Update comments in staking tes
gztensor May 22, 2024
1e37c13
chore: comment out publish ci
May 22, 2024
54e620c
chore: pr comments
May 22, 2024
74778a6
fmt , delete publish job
May 22, 2024
8aa14d9
fix: test
May 22, 2024
8153831
Merge pull request #451 from opentensor/patch/delegate_take
distributedstatemachine May 22, 2024
2e586d7
typo
orriin Apr 30, 2024
2530066
use removed stake to update balance in clear nom
camfairchild May 23, 2024
e380c6b
add tests
camfairchild May 23, 2024
dd25a7c
Sweep nom stake below minimum
camfairchild May 23, 2024
a4a8b87
Fix hotregs hotpatch rebased off of main
shibshib Apr 29, 2024
ac0be46
fix test for POW register
camfairchild May 23, 2024
94a55e6
bump spec
camfairchild May 23, 2024
33284b1
Merge pull request #463 from opentensor/fix/fix-reg-interval-too-short
distributedstatemachine May 23, 2024
55195c9
Merge pull request #462 from opentensor/fix/allow-unstake-below-nom-l…
distributedstatemachine May 23, 2024
b02c42e
Merge branch 'development' into backport/dev_registrations_unstake_all
distributedstatemachine May 24, 2024
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
102 changes: 0 additions & 102 deletions .github/workflows/publish-tag.yml

This file was deleted.

2 changes: 1 addition & 1 deletion pallets/admin-utils/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ parameter_types! {
pub const InitialStakePruningMin: u16 = 0;
pub const InitialFoundationDistribution: u64 = 0;
pub const InitialDefaultTake: u16 = 11_796; // 18% honest number.
pub const InitialMinTake: u16 = 0;
pub const InitialMinTake: u16 = 5_898; // 9%;
pub const InitialWeightsVersionKey: u16 = 0;
pub const InitialServingRateLimit: u64 = 0; // No limit.
pub const InitialTxRateLimit: u64 = 0; // Disable rate limit for testing
Expand Down
4 changes: 2 additions & 2 deletions pallets/admin-utils/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ mod sudo_set_nominator_min_required_stake {
assert_ok!(SubtensorModule::do_become_delegate(
<<Test as Config>::RuntimeOrigin>::signed(cold1),
hot1,
0
u16::MAX / 10
));
assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot1), cold1);

Expand All @@ -954,7 +954,7 @@ mod sudo_set_nominator_min_required_stake {
assert_ok!(SubtensorModule::do_become_delegate(
<<Test as Config>::RuntimeOrigin>::signed(cold2),
hot2,
0
u16::MAX / 10
));
assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot2), cold2);

Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ where
Pallet::<T>::get_registrations_this_interval(*netuid);
let max_registrations_per_interval =
Pallet::<T>::get_target_registrations_per_interval(*netuid);
if registrations_this_interval >= max_registrations_per_interval {
if registrations_this_interval >= (max_registrations_per_interval * 3) {
// If the registration limit for the interval is exceeded, reject the transaction
return InvalidTransaction::ExhaustsResources.into();
}
Expand Down
35 changes: 17 additions & 18 deletions pallets/subtensor/src/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,26 +432,18 @@ impl<T: Config> Pallet<T> {
Error::<T>::UnstakeRateLimitExceeded
);

// If this is a nomination stake, check if total stake after removing will be above
// the minimum required stake.

// If coldkey is not owner of the hotkey, it's a nomination stake.
if !Self::coldkey_owns_hotkey(&coldkey, &hotkey) {
let total_stake_after_remove =
Stake::<T>::get(&hotkey, &coldkey).saturating_sub(stake_to_be_removed);

ensure!(
total_stake_after_remove >= NominatorMinRequiredStake::<T>::get(),
Error::<T>::NomStakeBelowMinimumThreshold
);
}

// We remove the balance from the hotkey.
Self::decrease_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, stake_to_be_removed);

// We add the balancer to the coldkey. If the above fails we will not credit this coldkey.
// We add the balance to the coldkey. If the above fails we will not credit this coldkey.
Self::add_balance_to_coldkey_account(&coldkey, stake_to_be_removed);

// If the stake is below the minimum, we clear the nomination from storage.
// Not, this only applies to nominator stakes.
// If the coldkey does not own the hotkey, it's a nominator stake.
let new_stake = Self::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey);
Self::clear_small_nomination_if_required(&hotkey, &coldkey, new_stake);

// Set last block for rate limiting
let block: u64 = Self::get_current_block_as_u64();
Self::set_last_tx_block(&coldkey, block);
Expand Down Expand Up @@ -675,17 +667,24 @@ impl<T: Config> Pallet<T> {
/// It also removes the stake entry for the hotkey-coldkey pairing and adjusts the TotalStake
/// and TotalIssuance by subtracting the removed stake amount.
///
/// Returns the amount of stake that was removed.
///
/// # Arguments
///
/// * `coldkey` - A reference to the AccountId of the coldkey involved in the staking.
/// * `hotkey` - A reference to the AccountId of the hotkey associated with the coldkey.
pub fn empty_stake_on_coldkey_hotkey_account(coldkey: &T::AccountId, hotkey: &T::AccountId) {
pub fn empty_stake_on_coldkey_hotkey_account(
coldkey: &T::AccountId,
hotkey: &T::AccountId,
) -> u64 {
let current_stake: u64 = Stake::<T>::get(hotkey, coldkey);
TotalColdkeyStake::<T>::mutate(coldkey, |old| *old = old.saturating_sub(current_stake));
TotalHotkeyStake::<T>::mutate(hotkey, |stake| *stake = stake.saturating_sub(current_stake));
Stake::<T>::remove(hotkey, coldkey);
TotalStake::<T>::mutate(|stake| *stake = stake.saturating_sub(current_stake));
TotalIssuance::<T>::mutate(|issuance| *issuance = issuance.saturating_sub(current_stake));

current_stake
}

/// Clears the nomination for an account, if it is a nominator account and the stake is below the minimum required threshold.
Expand All @@ -700,9 +699,9 @@ impl<T: Config> Pallet<T> {
if stake < Self::get_nominator_min_required_stake() {
// Remove the stake from the nominator account. (this is a more forceful unstake operation which )
// Actually deletes the staking account.
Self::empty_stake_on_coldkey_hotkey_account(coldkey, hotkey);
let cleared_stake = Self::empty_stake_on_coldkey_hotkey_account(coldkey, hotkey);
// Add the stake to the coldkey account.
Self::add_balance_to_coldkey_account(coldkey, stake);
Self::add_balance_to_coldkey_account(coldkey, cleared_stake);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pallets/subtensor/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ parameter_types! {
pub const InitialStakePruningMin: u16 = 0;
pub const InitialFoundationDistribution: u64 = 0;
pub const InitialDefaultTake: u16 = 11_796; // 18%, same as in production
pub const InitialMinTake: u16 = 0;
pub const InitialMinTake: u16 =5_898; // 9%;
pub const InitialWeightsVersionKey: u16 = 0;
pub const InitialServingRateLimit: u64 = 0; // No limit.
pub const InitialTxRateLimit: u64 = 0; // Disable rate limit for testing
Expand All @@ -143,7 +143,7 @@ parameter_types! {
pub const InitialAdjustmentInterval: u16 = 100;
pub const InitialAdjustmentAlpha: u64 = 0; // no weight to previous value.
pub const InitialMaxRegistrationsPerBlock: u16 = 3;
pub const InitialTargetRegistrationsPerInterval: u16 = 2;
pub const InitialTargetRegistrationsPerInterval: u16 = 3;
pub const InitialPruningScore : u16 = u16::MAX;
pub const InitialRegistrationRequirement: u16 = u16::MAX; // Top 100%
pub const InitialMinDifficulty: u64 = 1;
Expand Down
100 changes: 74 additions & 26 deletions pallets/subtensor/tests/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ fn test_registration_rate_limit_exceeded() {
let coldkey_account_id = U256::from(667);
let who: <Test as frame_system::Config>::AccountId = hotkey_account_id;

let max_registrants = 1;
SubtensorModule::set_target_registrations_per_interval(netuid, max_registrants);
SubtensorModule::set_registrations_this_interval(netuid, 1);
let target_registrants = 1;
let max_registrants = target_registrants * 3;
SubtensorModule::set_target_registrations_per_interval(netuid, target_registrants);
SubtensorModule::set_registrations_this_interval(netuid, max_registrants);

let (nonce, work) = SubtensorModule::create_work_for_block_number(
netuid,
Expand Down Expand Up @@ -290,18 +291,18 @@ fn test_burned_registration_under_limit() {
let netuid: u16 = 1;
let hotkey_account_id: U256 = U256::from(1);
let coldkey_account_id = U256::from(667);
let who: <Test as frame_system::Config>::AccountId = hotkey_account_id;
let block_number: u64 = 0;
let who: <Test as frame_system::Config>::AccountId = coldkey_account_id;
let burn_cost = 1000;
// Set the burn cost
SubtensorModule::set_burn(netuid, burn_cost);

let (nonce, work) = SubtensorModule::create_work_for_block_number(
netuid,
block_number,
129123813,
&hotkey_account_id,
);
add_network(netuid, 13, 0); // Add the network
// Give it some TAO to the coldkey balance; more than the burn cost
SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, burn_cost + 10_000);

let max_registrants = 2;
SubtensorModule::set_target_registrations_per_interval(netuid, max_registrants);
let target_registrants = 2;
let max_registrants = target_registrants * 3; // Maximum is 3 times the target
SubtensorModule::set_target_registrations_per_interval(netuid, target_registrants);

let call_burned_register: pallet_subtensor::Call<Test> =
pallet_subtensor::Call::burned_register {
Expand All @@ -317,21 +318,15 @@ fn test_burned_registration_under_limit() {
extension.validate(&who, &call_burned_register.into(), &info, 10);
assert_ok!(burned_register_result);

add_network(netuid, 13, 0);
//actually call register
assert_ok!(SubtensorModule::register(
<<Test as Config>::RuntimeOrigin>::signed(hotkey_account_id),
assert_ok!(SubtensorModule::burned_register(
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
netuid,
block_number,
nonce,
work,
hotkey_account_id,
coldkey_account_id
));

let current_registrants = SubtensorModule::get_registrations_this_interval(netuid);
let target_registrants = SubtensorModule::get_target_registrations_per_interval(netuid);
assert!(current_registrants <= target_registrants);
assert!(current_registrants <= max_registrants);
});
}

Expand All @@ -340,11 +335,15 @@ fn test_burned_registration_rate_limit_exceeded() {
new_test_ext(1).execute_with(|| {
let netuid: u16 = 1;
let hotkey_account_id: U256 = U256::from(1);
let who: <Test as frame_system::Config>::AccountId = hotkey_account_id;
let max_registrants = 1;
let coldkey_account_id = U256::from(667);
let who: <Test as frame_system::Config>::AccountId = coldkey_account_id;

SubtensorModule::set_target_registrations_per_interval(netuid, max_registrants);
SubtensorModule::set_registrations_this_interval(netuid, 1);
let target_registrants = 1;
let max_registrants = target_registrants * 3; // Maximum is 3 times the target

SubtensorModule::set_target_registrations_per_interval(netuid, target_registrants);
// Set the current registrations to the maximum; should not be able to register more
SubtensorModule::set_registrations_this_interval(netuid, max_registrants);

let call_burned_register: pallet_subtensor::Call<Test> =
pallet_subtensor::Call::burned_register {
Expand All @@ -369,6 +368,55 @@ fn test_burned_registration_rate_limit_exceeded() {
});
}

#[test]
fn test_burned_registration_rate_allows_burn_adjustment() {
// We need to be able to register more than the *target* registrations per interval
new_test_ext(1).execute_with(|| {
let netuid: u16 = 1;
let hotkey_account_id: U256 = U256::from(1);
let coldkey_account_id = U256::from(667);
let who: <Test as frame_system::Config>::AccountId = coldkey_account_id;

let burn_cost = 1000;
// Set the burn cost
SubtensorModule::set_burn(netuid, burn_cost);

add_network(netuid, 13, 0); // Add the network
// Give it some TAO to the coldkey balance; more than the burn cost
SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, burn_cost + 10_000);

let target_registrants = 1; // Target is 1, but we can register more than that, up to some maximum.
SubtensorModule::set_target_registrations_per_interval(netuid, target_registrants);
// Set the current registrations to above the target; we should be able to register at least 1 more
SubtensorModule::set_registrations_this_interval(netuid, target_registrants);

// Register one more, so the current registrations are above the target
let call_burned_register: pallet_subtensor::Call<Test> =
pallet_subtensor::Call::burned_register {
netuid,
hotkey: hotkey_account_id,
};

let info: DispatchInfo =
DispatchInfoOf::<<Test as frame_system::Config>::RuntimeCall>::default();
let extension = SubtensorSignedExtension::<Test>::new();
//does not actually call register
let burned_register_result =
extension.validate(&who, &call_burned_register.into(), &info, 10);
assert_ok!(burned_register_result);

//actually call register
assert_ok!(SubtensorModule::burned_register(
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
netuid,
hotkey_account_id
));

let current_registrants = SubtensorModule::get_registrations_this_interval(netuid);
assert!(current_registrants > target_registrants); // Should be able to register more than the target
});
}

#[test]
fn test_burned_registration_ok() {
new_test_ext(1).execute_with(|| {
Expand Down
Loading
Loading