Skip to content

Commit 01203b3

Browse files
committed
add alpha swapped tracker
1 parent eef3ce6 commit 01203b3

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ impl<T: Config> Pallet<T> {
231231
PendingRootDivs::<T>::mutate(*netuid, |total| {
232232
*total = total.saturating_add(root_emission_in_tao);
233233
});
234+
// Accumulate alpha that was swapped for the pending root divs.
235+
PendingAlphaSwapped::<T>::mutate(*netuid, |total| {
236+
*total = total.saturating_add(root_emission_in_alpha.to_num::<u64>());
237+
});
234238
// Accumulate alpha emission in pending.
235239
PendingEmission::<T>::mutate(*netuid, |total| {
236240
*total = total.saturating_add(pending_alpha_emission.to_num::<u64>());
@@ -261,10 +265,14 @@ impl<T: Config> Pallet<T> {
261265
let pending_emission: u64 = PendingEmission::<T>::get(netuid);
262266
PendingEmission::<T>::insert(netuid, 0);
263267

264-
// 5.2.2 Get and drain the subnet pending root divs.
268+
// 5.2.2a Get and drain the subnet pending root divs.
265269
let pending_root_divs: u64 = PendingRootDivs::<T>::get(netuid);
266270
PendingRootDivs::<T>::insert(netuid, 0);
267271

272+
// 5.2.2b Get this amount as alpha that was swapped for pending root divs.
273+
let pending_alpha_swapped: u64 = PendingAlphaSwapped::<T>::get(netuid);
274+
PendingAlphaSwapped::<T>::insert(netuid, 0);
275+
268276
// 5.2.3 Get owner cut and drain.
269277
let owner_cut: u64 = PendingOwnerCut::<T>::get(netuid);
270278
PendingOwnerCut::<T>::insert(netuid, 0);
@@ -274,6 +282,7 @@ impl<T: Config> Pallet<T> {
274282
netuid,
275283
pending_emission,
276284
pending_root_divs,
285+
pending_alpha_swapped,
277286
owner_cut,
278287
);
279288
} else {
@@ -287,19 +296,24 @@ impl<T: Config> Pallet<T> {
287296
netuid: u16,
288297
pending_alpha_emission: u64,
289298
pending_root_divs: u64,
299+
pending_alpha_swapped: u64,
290300
owner_cut: u64,
291301
) {
292302
log::debug!(
293-
"Draining pending alpha emission for netuid {:?}: {:?}, with pending root divs {:?}, and owner cut {:?}",
303+
"Draining pending alpha emission for netuid {:?}: {:?}, with pending root divs {:?}, pending alpha swapped {:?}, and owner cut {:?}",
294304
netuid,
295305
pending_alpha_emission,
296306
pending_root_divs,
307+
pending_alpha_swapped,
297308
owner_cut
298309
);
299310

300311
// Run the epoch() --> hotkey emission.
301-
let hotkey_emission: Vec<(T::AccountId, u64, u64)> =
302-
Self::epoch(netuid, pending_alpha_emission);
312+
// Needs to run on the full emission to the subnet.
313+
let hotkey_emission: Vec<(T::AccountId, u64, u64)> = Self::epoch(
314+
netuid,
315+
pending_alpha_emission.saturating_add(pending_alpha_swapped),
316+
);
303317
log::debug!(
304318
"Hotkey emission for netuid {:?}: {:?}",
305319
netuid,

pallets/subtensor/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,10 @@ pub mod pallet {
10971097
/// --- MAP ( netuid ) --> pending_root_emission
10981098
pub type PendingRootDivs<T> = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
10991099
#[pallet::storage]
1100+
/// --- MAP ( netuid ) --> pending_alpha_swapped
1101+
pub type PendingAlphaSwapped<T> =
1102+
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
1103+
#[pallet::storage]
11001104
/// --- MAP ( netuid ) --> pending_owner_cut
11011105
pub type PendingOwnerCut<T> = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
11021106
#[pallet::storage]

0 commit comments

Comments
 (0)