@@ -982,14 +982,36 @@ fn test_512_graph_random_weights() {
982
982
// });
983
983
// }
984
984
985
+ fn next_block_no_epoch ( netuid : u16 ) -> u64 {
986
+ // high tempo to skip automatic epochs in on_initialize
987
+ let high_tempo: u16 = u16:: MAX - 1 ;
988
+ let old_tempo: u16 = SubtensorModule :: get_tempo ( netuid) ;
989
+
990
+ SubtensorModule :: set_tempo ( netuid, high_tempo) ;
991
+ let new_block = next_block ( ) ;
992
+ SubtensorModule :: set_tempo ( netuid, old_tempo) ;
993
+
994
+ new_block
995
+ }
996
+
997
+ fn run_to_block_no_epoch ( netuid : u16 , n : u64 ) {
998
+ // high tempo to skip automatic epochs in on_initialize
999
+ let high_tempo: u16 = u16:: MAX - 1 ;
1000
+ let old_tempo: u16 = SubtensorModule :: get_tempo ( netuid) ;
1001
+
1002
+ SubtensorModule :: set_tempo ( netuid, high_tempo) ;
1003
+ run_to_block ( n) ;
1004
+ SubtensorModule :: set_tempo ( netuid, old_tempo) ;
1005
+ }
1006
+
985
1007
// Test bonds exponential moving average over a sequence of epochs.
986
1008
#[ test]
987
1009
fn test_bonds ( ) {
988
1010
new_test_ext ( 1 ) . execute_with ( || {
989
1011
let sparse: bool = true ;
990
1012
let n: u16 = 8 ;
991
1013
let netuid: u16 = 1 ;
992
- let tempo: u16 = u16 :: MAX - 1 ; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead
1014
+ let tempo: u16 = 1 ;
993
1015
let max_stake: u64 = 4 ;
994
1016
let stakes: Vec < u64 > = vec ! [ 1 , 2 , 3 , 4 , 0 , 0 , 0 , 0 ] ;
995
1017
let block_number = System :: block_number ( ) ;
@@ -1018,7 +1040,7 @@ fn test_bonds() {
1018
1040
SubtensorModule :: set_max_allowed_validators ( netuid, n) ;
1019
1041
assert_eq ! ( SubtensorModule :: get_max_allowed_validators( netuid) , n) ;
1020
1042
SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ; // run first epoch to set allowed validators
1021
- next_block ( ) ; // run to next block to ensure weights are set on nodes after their registration block
1043
+ next_block_no_epoch ( netuid ) ; // run to next block to ensure weights are set on nodes after their registration block
1022
1044
1023
1045
// === Set weights [val->srv1: 0.1, val->srv2: 0.2, val->srv3: 0.3, val->srv4: 0.4]
1024
1046
for uid in 0 ..( n/2 ) as u64 {
@@ -1068,7 +1090,8 @@ fn test_bonds() {
1068
1090
// === Set self-weight only on val1
1069
1091
let uid = 0 ;
1070
1092
assert_ok ! ( SubtensorModule :: set_weights( RuntimeOrigin :: signed( U256 :: from( uid) ) , netuid, vec![ uid] , vec![ u16 :: MAX ] , 0 ) ) ;
1071
- next_block ( ) ;
1093
+ next_block_no_epoch ( netuid) ;
1094
+
1072
1095
if sparse { SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ; }
1073
1096
else { SubtensorModule :: epoch_dense ( netuid, 1_000_000_000 ) ; }
1074
1097
/* n: 8
@@ -1115,7 +1138,8 @@ fn test_bonds() {
1115
1138
// === Set self-weight only on val2
1116
1139
let uid = 1 ;
1117
1140
assert_ok ! ( SubtensorModule :: set_weights( RuntimeOrigin :: signed( U256 :: from( uid) ) , netuid, vec![ uid] , vec![ u16 :: MAX ] , 0 ) ) ;
1118
- next_block ( ) ;
1141
+ next_block_no_epoch ( netuid) ;
1142
+
1119
1143
if sparse { SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ; }
1120
1144
else { SubtensorModule :: epoch_dense ( netuid, 1_000_000_000 ) ; }
1121
1145
/* current_block: 3
@@ -1151,7 +1175,8 @@ fn test_bonds() {
1151
1175
// === Set self-weight only on val3
1152
1176
let uid = 2 ;
1153
1177
assert_ok ! ( SubtensorModule :: set_weights( RuntimeOrigin :: signed( U256 :: from( uid) ) , netuid, vec![ uid] , vec![ u16 :: MAX ] , 0 ) ) ;
1154
- next_block ( ) ;
1178
+ next_block_no_epoch ( netuid) ;
1179
+
1155
1180
if sparse { SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ; }
1156
1181
else { SubtensorModule :: epoch_dense ( netuid, 1_000_000_000 ) ; }
1157
1182
/* current_block: 4
@@ -1186,7 +1211,8 @@ fn test_bonds() {
1186
1211
1187
1212
// === Set val3->srv4: 1
1188
1213
assert_ok ! ( SubtensorModule :: set_weights( RuntimeOrigin :: signed( U256 :: from( 2 ) ) , netuid, vec![ 7 ] , vec![ u16 :: MAX ] , 0 ) ) ;
1189
- next_block ( ) ;
1214
+ next_block_no_epoch ( netuid) ;
1215
+
1190
1216
if sparse { SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ; }
1191
1217
else { SubtensorModule :: epoch_dense ( netuid, 1_000_000_000 ) ; }
1192
1218
/* current_block: 5
@@ -1219,7 +1245,8 @@ fn test_bonds() {
1219
1245
assert_eq ! ( bonds[ 2 ] [ 7 ] , 49150 ) ;
1220
1246
assert_eq ! ( bonds[ 3 ] [ 7 ] , 65535 ) ;
1221
1247
1222
- next_block ( ) ;
1248
+ next_block_no_epoch ( netuid) ;
1249
+
1223
1250
if sparse { SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ; }
1224
1251
else { SubtensorModule :: epoch_dense ( netuid, 1_000_000_000 ) ; }
1225
1252
/* current_block: 6
@@ -1240,7 +1267,8 @@ fn test_bonds() {
1240
1267
assert_eq ! ( bonds[ 2 ] [ 7 ] , 49150 ) ;
1241
1268
assert_eq ! ( bonds[ 3 ] [ 7 ] , 65535 ) ;
1242
1269
1243
- next_block ( ) ;
1270
+ next_block_no_epoch ( netuid) ;
1271
+
1244
1272
if sparse { SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ; }
1245
1273
else { SubtensorModule :: epoch_dense ( netuid, 1_000_000_000 ) ; }
1246
1274
/* current_block: 7
@@ -1261,7 +1289,8 @@ fn test_bonds() {
1261
1289
assert_eq ! ( bonds[ 2 ] [ 7 ] , 49150 ) ;
1262
1290
assert_eq ! ( bonds[ 3 ] [ 7 ] , 65535 ) ;
1263
1291
1264
- next_block ( ) ;
1292
+ next_block_no_epoch ( netuid) ;
1293
+
1265
1294
if sparse { SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ; }
1266
1295
else { SubtensorModule :: epoch_dense ( netuid, 1_000_000_000 ) ; }
1267
1296
/* current_block: 8
@@ -1286,7 +1315,7 @@ fn test_bonds_with_liquid_alpha() {
1286
1315
let sparse: bool = true ;
1287
1316
let n: u16 = 8 ;
1288
1317
let netuid: u16 = 1 ;
1289
- let tempo: u16 = u16 :: MAX - 1 ; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead
1318
+ let tempo: u16 = 1 ;
1290
1319
let max_stake: u64 = 4 ;
1291
1320
let stakes: Vec < u64 > = vec ! [ 1 , 2 , 3 , 4 , 0 , 0 , 0 , 0 ] ;
1292
1321
let block_number = System :: block_number ( ) ;
@@ -1326,7 +1355,7 @@ fn test_bonds_with_liquid_alpha() {
1326
1355
1327
1356
// Initilize with first epoch
1328
1357
SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ;
1329
- next_block ( ) ;
1358
+ next_block_no_epoch ( netuid ) ;
1330
1359
1331
1360
// Set weights
1332
1361
for uid in 0 ..( n / 2 ) {
@@ -1417,7 +1446,7 @@ fn test_bonds_with_liquid_alpha() {
1417
1446
vec![ u16 :: MAX ] ,
1418
1447
0
1419
1448
) ) ;
1420
- next_block ( ) ;
1449
+ next_block_no_epoch ( netuid ) ;
1421
1450
if sparse {
1422
1451
SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ;
1423
1452
} else {
@@ -1439,7 +1468,7 @@ fn test_bonds_with_liquid_alpha() {
1439
1468
vec![ u16 :: MAX ] ,
1440
1469
0
1441
1470
) ) ;
1442
- next_block ( ) ;
1471
+ next_block_no_epoch ( netuid ) ;
1443
1472
if sparse {
1444
1473
SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ;
1445
1474
} else {
@@ -1543,7 +1572,7 @@ fn test_active_stake() {
1543
1572
let sparse: bool = true ;
1544
1573
let n: u16 = 4 ;
1545
1574
let netuid: u16 = 1 ;
1546
- let tempo: u16 = u16 :: MAX - 1 ; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead
1575
+ let tempo: u16 = 1 ;
1547
1576
let block_number: u64 = System :: block_number ( ) ;
1548
1577
let stake: u64 = 1 ;
1549
1578
add_network ( netuid, tempo, 0 ) ;
@@ -1586,7 +1615,7 @@ fn test_active_stake() {
1586
1615
SubtensorModule :: set_max_allowed_validators ( netuid, n) ;
1587
1616
assert_eq ! ( SubtensorModule :: get_max_allowed_validators( netuid) , n) ;
1588
1617
SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ; // run first epoch to set allowed validators
1589
- next_block ( ) ; // run to next block to ensure weights are set on nodes after their registration block
1618
+ next_block_no_epoch ( netuid ) ; // run to next block to ensure weights are set on nodes after their registration block
1590
1619
1591
1620
// === Set weights [val1->srv1: 0.5, val1->srv2: 0.5, val2->srv1: 0.5, val2->srv2: 0.5]
1592
1621
for uid in 0 ..( n / 2 ) as u64 {
@@ -1627,7 +1656,7 @@ fn test_active_stake() {
1627
1656
}
1628
1657
}
1629
1658
let activity_cutoff: u64 = SubtensorModule :: get_activity_cutoff ( netuid) as u64 ;
1630
- run_to_block ( activity_cutoff + 2 ) ; // run to block where validator (uid 0, 1) weights become outdated
1659
+ run_to_block_no_epoch ( netuid , activity_cutoff + 2 ) ; // run to block where validator (uid 0, 1) weights become outdated
1631
1660
1632
1661
// === Update uid 0 weights
1633
1662
assert_ok ! ( SubtensorModule :: set_weights(
@@ -1697,7 +1726,7 @@ fn test_active_stake() {
1697
1726
vec![ u16 :: MAX / ( n / 2 ) ; ( n / 2 ) as usize ] ,
1698
1727
0
1699
1728
) ) ;
1700
- run_to_block ( activity_cutoff + 3 ) ; // run to block where validator (uid 0, 1) weights become outdated
1729
+ run_to_block_no_epoch ( netuid , activity_cutoff + 3 ) ; // run to block where validator (uid 0, 1) weights become outdated
1701
1730
if sparse {
1702
1731
SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ;
1703
1732
} else {
@@ -1750,7 +1779,7 @@ fn test_outdated_weights() {
1750
1779
let sparse: bool = true ;
1751
1780
let n: u16 = 4 ;
1752
1781
let netuid: u16 = 1 ;
1753
- let tempo: u16 = u16 :: MAX - 1 ; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead
1782
+ let tempo: u16 = 0 ;
1754
1783
let mut block_number: u64 = System :: block_number ( ) ;
1755
1784
let stake: u64 = 1 ;
1756
1785
add_network ( netuid, tempo, 0 ) ;
@@ -1796,7 +1825,7 @@ fn test_outdated_weights() {
1796
1825
assert_eq ! ( SubtensorModule :: get_max_allowed_validators( netuid) , n) ;
1797
1826
SubtensorModule :: epoch ( netuid, 1_000_000_000 ) ; // run first epoch to set allowed validators
1798
1827
assert_eq ! ( SubtensorModule :: get_registrations_this_block( netuid) , 4 ) ;
1799
- block_number = next_block ( ) ; // run to next block to ensure weights are set on nodes after their registration block
1828
+ block_number = next_block_no_epoch ( netuid ) ; // run to next block to ensure weights are set on nodes after their registration block
1800
1829
assert_eq ! ( SubtensorModule :: get_registrations_this_block( netuid) , 0 ) ;
1801
1830
1802
1831
// === Set weights [val1->srv1: 2/3, val1->srv2: 1/3, val2->srv1: 2/3, val2->srv2: 1/3, srv1->srv1: 1, srv2->srv2: 1]
@@ -1877,7 +1906,7 @@ fn test_outdated_weights() {
1877
1906
SubtensorModule :: get_hotkey_for_net_and_uid( netuid, deregistered_uid)
1878
1907
. expect( "Not registered" )
1879
1908
) ;
1880
- next_block ( ) ; // run to next block to outdate weights and bonds set on deregistered uid
1909
+ next_block_no_epoch ( netuid ) ; // run to next block to outdate weights and bonds set on deregistered uid
1881
1910
1882
1911
// === Update weights from only uid=0
1883
1912
assert_ok ! ( SubtensorModule :: set_weights(
@@ -2290,7 +2319,7 @@ fn test_deregistered_miner_bonds() {
2290
2319
// We expect the old bonds for server2, (uid3), to be reset.
2291
2320
// For server1, (uid2), the bond should be higher than before.
2292
2321
assert ! (
2293
- bond_0_2_new > bond_0_2,
2322
+ bond_0_2_new >= bond_0_2,
2294
2323
"bond_0_2_new: {}, bond_0_2: {}" ,
2295
2324
bond_0_2_new,
2296
2325
bond_0_2
0 commit comments