Skip to content

Commit 2c2a15d

Browse files
authored
Merge branch 'devnet-ready' into subnet-identities
2 parents 979d46d + 3496c34 commit 2c2a15d

File tree

15 files changed

+636
-37
lines changed

15 files changed

+636
-37
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
**/*.lock
88

9+
*.ipynb
10+
911
# Generated by code coverage
1012
*.profraw
1113
*.profdata

Cargo.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ repository = "https://github.com/opentensor/subtensor"
1111

1212
[dependencies]
1313
node-subtensor = { path = "node", version = "4.0.0-dev" }
14-
pallet-commitments = { path = "pallets/commitments", version = "4.0.0-dev" }
15-
pallet-subtensor = { path = "pallets/subtensor", version = "4.0.0-dev" }
1614
node-subtensor-runtime = { path = "runtime", version = "4.0.0-dev" }
17-
subtensor-macros = { path = "support/macros", version = "0.1.0" }
1815

1916
[build-dependencies]
2017
subtensor-linting = { path = "support/linting", version = "0.1.0" }
@@ -167,3 +164,8 @@ opt-level = 3
167164
inherits = "release"
168165
lto = true
169166
codegen-units = 1
167+
168+
[features]
169+
default = []
170+
try-runtime = ["node-subtensor/try-runtime", "node-subtensor-runtime/try-runtime"]
171+
runtime-benchmarks = ["node-subtensor/runtime-benchmarks", "node-subtensor-runtime/runtime-benchmarks"]

docs/delegate-info.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,5 +390,19 @@
390390
"url": "https://cortex.foundation/",
391391
"description": "Cortex Foundation is committed to advancing the integration of decentralized AI. Our validator is designed for transparency, reliability, and community engagement.",
392392
"signature": "7a6274ff6b0f7ddca97e37ef4a9b90781012ff3cf7baa3159f6feaafc43c557975aad324ea608d6b8abeb21f8f3ca2595e54b81a7564574d0242b803d969618a"
393+
},
394+
{
395+
"address":"5F27Eqz2PhyMtGMEce898x31DokNqRVxkm5AhDDe6rDGNvoY",
396+
"name": "Love",
397+
"url": "https://love.cosimo.fund",
398+
"description": "Love validator exists to accelerate open source AI and be good stewards of the Bittensorr network",
399+
"signature": "c221a3de3be031c149a7be912b3b75e0355605f041dc975153302b23b4d93e45e9cc7453532491e92076ccd333a4c1f95f4a2229aae8f4fcfb88e5dec3f14c87"
400+
},
401+
{
402+
"address": "5Hb63SvXBXqZ8zw6mwW1A39fHdqUrJvohXgepyhp2jgWedSB",
403+
"name": "TAO Miner's Union",
404+
"url": "https://minersunion.ai",
405+
"description": "The first Bittensor validator that empowers you to choose which subnets to incentivize. Committed to transparency and integrity, we ensure fair and honest validation processes that contribute to the growth and strength of the network.",
406+
"signature": "e8c68bc766a06f36c633e1f68d5aca4c4090a26e394372f64d5b00cc13621f361ec9df85fc9f0d247dbc1fe452bd53ffc0224dee2bc85c9d82cb250e4ac10984"
393407
}
394408
]

pallets/admin-utils/src/lib.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub use pallet::*;
44
pub mod weights;
55
pub use weights::WeightInfo;
66

7+
use frame_system::pallet_prelude::BlockNumberFor;
78
use sp_runtime::{traits::Member, RuntimeAppPublic};
89

910
mod benchmarking;
@@ -1128,6 +1129,73 @@ pub mod pallet {
11281129

11291130
Ok(())
11301131
}
1132+
1133+
/// Sets the duration of the coldkey swap schedule.
1134+
///
1135+
/// This extrinsic allows the root account to set the duration for the coldkey swap schedule.
1136+
/// The coldkey swap schedule determines how long it takes for a coldkey swap operation to complete.
1137+
///
1138+
/// # Arguments
1139+
/// * `origin` - The origin of the call, which must be the root account.
1140+
/// * `duration` - The new duration for the coldkey swap schedule, in number of blocks.
1141+
///
1142+
/// # Errors
1143+
/// * `BadOrigin` - If the caller is not the root account.
1144+
///
1145+
/// # Weight
1146+
/// Weight is handled by the `#[pallet::weight]` attribute.
1147+
#[pallet::call_index(54)]
1148+
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1149+
pub fn sudo_set_coldkey_swap_schedule_duration(
1150+
origin: OriginFor<T>,
1151+
duration: BlockNumberFor<T>,
1152+
) -> DispatchResult {
1153+
// Ensure the call is made by the root account
1154+
ensure_root(origin)?;
1155+
1156+
// Set the new duration of schedule coldkey swap
1157+
pallet_subtensor::Pallet::<T>::set_coldkey_swap_schedule_duration(duration);
1158+
1159+
// Log the change
1160+
log::trace!("ColdkeySwapScheduleDurationSet( duration: {:?} )", duration);
1161+
1162+
Ok(())
1163+
}
1164+
1165+
/// Sets the duration of the dissolve network schedule.
1166+
///
1167+
/// This extrinsic allows the root account to set the duration for the dissolve network schedule.
1168+
/// The dissolve network schedule determines how long it takes for a network dissolution operation to complete.
1169+
///
1170+
/// # Arguments
1171+
/// * `origin` - The origin of the call, which must be the root account.
1172+
/// * `duration` - The new duration for the dissolve network schedule, in number of blocks.
1173+
///
1174+
/// # Errors
1175+
/// * `BadOrigin` - If the caller is not the root account.
1176+
///
1177+
/// # Weight
1178+
/// Weight is handled by the `#[pallet::weight]` attribute.
1179+
#[pallet::call_index(55)]
1180+
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1181+
pub fn sudo_set_dissolve_network_schedule_duration(
1182+
origin: OriginFor<T>,
1183+
duration: BlockNumberFor<T>,
1184+
) -> DispatchResult {
1185+
// Ensure the call is made by the root account
1186+
ensure_root(origin)?;
1187+
1188+
// Set the duration of schedule dissolve network
1189+
pallet_subtensor::Pallet::<T>::set_dissolve_network_schedule_duration(duration);
1190+
1191+
// Log the change
1192+
log::trace!(
1193+
"DissolveNetworkScheduleDurationSet( duration: {:?} )",
1194+
duration
1195+
);
1196+
1197+
Ok(())
1198+
}
11311199
}
11321200
}
11331201

pallets/admin-utils/tests/tests.rs

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use frame_support::sp_runtime::DispatchError;
22
use frame_support::{
3-
assert_err, assert_ok,
3+
assert_err, assert_noop, assert_ok,
44
dispatch::{DispatchClass, GetDispatchInfo, Pays},
55
};
66
use frame_system::Config;
@@ -1361,3 +1361,77 @@ fn test_sudo_get_set_alpha() {
13611361
));
13621362
});
13631363
}
1364+
1365+
#[test]
1366+
fn test_sudo_set_coldkey_swap_schedule_duration() {
1367+
new_test_ext().execute_with(|| {
1368+
// Arrange
1369+
let root = RuntimeOrigin::root();
1370+
let non_root = RuntimeOrigin::signed(U256::from(1));
1371+
let new_duration = 100u32.into();
1372+
1373+
// Act & Assert: Non-root account should fail
1374+
assert_noop!(
1375+
AdminUtils::sudo_set_coldkey_swap_schedule_duration(non_root, new_duration),
1376+
DispatchError::BadOrigin
1377+
);
1378+
1379+
// Act: Root account should succeed
1380+
assert_ok!(AdminUtils::sudo_set_coldkey_swap_schedule_duration(
1381+
root.clone(),
1382+
new_duration
1383+
));
1384+
1385+
// Assert: Check if the duration was actually set
1386+
assert_eq!(
1387+
pallet_subtensor::ColdkeySwapScheduleDuration::<Test>::get(),
1388+
new_duration
1389+
);
1390+
1391+
// Act & Assert: Setting the same value again should succeed (idempotent operation)
1392+
assert_ok!(AdminUtils::sudo_set_coldkey_swap_schedule_duration(
1393+
root,
1394+
new_duration
1395+
));
1396+
1397+
// You might want to check for events here if your pallet emits them
1398+
System::assert_last_event(Event::ColdkeySwapScheduleDurationSet(new_duration).into());
1399+
});
1400+
}
1401+
1402+
#[test]
1403+
fn test_sudo_set_dissolve_network_schedule_duration() {
1404+
new_test_ext().execute_with(|| {
1405+
// Arrange
1406+
let root = RuntimeOrigin::root();
1407+
let non_root = RuntimeOrigin::signed(U256::from(1));
1408+
let new_duration = 200u32.into();
1409+
1410+
// Act & Assert: Non-root account should fail
1411+
assert_noop!(
1412+
AdminUtils::sudo_set_dissolve_network_schedule_duration(non_root, new_duration),
1413+
DispatchError::BadOrigin
1414+
);
1415+
1416+
// Act: Root account should succeed
1417+
assert_ok!(AdminUtils::sudo_set_dissolve_network_schedule_duration(
1418+
root.clone(),
1419+
new_duration
1420+
));
1421+
1422+
// Assert: Check if the duration was actually set
1423+
assert_eq!(
1424+
pallet_subtensor::DissolveNetworkScheduleDuration::<Test>::get(),
1425+
new_duration
1426+
);
1427+
1428+
// Act & Assert: Setting the same value again should succeed (idempotent operation)
1429+
assert_ok!(AdminUtils::sudo_set_dissolve_network_schedule_duration(
1430+
root,
1431+
new_duration
1432+
));
1433+
1434+
// You might want to check for events here if your pallet emits them
1435+
System::assert_last_event(Event::DissolveNetworkScheduleDurationSet(new_duration).into());
1436+
});
1437+
}

pallets/subtensor/src/benchmarks.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ benchmarks! {
314314
assert_ok!(Subtensor::<T>::register_network(RawOrigin::Signed(coldkey.clone()).into(), None));
315315
}: dissolve_network(RawOrigin::Signed(coldkey), 1)
316316

317+
317318
// swap_hotkey {
318319
// let seed: u32 = 1;
319320
// let coldkey: T::AccountId = account("Alice", 0, seed);
@@ -444,7 +445,7 @@ reveal_weights {
444445
let new_rate_limit: u64 = 100;
445446
}: sudo_set_tx_childkey_take_rate_limit(RawOrigin::Root, new_rate_limit)
446447

447-
benchmark_set_childkey_take {
448+
benchmark_set_childkey_take {
448449
// Setup
449450
let netuid: u16 = 1;
450451
let tempo: u16 = 1;
@@ -462,4 +463,62 @@ benchmark_set_childkey_take {
462463
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey, amount_to_be_staked);
463464
assert_ok!(Subtensor::<T>::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone()));
464465
}: set_childkey_take(RawOrigin::Signed(coldkey), hotkey, netuid, take)
466+
467+
swap_coldkey {
468+
// Set up initial state
469+
let old_coldkey: T::AccountId = account("old_coldkey", 0, 0);
470+
let new_coldkey: T::AccountId = account("new_coldkey", 0, 0);
471+
let hotkey1: T::AccountId = account("hotkey1", 0, 0);
472+
let netuid = 1u16;
473+
let stake_amount1 = 1000u64;
474+
let stake_amount2 = 2000u64;
475+
let swap_cost = Subtensor::<T>::get_key_swap_cost();
476+
let free_balance_old = 12345u64 + swap_cost;
477+
let tempo: u16 = 1;
478+
479+
// Setup initial state
480+
Subtensor::<T>::init_new_network(netuid, tempo);
481+
Subtensor::<T>::set_network_registration_allowed(netuid, true);
482+
Subtensor::<T>::set_network_pow_registration_allowed(netuid, true);
483+
484+
let block_number: u64 = Subtensor::<T>::get_current_block_as_u64();
485+
let (nonce, work): (u64, Vec<u8>) = Subtensor::<T>::create_work_for_block_number(
486+
netuid,
487+
block_number,
488+
3,
489+
&hotkey1,
490+
);
491+
492+
let _ = Subtensor::<T>::register(
493+
<T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(old_coldkey.clone())),
494+
netuid,
495+
block_number,
496+
nonce,
497+
work.clone(),
498+
hotkey1.clone(),
499+
old_coldkey.clone(),
500+
);
501+
502+
// Add balance to old coldkey
503+
Subtensor::<T>::add_balance_to_coldkey_account(
504+
&old_coldkey,
505+
stake_amount1 + stake_amount2 + free_balance_old,
506+
);
507+
508+
// Insert an Identity
509+
let name: Vec<u8> = b"The fourth Coolest Identity".to_vec();
510+
let identity: ChainIdentity = ChainIdentity {
511+
name: name.clone(),
512+
url: vec![],
513+
image: vec![],
514+
discord: vec![],
515+
description: vec![],
516+
additional: vec![],
517+
};
518+
519+
Identities::<T>::insert(&old_coldkey, identity);
520+
521+
// Benchmark setup complete, now execute the extrinsic
522+
}: swap_coldkey(RawOrigin::Signed(old_coldkey.clone()), old_coldkey.clone(), new_coldkey.clone())
523+
465524
}

pallets/subtensor/src/coinbase/root.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,17 +1015,14 @@ impl<T: Config> Pallet<T> {
10151015
/// * 'SubNetworkDoesNotExist': If the specified network does not exist.
10161016
/// * 'NotSubnetOwner': If the caller does not own the specified subnet.
10171017
///
1018-
pub fn user_remove_network(origin: T::RuntimeOrigin, netuid: u16) -> dispatch::DispatchResult {
1019-
// --- 1. Ensure the function caller is a signed user.
1020-
let coldkey = ensure_signed(origin)?;
1021-
1022-
// --- 2. Ensure this subnet exists.
1018+
pub fn user_remove_network(coldkey: T::AccountId, netuid: u16) -> dispatch::DispatchResult {
1019+
// --- 1. Ensure this subnet exists.
10231020
ensure!(
10241021
Self::if_subnet_exist(netuid),
10251022
Error::<T>::SubNetworkDoesNotExist
10261023
);
10271024

1028-
// --- 3. Ensure the caller owns this subnet.
1025+
// --- 2. Ensure the caller owns this subnet.
10291026
ensure!(
10301027
SubnetOwner::<T>::get(netuid) == coldkey,
10311028
Error::<T>::NotSubnetOwner

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -672,16 +672,17 @@ mod dispatches {
672672
///
673673
/// Weight is calculated based on the number of database reads and writes.
674674
#[pallet::call_index(71)]
675-
#[pallet::weight((Weight::from_parts(1_940_000_000, 0)
676-
.saturating_add(T::DbWeight::get().reads(272))
677-
.saturating_add(T::DbWeight::get().writes(527)), DispatchClass::Operational, Pays::No))]
675+
#[pallet::weight((Weight::from_parts(127_713_000, 0)
676+
.saturating_add(Weight::from_parts(0, 11645))
677+
.saturating_add(T::DbWeight::get().reads(18))
678+
.saturating_add(T::DbWeight::get().writes(12)), DispatchClass::Operational, Pays::No))]
678679
pub fn swap_coldkey(
679680
origin: OriginFor<T>,
680681
old_coldkey: T::AccountId,
681682
new_coldkey: T::AccountId,
682683
) -> DispatchResultWithPostInfo {
683684
// Ensure it's called with root privileges (scheduler has root privileges)
684-
ensure_root(origin.clone())?;
685+
ensure_root(origin)?;
685686
log::info!("swap_coldkey: {:?} -> {:?}", old_coldkey, new_coldkey);
686687

687688
Self::do_swap_coldkey(&old_coldkey, &new_coldkey)
@@ -933,8 +934,13 @@ mod dispatches {
933934
#[pallet::weight((Weight::from_parts(119_000_000, 0)
934935
.saturating_add(T::DbWeight::get().reads(6))
935936
.saturating_add(T::DbWeight::get().writes(31)), DispatchClass::Operational, Pays::No))]
936-
pub fn dissolve_network(origin: OriginFor<T>, netuid: u16) -> DispatchResult {
937-
Self::user_remove_network(origin, netuid)
937+
pub fn dissolve_network(
938+
origin: OriginFor<T>,
939+
coldkey: T::AccountId,
940+
netuid: u16,
941+
) -> DispatchResult {
942+
ensure_root(origin)?;
943+
Self::user_remove_network(coldkey, netuid)
938944
}
939945

940946
/// Set a single child for a given hotkey on a specified network.
@@ -1103,7 +1109,10 @@ mod dispatches {
11031109
let duration: BlockNumberFor<T> = DissolveNetworkScheduleDuration::<T>::get();
11041110
let when: BlockNumberFor<T> = current_block.saturating_add(duration);
11051111

1106-
let call = Call::<T>::dissolve_network { netuid };
1112+
let call = Call::<T>::dissolve_network {
1113+
coldkey: who.clone(),
1114+
netuid,
1115+
};
11071116

11081117
let bound_call = T::Preimages::bound(LocalCallOf::<T>::from(call.clone()))
11091118
.map_err(|_| Error::<T>::FailedToSchedule)?;
@@ -1112,7 +1121,7 @@ mod dispatches {
11121121
DispatchTime::At(when),
11131122
None,
11141123
63,
1115-
frame_system::RawOrigin::Signed(who.clone()).into(),
1124+
frame_system::RawOrigin::Root.into(),
11161125
bound_call,
11171126
)
11181127
.map_err(|_| Error::<T>::FailedToSchedule)?;

0 commit comments

Comments
 (0)