Skip to content

Commit ff8431b

Browse files
authored
Merge pull request #1173 from opentensor/fix/owner-cut-pending
[RAO] put owner cut in a pending
2 parents 8cda336 + 01203b3 commit ff8431b

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ pub struct WeightsTlockPayload {
1818
}
1919

2020
impl<T: Config> Pallet<T> {
21-
pub fn get_root_divs_in_alpha(netuid: u16, alpha_out_emission: I96F32) -> I96F32 {
21+
pub fn get_root_divs_in_alpha(
22+
netuid: u16,
23+
alpha_out_emission: I96F32,
24+
validator_proportion: I96F32,
25+
) -> I96F32 {
2226
// Get total TAO on root.
2327
let total_root_tao: I96F32 = I96F32::from_num(SubnetTAO::<T>::get(0));
2428
// Get total ALPHA on subnet.
@@ -32,7 +36,8 @@ impl<T: Config> Pallet<T> {
3236
// Get root proportion of alpha_out dividends.
3337
let root_divs_in_alpha: I96F32 = root_proportion
3438
.saturating_mul(alpha_out_emission)
35-
.saturating_mul(I96F32::from_num(0.41));
39+
.saturating_mul(validator_proportion); // % of emission that goes to *all* validators.
40+
3641
// Return
3742
root_divs_in_alpha
3843
}
@@ -207,9 +212,14 @@ impl<T: Config> Pallet<T> {
207212
remaining_emission
208213
);
209214

215+
// Validators get 50% of remaining emission.
216+
let validator_proportion: I96F32 = I96F32::from_num(0.5);
210217
// Get proportion of alpha out emission as root divs.
211-
let root_emission_in_alpha: I96F32 =
212-
Self::get_root_divs_in_alpha(*netuid, I96F32::from_num(remaining_emission));
218+
let root_emission_in_alpha: I96F32 = Self::get_root_divs_in_alpha(
219+
*netuid,
220+
I96F32::from_num(remaining_emission),
221+
validator_proportion,
222+
);
213223
// Subtract root divs from alpha divs.
214224
let pending_alpha_emission: I96F32 =
215225
I96F32::from_num(remaining_emission).saturating_sub(root_emission_in_alpha);
@@ -221,10 +231,18 @@ impl<T: Config> Pallet<T> {
221231
PendingRootDivs::<T>::mutate(*netuid, |total| {
222232
*total = total.saturating_add(root_emission_in_tao);
223233
});
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+
});
224238
// Accumulate alpha emission in pending.
225239
PendingEmission::<T>::mutate(*netuid, |total| {
226240
*total = total.saturating_add(pending_alpha_emission.to_num::<u64>());
227241
});
242+
// Accumulate the owner cut in pending.
243+
PendingOwnerCut::<T>::mutate(*netuid, |total| {
244+
*total = total.saturating_add(owner_cut);
245+
});
228246
}
229247

230248
// --- 5. Drain pending emission through the subnet based on tempo.
@@ -247,18 +265,24 @@ impl<T: Config> Pallet<T> {
247265
let pending_emission: u64 = PendingEmission::<T>::get(netuid);
248266
PendingEmission::<T>::insert(netuid, 0);
249267

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

254-
// 5.2.3 Get owner cut.
255-
let owner_cut: u64 = *owner_cuts.get(&netuid).unwrap_or(&0);
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+
276+
// 5.2.3 Get owner cut and drain.
277+
let owner_cut: u64 = PendingOwnerCut::<T>::get(netuid);
278+
PendingOwnerCut::<T>::insert(netuid, 0);
256279

257280
// 5.2.4 Drain pending root divs, alpha emission, and owner cut.
258281
Self::drain_pending_emission(
259282
netuid,
260283
pending_emission,
261284
pending_root_divs,
285+
pending_alpha_swapped,
262286
owner_cut,
263287
);
264288
} else {
@@ -272,19 +296,24 @@ impl<T: Config> Pallet<T> {
272296
netuid: u16,
273297
pending_alpha_emission: u64,
274298
pending_root_divs: u64,
299+
pending_alpha_swapped: u64,
275300
owner_cut: u64,
276301
) {
277302
log::debug!(
278-
"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 {:?}",
279304
netuid,
280305
pending_alpha_emission,
281306
pending_root_divs,
307+
pending_alpha_swapped,
282308
owner_cut
283309
);
284310

285311
// Run the epoch() --> hotkey emission.
286-
let hotkey_emission: Vec<(T::AccountId, u64, u64)> =
287-
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+
);
288317
log::debug!(
289318
"Hotkey emission for netuid {:?}: {:?}",
290319
netuid,

pallets/subtensor/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,13 @@ pub mod pallet {
11021102
/// --- MAP ( netuid ) --> pending_root_emission
11031103
pub type PendingRootDivs<T> = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
11041104
#[pallet::storage]
1105+
/// --- MAP ( netuid ) --> pending_alpha_swapped
1106+
pub type PendingAlphaSwapped<T> =
1107+
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
1108+
#[pallet::storage]
1109+
/// --- MAP ( netuid ) --> pending_owner_cut
1110+
pub type PendingOwnerCut<T> = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
1111+
#[pallet::storage]
11051112
/// --- MAP ( netuid ) --> blocks_since_last_step
11061113
pub type BlocksSinceLastStep<T> =
11071114
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultBlocksSinceLastStep<T>>;

0 commit comments

Comments
 (0)