Skip to content

Commit 340060c

Browse files
authored
Merge pull request #1469 from opentensor/fix/min-burn-set-low-on-new-subnet
Fix/min burn set low on new subnet
2 parents 96939a7 + c3b3f92 commit 340060c

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

pallets/subtensor/src/subnets/subnet.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<T: Config> Pallet<T> {
239239
netuid_to_register,
240240
mechid
241241
);
242-
Self::deposit_event(Event::NetworkAdded(netuid_to_register, 0));
242+
Self::deposit_event(Event::NetworkAdded(netuid_to_register, mechid));
243243

244244
// --- 17. Return success.
245245
Ok(())
@@ -272,7 +272,6 @@ impl<T: Config> Pallet<T> {
272272
Self::set_target_registrations_per_interval(netuid, 1);
273273
Self::set_adjustment_alpha(netuid, 17_893_341_751_498_265_066); // 18_446_744_073_709_551_615 * 0.97 = 17_893_341_751_498_265_066
274274
Self::set_immunity_period(netuid, 5000);
275-
Self::set_min_burn(netuid, 1);
276275
Self::set_min_difficulty(netuid, u64::MAX);
277276
Self::set_max_difficulty(netuid, u64::MAX);
278277

pallets/subtensor/src/tests/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ parameter_types! {
152152
pub const InitialTxDelegateTakeRateLimit: u64 = 1; // 1 block take rate limit for testing
153153
pub const InitialTxChildKeyTakeRateLimit: u64 = 1; // 1 block take rate limit for testing
154154
pub const InitialBurn: u64 = 0;
155-
pub const InitialMinBurn: u64 = 0;
155+
pub const InitialMinBurn: u64 = 500_000;
156156
pub const InitialMaxBurn: u64 = 1_000_000_000;
157157
pub const InitialValidatorPruneLen: u64 = 0;
158158
pub const InitialScalingLawPower: u16 = 50;

pallets/subtensor/src/tests/registration.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(clippy::unwrap_used)]
22

3+
use approx::assert_abs_diff_eq;
34
use frame_support::traits::Currency;
45

56
use super::mock::*;
@@ -535,11 +536,11 @@ fn test_burn_adjustment() {
535536
new_test_ext(1).execute_with(|| {
536537
let netuid: u16 = 1;
537538
let tempo: u16 = 13;
538-
let burn_cost: u64 = 1000;
539+
let init_burn_cost: u64 = InitialMinBurn::get() + 10_000;
539540
let adjustment_interval = 1;
540541
let target_registrations_per_interval = 1;
541542
add_network(netuid, tempo, 0);
542-
SubtensorModule::set_burn(netuid, burn_cost);
543+
SubtensorModule::set_burn(netuid, init_burn_cost);
543544
SubtensorModule::set_adjustment_interval(netuid, adjustment_interval);
544545
SubtensorModule::set_adjustment_alpha(netuid, 58000); // Set to old value.
545546
SubtensorModule::set_target_registrations_per_interval(
@@ -550,7 +551,7 @@ fn test_burn_adjustment() {
550551
// Register key 1.
551552
let hotkey_account_id_1 = U256::from(1);
552553
let coldkey_account_id_1 = U256::from(1);
553-
SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id_1, 10000);
554+
SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id_1, init_burn_cost);
554555
assert_ok!(SubtensorModule::burned_register(
555556
<<Test as Config>::RuntimeOrigin>::signed(hotkey_account_id_1),
556557
netuid,
@@ -560,7 +561,7 @@ fn test_burn_adjustment() {
560561
// Register key 2.
561562
let hotkey_account_id_2 = U256::from(2);
562563
let coldkey_account_id_2 = U256::from(2);
563-
SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id_2, 10000);
564+
SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id_2, init_burn_cost);
564565
assert_ok!(SubtensorModule::burned_register(
565566
<<Test as Config>::RuntimeOrigin>::signed(hotkey_account_id_2),
566567
netuid,
@@ -571,8 +572,13 @@ fn test_burn_adjustment() {
571572
// Step the block and trigger the adjustment.
572573
step_block(1);
573574

574-
// Check the adjusted burn.
575-
assert_eq!(SubtensorModule::get_burn_as_u64(netuid), 1500);
575+
// Check the adjusted burn is above the initial min burn.
576+
assert!(SubtensorModule::get_burn_as_u64(netuid) > init_burn_cost);
577+
assert_abs_diff_eq!(
578+
SubtensorModule::get_burn_as_u64(netuid),
579+
init_burn_cost.saturating_mul(3).saturating_div(2), // 1.5x
580+
epsilon = 1000
581+
);
576582
});
577583
}
578584

pallets/subtensor/src/tests/subnet.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,40 @@ fn test_do_start_call_ok_with_same_block_number_after_coinbase() {
222222
}
223223
});
224224
}
225+
226+
#[test]
227+
fn test_register_network_min_burn_at_default() {
228+
new_test_ext(1).execute_with(|| {
229+
let sn_owner_coldkey = U256::from(0);
230+
let sn_owner_hotkey = U256::from(1);
231+
let cost = SubtensorModule::get_network_lock_cost();
232+
233+
// Give coldkey enough for lock
234+
SubtensorModule::add_balance_to_coldkey_account(&sn_owner_coldkey, cost + 10_000_000_000);
235+
236+
// Register network
237+
assert_ok!(SubtensorModule::register_network(
238+
<<Test as Config>::RuntimeOrigin>::signed(sn_owner_coldkey),
239+
sn_owner_hotkey
240+
));
241+
// Get last events
242+
let events = System::events();
243+
let min_burn_event = events
244+
.iter()
245+
.filter(|event| {
246+
matches!(
247+
event.event,
248+
RuntimeEvent::SubtensorModule(Event::<Test>::NetworkAdded(..))
249+
)
250+
})
251+
.last();
252+
253+
let netuid = match min_burn_event.map(|event| event.event.clone()) {
254+
Some(RuntimeEvent::SubtensorModule(Event::<Test>::NetworkAdded(netuid, _))) => netuid,
255+
_ => panic!("Expected NetworkAdded event"),
256+
};
257+
258+
// Check min burn is set to default
259+
assert_eq!(MinBurn::<Test>::get(netuid), InitialMinBurn::get());
260+
});
261+
}

0 commit comments

Comments
 (0)