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 Deployment 27082024 #757

Merged
merged 49 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
ce31915
add delegate id
JohnReedV Jul 31, 2024
ad827b4
add swap & tests
JohnReedV Aug 1, 2024
9d13693
expand check
JohnReedV Aug 1, 2024
3ce54bd
fix doc comment
JohnReedV Aug 1, 2024
28a00fe
remove swap_id_coldkey fn
JohnReedV Aug 1, 2024
7058b51
update & move tests
JohnReedV Aug 2, 2024
2fc87ca
add swap_coldkey benchmark
JohnReedV Aug 2, 2024
dcb198f
initial
Aug 3, 2024
7a77dfd
initia;
Aug 3, 2024
71beff0
Merge branch 'add-a-delegate-id' into swap_ids
Aug 3, 2024
f33d701
add subnet identities
JohnReedV Aug 14, 2024
fa8da4c
fix comments
JohnReedV Aug 15, 2024
ba508aa
freeze SubnetIdentity struct
JohnReedV Aug 15, 2024
f373434
add identities to subnet registration process
JohnReedV Aug 15, 2024
7425602
check if identity is valid
JohnReedV Aug 15, 2024
136dd47
Expand test
JohnReedV Aug 16, 2024
fd379bc
match existing pattern
JohnReedV Aug 16, 2024
e7aee7a
Merge branch 'devnet-ready' into subnet-identities
JohnReedV Aug 19, 2024
1be0904
Merge branch 'devnet-ready' into subnet-identities
JohnReedV Aug 19, 2024
57ed878
fix pallet index conflict
JohnReedV Aug 19, 2024
1e4312b
fix workspace root package
sam0x17 Aug 19, 2024
917217f
bump CI
sam0x17 Aug 19, 2024
6b621e6
add sudo call to set duration
open-junius Aug 20, 2024
092a373
add value check
open-junius Aug 20, 2024
9be558e
upgrade version
open-junius Aug 20, 2024
0d34bfc
Merge branch 'devnet-ready' into subnet-identities
JohnReedV Aug 20, 2024
1666746
fix pallet index conflict
JohnReedV Aug 20, 2024
8d9bb2d
add more test
open-junius Aug 20, 2024
9424806
fix clippy
open-junius Aug 20, 2024
8ea7255
update dissolve network origin
open-junius Aug 21, 2024
039bb08
fix unit test
open-junius Aug 21, 2024
858141f
Merge branch 'devnet-ready' into swap_ids
JohnReedV Aug 21, 2024
120da50
fix tests and benchmarks
JohnReedV Aug 21, 2024
bc1631e
add a delegate ID
JohnReedV Aug 21, 2024
93233fc
clippy
JohnReedV Aug 21, 2024
979d46d
bump spec
JohnReedV Aug 22, 2024
cdb0759
bump spec
JohnReedV Aug 22, 2024
b4c1712
fix comment index
open-junius Aug 23, 2024
9e2686e
Merge pull request #747 from opentensor/swap_ids
unconst Aug 23, 2024
e2a60a1
Merge pull request #745 from opentensor/junius-add-sudo-call-for-sche…
unconst Aug 23, 2024
3496c34
Merge pull request #744 from opentensor/sam-fix-workspace-deps
unconst Aug 23, 2024
2c2a15d
Merge branch 'devnet-ready' into subnet-identities
unconst Aug 23, 2024
8c17cfd
Merge pull request #736 from opentensor/subnet-identities
unconst Aug 23, 2024
41b6ae6
feat: implement subnetinfov2 , add_network with identities
Aug 26, 2024
803c5e3
remove user_add_network
JohnReedV Aug 26, 2024
619757f
fix benchmarks
JohnReedV Aug 26, 2024
5af9888
revert rename user_add_network
JohnReedV Aug 26, 2024
5567133
Merge pull request #753 from opentensor/spiigot/subnet_info_versioning
JohnReedV Aug 26, 2024
c23c7fd
Merge pull request #752 from opentensor/feat/subnet_info_versioning
unconst Aug 27, 2024
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

