From 56f6c024e5cd6acd41a865cf6784cc268f784b52 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Wed, 22 May 2024 12:25:08 +0400 Subject: [PATCH 1/9] feat: min take 9% --- pallets/admin-utils/tests/mock.rs | 2 +- pallets/subtensor/tests/mock.rs | 2 +- pallets/subtensor/tests/staking.rs | 123 ++++++++++++++--------------- runtime/src/lib.rs | 2 +- 4 files changed, 64 insertions(+), 65 deletions(-) diff --git a/pallets/admin-utils/tests/mock.rs b/pallets/admin-utils/tests/mock.rs index 72961dd46..b13b718cc 100644 --- a/pallets/admin-utils/tests/mock.rs +++ b/pallets/admin-utils/tests/mock.rs @@ -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 diff --git a/pallets/subtensor/tests/mock.rs b/pallets/subtensor/tests/mock.rs index c43566b26..9b964fcb0 100644 --- a/pallets/subtensor/tests/mock.rs +++ b/pallets/subtensor/tests/mock.rs @@ -124,7 +124,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 diff --git a/pallets/subtensor/tests/staking.rs b/pallets/subtensor/tests/staking.rs index 8b48c2715..a004fdf66 100644 --- a/pallets/subtensor/tests/staking.rs +++ b/pallets/subtensor/tests/staking.rs @@ -1423,12 +1423,12 @@ fn test_full_with_delegating() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - 10 + u16::MAX/10 )); assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey1), hotkey1, - 10 + u16::MAX/10 )); assert!(SubtensorModule::hotkey_is_delegate(&hotkey0)); assert!(SubtensorModule::hotkey_is_delegate(&hotkey1)); @@ -1438,7 +1438,7 @@ fn test_full_with_delegating() { SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - 1000 + u16::MAX/10 ), Err(Error::::AlreadyDelegate.into()) ); @@ -1446,7 +1446,7 @@ fn test_full_with_delegating() { SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey1), hotkey1, - 1000 + u16::MAX/10 ), Err(Error::::AlreadyDelegate.into()) ); @@ -1505,21 +1505,21 @@ fn test_full_with_delegating() { SubtensorModule::emit_inflation_through_hotkey_account(&hotkey1, 0, 1000); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey0), - 601 - ); // 200 + 1000 x ( 200 / 500 ) = 200 + 400 = 600 ~= 601 + 660 + ); // 200 + 1000 x ( 200 / 500 )+ 60 = 200 + 400 ~= 660 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey1), - 700 - ); // 200 + 1000 x ( 200 / 400 ) = 200 + 500 = 700 + 650 + ); // 200 + 1000 x ( 200 / 400 ) - 50 = 200 + 500 = 700 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey0), - 899 - ); // 300 + 1000 x ( 300 / 500 ) = 300 + 600 = 900 ~= 899 + 840 + ); // 300 + 1000 x ( 300 / 500 ) - 60= 300 + 600 = 840 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey1), - 700 - ); // 200 + 1000 x ( 200 / 400 ) = 300 + 600 = 700 - assert_eq!(SubtensorModule::get_total_stake(), 2900); // 600 + 700 + 900 + 700 = 2900 + 750 + ); // 200 + 1000 x ( 200 / 400 ) + 50 = 300 + 600 + 50 = 750 + assert_eq!(SubtensorModule::get_total_stake(), 2900); // 600 + 700 + 900 + 750 = 2900 // // Try unstaking too much. assert_eq!( @@ -1580,19 +1580,19 @@ fn test_full_with_delegating() { // All the amounts have been decreased. assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey0), - 501 + 560 ); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey1), - 600 + 550 ); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey0), - 799 + 740 ); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey1), - 600 + 650 ); // Lets register and stake a new key. @@ -1876,12 +1876,12 @@ fn test_full_with_delegating_some_servers() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - 10 + u16::MAX/10 )); assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey1), hotkey1, - 10 + u16::MAX/10 )); assert!(SubtensorModule::hotkey_is_delegate(&hotkey0)); assert!(SubtensorModule::hotkey_is_delegate(&hotkey1)); @@ -1939,22 +1939,22 @@ fn test_full_with_delegating_some_servers() { SubtensorModule::emit_inflation_through_hotkey_account(&hotkey1, 123, 2_000); // 2_123 total emission. assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey0), - 801 - ); // 200 + (200 + 1000 x ( 200 / 500 )) = 200 + (200 + 400) = 800 ~= 801 + 860 + ); // 200 + (200 + 1000 x ( 200 / 500 )) + 60 = 200 + (200 + 400) + 60 = 860 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey0), - 899 - ); // 300 + 1000 x ( 300 / 500 ) = 300 + 600 = 900 ~= 899 + 840 + ); // 300 + 1000 x ( 300 / 500 ) - 50 = 300 + 600 - 50 = 840 assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey0), 1_700); // initial + server emission + validator emission = 799 + 899 = 1_698 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey1), - 1_200 - ); // 200 + (0 + 2000 x ( 200 / 400 )) = 200 + (1000) = 1_200 + 1_100 + ); // 200 + (0 + 2000 x ( 200 / 400 )) - 100 = 200 + (1000) - 100= 1_100 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey1), - 1_323 - ); // 200 + (123 + 2000 x ( 200 / 400 )) = 200 + (1_200) = 1_323 + 1_423 + ); // 200 + (123 + 2000 x ( 200 / 400 )) + 100 = 200 + (1_200)+ 100 = 1_423 assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey1), 2_523); // 400 + 2_123 assert_eq!(SubtensorModule::get_total_stake(), 4_223); // 1_700 + 2_523 = 4_223 @@ -1964,20 +1964,20 @@ fn test_full_with_delegating_some_servers() { SubtensorModule::emit_inflation_through_hotkey_account(&hotkey1, 150, 0); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey0), - 1_151 - ); // + 350 = 1_151 + 1_210 + ); // + 350 + 60 = 1_210 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey1), - 1_200 + 1_100 ); // No change. assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey0), - 899 + 840 ); // No change. assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey1), - 1_473 - ); // 1_323 + 150 = 1_473 + 1_573 + ); // 1_323 + 150 + 100 = 1_573 assert_eq!(SubtensorModule::get_total_stake(), 4_723); // 4_223 + 500 = 4_823 // Lets register and stake a new key. @@ -2204,12 +2204,12 @@ fn test_full_block_emission_occurs() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - 10 + u16::MAX/10 )); assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey1), hotkey1, - 10 + u16::MAX/10 )); assert!(SubtensorModule::hotkey_is_delegate(&hotkey0)); assert!(SubtensorModule::hotkey_is_delegate(&hotkey1)); @@ -2455,7 +2455,7 @@ fn test_clear_small_nominations() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(cold1), hot1, - 0 + SubtensorModule::get_min_take() )); assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot1), cold1); @@ -2464,7 +2464,7 @@ fn test_clear_small_nominations() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(cold2), hot2, - 0 + SubtensorModule::get_min_take() )); assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot2), cold2); @@ -2725,13 +2725,12 @@ fn test_delegate_take_can_be_decreased() { )); assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); - // Coldkey / hotkey 0 decreases take to 5% - assert_ok!(SubtensorModule::do_decrease_take( + // Coldkey / hotkey 0 decreases take to 5%. This should fail as the minimum take is 9% + assert_err!(SubtensorModule::do_decrease_take( <::RuntimeOrigin>::signed(coldkey0), hotkey0, u16::MAX / 20 - )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 20); + ), Error::::InvalidTake); }); } @@ -2764,7 +2763,7 @@ fn test_can_set_min_take_ok() { hotkey0, SubtensorModule::get_min_take() )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), 0); + assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), SubtensorModule::get_min_take()); }); } @@ -2784,24 +2783,24 @@ fn test_delegate_take_can_not_be_increased_with_decrease_take() { add_network(netuid, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); - // Coldkey / hotkey 0 become delegates with 5% take + // Coldkey / hotkey 0 become delegates with 10% take assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 20 + u16::MAX / 10 )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 20); + assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); - // Coldkey / hotkey 0 tries to increase take to 10% + // Coldkey / hotkey 0 tries to increase take to 12.5% assert_eq!( SubtensorModule::do_decrease_take( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + u16::MAX / 8 ), Err(Error::::InvalidTake.into()) ); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 20); + assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); }); } @@ -2821,23 +2820,23 @@ fn test_delegate_take_can_be_increased() { add_network(netuid, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); - // Coldkey / hotkey 0 become delegates with 5% take + // Coldkey / hotkey 0 become delegates with 10% take assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 20 + u16::MAX / 10 )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 20); + assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); step_block(1 + InitialTxDelegateTakeRateLimit::get() as u16); - // Coldkey / hotkey 0 decreases take to 10% + // Coldkey / hotkey 0 decreases take to 12.5% assert_ok!(SubtensorModule::do_increase_take( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + u16::MAX / 8 )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); + assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 8); }); } @@ -3006,24 +3005,24 @@ fn test_rate_limits_enforced_on_increase_take() { add_network(netuid, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); - // Coldkey / hotkey 0 become delegates with 5% take + // Coldkey / hotkey 0 become delegates with 10% take assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 20 + u16::MAX / 10 )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 20); + assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); - // Coldkey / hotkey 0 increases take to 10% + // Coldkey / hotkey 0 increases take to 12.5% assert_eq!( SubtensorModule::do_increase_take( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + u16::MAX / 8 ), Err(Error::::TxRateLimitExceeded.into()) ); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 20); + assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); step_block(1 + InitialTxDelegateTakeRateLimit::get() as u16); @@ -3031,8 +3030,8 @@ fn test_rate_limits_enforced_on_increase_take() { assert_ok!(SubtensorModule::do_increase_take( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + u16::MAX / 8 )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); + assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 8); }); } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index b954d2b3f..7360e6c90 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -779,7 +779,7 @@ parameter_types! { pub const SubtensorInitialPruningScore : u16 = u16::MAX; pub const SubtensorInitialBondsMovingAverage: u64 = 900_000; pub const SubtensorInitialDefaultTake: u16 = 11_796; // 18% honest number. - pub const SubtensorInitialMinTake: u16 = 11_796; // 18%, no change is allowed initially + pub const SubtensorInitialMinTake: u16 = 5_898; // 9% pub const SubtensorInitialWeightsVersionKey: u64 = 0; pub const SubtensorInitialMinDifficulty: u64 = 10_000_000; pub const SubtensorInitialMaxDifficulty: u64 = u64::MAX / 4; From c0e3078fbb7d807ed8844eb92b2a56c50ec1b134 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Wed, 22 May 2024 12:35:49 +0400 Subject: [PATCH 2/9] chore: fmt --- pallets/subtensor/tests/staking.rs | 34 ++++++++++++++++++------------ runtime/src/lib.rs | 2 +- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/pallets/subtensor/tests/staking.rs b/pallets/subtensor/tests/staking.rs index a004fdf66..4cf775b7a 100644 --- a/pallets/subtensor/tests/staking.rs +++ b/pallets/subtensor/tests/staking.rs @@ -1423,12 +1423,12 @@ fn test_full_with_delegating() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX/10 + u16::MAX / 10 )); assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey1), hotkey1, - u16::MAX/10 + u16::MAX / 10 )); assert!(SubtensorModule::hotkey_is_delegate(&hotkey0)); assert!(SubtensorModule::hotkey_is_delegate(&hotkey1)); @@ -1438,7 +1438,7 @@ fn test_full_with_delegating() { SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX/10 + u16::MAX / 10 ), Err(Error::::AlreadyDelegate.into()) ); @@ -1446,7 +1446,7 @@ fn test_full_with_delegating() { SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey1), hotkey1, - u16::MAX/10 + u16::MAX / 10 ), Err(Error::::AlreadyDelegate.into()) ); @@ -1876,12 +1876,12 @@ fn test_full_with_delegating_some_servers() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX/10 + u16::MAX / 10 )); assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey1), hotkey1, - u16::MAX/10 + u16::MAX / 10 )); assert!(SubtensorModule::hotkey_is_delegate(&hotkey0)); assert!(SubtensorModule::hotkey_is_delegate(&hotkey1)); @@ -2204,12 +2204,12 @@ fn test_full_block_emission_occurs() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX/10 + u16::MAX / 10 )); assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey1), hotkey1, - u16::MAX/10 + u16::MAX / 10 )); assert!(SubtensorModule::hotkey_is_delegate(&hotkey0)); assert!(SubtensorModule::hotkey_is_delegate(&hotkey1)); @@ -2726,11 +2726,14 @@ fn test_delegate_take_can_be_decreased() { assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); // Coldkey / hotkey 0 decreases take to 5%. This should fail as the minimum take is 9% - assert_err!(SubtensorModule::do_decrease_take( - <::RuntimeOrigin>::signed(coldkey0), - hotkey0, - u16::MAX / 20 - ), Error::::InvalidTake); + assert_err!( + SubtensorModule::do_decrease_take( + <::RuntimeOrigin>::signed(coldkey0), + hotkey0, + u16::MAX / 20 + ), + Error::::InvalidTake + ); }); } @@ -2763,7 +2766,10 @@ fn test_can_set_min_take_ok() { hotkey0, SubtensorModule::get_min_take() )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), SubtensorModule::get_min_take()); + assert_eq!( + SubtensorModule::get_hotkey_take(&hotkey0), + SubtensorModule::get_min_take() + ); }); } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 7360e6c90..b7cc7bea4 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -779,7 +779,7 @@ parameter_types! { pub const SubtensorInitialPruningScore : u16 = u16::MAX; pub const SubtensorInitialBondsMovingAverage: u64 = 900_000; pub const SubtensorInitialDefaultTake: u16 = 11_796; // 18% honest number. - pub const SubtensorInitialMinTake: u16 = 5_898; // 9% + pub const SubtensorInitialMinTake: u16 = 5_898; // 9% pub const SubtensorInitialWeightsVersionKey: u64 = 0; pub const SubtensorInitialMinDifficulty: u64 = 10_000_000; pub const SubtensorInitialMaxDifficulty: u64 = u64::MAX / 4; From 5bdb80d3f803db5811ae59e924e082a057126c84 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Wed, 22 May 2024 12:53:23 +0400 Subject: [PATCH 3/9] fix: admin-utils tests --- pallets/admin-utils/tests/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/admin-utils/tests/tests.rs b/pallets/admin-utils/tests/tests.rs index 5e50c7420..e63b67657 100644 --- a/pallets/admin-utils/tests/tests.rs +++ b/pallets/admin-utils/tests/tests.rs @@ -945,7 +945,7 @@ mod sudo_set_nominator_min_required_stake { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(cold1), hot1, - 0 + u16::MAX/10 )); assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot1), cold1); @@ -954,7 +954,7 @@ mod sudo_set_nominator_min_required_stake { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(cold2), hot2, - 0 + u16::MAX/10 )); assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot2), cold2); From 29814dc487af7a263db0d10859d20531e7df18d5 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Wed, 22 May 2024 12:57:26 +0400 Subject: [PATCH 4/9] chore: fmt --- pallets/admin-utils/tests/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/admin-utils/tests/tests.rs b/pallets/admin-utils/tests/tests.rs index e63b67657..c541d89e4 100644 --- a/pallets/admin-utils/tests/tests.rs +++ b/pallets/admin-utils/tests/tests.rs @@ -945,7 +945,7 @@ mod sudo_set_nominator_min_required_stake { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(cold1), hot1, - u16::MAX/10 + u16::MAX / 10 )); assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot1), cold1); @@ -954,7 +954,7 @@ mod sudo_set_nominator_min_required_stake { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(cold2), hot2, - u16::MAX/10 + u16::MAX / 10 )); assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot2), cold2); From 7a09392ed06972dcbd43213b12fa25eddebe2c5e Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Wed, 22 May 2024 11:04:12 -0400 Subject: [PATCH 5/9] Update comments in staking tes --- pallets/subtensor/tests/staking.rs | 33 +++++++++++++++++++----------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/pallets/subtensor/tests/staking.rs b/pallets/subtensor/tests/staking.rs index 4cf775b7a..7ab2aa480 100644 --- a/pallets/subtensor/tests/staking.rs +++ b/pallets/subtensor/tests/staking.rs @@ -1503,23 +1503,32 @@ fn test_full_with_delegating() { // Lets emit inflation through the hot and coldkeys. SubtensorModule::emit_inflation_through_hotkey_account(&hotkey0, 0, 1000); SubtensorModule::emit_inflation_through_hotkey_account(&hotkey1, 0, 1000); + + // validator_take = take * validator_emission = 10% * 1000 = 100 + // old_stake + (validator_emission - validator_take) * stake_for_coldkey_and_hotkey / total_stake_for_hotkey + validator_take + // = + // 200 + 900 * 200 / 500 + 100 = 660 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey0), 660 - ); // 200 + 1000 x ( 200 / 500 )+ 60 = 200 + 400 ~= 660 + ); + // validator_take = take * validator_emission = 10% * 1000 = 100 + // old_stake + (validator_emission - validator_take) * stake_for_coldkey_and_hotkey / total_stake_for_hotkey + // = + // 200 + 900 * 200 / 400 = 650 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey1), 650 - ); // 200 + 1000 x ( 200 / 400 ) - 50 = 200 + 500 = 700 + ); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey0), 840 - ); // 300 + 1000 x ( 300 / 500 ) - 60= 300 + 600 = 840 + ); // 300 + 900 * ( 300 / 500 ) = 840 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey1), 750 - ); // 200 + 1000 x ( 200 / 400 ) + 50 = 300 + 600 + 50 = 750 - assert_eq!(SubtensorModule::get_total_stake(), 2900); // 600 + 700 + 900 + 750 = 2900 + ); // 200 + 900 * ( 200 / 400 ) + 100 = 750 + assert_eq!(SubtensorModule::get_total_stake(), 2900); // 900 + 2000 // // Try unstaking too much. assert_eq!( @@ -1940,23 +1949,23 @@ fn test_full_with_delegating_some_servers() { assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey0), 860 - ); // 200 + (200 + 1000 x ( 200 / 500 )) + 60 = 200 + (200 + 400) + 60 = 860 + ); // 200 + (200 + 900 x ( 200 / 500 )) + 100 = 860 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey0), 840 - ); // 300 + 1000 x ( 300 / 500 ) - 50 = 300 + 600 - 50 = 840 + ); // 300 + 900 x ( 300 / 500 ) = 840 assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey0), 1_700); // initial + server emission + validator emission = 799 + 899 = 1_698 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey1), 1_100 - ); // 200 + (0 + 2000 x ( 200 / 400 )) - 100 = 200 + (1000) - 100= 1_100 + ); // 200 + 1800 x ( 200 / 400 )) = 1_100 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey1), 1_423 - ); // 200 + (123 + 2000 x ( 200 / 400 )) + 100 = 200 + (1_200)+ 100 = 1_423 + ); // 200 + (123 + 1800 x ( 200 / 400 )) + 200 = 1_423 assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey1), 2_523); // 400 + 2_123 - assert_eq!(SubtensorModule::get_total_stake(), 4_223); // 1_700 + 2_523 = 4_223 + assert_eq!(SubtensorModule::get_total_stake(), 4_223); // 2_100 + 2_123 = 4_223 // Lets emit MORE inflation through the hot and coldkeys. // This time only server emission. This should go to the owner of the hotkey. @@ -1965,7 +1974,7 @@ fn test_full_with_delegating_some_servers() { assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey0), 1_210 - ); // + 350 + 60 = 1_210 + ); // 860 + 350 = 1_210 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey1), 1_100 @@ -1977,7 +1986,7 @@ fn test_full_with_delegating_some_servers() { assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey1), 1_573 - ); // 1_323 + 150 + 100 = 1_573 + ); // 1_423 + 150 = 1_573 assert_eq!(SubtensorModule::get_total_stake(), 4_723); // 4_223 + 500 = 4_823 // Lets register and stake a new key. From 1e37c1352b560d1712f7397489dc06d63764cd6f Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Wed, 22 May 2024 17:58:51 +0400 Subject: [PATCH 6/9] chore: comment out publish ci --- .github/workflows/publish-tag.yml | 202 +++++++++++++++--------------- 1 file changed, 101 insertions(+), 101 deletions(-) diff --git a/.github/workflows/publish-tag.yml b/.github/workflows/publish-tag.yml index 53d7a4760..4efa713a4 100644 --- a/.github/workflows/publish-tag.yml +++ b/.github/workflows/publish-tag.yml @@ -1,102 +1,102 @@ -name: Rust build, benchmarks, and tests - -concurrency: - group: ci-${{ github.ref }} - cancel-in-progress: true - -## -on: - ## - # Run when a semantic version is tagged - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' - -## -# Environment variables shared for all targets -env: - CARGO_TERM_COLOR: always - RELEASE: true - RELEASE_NAME: release - RUSTFLAGS: -A warnings - RUST_BACKTRACE: full - SKIP_WASM_BUILD: 1 - VERBOSE: ${{ github.events.input.verbose }} - -## -# Test and build and publish -jobs: - check: - name: Tests and publishes targeting ${{ matrix.rust-target }} for OS ${{ matrix.os }} - runs-on: ${{ matrix.os }} - - ## - # Define multiple targets for builds and tests - strategy: - matrix: - rust-branch: - - stable - - rust-target: - - x86_64-unknown-linux-gnu - - x86_64-apple-darwin - - os: - - ubuntu-latest - - macos-latest - - include: - - os: ubuntu-latest - - os: macos-latest - - ## - # Environment variables specific to each target - env: - RUSTV: ${{ matrix.rust-branch }} - RUST_BIN_DIR: target/${{ matrix.rust-target }}/release - TARGET: ${{ matrix.rust-target }} - - ## - steps: - - name: Check-out repository under $GITHUB_WORKSPACE - uses: actions/checkout@v2 - - - name: Install dependencies - run: | - sudo apt update && - sudo apt install -y git clang curl libssl-dev llvm libudev-dev protobuf-compiler - - - name: Install Rust ${{ matrix.rust-branch }} - uses: actions-rs/toolchain@v1.0.6 - with: - toolchain: ${{ matrix.rust-branch }} - profile: minimal - - - name: Utilize Rust shared cached - uses: Swatinem/rust-cache@v2.2.1 - with: - key: ${{ matrix.os }}-${{ env.RUST_BIN_DIR }} - - - name: Run tests - run: | - cargo test --tests - - - name: Build executable - run: | - cargo build --release - - ## TODO: double-check `artifacts` path(s) be correct - # :warning: values for the following must always match; - # - RUST_BIN_DIR - # - target/${{ matrix.rust-target }}/release/node-subtensor - - name: Create Release - uses: ncipollo/release-action@v1.12.0 - with: - allowUpdates: false - artifactErrorsFailBuild: true - bodyFile: CHANGELOG.md - makeLatest: true - tag: ${{ github.ref }}-${{ matrix.rust-target }} - name: Release ${{ github.ref }} for ${{ matrix.rust-target }} - artifacts: 'raw_spec.json,raw_spec_finney.json,target/${{ matrix.rust-target }}/release/node-subtensor' +# name: Rust build, benchmarks, and tests + +# concurrency: +# group: ci-${{ github.ref }} +# cancel-in-progress: true + +# ## +# on: +# ## +# # Run when a semantic version is tagged +# push: +# tags: +# - 'v[0-9]+.[0-9]+.[0-9]+' + +# ## +# # Environment variables shared for all targets +# env: +# CARGO_TERM_COLOR: always +# RELEASE: true +# RELEASE_NAME: release +# RUSTFLAGS: -A warnings +# RUST_BACKTRACE: full +# SKIP_WASM_BUILD: 1 +# VERBOSE: ${{ github.events.input.verbose }} + +# ## +# # Test and build and publish +# jobs: +# check: +# name: Tests and publishes targeting ${{ matrix.rust-target }} for OS ${{ matrix.os }} +# runs-on: ${{ matrix.os }} + +# ## +# # Define multiple targets for builds and tests +# strategy: +# matrix: +# rust-branch: +# - stable + +# rust-target: +# - x86_64-unknown-linux-gnu +# - x86_64-apple-darwin + +# os: +# - ubuntu-latest +# - macos-latest + +# include: +# - os: ubuntu-latest +# - os: macos-latest + +# ## +# # Environment variables specific to each target +# env: +# RUSTV: ${{ matrix.rust-branch }} +# RUST_BIN_DIR: target/${{ matrix.rust-target }}/release +# TARGET: ${{ matrix.rust-target }} + +# ## +# steps: +# - name: Check-out repository under $GITHUB_WORKSPACE +# uses: actions/checkout@v2 + +# - name: Install dependencies +# run: | +# sudo apt update && +# sudo apt install -y git clang curl libssl-dev llvm libudev-dev protobuf-compiler + +# - name: Install Rust ${{ matrix.rust-branch }} +# uses: actions-rs/toolchain@v1.0.6 +# with: +# toolchain: ${{ matrix.rust-branch }} +# profile: minimal + +# - name: Utilize Rust shared cached +# uses: Swatinem/rust-cache@v2.2.1 +# with: +# key: ${{ matrix.os }}-${{ env.RUST_BIN_DIR }} + +# - name: Run tests +# run: | +# cargo test --tests + +# - name: Build executable +# run: | +# cargo build --release + +# ## TODO: double-check `artifacts` path(s) be correct +# # :warning: values for the following must always match; +# # - RUST_BIN_DIR +# # - target/${{ matrix.rust-target }}/release/node-subtensor +# - name: Create Release +# uses: ncipollo/release-action@v1.12.0 +# with: +# allowUpdates: false +# artifactErrorsFailBuild: true +# bodyFile: CHANGELOG.md +# makeLatest: true +# tag: ${{ github.ref }}-${{ matrix.rust-target }} +# name: Release ${{ github.ref }} for ${{ matrix.rust-target }} +# artifacts: 'raw_spec.json,raw_spec_finney.json,target/${{ matrix.rust-target }}/release/node-subtensor' From 54e620cd0ca29ebbb4d1bd0b2d8ad18afbda5287 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Wed, 22 May 2024 19:53:40 +0400 Subject: [PATCH 7/9] chore: pr comments --- pallets/subtensor/tests/staking.rs | 193 +++++++++++++++++------------ 1 file changed, 113 insertions(+), 80 deletions(-) diff --git a/pallets/subtensor/tests/staking.rs b/pallets/subtensor/tests/staking.rs index 7ab2aa480..3c798855e 100644 --- a/pallets/subtensor/tests/staking.rs +++ b/pallets/subtensor/tests/staking.rs @@ -1423,12 +1423,12 @@ fn test_full_with_delegating() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + SubtensorModule::get_min_take() )); assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey1), hotkey1, - u16::MAX / 10 + SubtensorModule::get_min_take() )); assert!(SubtensorModule::hotkey_is_delegate(&hotkey0)); assert!(SubtensorModule::hotkey_is_delegate(&hotkey1)); @@ -1438,7 +1438,7 @@ fn test_full_with_delegating() { SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + SubtensorModule::get_min_take() ), Err(Error::::AlreadyDelegate.into()) ); @@ -1510,25 +1510,25 @@ fn test_full_with_delegating() { // 200 + 900 * 200 / 500 + 100 = 660 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey0), - 660 + 654 ); - // validator_take = take * validator_emission = 10% * 1000 = 100 + // validator_take = take * validator_emission = 9% * 1000 = 90 // old_stake + (validator_emission - validator_take) * stake_for_coldkey_and_hotkey / total_stake_for_hotkey // = - // 200 + 900 * 200 / 400 = 650 + // 200 + (1000 - 90) * 200 / 400 = 655 ~ 654 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey1), - 650 - ); + 655 + ); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey0), - 840 - ); // 300 + 900 * ( 300 / 500 ) = 840 + 846 + ); // 300 + 910 x ( 300 / 500 ) = 300 + 546 = 846 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey1), - 750 - ); // 200 + 900 * ( 200 / 400 ) + 100 = 750 - assert_eq!(SubtensorModule::get_total_stake(), 2900); // 900 + 2000 + 745 + ); // 200 + 1090 x ( 200 / 400 ) = 300 + 545 = 745 + assert_eq!(SubtensorModule::get_total_stake(), 2900); // 600 + 700 + 900 + 750 = 2900 // // Try unstaking too much. assert_eq!( @@ -1589,19 +1589,19 @@ fn test_full_with_delegating() { // All the amounts have been decreased. assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey0), - 560 + 554 ); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey1), - 550 + 555 ); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey0), - 740 + 746 ); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey1), - 650 + 645 ); // Lets register and stake a new key. @@ -1651,7 +1651,7 @@ fn test_full_with_delegating() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey2), hotkey2, - u16::MAX / 10 + SubtensorModule::get_min_take() )); // Add nominate some stake. @@ -1689,15 +1689,15 @@ fn test_full_with_delegating() { SubtensorModule::emit_inflation_through_hotkey_account(&hotkey2, 0, 1000); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey2, &hotkey2), - 1_400 - ); // 1000 + 100 + 900 * (1000/3000) = 1400 + 1_394 + ); // 1000 + 94 + 900 * (1000/3000) = 1400 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey2), - 1_300 + 1_303 ); // 1000 + 900 * (1000/3000) = 1300 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey2), - 1_300 + 1_303 ); // 1000 + 900 * (1000/3000) = 1300 assert_eq!(SubtensorModule::get_total_stake(), 6_500); // before + 1_000 = 5_500 + 1_000 = 6_500 @@ -1719,7 +1719,7 @@ fn test_full_with_delegating() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey3), hotkey3, - u16::MAX / 10 + SubtensorModule::get_min_take() )); // Full take. assert_ok!(SubtensorModule::add_stake( <::RuntimeOrigin>::signed(coldkey0), @@ -1757,19 +1757,19 @@ fn test_full_with_delegating() { SubtensorModule::emit_inflation_through_hotkey_account(&hotkey3, 0, 1000); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey3), - 1225 + 1227 ); // 1000 + 90% * 1000 * 1000/4000 = 1225 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey3), - 1225 + 1227 ); // 1000 + 90% * 1000 * 1000/4000 = 1225 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey2, &hotkey3), - 1225 + 1227 ); // 1000 + 90% * 1000 * 1000/4000 = 1225 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey3, &hotkey3), - 1325 + 1319 ); // 1000 + 25 * 3 + 1000 * 1000/4000 = 1325 assert_eq!(SubtensorModule::get_total_stake(), 11_500); // before + 1_000 = 10_500 + 1_000 = 11_500 }); @@ -1885,12 +1885,12 @@ fn test_full_with_delegating_some_servers() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + SubtensorModule::get_min_take() )); assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey1), hotkey1, - u16::MAX / 10 + SubtensorModule::get_min_take() )); assert!(SubtensorModule::hotkey_is_delegate(&hotkey0)); assert!(SubtensorModule::hotkey_is_delegate(&hotkey1)); @@ -1948,22 +1948,22 @@ fn test_full_with_delegating_some_servers() { SubtensorModule::emit_inflation_through_hotkey_account(&hotkey1, 123, 2_000); // 2_123 total emission. assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey0), - 860 - ); // 200 + (200 + 900 x ( 200 / 500 )) + 100 = 860 + 854 + ); // 200 + (200 + 910 x ( 200 / 500 )) = 200 + (200 + 400) + 60 = 854 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey0), - 840 - ); // 300 + 900 x ( 300 / 500 ) = 840 + 854 + ); // 300 + 1000 x ( 300 / 500 ) - 50 = 300 + 600 - 50 = 854 assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey0), 1_700); // initial + server emission + validator emission = 799 + 899 = 1_698 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey1), - 1_100 - ); // 200 + 1800 x ( 200 / 400 )) = 1_100 + 1_110 + ); // 200 + (0 + 2000 x ( 200 / 400 )) - 100 = 200 + (1000) - 100= 1_110 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey1), - 1_423 - ); // 200 + (123 + 1800 x ( 200 / 400 )) + 200 = 1_423 + 1_413 + ); // 200 + (123 + 2000 x ( 200 / 400 )) + 100 = 200 + (1_200)+ 100 = 1_423 assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey1), 2_523); // 400 + 2_123 assert_eq!(SubtensorModule::get_total_stake(), 4_223); // 2_100 + 2_123 = 4_223 @@ -1973,20 +1973,20 @@ fn test_full_with_delegating_some_servers() { SubtensorModule::emit_inflation_through_hotkey_account(&hotkey1, 150, 0); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey0), - 1_210 - ); // 860 + 350 = 1_210 + 1_204 + ); // + 350 + 54 = 1_204 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey1), - 1_100 + 1_110 ); // No change. assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey0), - 840 + 846 ); // No change. assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey1), - 1_573 - ); // 1_423 + 150 = 1_573 + 1_563 + ); // 1_323 + 150 + 90 = 1_573 assert_eq!(SubtensorModule::get_total_stake(), 4_723); // 4_223 + 500 = 4_823 // Lets register and stake a new key. @@ -2027,11 +2027,11 @@ fn test_full_with_delegating_some_servers() { assert_eq!(SubtensorModule::get_total_stake(), 5_623); // 4_723 + 900 = 5_623 - // Lets make this new key a delegate with a 10% take. + // Lets make this new key a delegate with a 9% take. assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey2), hotkey2, - u16::MAX / 10 + SubtensorModule::get_min_take() )); // Add nominate some stake. @@ -2071,15 +2071,15 @@ fn test_full_with_delegating_some_servers() { SubtensorModule::emit_inflation_through_hotkey_account(&hotkey2, 100, 1000); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey2, &hotkey2), - 1_500 - ); // 1000 + 100 + 100 + 900 * (1000/3000) = 1000 + 200 + 300 = 1500 + 1_494 + ); // 1000 + 100 + 94 + 900 * (1000/3000) = 1000 + 200 + 300 = 1_494 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey2), - 1_300 - ); // 1000 + 900 * (1000/3000) = 1000 + 300 = 1300 + 1_303 + ); // 1000 + 900 * (1000/3000) = 1000 + 300 = 1_303 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey2), - 1_300 + 1_303 ); // 1000 + 900 * (1000/3000) = 1000 + 300 = 1300 assert_eq!(SubtensorModule::get_total_stake(), 8_823); // 7_723 + 1_100 = 8_823 @@ -2090,15 +2090,15 @@ fn test_full_with_delegating_some_servers() { SubtensorModule::emit_inflation_through_hotkey_account(&hotkey2, 123, 0); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey2, &hotkey2), - 1_623 - ); // 1_500 + 123 = 1_623 + 1_617 + ); // 1_500 + 117 = 1_617 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey2), - 1_300 + 1_303 ); // No change. assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey2), - 1_300 + 1_303 ); // No change. assert_eq!(SubtensorModule::get_total_stake(), 8_946); // 8_823 + 123 = 8_946 }); @@ -2213,12 +2213,12 @@ fn test_full_block_emission_occurs() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + SubtensorModule::get_min_take() )); assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey1), hotkey1, - u16::MAX / 10 + SubtensorModule::get_min_take() )); assert!(SubtensorModule::hotkey_is_delegate(&hotkey0)); assert!(SubtensorModule::hotkey_is_delegate(&hotkey1)); @@ -2726,13 +2726,16 @@ fn test_delegate_take_can_be_decreased() { add_network(netuid, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); - // Coldkey / hotkey 0 become delegates with 10% take + // Coldkey / hotkey 0 become delegates with 9% take assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + SubtensorModule::get_min_take() )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); + assert_eq!( + SubtensorModule::get_hotkey_take(&hotkey0), + SubtensorModule::get_min_take() + ); // Coldkey / hotkey 0 decreases take to 5%. This should fail as the minimum take is 9% assert_err!( @@ -2802,9 +2805,12 @@ fn test_delegate_take_can_not_be_increased_with_decrease_take() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + SubtensorModule::get_min_take() )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); + assert_eq!( + SubtensorModule::get_hotkey_take(&hotkey0), + SubtensorModule::get_min_take() + ); // Coldkey / hotkey 0 tries to increase take to 12.5% assert_eq!( @@ -2815,7 +2821,10 @@ fn test_delegate_take_can_not_be_increased_with_decrease_take() { ), Err(Error::::InvalidTake.into()) ); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); + assert_eq!( + SubtensorModule::get_hotkey_take(&hotkey0), + SubtensorModule::get_min_take() + ); }); } @@ -2835,13 +2844,16 @@ fn test_delegate_take_can_be_increased() { add_network(netuid, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); - // Coldkey / hotkey 0 become delegates with 10% take + // Coldkey / hotkey 0 become delegates with 9% take assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + SubtensorModule::get_min_take() )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); + assert_eq!( + SubtensorModule::get_hotkey_take(&hotkey0), + SubtensorModule::get_min_take() + ); step_block(1 + InitialTxDelegateTakeRateLimit::get() as u16); @@ -2871,13 +2883,16 @@ fn test_delegate_take_can_not_be_decreased_with_increase_take() { add_network(netuid, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); - // Coldkey / hotkey 0 become delegates with 10% take + // Coldkey / hotkey 0 become delegates with 9% take assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + SubtensorModule::get_min_take() )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); + assert_eq!( + SubtensorModule::get_hotkey_take(&hotkey0), + SubtensorModule::get_min_take() + ); // Coldkey / hotkey 0 tries to decrease take to 5% assert_eq!( @@ -2888,7 +2903,10 @@ fn test_delegate_take_can_not_be_decreased_with_increase_take() { ), Err(Error::::InvalidTake.into()) ); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); + assert_eq!( + SubtensorModule::get_hotkey_take(&hotkey0), + SubtensorModule::get_min_take() + ); }); } @@ -2908,13 +2926,16 @@ fn test_delegate_take_can_be_increased_to_limit() { add_network(netuid, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); - // Coldkey / hotkey 0 become delegates with 10% take + // Coldkey / hotkey 0 become delegates with 9% take assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + SubtensorModule::get_min_take() )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); + assert_eq!( + SubtensorModule::get_hotkey_take(&hotkey0), + SubtensorModule::get_min_take() + ); step_block(1 + InitialTxDelegateTakeRateLimit::get() as u16); @@ -2980,13 +3001,16 @@ fn test_delegate_take_can_not_be_increased_beyond_limit() { add_network(netuid, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); - // Coldkey / hotkey 0 become delegates with 10% take + // Coldkey / hotkey 0 become delegates with 9% take assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + SubtensorModule::get_min_take() )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); + assert_eq!( + SubtensorModule::get_hotkey_take(&hotkey0), + SubtensorModule::get_min_take() + ); // Coldkey / hotkey 0 tries to increase take to InitialDefaultTake+1 // (Disable this check if InitialDefaultTake is u16::MAX) @@ -3000,7 +3024,10 @@ fn test_delegate_take_can_not_be_increased_beyond_limit() { Err(Error::::InvalidTake.into()) ); } - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); + assert_eq!( + SubtensorModule::get_hotkey_take(&hotkey0), + SubtensorModule::get_min_take() + ); }); } @@ -3020,13 +3047,16 @@ fn test_rate_limits_enforced_on_increase_take() { add_network(netuid, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); - // Coldkey / hotkey 0 become delegates with 10% take + // Coldkey / hotkey 0 become delegates with 9% take assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - u16::MAX / 10 + SubtensorModule::get_min_take() )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); + assert_eq!( + SubtensorModule::get_hotkey_take(&hotkey0), + SubtensorModule::get_min_take() + ); // Coldkey / hotkey 0 increases take to 12.5% assert_eq!( @@ -3037,7 +3067,10 @@ fn test_rate_limits_enforced_on_increase_take() { ), Err(Error::::TxRateLimitExceeded.into()) ); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 10); + assert_eq!( + SubtensorModule::get_hotkey_take(&hotkey0), + SubtensorModule::get_min_take() + ); step_block(1 + InitialTxDelegateTakeRateLimit::get() as u16); From 74778a61d9fd70efac7433313979a437609bf571 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Wed, 22 May 2024 20:16:03 +0400 Subject: [PATCH 8/9] fmt , delete publish job --- .github/workflows/publish-tag.yml | 102 ----------------------------- pallets/subtensor/tests/staking.rs | 2 +- 2 files changed, 1 insertion(+), 103 deletions(-) delete mode 100644 .github/workflows/publish-tag.yml diff --git a/.github/workflows/publish-tag.yml b/.github/workflows/publish-tag.yml deleted file mode 100644 index 4efa713a4..000000000 --- a/.github/workflows/publish-tag.yml +++ /dev/null @@ -1,102 +0,0 @@ -# name: Rust build, benchmarks, and tests - -# concurrency: -# group: ci-${{ github.ref }} -# cancel-in-progress: true - -# ## -# on: -# ## -# # Run when a semantic version is tagged -# push: -# tags: -# - 'v[0-9]+.[0-9]+.[0-9]+' - -# ## -# # Environment variables shared for all targets -# env: -# CARGO_TERM_COLOR: always -# RELEASE: true -# RELEASE_NAME: release -# RUSTFLAGS: -A warnings -# RUST_BACKTRACE: full -# SKIP_WASM_BUILD: 1 -# VERBOSE: ${{ github.events.input.verbose }} - -# ## -# # Test and build and publish -# jobs: -# check: -# name: Tests and publishes targeting ${{ matrix.rust-target }} for OS ${{ matrix.os }} -# runs-on: ${{ matrix.os }} - -# ## -# # Define multiple targets for builds and tests -# strategy: -# matrix: -# rust-branch: -# - stable - -# rust-target: -# - x86_64-unknown-linux-gnu -# - x86_64-apple-darwin - -# os: -# - ubuntu-latest -# - macos-latest - -# include: -# - os: ubuntu-latest -# - os: macos-latest - -# ## -# # Environment variables specific to each target -# env: -# RUSTV: ${{ matrix.rust-branch }} -# RUST_BIN_DIR: target/${{ matrix.rust-target }}/release -# TARGET: ${{ matrix.rust-target }} - -# ## -# steps: -# - name: Check-out repository under $GITHUB_WORKSPACE -# uses: actions/checkout@v2 - -# - name: Install dependencies -# run: | -# sudo apt update && -# sudo apt install -y git clang curl libssl-dev llvm libudev-dev protobuf-compiler - -# - name: Install Rust ${{ matrix.rust-branch }} -# uses: actions-rs/toolchain@v1.0.6 -# with: -# toolchain: ${{ matrix.rust-branch }} -# profile: minimal - -# - name: Utilize Rust shared cached -# uses: Swatinem/rust-cache@v2.2.1 -# with: -# key: ${{ matrix.os }}-${{ env.RUST_BIN_DIR }} - -# - name: Run tests -# run: | -# cargo test --tests - -# - name: Build executable -# run: | -# cargo build --release - -# ## TODO: double-check `artifacts` path(s) be correct -# # :warning: values for the following must always match; -# # - RUST_BIN_DIR -# # - target/${{ matrix.rust-target }}/release/node-subtensor -# - name: Create Release -# uses: ncipollo/release-action@v1.12.0 -# with: -# allowUpdates: false -# artifactErrorsFailBuild: true -# bodyFile: CHANGELOG.md -# makeLatest: true -# tag: ${{ github.ref }}-${{ matrix.rust-target }} -# name: Release ${{ github.ref }} for ${{ matrix.rust-target }} -# artifacts: 'raw_spec.json,raw_spec_finney.json,target/${{ matrix.rust-target }}/release/node-subtensor' - diff --git a/pallets/subtensor/tests/staking.rs b/pallets/subtensor/tests/staking.rs index 3c798855e..728f93d99 100644 --- a/pallets/subtensor/tests/staking.rs +++ b/pallets/subtensor/tests/staking.rs @@ -1519,7 +1519,7 @@ fn test_full_with_delegating() { assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey1), 655 - ); + ); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey0), 846 From 8aa14d98c77dc72c24a7066e38948789081ac908 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Wed, 22 May 2024 20:35:15 +0400 Subject: [PATCH 9/9] fix: test --- pallets/subtensor/tests/staking.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/tests/staking.rs b/pallets/subtensor/tests/staking.rs index 728f93d99..f968ac55e 100644 --- a/pallets/subtensor/tests/staking.rs +++ b/pallets/subtensor/tests/staking.rs @@ -1952,8 +1952,8 @@ fn test_full_with_delegating_some_servers() { ); // 200 + (200 + 910 x ( 200 / 500 )) = 200 + (200 + 400) + 60 = 854 assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1, &hotkey0), - 854 - ); // 300 + 1000 x ( 300 / 500 ) - 50 = 300 + 600 - 50 = 854 + 846 + ); // 300 + 910 x ( 300 / 500 ) = 300 + 546 = 846 assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey0), 1_700); // initial + server emission + validator emission = 799 + 899 = 1_698 assert_eq!(