@@ -22,6 +22,10 @@ impl<T: Config> Pallet<T> {
22
22
let current_block: u64 = Self :: get_current_block_as_u64 ( ) ;
23
23
log:: trace!( "current_block:\n {:?}\n " , current_block) ;
24
24
25
+ // Get tempo.
26
+ let tempo: u64 = Self :: get_tempo ( netuid) . into ( ) ;
27
+ log:: trace!( "tempo:\n {:?}\n " , tempo) ;
28
+
25
29
// Get activity cutoff.
26
30
let activity_cutoff: u64 = Self :: get_activity_cutoff ( netuid) as u64 ;
27
31
log:: trace!( "activity_cutoff:\n {:?}\n " , activity_cutoff) ;
@@ -44,7 +48,7 @@ impl<T: Config> Pallet<T> {
44
48
let block_at_registration: Vec < u64 > = Self :: get_block_at_registration ( netuid) ;
45
49
log:: trace!( "Block at registration:\n {:?}\n " , & block_at_registration) ;
46
50
47
- // Outdated matrix, updated_ij =True if i has last updated (weights) after j has last registered.
51
+ // Outdated matrix, outdated_ij =True if i has last updated (weights) after j has last registered.
48
52
let outdated: Vec < Vec < bool > > = last_update
49
53
. iter ( )
50
54
. map ( |updated| {
@@ -56,6 +60,16 @@ impl<T: Config> Pallet<T> {
56
60
. collect ( ) ;
57
61
log:: trace!( "Outdated:\n {:?}\n " , & outdated) ;
58
62
63
+ // Recently registered matrix, recently_ij=True if last_tempo was *before* j was last registered.
64
+ // Mask if: the last tempo block happened *before* the registration block
65
+ // ==> last_tempo <= registered
66
+ let last_tempo: u64 = current_block. saturating_sub ( tempo) ;
67
+ let recently_registered: Vec < bool > = block_at_registration
68
+ . iter ( )
69
+ . map ( |registered| last_tempo <= * registered)
70
+ . collect ( ) ;
71
+ log:: trace!( "Recently registered:\n {:?}\n " , & recently_registered) ;
72
+
59
73
// ===========
60
74
// == Stake ==
61
75
// ===========
@@ -185,17 +199,16 @@ impl<T: Config> Pallet<T> {
185
199
186
200
// Access network bonds.
187
201
let mut bonds: Vec < Vec < I32F32 > > = Self :: get_bonds ( netuid) ;
188
- inplace_mask_matrix ( & outdated , & mut bonds ) ; // mask outdated bonds
189
- inplace_col_normalize ( & mut bonds) ; // sum_i b_ij = 1
190
- log :: trace! ( "B: \n {:?} \n " , & bonds) ;
202
+
203
+ // Remove bonds referring to neurons that have registered since last tempo.
204
+ inplace_mask_cols ( & recently_registered , & mut bonds) ; // mask recently registered bonds
191
205
192
206
// Compute bonds delta column normalized.
193
- let mut bonds_delta: Vec < Vec < I32F32 > > = row_hadamard ( & weights_for_bonds, & active_stake) ; // ΔB = W◦S
194
- inplace_col_normalize ( & mut bonds_delta) ; // sum_i b_ij = 1
207
+ let bonds_delta: Vec < Vec < I32F32 > > = row_hadamard ( & weights_for_bonds, & active_stake) ; // ΔB = W◦S
195
208
log:: trace!( "ΔB:\n {:?}\n " , & bonds_delta) ;
209
+
196
210
// Compute the Exponential Moving Average (EMA) of bonds.
197
- let mut ema_bonds = Self :: compute_ema_bonds ( netuid, consensus. clone ( ) , bonds_delta, bonds) ;
198
- inplace_col_normalize ( & mut ema_bonds) ; // sum_i b_ij = 1
211
+ let ema_bonds = Self :: compute_ema_bonds ( netuid, consensus. clone ( ) , bonds_delta, bonds) ;
199
212
log:: trace!( "emaB:\n {:?}\n " , & ema_bonds) ;
200
213
201
214
// Compute dividends: d_i = SUM(j) b_ij * inc_j
@@ -326,10 +339,6 @@ impl<T: Config> Pallet<T> {
326
339
ValidatorTrust :: < T > :: insert ( netuid, cloned_validator_trust) ;
327
340
ValidatorPermit :: < T > :: insert ( netuid, new_validator_permits. clone ( ) ) ;
328
341
329
- // Column max-upscale EMA bonds for storage: max_i w_ij = 1.
330
- inplace_col_max_upscale ( & mut ema_bonds) ;
331
- // Then normalize.
332
- inplace_col_normalize ( & mut ema_bonds) ;
333
342
new_validator_permits
334
343
. iter ( )
335
344
. zip ( validator_permits)
@@ -388,6 +397,10 @@ impl<T: Config> Pallet<T> {
388
397
let current_block: u64 = Self :: get_current_block_as_u64 ( ) ;
389
398
log:: trace!( "current_block: {:?}" , current_block) ;
390
399
400
+ // Get tempo.
401
+ let tempo: u64 = Self :: get_tempo ( netuid) . into ( ) ;
402
+ log:: trace!( "tempo: {:?}" , tempo) ;
403
+
391
404
// Get activity cutoff.
392
405
let activity_cutoff: u64 = Self :: get_activity_cutoff ( netuid) as u64 ;
393
406
log:: trace!( "activity_cutoff: {:?}" , activity_cutoff) ;
@@ -550,33 +563,26 @@ impl<T: Config> Pallet<T> {
550
563
let mut bonds: Vec < Vec < ( u16 , I32F32 ) > > = Self :: get_bonds_sparse ( netuid) ;
551
564
log:: trace!( "B: {:?}" , & bonds) ;
552
565
553
- // Remove bonds referring to deregistered neurons.
554
- bonds = vec_mask_sparse_matrix (
566
+ // Remove bonds referring to neurons that have registered since last tempo.
567
+ // Mask if: the last tempo block happened *before* the registration block
568
+ // ==> last_tempo <= registered
569
+ let last_tempo: u64 = current_block. saturating_sub ( tempo) ;
570
+ bonds = scalar_vec_mask_sparse_matrix (
555
571
& bonds,
556
- & last_update ,
572
+ last_tempo ,
557
573
& block_at_registration,
558
- & |updated , registered| updated <= registered,
574
+ & |last_tempo , registered| last_tempo <= registered,
559
575
) ;
560
576
log:: trace!( "B (outdatedmask): {:?}" , & bonds) ;
561
577
562
- // Normalize remaining bonds: sum_i b_ij = 1.
563
- inplace_col_normalize_sparse ( & mut bonds, n) ;
564
- log:: trace!( "B (mask+norm): {:?}" , & bonds) ;
565
-
566
578
// Compute bonds delta column normalized.
567
- let mut bonds_delta: Vec < Vec < ( u16 , I32F32 ) > > =
579
+ let bonds_delta: Vec < Vec < ( u16 , I32F32 ) > > =
568
580
row_hadamard_sparse ( & weights_for_bonds, & active_stake) ; // ΔB = W◦S (outdated W masked)
569
581
log:: trace!( "ΔB: {:?}" , & bonds_delta) ;
570
582
571
- // Normalize bonds delta.
572
- inplace_col_normalize_sparse ( & mut bonds_delta, n) ; // sum_i b_ij = 1
573
- log:: trace!( "ΔB (norm): {:?}" , & bonds_delta) ;
574
-
575
583
// Compute the Exponential Moving Average (EMA) of bonds.
576
- let mut ema_bonds =
584
+ let ema_bonds =
577
585
Self :: compute_ema_bonds_sparse ( netuid, consensus. clone ( ) , bonds_delta, bonds) ;
578
- // Normalize EMA bonds.
579
- inplace_col_normalize_sparse ( & mut ema_bonds, n) ; // sum_i b_ij = 1
580
586
log:: trace!( "Exponential Moving Average Bonds: {:?}" , & ema_bonds) ;
581
587
582
588
// Compute dividends: d_i = SUM(j) b_ij * inc_j.
@@ -714,10 +720,6 @@ impl<T: Config> Pallet<T> {
714
720
ValidatorTrust :: < T > :: insert ( netuid, cloned_validator_trust) ;
715
721
ValidatorPermit :: < T > :: insert ( netuid, new_validator_permits. clone ( ) ) ;
716
722
717
- // Column max-upscale EMA bonds for storage: max_i w_ij = 1.
718
- inplace_col_max_upscale_sparse ( & mut ema_bonds, n) ;
719
- // Then normalize.
720
- inplace_col_normalize_sparse ( & mut ema_bonds, n) ;
721
723
new_validator_permits
722
724
. iter ( )
723
725
. zip ( validator_permits)
0 commit comments