Skip to content

Commit a680a64

Browse files
author
unconst
committed
add moving price to metagraph
1 parent f2eff11 commit a680a64

File tree

3 files changed

+107
-2
lines changed

3 files changed

+107
-2
lines changed

pallets/subtensor/src/rpc_info/dynamic_info.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use super::*;
22
extern crate alloc;
33
use codec::Compact;
44
use frame_support::pallet_prelude::{Decode, Encode};
5+
use substrate_fixed::types::I96F32;
56
use subtensor_macros::freeze_struct;
67

7-
#[freeze_struct("f728ab9f6ffbf7f2")]
8+
#[freeze_struct("7fbd2013e8262885")]
89
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)]
910
pub struct DynamicInfo<AccountId: TypeInfo + Encode + Decode> {
1011
netuid: Compact<u16>,
@@ -27,6 +28,8 @@ pub struct DynamicInfo<AccountId: TypeInfo + Encode + Decode> {
2728
subnet_volume: Compact<u128>,
2829
network_registered_at: Compact<u64>,
2930
subnet_identity: Option<SubnetIdentityV2>,
31+
moving_price: I96F32,
32+
3033
}
3134

3235
impl<T: Config> Pallet<T> {
@@ -64,6 +67,7 @@ impl<T: Config> Pallet<T> {
6467
subnet_volume: SubnetVolume::<T>::get(netuid).into(),
6568
network_registered_at: NetworkRegisteredAt::<T>::get(netuid).into(),
6669
subnet_identity: SubnetIdentitiesV2::<T>::get(netuid),
70+
moving_price: SubnetMovingPrice::<T>::get( netuid ).into(),
6771
})
6872
}
6973
pub fn get_all_dynamic_info() -> Vec<Option<DynamicInfo<T::AccountId>>> {

pallets/subtensor/src/rpc_info/metagraph.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use crate::epoch::math::*;
44
use codec::Compact;
55
use frame_support::pallet_prelude::{Decode, Encode};
66
use substrate_fixed::types::I64F64;
7+
use substrate_fixed::types::I96F32;
78
use subtensor_macros::freeze_struct;
89

9-
#[freeze_struct("4fc6eea3706b9c0c")]
10+
#[freeze_struct("cb3ff125c0c35c9e")]
1011
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)]
1112
pub struct Metagraph<AccountId: TypeInfo + Encode + Decode> {
1213
// Subnet index
@@ -39,6 +40,7 @@ pub struct Metagraph<AccountId: TypeInfo + Encode + Decode> {
3940
pending_alpha_emission: Compact<u64>, // pending alpha to be distributed
4041
pending_root_emission: Compact<u64>, // panding tao for root divs to be distributed
4142
subnet_volume: Compact<u128>, // volume of the subnet in TAO
43+
moving_price: I96F32, // subnet moving price.
4244

4345
// Hparams for epoch
4446
rho: Compact<u16>, // subnet rho param
@@ -181,6 +183,7 @@ impl<T: Config> Pallet<T> {
181183
pending_alpha_emission: PendingEmission::<T>::get(netuid).into(), // pending alpha to be distributed
182184
pending_root_emission: PendingRootDivs::<T>::get(netuid).into(), // panding tao for root divs to be distributed
183185
subnet_volume: subnet_volume.into(),
186+
moving_price: SubnetMovingPrice::<T>::get(netuid).into(),
184187

185188
// Hparams for epoch
186189
rho: Self::get_rho(netuid).into(), // subnet rho param

pallets/subtensor/src/tests/coinbase.rs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,3 +1251,101 @@ fn test_get_root_children_drain_with_half_take() {
12511251
);
12521252
});
12531253
}
1254+
1255+
// // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_get_root_children_with_weights --exact --show-output --nocapture
1256+
// #[test]
1257+
// fn test_get_root_children_with_weights() {
1258+
// new_test_ext(1).execute_with(|| {
1259+
// // Init netuid 1
1260+
// let root: u16 = 0;
1261+
// let alpha: u16 = 1;
1262+
// add_network(root, 1, 0);
1263+
// add_network(alpha, 1, 0);
1264+
// // Set TAO weight to 1.
1265+
// SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1.
1266+
// // Create keys.
1267+
// let cold = U256::from(0);
1268+
// let alice = U256::from(1);
1269+
// let bob = U256::from(2);
1270+
// // Register Alice and Bob to the root network and alpha subnet.
1271+
// register_ok_neuron(alpha, alice, cold, 0);
1272+
// register_ok_neuron(alpha, bob, cold, 0);
1273+
// assert_ok!(SubtensorModule::root_register(
1274+
// RuntimeOrigin::signed(cold).clone(),
1275+
// alice,
1276+
// ));
1277+
// assert_ok!(SubtensorModule::root_register(
1278+
// RuntimeOrigin::signed(cold).clone(),
1279+
// bob,
1280+
// ));
1281+
// // Add stake for Alice and Bob on root.
1282+
// let alice_root_stake: u64 = 1_000_000_000;
1283+
// SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
1284+
// &alice,
1285+
// &cold,
1286+
// root,
1287+
// alice_root_stake,
1288+
// );
1289+
// let bob_root_stake: u64 = 1_000_000_000;
1290+
// SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
1291+
// &bob,
1292+
// &cold,
1293+
// root,
1294+
// alice_root_stake,
1295+
// );
1296+
// // Add stake for Alice and Bob on netuid.
1297+
// let alice_alpha_stake: u64 = 1_000_000_000;
1298+
// SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
1299+
// &alice,
1300+
// &cold,
1301+
// alpha,
1302+
// alice_alpha_stake,
1303+
// );
1304+
// let bob_alpha_stake: u64 = 1_000_000_000;
1305+
// SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
1306+
// &bob,
1307+
// &cold,
1308+
// alpha,
1309+
// bob_alpha_stake,
1310+
// );
1311+
// // Set Bob as 100% child of Alice on root.
1312+
// mock_set_children_no_epochs(alpha, &alice, &[(u64::MAX, bob)]);
1313+
1314+
// // Set Bob childkey take to zero.
1315+
// ChildkeyTake::<Test>::insert(bob, alpha, 0);
1316+
// Delegates::<Test>::insert(alice, 0);
1317+
// Delegates::<Test>::insert(bob, 0);
1318+
1319+
// // Set weights on the subnet.
1320+
// assert_ok!(SubtensorModule::set_weights(
1321+
// RuntimeOrigin::signed(alice),
1322+
// alpha,
1323+
// vec![0, 1],
1324+
// vec![1, 1],
1325+
// 0,
1326+
// ));
1327+
// assert_ok!(SubtensorModule::set_weights(
1328+
// RuntimeOrigin::signed(bob),
1329+
// alpha,
1330+
// vec![0, 1],
1331+
// vec![1, 1],
1332+
// 0,
1333+
// ));
1334+
1335+
// // Lets drain!
1336+
// let pending_alpha: u64 = 1_000_000_000;
1337+
// SubtensorModule::drain_pending_emission(alpha, pending_alpha, 0, 0, 0);
1338+
1339+
// // Alice and Bob make the same amount.
1340+
// close(
1341+
// AlphaDividendsPerSubnet::<Test>::get(alpha, alice),
1342+
// pending_alpha / 2,
1343+
// 10,
1344+
// );
1345+
// close(
1346+
// AlphaDividendsPerSubnet::<Test>::get(alpha, bob),
1347+
// pending_alpha / 2,
1348+
// 10,
1349+
// );
1350+
// });
1351+
// }

0 commit comments

Comments
 (0)