@@ -224,31 +224,35 @@ impl<T: Config> Pallet<T> {
224
224
// Restart counters.
225
225
BlocksSinceLastStep :: < T > :: insert ( netuid, 0 ) ;
226
226
LastMechansimStepBlock :: < T > :: insert ( netuid, current_block) ;
227
+
228
+ // 5.2 Get and drain the subnet pending emission.
229
+ let pending_emission: u64 = PendingEmission :: < T > :: get ( netuid) ;
230
+ PendingEmission :: < T > :: insert ( netuid, 0 ) ;
231
+
227
232
// Drain pending root divs and alpha emission.
228
- Self :: drain_pending_emission ( netuid) ;
233
+ Self :: drain_pending_emission ( netuid, pending_emission ) ;
229
234
} else {
230
235
// Increment
231
236
BlocksSinceLastStep :: < T > :: mutate ( netuid, |total| * total = total. saturating_add ( 1 ) ) ;
232
237
}
233
238
}
234
239
}
235
240
236
- pub fn drain_pending_emission ( netuid : u16 ) {
237
- // 7.2 Get and drain the subnet pending emission.
238
- let alpha_out : u64 = PendingEmission :: < T > :: get ( netuid ) ;
241
+ pub fn drain_pending_emission ( netuid : u16 , pending_emission : u64 ) {
242
+ let alpha_out : u64 = pending_emission ;
243
+
239
244
log:: debug!(
240
245
"Draining pending emission for netuid {:?}: {:?}" ,
241
246
netuid,
242
247
alpha_out
243
248
) ;
244
- PendingEmission :: < T > :: insert ( netuid, 0 ) ;
245
249
246
- // 7.4 Distribute the 18% owner cut.
250
+ // 6.1 Distribute the 18% owner cut.
247
251
let owner_cut: u64 = I96F32 :: from_num ( alpha_out)
248
252
. saturating_mul ( Self :: get_float_subnet_owner_cut ( ) )
249
253
. to_num :: < u64 > ( ) ;
250
254
log:: debug!( "Owner cut for netuid {:?}: {:?}" , netuid, owner_cut) ;
251
- // 7.4 .1: Check for existence of owner cold/hot pair and distribute emission directly to them.
255
+ // 6.1 .1: Check for existence of owner cold/hot pair and distribute emission directly to them.
252
256
if let Ok ( owner_coldkey) = SubnetOwner :: < T > :: try_get ( netuid) {
253
257
if let Ok ( owner_hotkey) = SubnetOwnerHotkey :: < T > :: try_get ( netuid) {
254
258
// Increase stake for both coldkey and hotkey on the subnet
@@ -268,7 +272,7 @@ impl<T: Config> Pallet<T> {
268
272
remaining_emission
269
273
) ;
270
274
271
- // 7.5 Run the epoch() --> hotkey emission.
275
+ // 6.2 Run the epoch() --> hotkey emission.
272
276
let hotkey_emission: Vec < ( T :: AccountId , u64 , u64 ) > =
273
277
Self :: epoch ( netuid, remaining_emission) ;
274
278
log:: debug!(
@@ -277,7 +281,7 @@ impl<T: Config> Pallet<T> {
277
281
hotkey_emission
278
282
) ;
279
283
280
- // 7.6 Pay out the hotkey alpha dividends.
284
+ // 6.3 Pay out the hotkey alpha dividends.
281
285
// First clear the netuid from HotkeyDividends
282
286
let mut total_root_alpha_divs: u64 = 0 ;
283
287
let mut root_alpha_divs: BTreeMap < T :: AccountId , u64 > = BTreeMap :: new ( ) ;
@@ -290,7 +294,7 @@ impl<T: Config> Pallet<T> {
290
294
dividends
291
295
) ;
292
296
293
- // 7.6 .1: Distribute mining incentive immediately.
297
+ // 6.3 .1: Distribute mining incentive immediately.
294
298
Self :: increase_stake_for_hotkey_and_coldkey_on_subnet (
295
299
& hotkey. clone ( ) ,
296
300
& Owner :: < T > :: get ( hotkey. clone ( ) ) ,
@@ -304,7 +308,7 @@ impl<T: Config> Pallet<T> {
304
308
incentive
305
309
) ;
306
310
307
- // 7.6 .2: Get dividend tuples for parents and self based on childkey relationships and child-take.
311
+ // 6.3 .2: Get dividend tuples for parents and self based on childkey relationships and child-take.
308
312
let dividend_tuples: Vec < ( T :: AccountId , u64 ) > =
309
313
Self :: get_parent_dividends ( & hotkey, netuid, dividends) ;
310
314
log:: debug!(
@@ -314,7 +318,7 @@ impl<T: Config> Pallet<T> {
314
318
dividend_tuples
315
319
) ;
316
320
317
- // 7.6 .3 Pay out dividends to hotkeys based on the local vs root proportion.
321
+ // 6.3 .3 Pay out dividends to hotkeys based on the local vs root proportion.
318
322
for ( hotkey_j, divs_j) in dividend_tuples {
319
323
log:: debug!(
320
324
"Processing dividend for hotkey {:?} to hotkey {:?}: {:?}" ,
@@ -323,7 +327,7 @@ impl<T: Config> Pallet<T> {
323
327
divs_j
324
328
) ;
325
329
326
- // 7.6 .3.1: Remove the hotkey take straight off the top.
330
+ // 6.3 .3.1: Remove the hotkey take straight off the top.
327
331
let take_prop: I96F32 = I96F32 :: from_num ( Self :: get_hotkey_take ( & hotkey_j) )
328
332
. checked_div ( I96F32 :: from_num ( u16:: MAX ) )
329
333
. unwrap_or ( I96F32 :: from_num ( 0.0 ) ) ;
@@ -336,7 +340,7 @@ impl<T: Config> Pallet<T> {
336
340
rem_divs_j
337
341
) ;
338
342
339
- // 7.6 .3.2: Distribute validator take automatically.
343
+ // 6.3 .3.2: Distribute validator take automatically.
340
344
Self :: increase_stake_for_hotkey_and_coldkey_on_subnet (
341
345
& hotkey_j,
342
346
& Owner :: < T > :: get ( hotkey_j. clone ( ) ) ,
@@ -350,7 +354,7 @@ impl<T: Config> Pallet<T> {
350
354
validator_take. to_num:: <u64 >( )
351
355
) ;
352
356
353
- // 7.6 .3.3: Get the local alpha and root alpha.
357
+ // 6.3 .3.3: Get the local alpha and root alpha.
354
358
let hotkey_tao: I96F32 = I96F32 :: from_num ( Self :: get_stake_for_hotkey_on_subnet (
355
359
& hotkey,
356
360
Self :: get_root_netuid ( ) ,
@@ -360,7 +364,7 @@ impl<T: Config> Pallet<T> {
360
364
I96F32 :: from_num ( Self :: get_stake_for_hotkey_on_subnet ( & hotkey, netuid) ) ;
361
365
log:: debug!( "Hotkey tao for hotkey {:?} on root netuid: {:?}, hotkey tao as alpha: {:?}, hotkey alpha: {:?}" , hotkey, hotkey_tao, hotkey_tao_as_alpha, hotkey_alpha) ;
362
366
363
- // 7. 6.3.3 Compute alpha and root proportions.
367
+ // 6.3.3.4 Compute alpha and root proportions.
364
368
let alpha_prop: I96F32 = hotkey_alpha
365
369
. checked_div ( hotkey_alpha. saturating_add ( hotkey_tao_as_alpha) )
366
370
. unwrap_or ( I96F32 :: from_num ( 0.0 ) ) ;
@@ -373,15 +377,15 @@ impl<T: Config> Pallet<T> {
373
377
root_prop
374
378
) ;
375
379
376
- // 7.6 .3.5: Compute alpha and root dividends
380
+ // 6.3 .3.5: Compute alpha and root dividends
377
381
let root_divs: I96F32 = rem_divs_j. saturating_mul ( root_prop) ;
378
382
log:: debug!(
379
383
"Alpha dividends: {:?}, root dividends: {:?}" ,
380
384
rem_divs_j,
381
385
root_divs
382
386
) ;
383
387
384
- // 7.6 .3.6. Store the root alpha divs under hotkey_j
388
+ // 6.3 .3.6. Store the root alpha divs under hotkey_j
385
389
root_alpha_divs
386
390
. entry ( hotkey_j. clone ( ) )
387
391
. and_modify ( |e| * e = e. saturating_add ( root_divs. to_num :: < u64 > ( ) ) )
@@ -394,7 +398,7 @@ impl<T: Config> Pallet<T> {
394
398
root_divs. to_num:: <u64 >( )
395
399
) ;
396
400
397
- // 7.6 .3.7: Distribute the alpha divs to the hotkey.
401
+ // 6.3 .3.7: Distribute the alpha divs to the hotkey.
398
402
Self :: increase_stake_for_hotkey_on_subnet (
399
403
& hotkey_j,
400
404
netuid,
@@ -407,7 +411,7 @@ impl<T: Config> Pallet<T> {
407
411
rem_divs_j. to_num:: <u64 >( )
408
412
) ;
409
413
410
- // 7. 6.3.9 : Record dividends for this hotkey on this subnet.
414
+ // 6.3.3.8 : Record dividends for this hotkey on this subnet.
411
415
HotkeyDividendsPerSubnet :: < T > :: mutate ( netuid, hotkey_j. clone ( ) , |divs| {
412
416
* divs = divs. saturating_add ( divs_j) ;
413
417
} ) ;
@@ -449,7 +453,7 @@ impl<T: Config> Pallet<T> {
449
453
root_divs_to_pay
450
454
) ;
451
455
452
- // 7.6 .3.9: Record dividends for this hotkey on this subnet.
456
+ // 6.3 .3.9: Record dividends for this hotkey on this subnet.
453
457
RootDividendsPerSubnet :: < T > :: mutate ( netuid, hotkey_j. clone ( ) , |divs| {
454
458
* divs = divs. saturating_add ( root_divs_to_pay) ;
455
459
} ) ;
0 commit comments