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

devnet deploy 2/5/2025 #1244

Merged
merged 45 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c55b226
add new fields to ChainIdentity and SubnetIdentity
JohnReedV Jan 28, 2025
0c5eaec
add migration and test
JohnReedV Jan 28, 2025
380587c
Merge branch 'devnet-ready' into feat/identity-upgrades
JohnReedV Feb 3, 2025
ea96bec
address freeze_struct
JohnReedV Feb 3, 2025
a7232b0
rename commit_reveal_period
JohnReedV Feb 3, 2025
12f483c
remove subnet_info_v3
JohnReedV Feb 3, 2025
ea136bb
address lint
JohnReedV Feb 3, 2025
2d32d96
update register_network with identity precompile
JohnReedV Feb 3, 2025
625a3e0
Merge branch 'devnet-ready' into feat/identity-upgrades
JohnReedV Feb 3, 2025
913fb1a
remove SubnetInfov3 struct
JohnReedV Feb 3, 2025
69d2b77
rename emission_values => emission_value
JohnReedV Feb 3, 2025
6766f1d
bump spec
JohnReedV Feb 3, 2025
40c8214
Merge branch 'devnet-ready' into feat/identity-upgrades
camfairchild Feb 4, 2025
0213918
use saturating math
JohnReedV Feb 4, 2025
d479346
add cleaned coinbase
Feb 4, 2025
547ca27
noclaim
Feb 4, 2025
1a2ec64
remove complexity
Feb 4, 2025
d81238a
clean coinbase
Feb 5, 2025
b144f21
pre merge
Feb 5, 2025
8ec029d
Merge branch 'devnet-ready' of https://github.com/opentensor/subtenso…
Feb 5, 2025
f29c736
no tao in for non registration
Feb 5, 2025
ee37f6d
move to moving prices rather than tao reserves
Feb 5, 2025
f7058a2
Merge pull request #1242 from opentensor/devnet
sam0x17 Feb 5, 2025
e252e90
price
Feb 5, 2025
b2639e7
moving alpha
Feb 5, 2025
6c946db
bump spec
JohnReedV Feb 5, 2025
ea355f2
Fix tests
gztensor Feb 5, 2025
f91e7ca
add moving price tests
Feb 5, 2025
160b773
Merge branch 'nonclaim' of https://github.com/opentensor/subtensor in…
Feb 5, 2025
e4ccdfa
add alpha in tests
Feb 5, 2025
ba80bbb
Fix all tests
gztensor Feb 5, 2025
30475f1
Merge branch 'nonclaim' of github.com:opentensor/subtensor into nonclaim
gztensor Feb 5, 2025
3eca45f
Format
gztensor Feb 5, 2025
1ffefe1
Fix unsafe math
gztensor Feb 5, 2025
8af65df
alpha tests
Feb 5, 2025
009961d
fix test
Feb 5, 2025
0e367f7
set tao weight
Feb 5, 2025
290498e
reset default staking fee
Feb 5, 2025
ab105c7
fix names
Feb 5, 2025
452dbac
add mainnet names
Feb 5, 2025
5c96afd
cargo clippy
Feb 5, 2025
bce7cc6
cargo fmt
Feb 5, 2025
8729b25
Merge branch 'devnet-ready' into nonclaim
unconst Feb 5, 2025
8c8bc16
Merge pull request #1241 from opentensor/nonclaim
sam0x17 Feb 5, 2025
ffe3cc0
Merge pull request #1205 from opentensor/feat/identity-upgrades
sam0x17 Feb 5, 2025
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
2 changes: 0 additions & 2 deletions pallets/subtensor/src/coinbase/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
log::debug!("Block emission: {:?}", block_emission);
// --- 3. Run emission through network.
Self::run_coinbase(block_emission);

// --- 4. Set pending children on the epoch; but only after the coinbase has been run.
Self::try_set_pending_children(block_number);

// Return ok.
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions pallets/subtensor/src/coinbase/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ impl<T: Config> Pallet<T> {
);

