Skip to content

Commit 507df12

Browse files
committed
Merge branch 'devnet-ready' into add-missing-reads-to-admin-utils-dispatch
2 parents 39a8cf4 + f190dca commit 507df12

32 files changed

+2620
-297
lines changed

common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ pub enum ProxyType {
159159
SudoUncheckedSetCode,
160160
SwapHotkey,
161161
SubnetLeaseBeneficiary, // Used to operate the leased subnet
162+
RootClaim,
162163
}
163164

164165
impl Default for ProxyType {

pallets/admin-utils/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ pub mod pallet {
15901590
/// Weight is handled by the `#[pallet::weight]` attribute.
15911591
#[pallet::call_index(62)]
15921592
#[pallet::weight((
1593-
Weight::from_parts(6_392_000, 3507)
1593+
Weight::from_parts(10_020_000, 3507)
15941594
.saturating_add(T::DbWeight::get().reads(1_u64))
15951595
.saturating_add(T::DbWeight::get().writes(1_u64)),
15961596
DispatchClass::Operational,
@@ -1679,7 +1679,7 @@ pub mod pallet {
16791679
/// Weight is handled by the `#[pallet::weight]` attribute.
16801680
#[pallet::call_index(65)]
16811681
#[pallet::weight((
1682-
Weight::from_parts(3_918_000, 0)
1682+
Weight::from_parts(6_201_000, 0)
16831683
.saturating_add(T::DbWeight::get().reads(1_u64))
16841684
.saturating_add(T::DbWeight::get().writes(1_u64)),
16851685
DispatchClass::Operational,
@@ -1973,7 +1973,7 @@ pub mod pallet {
19731973
/// Only callable by root.
19741974
#[pallet::call_index(74)]
19751975
#[pallet::weight((
1976-
Weight::from_parts(9_418_000, 0)
1976+
Weight::from_parts(5_510_000, 0)
19771977
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(0_u64))
19781978
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)),
19791979
DispatchClass::Operational

pallets/admin-utils/src/tests/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,6 @@ fn test_trim_to_max_allowed_uids() {
26342634
assert!(!AlphaDividendsPerSubnet::<Test>::contains_key(
26352635
netuid, hotkey
26362636
));
2637-
assert!(!TaoDividendsPerSubnet::<Test>::contains_key(netuid, hotkey));
26382637
assert!(!Axons::<Test>::contains_key(netuid, hotkey));
26392638
assert!(!NeuronCertificates::<Test>::contains_key(netuid, hotkey));
26402639
assert!(!Prometheus::<Test>::contains_key(netuid, hotkey));

pallets/subtensor/src/benchmarks.rs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use sp_runtime::{
1414
BoundedVec, Percent,
1515
traits::{BlakeTwo256, Hash},
1616
};
17+
use sp_std::collections::btree_set::BTreeSet;
1718
use sp_std::vec;
1819
use subtensor_runtime_common::{AlphaCurrency, NetUid, TaoCurrency};
1920

@@ -1565,4 +1566,102 @@ mod pallet_benchmarks {
15651566
#[extrinsic_call]
15661567
_(RawOrigin::Signed(coldkey.clone()), netuid, hotkey.clone());
15671568
}
1569+
#[benchmark]
1570+
fn set_root_claim_type() {
1571+
let coldkey: T::AccountId = whitelisted_caller();
1572+
1573+
#[extrinsic_call]
1574+
_(RawOrigin::Signed(coldkey.clone()), RootClaimTypeEnum::Keep);
1575+
}
1576+
1577+
#[benchmark]
1578+
fn claim_root() {
1579+
let coldkey: T::AccountId = whitelisted_caller();
1580+
let hotkey: T::AccountId = account("A", 0, 1);
1581+
1582+
let netuid = Subtensor::<T>::get_next_netuid();
1583+
1584+
let lock_cost = Subtensor::<T>::get_network_lock_cost();
1585+
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey, lock_cost.into());
1586+
1587+
assert_ok!(Subtensor::<T>::register_network(
1588+
RawOrigin::Signed(coldkey.clone()).into(),
1589+
hotkey.clone()
1590+
));
1591+
1592+
SubtokenEnabled::<T>::insert(netuid, true);
1593+
Subtensor::<T>::set_network_pow_registration_allowed(netuid, true);
1594+
NetworkRegistrationAllowed::<T>::insert(netuid, true);
1595+
FirstEmissionBlockNumber::<T>::insert(netuid, 0);
1596+
1597+
SubnetMechanism::<T>::insert(netuid, 1);
1598+
SubnetworkN::<T>::insert(netuid, 1);
1599+
Subtensor::<T>::set_tao_weight(u64::MAX); // Set TAO weight to 1.0
1600+
1601+
let root_stake = 100_000_000u64;
1602+
Subtensor::<T>::increase_stake_for_hotkey_and_coldkey_on_subnet(
1603+
&hotkey,
1604+
&coldkey,
1605+
NetUid::ROOT,
1606+
root_stake.into(),
1607+
);
1608+
1609+
let initial_total_hotkey_alpha = 100_000_000u64;
1610+
Subtensor::<T>::increase_stake_for_hotkey_and_coldkey_on_subnet(
1611+
&hotkey,
1612+
&coldkey,
1613+
netuid,
1614+
initial_total_hotkey_alpha.into(),
1615+
);
1616+
1617+
let pending_root_alpha = 10_000_000u64;
1618+
Subtensor::<T>::drain_pending_emission(
1619+
netuid,
1620+
AlphaCurrency::ZERO,
1621+
pending_root_alpha.into(),
1622+
AlphaCurrency::ZERO,
1623+
);
1624+
1625+
let initial_stake =
1626+
Subtensor::<T>::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey, &coldkey, netuid);
1627+
1628+
assert_ok!(Subtensor::<T>::set_root_claim_type(
1629+
RawOrigin::Signed(coldkey.clone()).into(),
1630+
RootClaimTypeEnum::Keep
1631+
),);
1632+
1633+
#[extrinsic_call]
1634+
_(RawOrigin::Signed(coldkey.clone()), BTreeSet::from([netuid]));
1635+
1636+
// Verification
1637+
let new_stake =
1638+
Subtensor::<T>::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey, &coldkey, netuid);
1639+
1640+
assert!(new_stake > initial_stake);
1641+
}
1642+
1643+
#[benchmark]
1644+
fn sudo_set_num_root_claims() {
1645+
#[extrinsic_call]
1646+
_(RawOrigin::Root, 40);
1647+
}
1648+
1649+
#[benchmark]
1650+
fn sudo_set_root_claim_threshold() {
1651+
let coldkey: T::AccountId = whitelisted_caller();
1652+
let hotkey: T::AccountId = account("A", 0, 1);
1653+
1654+
let netuid = Subtensor::<T>::get_next_netuid();
1655+
1656+
let lock_cost = Subtensor::<T>::get_network_lock_cost();
1657+
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey, lock_cost.into());
1658+
1659+
assert_ok!(Subtensor::<T>::register_network(
1660+
RawOrigin::Signed(coldkey.clone()).into(),
1661+
hotkey.clone()
1662+
));
1663+
1664+
#[extrinsic_call]
1665+
_(RawOrigin::Root, netuid, 100);
1666+
}
15681667
}

