Skip to content

Commit b4ccab5

Browse files
author
YZX0
committed
Fix: Issue #1960 - Refactor InsufficientBalance error
1 parent be47139 commit b4ccab5

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

pallets/subtensor/src/macros/errors.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ mod errors {
3838
NotEnoughStakeToSetChildkeys,
3939
/// The caller is requesting adding more stake than there exists in the coldkey account.
4040
/// See: "[add_stake()]"
41-
NotEnoughBalanceToStake,
41+
/// The caller is requesting adding more stake than there exists in the coldkey account.
42+
/// See: "[add_stake()]"
43+
// NotEnoughBalanceToStake,
4244
/// The caller is trying to add stake, but for some reason the requested amount could not be
4345
/// withdrawn from the coldkey account.
4446
BalanceWithdrawalError,
@@ -210,8 +212,10 @@ mod errors {
210212
ZeroMaxStakeAmount,
211213
/// Invalid netuid duplication
212214
SameNetuid,
213-
/// The caller does not have enough balance for the operation.
214-
InsufficientBalance,
215+
/// The caller does not have enough balance to pay the fee.
216+
NotEnoughBalanceToPayFee,
217+
/// The caller does not have enough balance to pay the stake.
218+
NotEnoughBalanceToPayStake,
215219
/// Too frequent staking operations
216220
StakingOperationRateLimitExceeded,
217221
/// Invalid lease beneficiary to register the leased network.

pallets/subtensor/src/staking/stake_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ impl<T: Config> Pallet<T> {
971971
// Ensure the callers coldkey has enough stake to perform the transaction.
972972
ensure!(
973973
Self::can_remove_balance_from_coldkey_account(coldkey, stake_to_be_added.into()),
974-
Error::<T>::NotEnoughBalanceToStake
974+
Error::<T>::NotEnoughBalanceToPayStake
975975
);
976976

977977
// Ensure that the hotkey account exists this is only possible through registration.

pallets/subtensor/src/subnets/registration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<T: Config> Pallet<T> {
107107
let registration_cost = Self::get_burn(netuid);
108108
ensure!(
109109
Self::can_remove_balance_from_coldkey_account(&coldkey, registration_cost.into()),
110-
Error::<T>::NotEnoughBalanceToStake
110+
Error::<T>::NotEnoughBalanceToPayFee
111111
);
112112

113113
// If the network account does not exist we will create it here.

pallets/subtensor/src/tests/staking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ fn test_add_stake_err_not_enough_belance() {
249249
netuid,
250250
stake,
251251
),
252-
Error::<Test>::NotEnoughBalanceToStake
252+
Error::<Test>::NotEnoughBalanceToPayStake
253253
);
254254
});
255255
}

pallets/subtensor/src/transaction_extension.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ where
5454
Err(match err {
5555
Error::<T>::AmountTooLow => CustomTransactionError::StakeAmountTooLow.into(),
5656
Error::<T>::SubnetNotExists => CustomTransactionError::SubnetNotExists.into(),
57-
Error::<T>::NotEnoughBalanceToStake => CustomTransactionError::BalanceTooLow.into(),
57+
Error::<T>::NotEnoughBalanceToPayFee => CustomTransactionError::BalanceTooLow.into(),
58+
Error::<T>::NotEnoughBalanceToPayStake => CustomTransactionError::BalanceTooLow.into(),
5859
Error::<T>::HotKeyAccountNotExists => {
5960
CustomTransactionError::HotkeyAccountDoesntExist.into()
6061
}

0 commit comments

Comments
 (0)