Skip to content

Commit b45fcb3

Browse files
authored
Merge pull request #1727 from inference-labs-inc/feat/bonds-reset-hyperparam
Add `sudo_set_bonds_reset_enabled`
2 parents 3685d33 + 001e12a commit b45fcb3

File tree

5 files changed

+175
-0
lines changed

5 files changed

+175
-0
lines changed

pallets/admin-utils/src/lib.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ pub mod pallet {
8484
/// Indicates if the Yuma3 enable was enabled or disabled.
8585
enabled: bool,
8686
},
87+
/// Event emitted when Bonds Reset is toggled.
88+
BondsResetToggled {
89+
/// The network identifier.
90+
netuid: u16,
91+
/// Indicates if the Bonds Reset was enabled or disabled.
92+
enabled: bool,
93+
},
8794
}
8895

8996
// Errors inform users that something went wrong.
@@ -1604,6 +1611,34 @@ pub mod pallet {
16041611
Ok(())
16051612
}
16061613

1614+
/// Enables or disables Bonds Reset for a given subnet.
1615+
///
1616+
/// # Parameters
1617+
/// - `origin`: The origin of the call, which must be the root account or subnet owner.
1618+
/// - `netuid`: The unique identifier for the subnet.
1619+
/// - `enabled`: A boolean flag to enable or disable Bonds Reset.
1620+
///
1621+
/// # Weight
1622+
/// This function has a fixed weight of 0 and is classified as an operational transaction that does not incur any fees.
1623+
#[pallet::call_index(70)]
1624+
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1625+
pub fn sudo_set_bonds_reset_enabled(
1626+
origin: OriginFor<T>,
1627+
netuid: u16,
1628+
enabled: bool,
1629+
) -> DispatchResult {
1630+
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;
1631+
pallet_subtensor::Pallet::<T>::set_bonds_reset(netuid, enabled);
1632+
1633+
Self::deposit_event(Event::BondsResetToggled { netuid, enabled });
1634+
log::debug!(
1635+
"BondsResetToggled( netuid: {:?} bonds_reset: {:?} ) ",
1636+
netuid,
1637+
enabled
1638+
);
1639+
Ok(())
1640+
}
1641+
16071642
/// Sets or updates the hotkey account associated with the owner of a specific subnet.
16081643
///
16091644
/// This function allows either the root origin or the current subnet owner to set or update

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,3 +1780,77 @@ fn test_set_sn_owner_hotkey_root() {
17801780
assert_eq!(actual_hotkey, hotkey);
17811781
});
17821782
}
1783+
1784+
#[test]
1785+
fn test_sudo_set_bonds_reset_enabled() {
1786+
new_test_ext().execute_with(|| {
1787+
let netuid: u16 = 1;
1788+
let to_be_set: bool = true;
1789+
let sn_owner = U256::from(1);
1790+
add_network(netuid, 10);
1791+
let init_value: bool = SubtensorModule::get_bonds_reset(netuid);
1792+
1793+
assert_eq!(
1794+
AdminUtils::sudo_set_bonds_reset_enabled(
1795+
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
1796+
netuid,
1797+
to_be_set
1798+
),
1799+
Err(DispatchError::BadOrigin)
1800+
);
1801+
1802+
assert_ok!(AdminUtils::sudo_set_bonds_reset_enabled(
1803+
<<Test as Config>::RuntimeOrigin>::root(),
1804+
netuid,
1805+
to_be_set
1806+
));
1807+
assert_eq!(SubtensorModule::get_bonds_reset(netuid), to_be_set);
1808+
assert_ne!(SubtensorModule::get_bonds_reset(netuid), init_value);
1809+
1810+
pallet_subtensor::SubnetOwner::<Test>::insert(netuid, sn_owner);
1811+
1812+
assert_ok!(AdminUtils::sudo_set_bonds_reset_enabled(
1813+
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
1814+
netuid,
1815+
!to_be_set
1816+
));
1817+
assert_eq!(SubtensorModule::get_bonds_reset(netuid), !to_be_set);
1818+
});
1819+
}
1820+
1821+
#[test]
1822+
fn test_sudo_set_yuma3_enabled() {
1823+
new_test_ext().execute_with(|| {
1824+
let netuid: u16 = 1;
1825+
let to_be_set: bool = true;
1826+
let sn_owner = U256::from(1);
1827+
add_network(netuid, 10);
1828+
let init_value: bool = SubtensorModule::get_yuma3_enabled(netuid);
1829+
1830+
assert_eq!(
1831+
AdminUtils::sudo_set_yuma3_enabled(
1832+
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
1833+
netuid,
1834+
to_be_set
1835+
),
1836+
Err(DispatchError::BadOrigin)
1837+
);
1838+
1839+
assert_ok!(AdminUtils::sudo_set_yuma3_enabled(
1840+
<<Test as Config>::RuntimeOrigin>::root(),
1841+
netuid,
1842+
to_be_set
1843+
));
1844+
assert_eq!(SubtensorModule::get_yuma3_enabled(netuid), to_be_set);
1845+
assert_ne!(SubtensorModule::get_yuma3_enabled(netuid), init_value);
1846+
1847+
pallet_subtensor::SubnetOwner::<Test>::insert(netuid, sn_owner);
1848+
1849+
assert_ok!(AdminUtils::sudo_set_yuma3_enabled(
1850+
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
1851+
netuid,
1852+
!to_be_set
1853+
));
1854+
assert_eq!(SubtensorModule::get_yuma3_enabled(netuid), !to_be_set);
1855+
});
1856+
}