pallets/subtensor/src/coinbase/block_step.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
77
/// Executes the necessary operations for each block.
88
pub fn block_step() -> Result<(), &'static str> {
99
let block_number: u64 = Self::get_current_block_as_u64();
10-
log::debug!("block_step for block: {block_number:?} ");
10+
let last_block_hash: T::Hash = <frame_system::Pallet<T>>::parent_hash();
11+
1112
// --- 1. Adjust difficulties.
1213
Self::adjust_registration_terms_for_networks();
1314
// --- 2. Get the current coinbase emission.
@@ -21,6 +22,11 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
2122
Self::run_coinbase(block_emission);
2223
// --- 4. Set pending children on the epoch; but only after the coinbase has been run.
2324
Self::try_set_pending_children(block_number);
25+
// --- 5. Run auto-claim root divs.
26+
Self::run_auto_claim_root_divs(last_block_hash);
27+
// --- 6. Populate root coldkey maps.
28+
Self::populate_root_coldkey_staking_maps();
29+
2430
// Return ok.
2531
Ok(())
2632
}

pallets/subtensor/src/coinbase/root.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,24 @@ impl<T: Config> Pallet<T> {
204204
/// * 'NotSubnetOwner': If the caller does not own the specified subnet.
205205
///
206206
pub fn do_dissolve_network(netuid: NetUid) -> dispatch::DispatchResult {
207-
// 1. --- The network exists?
207+
// --- The network exists?
208208
ensure!(
209209
Self::if_subnet_exist(netuid) && netuid != NetUid::ROOT,
210210
Error::<T>::SubnetNotExists
211211
);
212212

213-
// 2. --- Perform the cleanup before removing the network.
213+
Self::finalize_all_subnet_root_dividends(netuid);
214+
215+
// --- Perform the cleanup before removing the network.
214216
T::SwapInterface::dissolve_all_liquidity_providers(netuid)?;
215217
Self::destroy_alpha_in_out_stakes(netuid)?;
216218
T::SwapInterface::clear_protocol_liquidity(netuid)?;
217219
T::CommitmentsInterface::purge_netuid(netuid);
218220

219-
// 3. --- Remove the network
221+
// --- Remove the network
220222
Self::remove_network(netuid);
221223

222-
// 4. --- Emit the NetworkRemoved event
224+
// --- Emit the NetworkRemoved event
223225
log::info!("NetworkRemoved( netuid:{netuid:?} )");
224226
Self::deposit_event(Event::NetworkRemoved(netuid));
225227

@@ -313,8 +315,7 @@ impl<T: Config> Pallet<T> {
313315
// --- 15. Mechanism step / emissions bookkeeping.
314316
FirstEmissionBlockNumber::<T>::remove(netuid);
315317
PendingEmission::<T>::remove(netuid);
316-
PendingRootDivs::<T>::remove(netuid);
317-
PendingAlphaSwapped::<T>::remove(netuid);
318+
PendingRootAlphaDivs::<T>::remove(netuid);
318319
PendingOwnerCut::<T>::remove(netuid);
319320
BlocksSinceLastStep::<T>::remove(netuid);
320321
LastMechansimStepBlock::<T>::remove(netuid);
@@ -347,6 +348,7 @@ impl<T: Config> Pallet<T> {
347348
RAORecycledForRegistration::<T>::remove(netuid);
348349
MaxRegistrationsPerBlock::<T>::remove(netuid);
349350
WeightsVersionKey::<T>::remove(netuid);
351+
PendingRootAlphaDivs::<T>::remove(netuid);
350352

351353
// --- 17. Subtoken / feature flags.
352354
LiquidAlphaOn::<T>::remove(netuid);
@@ -365,7 +367,6 @@ impl<T: Config> Pallet<T> {
365367
let _ = NeuronCertificates::<T>::clear_prefix(netuid, u32::MAX, None);
366368
let _ = Prometheus::<T>::clear_prefix(netuid, u32::MAX, None);
367369
let _ = AlphaDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
368-
let _ = TaoDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
369370
let _ = PendingChildKeys::<T>::clear_prefix(netuid, u32::MAX, None);
370371
let _ = AssociatedEvmAddress::<T>::clear_prefix(netuid, u32::MAX, None);
371372

0 commit comments

Comments
 (0)