Skip to content

Commit c18c3be

Browse files
committed
add a global min burn and migration
1 parent ffe3cc0 commit c18c3be

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

pallets/admin-utils/src/tests/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ parameter_types! {
100100
pub const InitialTxDelegateTakeRateLimit: u64 = 0; // Disable rate limit for testing
101101
pub const InitialTxChildKeyTakeRateLimit: u64 = 0; // Disable rate limit for testing
102102
pub const InitialBurn: u64 = 0;
103-
pub const InitialMinBurn: u64 = 0;
103+
pub const InitialMinBurn: u64 = 500_000;
104104
pub const InitialMaxBurn: u64 = 1_000_000_000;
105105
pub const InitialValidatorPruneLen: u64 = 0;
106106
pub const InitialScalingLawPower: u16 = 50;

pallets/subtensor/src/macros/hooks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ mod hooks {
7979
.saturating_add(migrations::migrate_fix_is_network_member::migrate_fix_is_network_member::<T>())
8080
.saturating_add(migrations::migrate_subnet_volume::migrate_subnet_volume::<T>())
8181
// Upgrade identities to V2
82-
.saturating_add(migrations::migrate_identities_v2::migrate_identities_to_v2::<T>());
82+
.saturating_add(migrations::migrate_identities_v2::migrate_identities_to_v2::<T>())
83+
// Set the min burn across all subnets to a new minimum
84+
.saturating_add(migrations::migrate_set_min_burn::migrate_set_min_burn::<T>());
8385
weight
8486
}
8587

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use alloc::string::String;
2+
3+
use frame_support::IterableStorageMap;
4+
use frame_support::{traits::Get, weights::Weight};
5+
6+
use super::*;
7+
8+
pub fn migrate_set_min_burn<T: Config>() -> Weight {
9+
let migration_name = b"migrate_set_min_burn".to_vec();
10+
11+
// Initialize the weight with one read operation.
12+
let mut weight = T::DbWeight::get().reads(1);
13+
14+
// Check if the migration has already run
15+
if HasMigrationRun::<T>::get(&migration_name) {
16+
log::info!(
17+
"Migration '{:?}' has already run. Skipping.",
18+
migration_name
19+
);
20+
return weight;
21+
}
22+
log::info!(
23+
"Running migration '{}'",
24+
String::from_utf8_lossy(&migration_name)
25+
);
26+
27+
let netuids: Vec<u16> = <NetworksAdded<T> as IterableStorageMap<u16, bool>>::iter()
28+
.map(|(netuid, _)| netuid)
29+
.collect();
30+
weight = weight.saturating_add(T::DbWeight::get().reads(netuids.len() as u64));
31+
32+
for netuid in netuids.iter().clone() {
33+
if *netuid == 0 {
34+
continue;
35+
}
36+
// Set min burn to the newest initial min burn
37+
Pallet::<T>::set_min_burn(*netuid, T::InitialMinBurn::get());
38+
weight = weight.saturating_add(T::DbWeight::get().writes(1));
39+
}
40+
41+
// Mark the migration as completed
42+
HasMigrationRun::<T>::insert(&migration_name, true);
43+
weight = weight.saturating_add(T::DbWeight::get().writes(1));
44+
45+
log::info!(
46+
"Migration '{:?}' completed.",
47+
String::from_utf8_lossy(&migration_name)
48+
);
49+
50+
// Return the migration weight.
51+
weight
52+
}

pallets/subtensor/src/migrations/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod migrate_init_total_issuance;
1111
pub mod migrate_populate_owned_hotkeys;
1212
pub mod migrate_populate_staking_hotkeys;
1313
pub mod migrate_rao;
14+
pub mod migrate_set_min_burn;
1415
pub mod migrate_stake_threshold;
1516
pub mod migrate_subnet_volume;
1617
pub mod migrate_to_v1_separate_emission;

0 commit comments

Comments
 (0)