Skip to content

Commit d6e7292

Browse files
authored
Merge pull request #2614 from opentensor/feat/alpha-fees-event
Add netuid to TransactionFeePaidWithAlpha event
2 parents b47d00e + 598cb10 commit d6e7292

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

pallets/subtensor/src/macros/events.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,8 @@ mod events {
542542
TransactionFeePaidWithAlpha {
543543
/// Account that paid the transaction fee.
544544
who: T::AccountId,
545+
/// Netuid
546+
netuid: NetUid,
545547
/// Exact fee deducted in Alpha units.
546548
alpha_fee: AlphaBalance,
547549
/// Resulting swapped TAO amount

pallets/transaction-fee/src/lib.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub trait AlphaFeeHandler<T: frame_system::Config> {
6767
coldkey: &AccountIdOf<T>,
6868
alpha_vec: &[(AccountIdOf<T>, NetUid)],
6969
tao_amount: TaoBalance,
70-
) -> (AlphaBalance, TaoBalance);
70+
) -> (AlphaBalance, TaoBalance, NetUid);
7171
fn get_all_netuids_for_coldkey_and_hotkey(
7272
coldkey: &AccountIdOf<T>,
7373
hotkey: &AccountIdOf<T>,
@@ -154,9 +154,9 @@ where
154154
coldkey: &AccountIdOf<T>,
155155
alpha_vec: &[(AccountIdOf<T>, NetUid)],
156156
tao_amount: TaoBalance,
157-
) -> (AlphaBalance, TaoBalance) {
157+
) -> (AlphaBalance, TaoBalance, NetUid) {
158158
if alpha_vec.len() != 1 {
159-
return (0.into(), 0.into());
159+
return (0.into(), 0.into(), NetUid::ROOT);
160160
}
161161

162162
if let Some((hotkey, netuid)) = alpha_vec.first() {
@@ -184,12 +184,12 @@ where
184184
);
185185

186186
if let Ok(tao_amount) = swap_result {
187-
(alpha_fee, tao_amount)
187+
(alpha_fee, tao_amount, *netuid)
188188
} else {
189-
(0.into(), 0.into())
189+
(0.into(), 0.into(), NetUid::ROOT)
190190
}
191191
} else {
192-
(0.into(), 0.into())
192+
(0.into(), 0.into(), NetUid::ROOT)
193193
}
194194
}
195195

@@ -215,7 +215,7 @@ pub enum WithdrawnFee<T: frame_system::Config, F: Balanced<AccountIdOf<T>>> {
215215
// Contains withdrawn TAO amount
216216
Tao(Credit<AccountIdOf<T>, F>),
217217
// Contains withdrawn Alpha amount and resulting swapped TAO
218-
Alpha((AlphaBalance, TaoBalance)),
218+
Alpha((AlphaBalance, TaoBalance, NetUid)),
219219
}
220220

221221
/// Custom OnChargeTransaction implementation based on standard FungibleAdapter from transaction_payment
@@ -336,9 +336,9 @@ where
336336
let alpha_vec = Self::fees_in_alpha::<T>(who, call);
337337
if !alpha_vec.is_empty() {
338338
let fee_u64: u64 = fee.saturated_into::<u64>();
339-
let (alpha_fee, tao_amount) =
339+
let (alpha_fee, tao_amount, netuid) =
340340
OU::withdraw_in_alpha(who, &alpha_vec, fee_u64.into());
341-
return Ok(Some(WithdrawnFee::Alpha((alpha_fee, tao_amount))));
341+
return Ok(Some(WithdrawnFee::Alpha((alpha_fee, tao_amount, netuid))));
342342
}
343343
Err(InvalidTransaction::Payment.into())
344344
}
@@ -405,7 +405,7 @@ where
405405
let (tip, fee) = adjusted_paid.split(tip);
406406
OU::on_unbalanceds(Some(fee).into_iter().chain(Some(tip)));
407407
}
408-
WithdrawnFee::Alpha((alpha_fee, tao_amount)) => {
408+
WithdrawnFee::Alpha((alpha_fee, tao_amount, netuid)) => {
409409
if let Some(author) = T::author() {
410410
// Pay block author
411411
let _ = F::deposit(&author, tao_amount.into(), Precision::BestEffort)
@@ -416,6 +416,7 @@ where
416416
frame_system::Pallet::<T>::deposit_event(
417417
pallet_subtensor::Event::<T>::TransactionFeePaidWithAlpha {
418418
who: who.clone(),
419+
netuid,
419420
alpha_fee,
420421
tao_amount,
421422
},

pallets/transaction-fee/src/tests/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn test_rejects_multi_subnet_alpha_fee_deduction() {
187187
&alpha_vec,
188188
1.into(),
189189
),
190-
(0.into(), 0.into())
190+
(0.into(), 0.into(), NetUid::ROOT)
191191
);
192192

193193
let alpha_after_0 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -300,9 +300,10 @@ fn test_remove_stake_fees_alpha() {
300300
&event_record.event,
301301
RuntimeEvent::SubtensorModule(SubtensorEvent::TransactionFeePaidWithAlpha {
302302
who,
303+
netuid,
303304
alpha_fee,
304305
tao_amount: _,
305-
}) if who == &sn.coldkey && *alpha_fee == actual_alpha_fee
306+
}) if who == &sn.coldkey && *alpha_fee == actual_alpha_fee && *netuid == sn.subnets[0].netuid
306307
)
307308
})
308309
.expect("expected TransactionFeePaidWithAlpha event");

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
272272
// `spec_version`, and `authoring_version` are the same between Wasm and native.
273273
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
274274
// the compatible custom types.
275-
spec_version: 400,
275+
spec_version: 401,
276276
impl_version: 1,
277277
apis: RUNTIME_API_VERSIONS,
278278
transaction_version: 1,

0 commit comments

Comments
 (0)