**/*.lock

*.ipynb

# Generated by code coverage
*.profraw
*.profdata
Expand Down
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ repository = "https://github.com/opentensor/subtensor"

[dependencies]
node-subtensor = { path = "node", version = "4.0.0-dev" }
pallet-commitments = { path = "pallets/commitments", version = "4.0.0-dev" }
pallet-subtensor = { path = "pallets/subtensor", version = "4.0.0-dev" }
node-subtensor-runtime = { path = "runtime", version = "4.0.0-dev" }
subtensor-macros = { path = "support/macros", version = "0.1.0" }

[build-dependencies]
subtensor-linting = { path = "support/linting", version = "0.1.0" }
Expand Down Expand Up @@ -167,3 +164,8 @@ opt-level = 3
inherits = "release"
lto = true
codegen-units = 1

[features]
default = []
try-runtime = ["node-subtensor/try-runtime", "node-subtensor-runtime/try-runtime"]
runtime-benchmarks = ["node-subtensor/runtime-benchmarks", "node-subtensor-runtime/runtime-benchmarks"]
14 changes: 14 additions & 0 deletions docs/delegate-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,19 @@
"url": "https://cortex.foundation/",
"description": "Cortex Foundation is committed to advancing the integration of decentralized AI. Our validator is designed for transparency, reliability, and community engagement.",
"signature": "7a6274ff6b0f7ddca97e37ef4a9b90781012ff3cf7baa3159f6feaafc43c557975aad324ea608d6b8abeb21f8f3ca2595e54b81a7564574d0242b803d969618a"
},
{
"address":"5F27Eqz2PhyMtGMEce898x31DokNqRVxkm5AhDDe6rDGNvoY",
"name": "Love",
"url": "https://love.cosimo.fund",
"description": "Love validator exists to accelerate open source AI and be good stewards of the Bittensorr network",
"signature": "c221a3de3be031c149a7be912b3b75e0355605f041dc975153302b23b4d93e45e9cc7453532491e92076ccd333a4c1f95f4a2229aae8f4fcfb88e5dec3f14c87"
},
{
"address": "5Hb63SvXBXqZ8zw6mwW1A39fHdqUrJvohXgepyhp2jgWedSB",
"name": "TAO Miner's Union",
"url": "https://minersunion.ai",
"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.",
"signature": "e8c68bc766a06f36c633e1f68d5aca4c4090a26e394372f64d5b00cc13621f361ec9df85fc9f0d247dbc1fe452bd53ffc0224dee2bc85c9d82cb250e4ac10984"
}
]
68 changes: 68 additions & 0 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub use pallet::*;
pub mod weights;
pub use weights::WeightInfo;

use frame_system::pallet_prelude::BlockNumberFor;
use sp_runtime::{traits::Member, RuntimeAppPublic};

mod benchmarking;
Expand Down Expand Up @@ -1128,6 +1129,73 @@ pub mod pallet {

Ok(())
}

/// Sets the duration of the coldkey swap schedule.
///
/// This extrinsic allows the root account to set the duration for the coldkey swap schedule.
/// The coldkey swap schedule determines how long it takes for a coldkey swap operation to complete.
///
/// # Arguments
/// * `origin` - The origin of the call, which must be the root account.
/// * `duration` - The new duration for the coldkey swap schedule, in number of blocks.
///
/// # Errors
/// * `BadOrigin` - If the caller is not the root account.
///
/// # Weight
/// Weight is handled by the `#[pallet::weight]` attribute.
#[pallet::call_index(54)]
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
pub fn sudo_set_coldkey_swap_schedule_duration(
origin: OriginFor<T>,
duration: BlockNumberFor<T>,
) -> DispatchResult {
// Ensure the call is made by the root account
ensure_root(origin)?;

// Set the new duration of schedule coldkey swap
pallet_subtensor::Pallet::<T>::set_coldkey_swap_schedule_duration(duration);

// Log the change
log::trace!("ColdkeySwapScheduleDurationSet( duration: {:?} )", duration);

Ok(())
}

/// Sets the duration of the dissolve network schedule.
///
/// This extrinsic allows the root account to set the duration for the dissolve network schedule.
/// The dissolve network schedule determines how long it takes for a network dissolution operation to complete.
///
/// # Arguments
/// * `origin` - The origin of the call, which must be the root account.
/// * `duration` - The new duration for the dissolve network schedule, in number of blocks.
///
/// # Errors
/// * `BadOrigin` - If the caller is not the root account.
///
/// # Weight
/// Weight is handled by the `#[pallet::weight]` attribute.
#[pallet::call_index(55)]
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
pub fn sudo_set_dissolve_network_schedule_duration(
origin: OriginFor<T>,
duration: BlockNumberFor<T>,
) -> DispatchResult {
// Ensure the call is made by the root account
ensure_root(origin)?;

// Set the duration of schedule dissolve network
pallet_subtensor::Pallet::<T>::set_dissolve_network_schedule_duration(duration);

// Log the change
log::trace!(
"DissolveNetworkScheduleDurationSet( duration: {:?} )",
duration
);

Ok(())
}
}
}

Expand Down
76 changes: 75 additions & 1 deletion pallets/admin-utils/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use frame_support::sp_runtime::DispatchError;
use frame_support::{
assert_err, assert_ok,
assert_err, assert_noop, assert_ok,
dispatch::{DispatchClass, GetDispatchInfo, Pays},
};
use frame_system::Config;
Expand Down Expand Up @@ -1361,3 +1361,77 @@ fn test_sudo_get_set_alpha() {
));
});
}

#[test]
fn test_sudo_set_coldkey_swap_schedule_duration() {
new_test_ext().execute_with(|| {
// Arrange
let root = RuntimeOrigin::root();
let non_root = RuntimeOrigin::signed(U256::from(1));
let new_duration = 100u32.into();

// Act & Assert: Non-root account should fail
assert_noop!(
AdminUtils::sudo_set_coldkey_swap_schedule_duration(non_root, new_duration),
DispatchError::BadOrigin
);

// Act: Root account should succeed
assert_ok!(AdminUtils::sudo_set_coldkey_swap_schedule_duration(
root.clone(),
new_duration
));

// Assert: Check if the duration was actually set
assert_eq!(
pallet_subtensor::ColdkeySwapScheduleDuration::<Test>::get(),
new_duration
);

// Act & Assert: Setting the same value again should succeed (idempotent operation)
assert_ok!(AdminUtils::sudo_set_coldkey_swap_schedule_duration(
root,
new_duration
));

// You might want to check for events here if your pallet emits them
System::assert_last_event(Event::ColdkeySwapScheduleDurationSet(new_duration).into());
});
}

#[test]
fn test_sudo_set_dissolve_network_schedule_duration() {
new_test_ext().execute_with(|| {
// Arrange
let root = RuntimeOrigin::root();
let non_root = RuntimeOrigin::signed(U256::from(1));
let new_duration = 200u32.into();

// Act & Assert: Non-root account should fail
assert_noop!(
AdminUtils::sudo_set_dissolve_network_schedule_duration(non_root, new_duration),
DispatchError::BadOrigin
);

// Act: Root account should succeed
assert_ok!(AdminUtils::sudo_set_dissolve_network_schedule_duration(
root.clone(),
new_duration
));

// Assert: Check if the duration was actually set
assert_eq!(
pallet_subtensor::DissolveNetworkScheduleDuration::<Test>::get(),
new_duration
);

// Act & Assert: Setting the same value again should succeed (idempotent operation)
assert_ok!(AdminUtils::sudo_set_dissolve_network_schedule_duration(
root,
new_duration
));

// You might want to check for events here if your pallet emits them
System::assert_last_event(Event::DissolveNetworkScheduleDurationSet(new_duration).into());
});
}
24 changes: 24 additions & 0 deletions pallets/subtensor/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ pub trait SubtensorCustomApi<BlockHash> {
fn get_subnet_info(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getSubnetsInfo")]
fn get_subnets_info(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getSubnetInfo_v2")]
fn get_subnet_info_v2(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getSubnetsInf_v2")]
fn get_subnets_info_v2(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getSubnetHyperparams")]
fn get_subnet_hyperparams(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;

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

fn get_subnet_info_v2(
&self,
netuid: u16,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<Vec<u8>> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);

api.get_subnet_info_v2(at, netuid)
.map_err(|e| Error::RuntimeError(format!("Unable to get subnet info: {:?}", e)).into())
}

fn get_subnets_info_v2(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);

api.get_subnets_info_v2(at)
.map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into())
}

fn get_network_lock_cost(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<u64> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);
Expand Down
2 changes: 2 additions & 0 deletions pallets/subtensor/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ sp_api::decl_runtime_apis! {
pub trait SubnetInfoRuntimeApi {
fn get_subnet_info(netuid: u16) -> Vec<u8>;
fn get_subnets_info() -> Vec<u8>;
fn get_subnet_info_v2(netuid: u16) -> Vec<u8>;
fn get_subnets_info_v2() -> Vec<u8>;
fn get_subnet_hyperparams(netuid: u16) -> Vec<u8>;
}

Expand Down
63 changes: 61 additions & 2 deletions pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ benchmarks! {
let amount_to_be_staked = 100_000_000_000_000u64;
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked);
assert_ok!(Subtensor::<T>::register_network(RawOrigin::Signed(coldkey.clone()).into()));
}: dissolve_network(RawOrigin::Signed(coldkey), 1)
}: dissolve_network(RawOrigin::Root, coldkey.clone(), 1)


// swap_hotkey {
// let seed: u32 = 1;
Expand Down Expand Up @@ -444,7 +445,7 @@ reveal_weights {
let new_rate_limit: u64 = 100;
}: sudo_set_tx_childkey_take_rate_limit(RawOrigin::Root, new_rate_limit)

benchmark_set_childkey_take {
benchmark_set_childkey_take {
// Setup
let netuid: u16 = 1;
let tempo: u16 = 1;
Expand All @@ -462,4 +463,62 @@ benchmark_set_childkey_take {
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey, amount_to_be_staked);
assert_ok!(Subtensor::<T>::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone()));
}: set_childkey_take(RawOrigin::Signed(coldkey), hotkey, netuid, take)

swap_coldkey {
// Set up initial state
let old_coldkey: T::AccountId = account("old_coldkey", 0, 0);
let new_coldkey: T::AccountId = account("new_coldkey", 0, 0);
let hotkey1: T::AccountId = account("hotkey1", 0, 0);
let netuid = 1u16;
let stake_amount1 = 1000u64;
let stake_amount2 = 2000u64;
let swap_cost = Subtensor::<T>::get_key_swap_cost();
let free_balance_old = 12345u64 + swap_cost;
let tempo: u16 = 1;

// Setup initial state
Subtensor::<T>::init_new_network(netuid, tempo);
Subtensor::<T>::set_network_registration_allowed(netuid, true);
Subtensor::<T>::set_network_pow_registration_allowed(netuid, true);

let block_number: u64 = Subtensor::<T>::get_current_block_as_u64();
let (nonce, work): (u64, Vec<u8>) = Subtensor::<T>::create_work_for_block_number(
netuid,
block_number,
3,
&hotkey1,
);

let _ = Subtensor::<T>::register(
<T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(old_coldkey.clone())),
netuid,
block_number,
nonce,
work.clone(),
hotkey1.clone(),
old_coldkey.clone(),
);

// Add balance to old coldkey
Subtensor::<T>::add_balance_to_coldkey_account(
&old_coldkey,
stake_amount1 + stake_amount2 + free_balance_old,
);

// Insert an Identity
let name: Vec<u8> = b"The fourth Coolest Identity".to_vec();
let identity: ChainIdentity = ChainIdentity {
name: name.clone(),
url: vec![],
image: vec![],
discord: vec![],
description: vec![],
additional: vec![],
};

Identities::<T>::insert(&old_coldkey, identity);

// Benchmark setup complete, now execute the extrinsic
}: swap_coldkey(RawOrigin::Root, old_coldkey.clone(), new_coldkey.clone())

}
Loading
Loading