Skip to content

Commit 60dffb3

Browse files
committed
Return actual recycled/burned alpha amount from pallet
1 parent 65357d3 commit 60dffb3

4 files changed

Lines changed: 24 additions & 24 deletions

File tree

chain-extensions/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -536,16 +536,16 @@ where
536536

537537
let caller = env.caller();
538538

539-
let call_result = pallet_subtensor::Pallet::<T>::recycle_alpha(
539+
let call_result = pallet_subtensor::Pallet::<T>::do_recycle_alpha(
540540
RawOrigin::Signed(caller).into(),
541541
hotkey,
542542
amount,
543543
netuid,
544544
);
545545

546546
match call_result {
547-
Ok(_) => {
548-
env.write_output(&amount.encode())
547+
Ok(real_amount) => {
548+
env.write_output(&real_amount.encode())
549549
.map_err(|_| DispatchError::Other("Failed to write output"))?;
550550
Ok(RetVal::Converging(Output::Success as u32))
551551
}
@@ -567,16 +567,16 @@ where
567567

568568
let caller = env.caller();
569569

570-
let call_result = pallet_subtensor::Pallet::<T>::burn_alpha(
570+
let call_result = pallet_subtensor::Pallet::<T>::do_burn_alpha(
571571
RawOrigin::Signed(caller).into(),
572572
hotkey,
573573
amount,
574574
netuid,
575575
);
576576

577577
match call_result {
578-
Ok(_) => {
579-
env.write_output(&amount.encode())
578+
Ok(real_amount) => {
579+
env.write_output(&real_amount.encode())
580580
.map_err(|_| DispatchError::Other("Failed to write output"))?;
581581
Ok(RetVal::Converging(Output::Success as u32))
582582
}
@@ -609,13 +609,13 @@ where
609609
Err(e) => return TransactionOutcome::Rollback(Err(e)),
610610
};
611611

612-
match pallet_subtensor::Pallet::<T>::recycle_alpha(
612+
match pallet_subtensor::Pallet::<T>::do_recycle_alpha(
613613
RawOrigin::Signed(caller).into(),
614614
hotkey,
615615
alpha,
616616
netuid,
617617
) {
618-
Ok(_) => TransactionOutcome::Commit(Ok(alpha)),
618+
Ok(real_alpha) => TransactionOutcome::Commit(Ok(real_alpha)),
619619
Err(e) => TransactionOutcome::Rollback(Err(e)),
620620
}
621621
});
@@ -655,13 +655,13 @@ where
655655
Err(e) => return TransactionOutcome::Rollback(Err(e)),
656656
};
657657

658-
match pallet_subtensor::Pallet::<T>::burn_alpha(
658+
match pallet_subtensor::Pallet::<T>::do_burn_alpha(
659659
RawOrigin::Signed(caller).into(),
660660
hotkey,
661661
alpha,
662662
netuid,
663663
) {
664-
Ok(_) => TransactionOutcome::Commit(Ok(alpha)),
664+
Ok(real_alpha) => TransactionOutcome::Commit(Ok(real_alpha)),
665665
Err(e) => TransactionOutcome::Rollback(Err(e)),
666666
}
667667
});

chain-extensions/src/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,8 +1141,8 @@ fn recycle_alpha_clamps_to_available_when_amount_exceeds_stake() {
11411141

11421142
let returned_amount = AlphaBalance::decode(&mut env.output()).unwrap();
11431143
assert_eq!(
1144-
returned_amount, huge_amount,
1145-
"should return requested amount"
1144+
returned_amount, alpha_before,
1145+
"should return actual clamped amount, not requested amount"
11461146
);
11471147

11481148
let alpha_after =
@@ -1242,8 +1242,8 @@ fn burn_alpha_clamps_to_available_when_amount_exceeds_stake() {
12421242

12431243
let returned_amount = AlphaBalance::decode(&mut env.output()).unwrap();
12441244
assert_eq!(
1245-
returned_amount, huge_amount,
1246-
"should return requested amount"
1245+
returned_amount, alpha_before,
1246+
"should return actual clamped amount, not requested amount"
12471247
);
12481248

12491249
let alpha_after =

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ mod dispatches {
18571857
amount: AlphaBalance,
18581858
netuid: NetUid,
18591859
) -> DispatchResult {
1860-
Self::do_recycle_alpha(origin, hotkey, amount, netuid)
1860+
Self::do_recycle_alpha(origin, hotkey, amount, netuid).map(|_| ())
18611861
}
18621862

18631863
/// Burns alpha from a cold/hot key pair without reducing `AlphaOut`
@@ -1878,7 +1878,7 @@ mod dispatches {
18781878
amount: AlphaBalance,
18791879
netuid: NetUid,
18801880
) -> DispatchResult {
1881-
Self::do_burn_alpha(origin, hotkey, amount, netuid)
1881+
Self::do_burn_alpha(origin, hotkey, amount, netuid).map(|_| ())
18821882
}
18831883

18841884
/// Sets the pending childkey cooldown (in blocks). Root only.

pallets/subtensor/src/staking/recycle_alpha.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ impl<T: Config> Pallet<T> {
1414
///
1515
/// # Returns
1616
///
17-
/// * `DispatchResult` - Success or error
18-
pub(crate) fn do_recycle_alpha(
17+
/// * `Result<AlphaBalance, DispatchError>` - The actual amount recycled, or error
18+
pub fn do_recycle_alpha(
1919
origin: OriginFor<T>,
2020
hotkey: T::AccountId,
2121
amount: AlphaBalance,
2222
netuid: NetUid,
23-
) -> DispatchResult {
23+
) -> Result<AlphaBalance, DispatchError> {
2424
let coldkey: T::AccountId = ensure_signed(origin)?;
2525

2626
ensure!(Self::if_subnet_exist(netuid), Error::<T>::SubnetNotExists);
@@ -58,7 +58,7 @@ impl<T: Config> Pallet<T> {
5858

5959
Self::deposit_event(Event::AlphaRecycled(coldkey, hotkey, amount, netuid));
6060

61-
Ok(())
61+
Ok(amount)
6262
}
6363

6464
/// Burns alpha from a cold/hot key pair without reducing AlphaOut
@@ -72,13 +72,13 @@ impl<T: Config> Pallet<T> {
7272
///
7373
/// # Returns
7474
///
75-
/// * `DispatchResult` - Success or error
76-
pub(crate) fn do_burn_alpha(
75+
/// * `Result<AlphaBalance, DispatchError>` - The actual amount burned, or error
76+
pub fn do_burn_alpha(
7777
origin: OriginFor<T>,
7878
hotkey: T::AccountId,
7979
amount: AlphaBalance,
8080
netuid: NetUid,
81-
) -> DispatchResult {
81+
) -> Result<AlphaBalance, DispatchError> {
8282
let coldkey = ensure_signed(origin)?;
8383

8484
ensure!(Self::if_subnet_exist(netuid), Error::<T>::SubnetNotExists);
@@ -116,7 +116,7 @@ impl<T: Config> Pallet<T> {
116116
// Deposit event
117117
Self::deposit_event(Event::AlphaBurned(coldkey, hotkey, amount, netuid));
118118

119-
Ok(())
119+
Ok(amount)
120120
}
121121
pub(crate) fn do_add_stake_burn(
122122
origin: OriginFor<T>,

0 commit comments

Comments
 (0)