// --- 4. Remove the subnet identity if it exists.
if SubnetIdentities::<T>::take(netuid).is_some() {
if SubnetIdentitiesV2::<T>::take(netuid).is_some() {
Self::deposit_event(Event::SubnetIdentityRemoved(netuid));
}

Expand Down Expand Up @@ -590,8 +590,8 @@ impl<T: Config> Pallet<T> {
SubnetOwner::<T>::remove(netuid);

// --- 13. Remove subnet identity if it exists.
if SubnetIdentities::<T>::contains_key(netuid) {
SubnetIdentities::<T>::remove(netuid);
if SubnetIdentitiesV2::<T>::contains_key(netuid) {
SubnetIdentitiesV2::<T>::remove(netuid);
Self::deposit_event(Event::SubnetIdentityRemoved(netuid));
}
}
Expand Down
823 changes: 281 additions & 542 deletions pallets/subtensor/src/coinbase/run_coinbase.rs

Large diffs are not rendered by default.

86 changes: 78 additions & 8 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ pub mod pallet {
pub ip_type: u8,
}

/// Struct for ChainIdentities.
/// Struct for ChainIdentities. (DEPRECATED for V2)
pub type ChainIdentityOf = ChainIdentity;

/// Data structure for Chain Identities.
/// Data structure for Chain Identities. (DEPRECATED for V2)
#[crate::freeze_struct("bbfd00438dbe2b58")]
#[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)]
pub struct ChainIdentity {
Expand All @@ -210,9 +210,32 @@ pub mod pallet {
pub additional: Vec<u8>,
}

/// Struct for SubnetIdentities.
/// Struct for ChainIdentities.
pub type ChainIdentityOfV2 = ChainIdentityV2;

/// Data structure for Chain Identities.
#[crate::freeze_struct("ad72a270be7b59d7")]
#[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)]
pub struct ChainIdentityV2 {
/// The name of the chain identity
pub name: Vec<u8>,
/// The URL associated with the chain identity
pub url: Vec<u8>,
/// The github repository associated with the identity
pub github_repo: Vec<u8>,
/// The image representation of the chain identity
pub image: Vec<u8>,
/// The Discord information for the chain identity
pub discord: Vec<u8>,
/// A description of the chain identity
pub description: Vec<u8>,
/// Additional information about the chain identity
pub additional: Vec<u8>,
}

/// Struct for SubnetIdentities. (DEPRECATED for V2)
pub type SubnetIdentityOf = SubnetIdentity;
/// Data structure for Subnet Identities
/// Data structure for Subnet Identities. (DEPRECATED for V2)
#[crate::freeze_struct("f448dc3dad763108")]
#[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)]
pub struct SubnetIdentity {
Expand All @@ -223,6 +246,28 @@ pub mod pallet {
/// The subnet's contact
pub subnet_contact: Vec<u8>,
}

/// Struct for SubnetIdentitiesV2.
pub type SubnetIdentityOfV2 = SubnetIdentityV2;
/// Data structure for Subnet Identities
#[crate::freeze_struct("e002be4cd05d7b3e")]
#[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)]
pub struct SubnetIdentityV2 {
/// The name of the subnet
pub subnet_name: Vec<u8>,
/// The github repository associated with the subnet
pub github_repo: Vec<u8>,
/// The subnet's contact
pub subnet_contact: Vec<u8>,
/// The subnet's website
pub subnet_url: Vec<u8>,
/// The subnet's discord
pub discord: Vec<u8>,
/// The subnet's description
pub description: Vec<u8>,
/// Additional information about the subnet
pub additional: Vec<u8>,
}
/// ============================
/// ==== Staking + Accounts ====
/// ============================
Expand Down Expand Up @@ -703,7 +748,7 @@ pub mod pallet {
#[pallet::type_value]
/// Default value for applying pending items (e.g. childkeys).
pub fn DefaultPendingCooldown<T: Config>() -> u64 {
7200
1
}

#[pallet::type_value]
Expand All @@ -717,7 +762,7 @@ pub mod pallet {
/// Default staking fee.
/// 500k rao matches $0.25 at $500/TAO
pub fn DefaultStakingFee<T: Config>() -> u64 {
500_000
50_000
}

#[pallet::type_value]
Expand All @@ -732,6 +777,18 @@ pub mod pallet {
T::InitialDissolveNetworkScheduleDuration::get()
}

#[pallet::type_value]
/// Default moving alpha for the moving price.
pub fn DefaultMovingAlpha<T: Config>() -> I96F32 {
// Moving average take 30 days to reach 50% of the price
// and 3.5 months to reach 90%.
I96F32::saturating_from_num(0.000003)
}
#[pallet::type_value]
/// Default subnet moving price.
pub fn DefaultMovingPrice<T: Config>() -> I96F32 {
I96F32::saturating_from_num(0.0)
}
#[pallet::type_value]
/// Default value for Share Pool variables
pub fn DefaultSharePoolZero<T: Config>() -> U64F64 {
Expand Down Expand Up @@ -910,6 +967,11 @@ pub mod pallet {
pub type TotalStake<T> = StorageValue<_, u64, ValueQuery>;
#[pallet::storage] // --- ITEM ( dynamic_block ) -- block when dynamic was turned on.
pub type DynamicBlock<T> = StorageValue<_, u64, ValueQuery>;
#[pallet::storage] // --- ITEM ( moving_alpha ) -- subnet moving alpha.
pub type SubnetMovingAlpha<T> = StorageValue<_, I96F32, ValueQuery, DefaultMovingAlpha<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> moving_price | The subnet moving price.
pub type SubnetMovingPrice<T: Config> =
StorageMap<_, Identity, u16, I96F32, ValueQuery, DefaultMovingPrice<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> total_volume | The total amount of TAO bought and sold since the start of the network.
pub type SubnetVolume<T: Config> =
StorageMap<_, Identity, u16, u128, ValueQuery, DefaultZeroU128<T>>;
Expand Down Expand Up @@ -1409,14 +1471,22 @@ pub mod pallet {
PrometheusInfoOf,
OptionQuery,
>;
#[pallet::storage] // --- MAP ( coldkey ) --> identity
#[pallet::storage] // --- MAP ( coldkey ) --> identity. (DEPRECATED for V2)
pub type Identities<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, ChainIdentityOf, OptionQuery>;

#[pallet::storage] // --- MAP ( netuid ) --> identity
#[pallet::storage] // --- MAP ( coldkey ) --> identity
pub type IdentitiesV2<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, ChainIdentityOfV2, OptionQuery>;

#[pallet::storage] // --- MAP ( netuid ) --> identity. (DEPRECATED for V2)
pub type SubnetIdentities<T: Config> =
StorageMap<_, Blake2_128Concat, u16, SubnetIdentityOf, OptionQuery>;

#[pallet::storage] // --- MAP ( netuid ) --> identityV2
pub type SubnetIdentitiesV2<T: Config> =
StorageMap<_, Blake2_128Concat, u16, SubnetIdentityOfV2, OptionQuery>;

/// =================================
/// ==== Axon / Promo Endpoints =====
/// =================================
Expand Down
30 changes: 27 additions & 3 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,12 +1453,22 @@ mod dispatches {
origin: OriginFor<T>,
name: Vec<u8>,
url: Vec<u8>,
github_repo: Vec<u8>,
image: Vec<u8>,
discord: Vec<u8>,
description: Vec<u8>,
additional: Vec<u8>,
) -> DispatchResult {
Self::do_set_identity(origin, name, url, image, discord, description, additional)
Self::do_set_identity(
origin,
name,
url,
github_repo,
image,
discord,
description,
additional,
)
}

/// ---- Set the identity information for a subnet.
Expand Down Expand Up @@ -1487,8 +1497,22 @@ mod dispatches {
subnet_name: Vec<u8>,
github_repo: Vec<u8>,
subnet_contact: Vec<u8>,
subnet_url: Vec<u8>,
discord: Vec<u8>,
description: Vec<u8>,
additional: Vec<u8>,
) -> DispatchResult {
Self::do_set_subnet_identity(origin, netuid, subnet_name, github_repo, subnet_contact)
Self::do_set_subnet_identity(
origin,
netuid,
subnet_name,
github_repo,
subnet_contact,
subnet_url,
discord,
description,
additional,
)
}

/// User register a new subnetwork
Expand All @@ -1499,7 +1523,7 @@ mod dispatches {
pub fn register_network_with_identity(
origin: OriginFor<T>,
hotkey: T::AccountId,
identity: Option<SubnetIdentityOf>,
identity: Option<SubnetIdentityOfV2>,
) -> DispatchResult {
Self::do_register_network(origin, &hotkey, 1, identity)
}
Expand Down
4 changes: 3 additions & 1 deletion pallets/subtensor/src/macros/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ mod hooks {
.saturating_add(migrations::migrate_rao::migrate_rao::<T>())
// Fix the IsNetworkMember map to be consistent with other storage maps
.saturating_add(migrations::migrate_fix_is_network_member::migrate_fix_is_network_member::<T>())
.saturating_add(migrations::migrate_subnet_volume::migrate_subnet_volume::<T>());
.saturating_add(migrations::migrate_subnet_volume::migrate_subnet_volume::<T>())
// Upgrade identities to V2
.saturating_add(migrations::migrate_identities_v2::migrate_identities_to_v2::<T>());
weight
}

Expand Down
91 changes: 91 additions & 0 deletions pallets/subtensor/src/migrations/migrate_identities_v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use super::*;
use frame_support::weights::Weight;
use log;
use scale_info::prelude::{string::String, vec::Vec};

pub fn migrate_identities_to_v2<T: Config>() -> Weight {
use frame_support::traits::Get;
let migration_name = b"migrate_identities_to_v2".to_vec();

// Start counting weight
let mut weight = T::DbWeight::get().reads(1);

// Check if we already ran this migration
if HasMigrationRun::<T>::get(&migration_name) {
log::info!(
target: "runtime",
"Migration '{:?}' has already run. Skipping.",
String::from_utf8_lossy(&migration_name)
);
return weight;
}

log::info!(
target: "runtime",
"Running migration '{}'",
String::from_utf8_lossy(&migration_name)
);

// -----------------------------
// 1) Migrate Chain Identities
// -----------------------------
let old_identities = Identities::<T>::iter().collect::<Vec<_>>();
for (account_id, old_identity) in old_identities.clone() {
let new_identity = ChainIdentityV2 {
name: old_identity.name,
url: old_identity.url,
github_repo: Vec::new(),
image: old_identity.image,
discord: old_identity.discord,
description: old_identity.description,
additional: old_identity.additional,
};

// Insert into the new storage map
IdentitiesV2::<T>::insert(&account_id, &new_identity);
weight = weight.saturating_add(T::DbWeight::get().writes(1));

Identities::<T>::remove(&account_id);
weight = weight.saturating_add(T::DbWeight::get().writes(1));
}

weight = weight.saturating_add(T::DbWeight::get().reads(old_identities.len() as u64));

// -----------------------------
// 2) Migrate Subnet Identities
// -----------------------------
let old_subnet_identities = SubnetIdentities::<T>::iter().collect::<Vec<_>>();
for (netuid, old_subnet_identity) in old_subnet_identities.clone() {
let new_subnet_identity = SubnetIdentityV2 {
subnet_name: old_subnet_identity.subnet_name,
github_repo: old_subnet_identity.github_repo,
subnet_contact: old_subnet_identity.subnet_contact,
subnet_url: Vec::new(),
discord: Vec::new(),
description: Vec::new(),
additional: Vec::new(),
};

// Insert into the new storage map
SubnetIdentitiesV2::<T>::insert(netuid, &new_subnet_identity);
weight = weight.saturating_add(T::DbWeight::get().writes(1));

SubnetIdentities::<T>::remove(netuid);
weight = weight.saturating_add(T::DbWeight::get().writes(1));
}
weight = weight.saturating_add(T::DbWeight::get().reads(old_subnet_identities.len() as u64));

// -----------------------------
// Mark the migration as done
// -----------------------------
HasMigrationRun::<T>::insert(&migration_name, true);
weight = weight.saturating_add(T::DbWeight::get().writes(1));

log::info!(
target: "runtime",
"Migration '{}' completed successfully.",
String::from_utf8_lossy(&migration_name)
);

weight
}
7 changes: 4 additions & 3 deletions pallets/subtensor/src/migrations/migrate_rao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,20 @@ pub fn migrate_rao<T: Config>() -> Weight {
let _neuron_uid: u16 = Pallet::<T>::register_neuron(*netuid, &owner_coldkey);
}
// Register the neuron immediately.
if !Identities::<T>::contains_key(owner_coldkey.clone()) {
if !IdentitiesV2::<T>::contains_key(owner_coldkey.clone()) {
// Set the identitiy for the Owner coldkey if non existent.
let identity = ChainIdentityOf {
let identity = ChainIdentityOfV2 {
name: format!("Owner{}", netuid).as_bytes().to_vec(),
url: Vec::new(),
image: Vec::new(),
github_repo: Vec::new(),
discord: Vec::new(),
description: Vec::new(),
additional: Vec::new(),
};
// Validate the created identity and set it.
if Pallet::<T>::is_valid_identity(&identity) {
Identities::<T>::insert(owner_coldkey.clone(), identity.clone());
IdentitiesV2::<T>::insert(owner_coldkey.clone(), identity.clone());
}
}
}
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod migrate_delete_subnet_21;
pub mod migrate_delete_subnet_3;
pub mod migrate_fix_is_network_member;
pub mod migrate_fix_total_coldkey_stake;
pub mod migrate_identities_v2;
pub mod migrate_init_total_issuance;
pub mod migrate_populate_owned_hotkeys;
pub mod migrate_populate_staking_hotkeys;
Expand Down
Loading
Loading