Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ pub mod pallet {
/// Indicates if the Yuma3 enable was enabled or disabled.
enabled: bool,
},
/// Event emitted when Bonds Reset is toggled.
BondsResetToggled {
/// The network identifier.
netuid: u16,
/// Indicates if the Bonds Reset was enabled or disabled.
enabled: bool,
},
}

// Errors inform users that something went wrong.
Expand Down Expand Up @@ -1602,6 +1609,34 @@ pub mod pallet {
Ok(())
}

/// Enables or disables Bonds Reset for a given subnet.
///
/// # Parameters
/// - `origin`: The origin of the call, which must be the root account or subnet owner.
/// - `netuid`: The unique identifier for the subnet.
/// - `enabled`: A boolean flag to enable or disable Bonds Reset.
///
/// # Weight
/// This function has a fixed weight of 0 and is classified as an operational transaction that does not incur any fees.
#[pallet::call_index(70)]
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
pub fn sudo_set_bonds_reset_enabled(
origin: OriginFor<T>,
netuid: u16,
enabled: bool,
) -> DispatchResult {
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;
pallet_subtensor::Pallet::<T>::set_bonds_reset(netuid, enabled);

Self::deposit_event(Event::BondsResetToggled { netuid, enabled });
log::debug!(
"BondsResetToggled( netuid: {:?} bonds_reset: {:?} ) ",
netuid,
enabled
);
Ok(())
}

/// Sets or updates the hotkey account associated with the owner of a specific subnet.
///
/// This function allows either the root origin or the current subnet owner to set or update
Expand Down
74 changes: 74 additions & 0 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,3 +1780,77 @@ fn test_set_sn_owner_hotkey_root() {
assert_eq!(actual_hotkey, hotkey);
});
}

#[test]
fn test_sudo_set_bonds_reset_enabled() {
new_test_ext().execute_with(|| {
let netuid: u16 = 1;
let to_be_set: bool = true;
let sn_owner = U256::from(1);
add_network(netuid, 10);
let init_value: bool = SubtensorModule::get_bonds_reset(netuid);

assert_eq!(
AdminUtils::sudo_set_bonds_reset_enabled(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
netuid,
to_be_set
),
Err(DispatchError::BadOrigin)
);

assert_ok!(AdminUtils::sudo_set_bonds_reset_enabled(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
to_be_set
));
assert_eq!(SubtensorModule::get_bonds_reset(netuid), to_be_set);
assert_ne!(SubtensorModule::get_bonds_reset(netuid), init_value);

pallet_subtensor::SubnetOwner::<Test>::insert(netuid, sn_owner);

assert_ok!(AdminUtils::sudo_set_bonds_reset_enabled(
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
netuid,
!to_be_set
));
assert_eq!(SubtensorModule::get_bonds_reset(netuid), !to_be_set);
});
}

#[test]
fn test_sudo_set_yuma3_enabled() {
new_test_ext().execute_with(|| {
let netuid: u16 = 1;
let to_be_set: bool = true;
let sn_owner = U256::from(1);
add_network(netuid, 10);
let init_value: bool = SubtensorModule::get_yuma3_enabled(netuid);

assert_eq!(
AdminUtils::sudo_set_yuma3_enabled(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
netuid,
to_be_set
),
Err(DispatchError::BadOrigin)
);

assert_ok!(AdminUtils::sudo_set_yuma3_enabled(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
to_be_set
));
assert_eq!(SubtensorModule::get_yuma3_enabled(netuid), to_be_set);
assert_ne!(SubtensorModule::get_yuma3_enabled(netuid), init_value);

pallet_subtensor::SubnetOwner::<Test>::insert(netuid, sn_owner);

assert_ok!(AdminUtils::sudo_set_yuma3_enabled(
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
netuid,
!to_be_set
));
assert_eq!(SubtensorModule::get_yuma3_enabled(netuid), !to_be_set);
});
}
37 changes: 37 additions & 0 deletions precompiles/src/solidity/subnet.abi
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint16",
"name": "netuid",
"type": "uint16"
}
],
"name": "getBondsResetEnabled",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -579,6 +598,24 @@
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint16",
"name": "netuid",
"type": "uint16"
},
{
"internalType": "bool",
"name": "bondsResetEnabled",
"type": "bool"
}
],
"name": "setBondsResetEnabled",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
Expand Down
8 changes: 8 additions & 0 deletions precompiles/src/solidity/subnet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ interface ISubnet {
bool yuma3Enabled
) external payable;

function getBondsResetEnabled(uint16 netuid) external view returns (bool);

function setBondsResetEnabled(
uint16 netuid,
bool bondsResetEnabled
) external payable;


function getAlphaValues(
uint16 netuid
) external view returns (uint16, uint16);
Expand Down
21 changes: 21 additions & 0 deletions precompiles/src/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,12 @@ where
Ok(pallet_subtensor::Yuma3On::<R>::get(netuid))
}

#[precompile::public("getBondsResetEnabled(uint16)")]
#[precompile::view]
fn get_bonds_reset_enabled(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult<bool> {
Ok(pallet_subtensor::BondsResetOn::<R>::get(netuid))
}

#[precompile::public("setYuma3Enabled(uint16,bool)")]
#[precompile::payable]
fn set_yuma3_enabled(
Expand All @@ -592,6 +598,21 @@ where
)
}

#[precompile::public("setBondsResetEnabled(uint16,bool)")]
#[precompile::payable]
fn set_bonds_reset_enabled(
handle: &mut impl PrecompileHandle,
netuid: u16,
enabled: bool,
) -> EvmResult<()> {
let call = pallet_admin_utils::Call::<R>::sudo_set_bonds_reset_enabled { netuid, enabled };

handle.try_dispatch_runtime_call::<R, _>(
call,
RawOrigin::Signed(handle.caller_account_id::<R>()),
)
}

#[precompile::public("getAlphaValues(uint16)")]
#[precompile::view]
fn get_alpha_values(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult<(u16, u16)> {
Expand Down
Loading