precompiles/src/solidity/subnet.abi

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@
8080
"stateMutability": "view",
8181
"type": "function"
8282
},
83+
{
84+
"inputs": [
85+
{
86+
"internalType": "uint16",
87+
"name": "netuid",
88+
"type": "uint16"
89+
}
90+
],
91+
"name": "getBondsResetEnabled",
92+
"outputs": [
93+
{
94+
"internalType": "bool",
95+
"name": "",
96+
"type": "bool"
97+
}
98+
],
99+
"stateMutability": "view",
100+
"type": "function"
101+
},
83102
{
84103
"inputs": [
85104
{
@@ -579,6 +598,24 @@
579598
"stateMutability": "payable",
580599
"type": "function"
581600
},
601+
{
602+
"inputs": [
603+
{
604+
"internalType": "uint16",
605+
"name": "netuid",
606+
"type": "uint16"
607+
},
608+
{
609+
"internalType": "bool",
610+
"name": "bondsResetEnabled",
611+
"type": "bool"
612+
}
613+
],
614+
"name": "setBondsResetEnabled",
615+
"outputs": [],
616+
"stateMutability": "payable",
617+
"type": "function"
618+
},
582619
{
583620
"inputs": [
584621
{

precompiles/src/solidity/subnet.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ interface ISubnet {
159159
bool yuma3Enabled
160160
) external payable;
161161

162+
function getBondsResetEnabled(uint16 netuid) external view returns (bool);
163+
164+
function setBondsResetEnabled(
165+
uint16 netuid,
166+
bool bondsResetEnabled
167+
) external payable;
168+
169+
162170
function getAlphaValues(
163171
uint16 netuid
164172
) external view returns (uint16, uint16);

precompiles/src/subnet.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,12 @@ where
577577
Ok(pallet_subtensor::Yuma3On::<R>::get(netuid))
578578
}
579579

580+
#[precompile::public("getBondsResetEnabled(uint16)")]
581+
#[precompile::view]
582+
fn get_bonds_reset_enabled(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult<bool> {
583+
Ok(pallet_subtensor::BondsResetOn::<R>::get(netuid))
584+
}
585+
580586
#[precompile::public("setYuma3Enabled(uint16,bool)")]
581587
#[precompile::payable]
582588
fn set_yuma3_enabled(
@@ -592,6 +598,21 @@ where
592598
)
593599
}
594600

601+
#[precompile::public("setBondsResetEnabled(uint16,bool)")]
602+
#[precompile::payable]
603+
fn set_bonds_reset_enabled(
604+
handle: &mut impl PrecompileHandle,
605+
netuid: u16,
606+
enabled: bool,
607+
) -> EvmResult<()> {
608+
let call = pallet_admin_utils::Call::<R>::sudo_set_bonds_reset_enabled { netuid, enabled };
609+
610+
handle.try_dispatch_runtime_call::<R, _>(
611+
call,
612+
RawOrigin::Signed(handle.caller_account_id::<R>()),
613+
)
614+
}
615+
595616
#[precompile::public("getAlphaValues(uint16)")]
596617
#[precompile::view]
597618
fn get_alpha_values(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult<(u16, u16)> {

0 commit comments

Comments
 (0)