Skip to content

Commit a81541c

Browse files
authored
Merge pull request #757 from opentensor/devnet-ready
Devnet Deployment 27082024
2 parents 939f21c + c23c7fd commit a81541c

File tree

23 files changed

+1255
-82
lines changed

23 files changed

+1255
-82
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/rpc/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ pub trait SubtensorCustomApi<BlockHash> {
4646
fn get_subnet_info(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
4747
#[method(name = "subnetInfo_getSubnetsInfo")]
4848
fn get_subnets_info(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
49+
#[method(name = "subnetInfo_getSubnetInfo_v2")]
50+
fn get_subnet_info_v2(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
51+
#[method(name = "subnetInfo_getSubnetsInf_v2")]
52+
fn get_subnets_info_v2(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
4953
#[method(name = "subnetInfo_getSubnetHyperparams")]
5054
fn get_subnet_hyperparams(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
5155

@@ -215,6 +219,26 @@ where
215219
.map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into())
216220
}
217221

222+
fn get_subnet_info_v2(
223+
&self,
224+
netuid: u16,
225+
at: Option<<Block as BlockT>::Hash>,
226+
) -> RpcResult<Vec<u8>> {
227+
let api = self.client.runtime_api();
228+
let at = at.unwrap_or_else(|| self.client.info().best_hash);
229+
230+
api.get_subnet_info_v2(at, netuid)
231+
.map_err(|e| Error::RuntimeError(format!("Unable to get subnet info: {:?}", e)).into())
232+
}
233+
234+
fn get_subnets_info_v2(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
235+
let api = self.client.runtime_api();
236+
let at = at.unwrap_or_else(|| self.client.info().best_hash);
237+
238+
api.get_subnets_info_v2(at)
239+
.map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into())
240+
}
241+
218242
fn get_network_lock_cost(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<u64> {
219243
let api = self.client.runtime_api();
220244
let at = at.unwrap_or_else(|| self.client.info().best_hash);

pallets/subtensor/runtime-api/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ sp_api::decl_runtime_apis! {
2121
pub trait SubnetInfoRuntimeApi {
2222
fn get_subnet_info(netuid: u16) -> Vec<u8>;
2323
fn get_subnets_info() -> Vec<u8>;
24+
fn get_subnet_info_v2(netuid: u16) -> Vec<u8>;
25+
fn get_subnets_info_v2() -> Vec<u8>;
2426
fn get_subnet_hyperparams(netuid: u16) -> Vec<u8>;
2527
}
2628

pallets/subtensor/src/benchmarks.rs

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ benchmarks! {
312312
let amount_to_be_staked = 100_000_000_000_000u64;
313313
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked);
314314
assert_ok!(Subtensor::<T>::register_network(RawOrigin::Signed(coldkey.clone()).into()));
315-
}: dissolve_network(RawOrigin::Signed(coldkey), 1)
315+
}: dissolve_network(RawOrigin::Root, coldkey.clone(), 1)
316+
316317

317318
// swap_hotkey {
318319
// let seed: u32 = 1;
@@ -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::Root, old_coldkey.clone(), new_coldkey.clone())
523+
465524
}

0 commit comments

Comments
 (0)