-
Notifications
You must be signed in to change notification settings - Fork 157
/
utils.rs
1109 lines (1037 loc) · 36.7 KB
/
utils.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use super::*;
use crate::system::{ensure_root, ensure_signed_or_root};
use frame_support::inherent::Vec;
use frame_support::pallet_prelude::DispatchResult;
use sp_core::U256;
impl<T: Config> Pallet<T> {
pub fn ensure_subnet_owner_or_root(o: T::RuntimeOrigin, netuid: u16) -> Result<(), DispatchError> {
let coldkey = ensure_signed_or_root(o);
match coldkey {
Ok(Some(who)) if SubnetOwner::<T>::get(netuid) == who => Ok(()),
Ok(Some(_)) => Err(DispatchError::BadOrigin.into()),
Ok(None) => Ok(()),
Err(x) => Err(x.into())
}
}
// ========================
// ==== Global Setters ====
// ========================
pub fn set_tempo(netuid: u16, tempo: u16) {
Tempo::<T>::insert(netuid, tempo);
}
pub fn set_last_adjustment_block(netuid: u16, last_adjustment_block: u64) {
LastAdjustmentBlock::<T>::insert(netuid, last_adjustment_block);
}
pub fn set_blocks_since_last_step(netuid: u16, blocks_since_last_step: u64) {
BlocksSinceLastStep::<T>::insert(netuid, blocks_since_last_step);
}
pub fn set_registrations_this_block(netuid: u16, registrations_this_block: u16) {
RegistrationsThisBlock::<T>::insert(netuid, registrations_this_block);
}
pub fn set_last_mechanism_step_block(netuid: u16, last_mechanism_step_block: u64) {
LastMechansimStepBlock::<T>::insert(netuid, last_mechanism_step_block);
}
pub fn set_registrations_this_interval(netuid: u16, registrations_this_interval: u16) {
RegistrationsThisInterval::<T>::insert(netuid, registrations_this_interval);
}
pub fn set_pow_registrations_this_interval(netuid: u16, pow_registrations_this_interval: u16) {
POWRegistrationsThisInterval::<T>::insert(netuid, pow_registrations_this_interval);
}
pub fn set_burn_registrations_this_interval(
netuid: u16,
burn_registrations_this_interval: u16,
) {
BurnRegistrationsThisInterval::<T>::insert(netuid, burn_registrations_this_interval);
}
// ========================
// ==== Global Getters ====
// ========================
pub fn get_total_issuance() -> u64 {
TotalIssuance::<T>::get()
}
pub fn get_block_emission() -> u64 {
BlockEmission::<T>::get()
}
pub fn get_current_block_as_u64() -> u64 {
TryInto::try_into(<frame_system::Pallet<T>>::block_number())
.ok()
.expect("blockchain will not exceed 2^64 blocks; QED.")
}
// ==============================
// ==== YumaConsensus params ====
// ==============================
pub fn get_rank(netuid: u16) -> Vec<u16> {
Rank::<T>::get(netuid)
}
pub fn get_trust(netuid: u16) -> Vec<u16> {
Trust::<T>::get(netuid)
}
pub fn get_active(netuid: u16) -> Vec<bool> {
Active::<T>::get(netuid)
}
pub fn get_emission(netuid: u16) -> Vec<u64> {
Emission::<T>::get(netuid)
}
pub fn get_consensus(netuid: u16) -> Vec<u16> {
Consensus::<T>::get(netuid)
}
pub fn get_incentive(netuid: u16) -> Vec<u16> {
Incentive::<T>::get(netuid)
}
pub fn get_dividends(netuid: u16) -> Vec<u16> {
Dividends::<T>::get(netuid)
}
pub fn get_last_update(netuid: u16) -> Vec<u64> {
LastUpdate::<T>::get(netuid)
}
pub fn get_pruning_score(netuid: u16) -> Vec<u16> {
PruningScores::<T>::get(netuid)
}
pub fn get_validator_trust(netuid: u16) -> Vec<u16> {
ValidatorTrust::<T>::get(netuid)
}
pub fn get_validator_permit(netuid: u16) -> Vec<bool> {
ValidatorPermit::<T>::get(netuid)
}
// ==================================
// ==== YumaConsensus UID params ====
// ==================================
pub fn set_last_update_for_uid(netuid: u16, uid: u16, last_update: u64) {
let mut updated_last_update_vec = Self::get_last_update(netuid);
if (uid as usize) < updated_last_update_vec.len() {
updated_last_update_vec[uid as usize] = last_update;
LastUpdate::<T>::insert(netuid, updated_last_update_vec);
}
}
pub fn set_active_for_uid(netuid: u16, uid: u16, active: bool) {
let mut updated_active_vec = Self::get_active(netuid);
if (uid as usize) < updated_active_vec.len() {
updated_active_vec[uid as usize] = active;
Active::<T>::insert(netuid, updated_active_vec);
}
}
pub fn set_pruning_score_for_uid(netuid: u16, uid: u16, pruning_score: u16) {
log::info!("netuid = {:?}", netuid);
log::info!(
"SubnetworkN::<T>::get( netuid ) = {:?}",
SubnetworkN::<T>::get(netuid)
);
log::info!("uid = {:?}", uid);
assert!(uid < SubnetworkN::<T>::get(netuid));
PruningScores::<T>::mutate(netuid, |v| v[uid as usize] = pruning_score);
}
pub fn set_validator_permit_for_uid(netuid: u16, uid: u16, validator_permit: bool) {
let mut updated_validator_permit = Self::get_validator_permit(netuid);
if (uid as usize) < updated_validator_permit.len() {
updated_validator_permit[uid as usize] = validator_permit;
ValidatorPermit::<T>::insert(netuid, updated_validator_permit);
}
}
pub fn get_rank_for_uid(netuid: u16, uid: u16) -> u16 {
let vec = Rank::<T>::get(netuid);
if (uid as usize) < vec.len() {
return vec[uid as usize];
} else {
return 0;
}
}
pub fn get_trust_for_uid(netuid: u16, uid: u16) -> u16 {
let vec = Trust::<T>::get(netuid);
if (uid as usize) < vec.len() {
return vec[uid as usize];
} else {
return 0;
}
}
pub fn get_emission_for_uid(netuid: u16, uid: u16) -> u64 {
let vec = Emission::<T>::get(netuid);
if (uid as usize) < vec.len() {
return vec[uid as usize];
} else {
return 0;
}
}
pub fn get_active_for_uid(netuid: u16, uid: u16) -> bool {
let vec = Active::<T>::get(netuid);
if (uid as usize) < vec.len() {
return vec[uid as usize];
} else {
return false;
}
}
pub fn get_consensus_for_uid(netuid: u16, uid: u16) -> u16 {
let vec = Consensus::<T>::get(netuid);
if (uid as usize) < vec.len() {
return vec[uid as usize];
} else {
return 0;
}
}
pub fn get_incentive_for_uid(netuid: u16, uid: u16) -> u16 {
let vec = Incentive::<T>::get(netuid);
if (uid as usize) < vec.len() {
return vec[uid as usize];
} else {
return 0;
}
}
pub fn get_dividends_for_uid(netuid: u16, uid: u16) -> u16 {
let vec = Dividends::<T>::get(netuid);
if (uid as usize) < vec.len() {
return vec[uid as usize];
} else {
return 0;
}
}
pub fn get_last_update_for_uid(netuid: u16, uid: u16) -> u64 {
let vec = LastUpdate::<T>::get(netuid);
if (uid as usize) < vec.len() {
return vec[uid as usize];
} else {
return 0;
}
}
pub fn get_pruning_score_for_uid(netuid: u16, uid: u16) -> u16 {
let vec = PruningScores::<T>::get(netuid);
if (uid as usize) < vec.len() {
return vec[uid as usize];
} else {
return u16::MAX;
}
}
pub fn get_validator_trust_for_uid(netuid: u16, uid: u16) -> u16 {
let vec = ValidatorTrust::<T>::get(netuid);
if (uid as usize) < vec.len() {
return vec[uid as usize];
} else {
return 0;
}
}
pub fn get_validator_permit_for_uid(netuid: u16, uid: u16) -> bool {
let vec = ValidatorPermit::<T>::get(netuid);
if (uid as usize) < vec.len() {
return vec[uid as usize];
} else {
return false;
}
}
// ============================
// ==== Subnetwork Getters ====
// ============================
pub fn get_tempo(netuid: u16) -> u16 {
Tempo::<T>::get(netuid)
}
pub fn get_emission_value(netuid: u16) -> u64 {
EmissionValues::<T>::get(netuid)
}
pub fn get_pending_emission(netuid: u16) -> u64 {
PendingEmission::<T>::get(netuid)
}
pub fn get_last_adjustment_block(netuid: u16) -> u64 {
LastAdjustmentBlock::<T>::get(netuid)
}
pub fn get_blocks_since_last_step(netuid: u16) -> u64 {
BlocksSinceLastStep::<T>::get(netuid)
}
pub fn get_difficulty(netuid: u16) -> U256 {
U256::from(Self::get_difficulty_as_u64(netuid))
}
pub fn get_registrations_this_block(netuid: u16) -> u16 {
RegistrationsThisBlock::<T>::get(netuid)
}
pub fn get_last_mechanism_step_block(netuid: u16) -> u64 {
LastMechansimStepBlock::<T>::get(netuid)
}
pub fn get_registrations_this_interval(netuid: u16) -> u16 {
RegistrationsThisInterval::<T>::get(netuid)
}
pub fn get_pow_registrations_this_interval(netuid: u16) -> u16 {
POWRegistrationsThisInterval::<T>::get(netuid)
}
pub fn get_burn_registrations_this_interval(netuid: u16) -> u16 {
BurnRegistrationsThisInterval::<T>::get(netuid)
}
pub fn get_neuron_block_at_registration(netuid: u16, neuron_uid: u16) -> u64 {
BlockAtRegistration::<T>::get(netuid, neuron_uid)
}
// ========================
// ==== Rate Limiting =====
// ========================
pub fn set_last_tx_block(key: &T::AccountId, block: u64) {
LastTxBlock::<T>::insert(key, block)
}
pub fn get_last_tx_block(key: &T::AccountId) -> u64 {
LastTxBlock::<T>::get(key)
}
pub fn exceeds_tx_rate_limit(prev_tx_block: u64, current_block: u64) -> bool {
let rate_limit: u64 = Self::get_tx_rate_limit();
if rate_limit == 0 || prev_tx_block == 0 {
return false;
}
return current_block - prev_tx_block <= rate_limit;
}
// ========================
// === Token Management ===
// ========================
pub fn burn_tokens(amount: u64) {
TotalIssuance::<T>::put(TotalIssuance::<T>::get().saturating_sub(amount));
}
pub fn get_default_take() -> u16 {
DefaultTake::<T>::get()
}
pub fn set_default_take(default_take: u16) {
DefaultTake::<T>::put(default_take)
}
pub fn do_sudo_set_default_take(origin: T::RuntimeOrigin, default_take: u16) -> DispatchResult {
ensure_root(origin)?;
Self::set_default_take(default_take);
log::info!("DefaultTakeSet( default_take: {:?} ) ", default_take);
Self::deposit_event(Event::DefaultTakeSet(default_take));
Ok(())
}
pub fn set_subnet_locked_balance(netuid: u16, amount: u64) {
SubnetLocked::<T>::insert(netuid, amount);
}
pub fn get_subnet_locked_balance(netuid: u16) -> u64 {
SubnetLocked::<T>::get(netuid)
}
// ========================
// ========= Sudo =========
// ========================
// Configure tx rate limiting
pub fn get_tx_rate_limit() -> u64 {
TxRateLimit::<T>::get()
}
pub fn set_tx_rate_limit(tx_rate_limit: u64) {
TxRateLimit::<T>::put(tx_rate_limit)
}
pub fn do_sudo_set_tx_rate_limit(
origin: T::RuntimeOrigin,
tx_rate_limit: u64,
) -> DispatchResult {
ensure_root(origin)?;
Self::set_tx_rate_limit(tx_rate_limit);
log::info!("TxRateLimitSet( tx_rate_limit: {:?} ) ", tx_rate_limit);
Self::deposit_event(Event::TxRateLimitSet(tx_rate_limit));
Ok(())
}
pub fn get_serving_rate_limit(netuid: u16) -> u64 {
ServingRateLimit::<T>::get(netuid)
}
pub fn set_serving_rate_limit(netuid: u16, serving_rate_limit: u64) {
ServingRateLimit::<T>::insert(netuid, serving_rate_limit)
}
pub fn do_sudo_set_serving_rate_limit(
origin: T::RuntimeOrigin,
netuid: u16,
serving_rate_limit: u64,
) -> DispatchResult {
Self::ensure_subnet_owner_or_root(origin, netuid)?;
Self::set_serving_rate_limit(netuid, serving_rate_limit);
log::info!(
"ServingRateLimitSet( serving_rate_limit: {:?} ) ",
serving_rate_limit
);
Self::deposit_event(Event::ServingRateLimitSet(netuid, serving_rate_limit));
Ok(())
}
pub fn get_min_difficulty(netuid: u16) -> u64 {
MinDifficulty::<T>::get(netuid)
}
pub fn set_min_difficulty(netuid: u16, min_difficulty: u64) {
MinDifficulty::<T>::insert(netuid, min_difficulty);
}
pub fn do_sudo_set_min_difficulty(
origin: T::RuntimeOrigin,
netuid: u16,
min_difficulty: u64,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_min_difficulty(netuid, min_difficulty);
log::info!(
"MinDifficultySet( netuid: {:?} min_difficulty: {:?} ) ",
netuid,
min_difficulty
);
Self::deposit_event(Event::MinDifficultySet(netuid, min_difficulty));
Ok(())
}
pub fn get_max_difficulty(netuid: u16) -> u64 {
MaxDifficulty::<T>::get(netuid)
}
pub fn set_max_difficulty(netuid: u16, max_difficulty: u64) {
MaxDifficulty::<T>::insert(netuid, max_difficulty);
}
pub fn do_sudo_set_max_difficulty(
origin: T::RuntimeOrigin,
netuid: u16,
max_difficulty: u64,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_max_difficulty(netuid, max_difficulty);
log::info!(
"MaxDifficultySet( netuid: {:?} max_difficulty: {:?} ) ",
netuid,
max_difficulty
);
Self::deposit_event(Event::MaxDifficultySet(netuid, max_difficulty));
Ok(())
}
pub fn get_weights_version_key(netuid: u16) -> u64 {
WeightsVersionKey::<T>::get(netuid)
}
pub fn set_weights_version_key(netuid: u16, weights_version_key: u64) {
WeightsVersionKey::<T>::insert(netuid, weights_version_key);
}
pub fn do_sudo_set_weights_version_key(
origin: T::RuntimeOrigin,
netuid: u16,
weights_version_key: u64,
) -> DispatchResult {
Self::ensure_subnet_owner_or_root(origin, netuid)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_weights_version_key(netuid, weights_version_key);
log::info!(
"WeightsVersionKeySet( netuid: {:?} weights_version_key: {:?} ) ",
netuid,
weights_version_key
);
Self::deposit_event(Event::WeightsVersionKeySet(netuid, weights_version_key));
Ok(())
}
pub fn get_weights_set_rate_limit(netuid: u16) -> u64 {
WeightsSetRateLimit::<T>::get(netuid)
}
pub fn set_weights_set_rate_limit(netuid: u16, weights_set_rate_limit: u64) {
WeightsSetRateLimit::<T>::insert(netuid, weights_set_rate_limit);
}
pub fn do_sudo_set_weights_set_rate_limit(
origin: T::RuntimeOrigin,
netuid: u16,
weights_set_rate_limit: u64,
) -> DispatchResult {
Self::ensure_subnet_owner_or_root(origin, netuid)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_weights_set_rate_limit(netuid, weights_set_rate_limit);
log::info!(
"WeightsSetRateLimitSet( netuid: {:?} weights_set_rate_limit: {:?} ) ",
netuid,
weights_set_rate_limit
);
Self::deposit_event(Event::WeightsSetRateLimitSet(
netuid,
weights_set_rate_limit,
));
Ok(())
}
pub fn get_adjustment_interval(netuid: u16) -> u16 {
AdjustmentInterval::<T>::get(netuid)
}
pub fn set_adjustment_interval(netuid: u16, adjustment_interval: u16) {
AdjustmentInterval::<T>::insert(netuid, adjustment_interval);
}
pub fn do_sudo_set_adjustment_interval(
origin: T::RuntimeOrigin,
netuid: u16,
adjustment_interval: u16,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_adjustment_interval(netuid, adjustment_interval);
log::info!(
"AdjustmentIntervalSet( netuid: {:?} adjustment_interval: {:?} ) ",
netuid,
adjustment_interval
);
Self::deposit_event(Event::AdjustmentIntervalSet(netuid, adjustment_interval));
Ok(())
}
pub fn get_adjustment_alpha(netuid: u16) -> u64 {
AdjustmentAlpha::<T>::get(netuid)
}
pub fn set_adjustment_alpha(netuid: u16, adjustment_alpha: u64) {
AdjustmentAlpha::<T>::insert(netuid, adjustment_alpha)
}
pub fn do_sudo_set_adjustment_alpha(
origin: T::RuntimeOrigin,
netuid: u16,
adjustment_alpha: u64,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_adjustment_alpha(netuid, adjustment_alpha);
log::info!(
"AdjustmentAlphaSet( adjustment_alpha: {:?} ) ",
adjustment_alpha
);
Self::deposit_event(Event::AdjustmentAlphaSet(netuid, adjustment_alpha));
Ok(())
}
pub fn get_validator_prune_len(netuid: u16) -> u64 {
ValidatorPruneLen::<T>::get(netuid)
}
pub fn set_validator_prune_len(netuid: u16, validator_prune_len: u64) {
ValidatorPruneLen::<T>::insert(netuid, validator_prune_len);
}
pub fn do_sudo_set_validator_prune_len(
origin: T::RuntimeOrigin,
netuid: u16,
validator_prune_len: u64,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_validator_prune_len(netuid, validator_prune_len);
log::info!(
"ValidatorPruneLenSet( netuid: {:?} validator_prune_len: {:?} ) ",
netuid,
validator_prune_len
);
Self::deposit_event(Event::ValidatorPruneLenSet(netuid, validator_prune_len));
Ok(())
}
pub fn get_scaling_law_power(netuid: u16) -> u16 {
ScalingLawPower::<T>::get(netuid)
}
pub fn set_scaling_law_power(netuid: u16, scaling_law_power: u16) {
ScalingLawPower::<T>::insert(netuid, scaling_law_power);
}
pub fn do_sudo_set_scaling_law_power(
origin: T::RuntimeOrigin,
netuid: u16,
scaling_law_power: u16,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
ensure!(scaling_law_power <= 100, Error::<T>::StorageValueOutOfRange); // The scaling law power must be between 0 and 100 => 0% and 100%
Self::set_scaling_law_power(netuid, scaling_law_power);
log::info!(
"ScalingLawPowerSet( netuid: {:?} scaling_law_power: {:?} ) ",
netuid,
scaling_law_power
);
Self::deposit_event(Event::ScalingLawPowerSet(netuid, scaling_law_power));
Ok(())
}
pub fn get_max_weight_limit(netuid: u16) -> u16 {
MaxWeightsLimit::<T>::get(netuid)
}
pub fn set_max_weight_limit(netuid: u16, max_weight_limit: u16) {
MaxWeightsLimit::<T>::insert(netuid, max_weight_limit);
}
pub fn do_sudo_set_max_weight_limit(
origin: T::RuntimeOrigin,
netuid: u16,
max_weight_limit: u16,
) -> DispatchResult {
Self::ensure_subnet_owner_or_root(origin, netuid)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_max_weight_limit(netuid, max_weight_limit);
log::info!(
"MaxWeightLimitSet( netuid: {:?} max_weight_limit: {:?} ) ",
netuid,
max_weight_limit
);
Self::deposit_event(Event::MaxWeightLimitSet(netuid, max_weight_limit));
Ok(())
}
pub fn get_immunity_period(netuid: u16) -> u16 {
ImmunityPeriod::<T>::get(netuid)
}
pub fn set_immunity_period(netuid: u16, immunity_period: u16) {
ImmunityPeriod::<T>::insert(netuid, immunity_period);
}
pub fn do_sudo_set_immunity_period(
origin: T::RuntimeOrigin,
netuid: u16,
immunity_period: u16,
) -> DispatchResult {
Self::ensure_subnet_owner_or_root(origin, netuid)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_immunity_period(netuid, immunity_period);
log::info!(
"ImmunityPeriodSet( netuid: {:?} immunity_period: {:?} ) ",
netuid,
immunity_period
);
Self::deposit_event(Event::ImmunityPeriodSet(netuid, immunity_period));
Ok(())
}
pub fn get_min_allowed_weights(netuid: u16) -> u16 {
MinAllowedWeights::<T>::get(netuid)
}
pub fn set_min_allowed_weights(netuid: u16, min_allowed_weights: u16) {
MinAllowedWeights::<T>::insert(netuid, min_allowed_weights);
}
pub fn do_sudo_set_min_allowed_weights(
origin: T::RuntimeOrigin,
netuid: u16,
min_allowed_weights: u16,
) -> DispatchResult {
Self::ensure_subnet_owner_or_root(origin, netuid)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_min_allowed_weights(netuid, min_allowed_weights);
log::info!(
"MinAllowedWeightSet( netuid: {:?} min_allowed_weights: {:?} ) ",
netuid,
min_allowed_weights
);
Self::deposit_event(Event::MinAllowedWeightSet(netuid, min_allowed_weights));
Ok(())
}
pub fn get_max_allowed_uids(netuid: u16) -> u16 {
MaxAllowedUids::<T>::get(netuid)
}
pub fn set_max_allowed_uids(netuid: u16, max_allowed: u16) {
MaxAllowedUids::<T>::insert(netuid, max_allowed);
}
pub fn do_sudo_set_max_allowed_uids(
origin: T::RuntimeOrigin,
netuid: u16,
max_allowed_uids: u16,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
ensure!(
Self::get_subnetwork_n(netuid) < max_allowed_uids,
Error::<T>::MaxAllowedUIdsNotAllowed
);
Self::set_max_allowed_uids(netuid, max_allowed_uids);
log::info!(
"MaxAllowedUidsSet( netuid: {:?} max_allowed_uids: {:?} ) ",
netuid,
max_allowed_uids
);
Self::deposit_event(Event::MaxAllowedUidsSet(netuid, max_allowed_uids));
Ok(())
}
pub fn get_kappa(netuid: u16) -> u16 {
Kappa::<T>::get(netuid)
}
pub fn set_kappa(netuid: u16, kappa: u16) {
Kappa::<T>::insert(netuid, kappa);
}
pub fn do_sudo_set_kappa(origin: T::RuntimeOrigin, netuid: u16, kappa: u16) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_kappa(netuid, kappa);
log::info!("KappaSet( netuid: {:?} kappa: {:?} ) ", netuid, kappa);
Self::deposit_event(Event::KappaSet(netuid, kappa));
Ok(())
}
pub fn get_rho(netuid: u16) -> u16 {
Rho::<T>::get(netuid)
}
pub fn set_rho(netuid: u16, rho: u16) {
Rho::<T>::insert(netuid, rho);
}
pub fn do_sudo_set_rho(origin: T::RuntimeOrigin, netuid: u16, rho: u16) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_rho(netuid, rho);
log::info!("RhoSet( netuid: {:?} rho: {:?} ) ", netuid, rho);
Self::deposit_event(Event::RhoSet(netuid, rho));
Ok(())
}
pub fn get_activity_cutoff(netuid: u16) -> u16 {
ActivityCutoff::<T>::get(netuid)
}
pub fn set_activity_cutoff(netuid: u16, activity_cutoff: u16) {
ActivityCutoff::<T>::insert(netuid, activity_cutoff);
}
pub fn do_sudo_set_activity_cutoff(
origin: T::RuntimeOrigin,
netuid: u16,
activity_cutoff: u16,
) -> DispatchResult {
Self::ensure_subnet_owner_or_root(origin, netuid)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_activity_cutoff(netuid, activity_cutoff);
log::info!(
"ActivityCutoffSet( netuid: {:?} activity_cutoff: {:?} ) ",
netuid,
activity_cutoff
);
Self::deposit_event(Event::ActivityCutoffSet(netuid, activity_cutoff));
Ok(())
}
// Registration Toggle utils
pub fn get_network_registration_allowed(netuid: u16) -> bool {
NetworkRegistrationAllowed::<T>::get(netuid)
}
pub fn set_network_registration_allowed(netuid: u16, registration_allowed: bool) {
NetworkRegistrationAllowed::<T>::insert(netuid, registration_allowed)
}
pub fn do_sudo_set_network_registration_allowed(
origin: T::RuntimeOrigin,
netuid: u16,
registration_allowed: bool,
) -> DispatchResult {
ensure_root(origin)?;
Self::set_network_registration_allowed(netuid, registration_allowed);
log::info!(
"NetworkRegistrationAllowed( registration_allowed: {:?} ) ",
registration_allowed
);
Self::deposit_event(Event::RegistrationAllowed(netuid, registration_allowed));
Ok(())
}
pub fn get_network_pow_registration_allowed(netuid: u16) -> bool {
NetworkPowRegistrationAllowed::<T>::get(netuid)
}
pub fn set_network_pow_registration_allowed(netuid: u16, registration_allowed: bool) {
NetworkPowRegistrationAllowed::<T>::insert(netuid, registration_allowed)
}
pub fn do_sudo_set_network_pow_registration_allowed(
origin: T::RuntimeOrigin,
netuid: u16,
registration_allowed: bool,
) -> DispatchResult {
ensure_root(origin)?;
Self::set_network_pow_registration_allowed(netuid, registration_allowed);
log::info!(
"NetworkPowRegistrationAllowed( registration_allowed: {:?} ) ",
registration_allowed
);
Self::deposit_event(Event::PowRegistrationAllowed(netuid, registration_allowed));
Ok(())
}
pub fn get_target_registrations_per_interval(netuid: u16) -> u16 {
TargetRegistrationsPerInterval::<T>::get(netuid)
}
pub fn set_target_registrations_per_interval(
netuid: u16,
target_registrations_per_interval: u16,
) {
TargetRegistrationsPerInterval::<T>::insert(netuid, target_registrations_per_interval);
}
pub fn do_sudo_set_target_registrations_per_interval(
origin: T::RuntimeOrigin,
netuid: u16,
target_registrations_per_interval: u16,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_target_registrations_per_interval(netuid, target_registrations_per_interval);
log::info!(
"RegistrationPerIntervalSet( netuid: {:?} target_registrations_per_interval: {:?} ) ",
netuid,
target_registrations_per_interval
);
Self::deposit_event(Event::RegistrationPerIntervalSet(
netuid,
target_registrations_per_interval,
));
Ok(())
}
pub fn get_burn_as_u64(netuid: u16) -> u64 {
Burn::<T>::get(netuid)
}
pub fn set_burn(netuid: u16, burn: u64) {
Burn::<T>::insert(netuid, burn);
}
pub fn get_min_burn_as_u64(netuid: u16) -> u64 {
MinBurn::<T>::get(netuid)
}
pub fn set_min_burn(netuid: u16, min_burn: u64) {
MinBurn::<T>::insert(netuid, min_burn);
}
pub fn do_sudo_set_min_burn(
origin: T::RuntimeOrigin,
netuid: u16,
min_burn: u64,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_min_burn(netuid, min_burn);
log::info!(
"MinBurnSet( netuid: {:?} min_burn: {:?} ) ",
netuid,
min_burn
);
Self::deposit_event(Event::MinBurnSet(netuid, min_burn));
Ok(())
}
pub fn get_max_burn_as_u64(netuid: u16) -> u64 {
MaxBurn::<T>::get(netuid)
}
pub fn set_max_burn(netuid: u16, max_burn: u64) {
MaxBurn::<T>::insert(netuid, max_burn);
}
pub fn do_sudo_set_max_burn(
origin: T::RuntimeOrigin,
netuid: u16,
max_burn: u64,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_max_burn(netuid, max_burn);
log::info!(
"MaxBurnSet( netuid: {:?} max_burn: {:?} ) ",
netuid,
max_burn
);
Self::deposit_event(Event::MaxBurnSet(netuid, max_burn));
Ok(())
}
pub fn get_difficulty_as_u64(netuid: u16) -> u64 {
Difficulty::<T>::get(netuid)
}
pub fn set_difficulty(netuid: u16, difficulty: u64) {
Difficulty::<T>::insert(netuid, difficulty);
}
pub fn do_sudo_set_difficulty(
origin: T::RuntimeOrigin,
netuid: u16,
difficulty: u64,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_difficulty(netuid, difficulty);
log::info!(
"DifficultySet( netuid: {:?} difficulty: {:?} ) ",
netuid,
difficulty
);
Self::deposit_event(Event::DifficultySet(netuid, difficulty));
Ok(())
}
pub fn get_max_allowed_validators(netuid: u16) -> u16 {
MaxAllowedValidators::<T>::get(netuid)
}
pub fn set_max_allowed_validators(netuid: u16, max_allowed_validators: u16) {
MaxAllowedValidators::<T>::insert(netuid, max_allowed_validators);
}
pub fn do_sudo_set_max_allowed_validators(
origin: T::RuntimeOrigin,
netuid: u16,
max_allowed_validators: u16,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
ensure!(
max_allowed_validators <= Self::get_max_allowed_uids(netuid),
Error::<T>::StorageValueOutOfRange
);
Self::set_max_allowed_validators(netuid, max_allowed_validators);
log::info!(
"MaxAllowedValidatorsSet( netuid: {:?} max_allowed_validators: {:?} ) ",
netuid,
max_allowed_validators
);
Self::deposit_event(Event::MaxAllowedValidatorsSet(
netuid,
max_allowed_validators,
));
Ok(())
}
pub fn get_bonds_moving_average(netuid: u16) -> u64 {
BondsMovingAverage::<T>::get(netuid)
}
pub fn set_bonds_moving_average(netuid: u16, bonds_moving_average: u64) {
BondsMovingAverage::<T>::insert(netuid, bonds_moving_average);
}
pub fn do_sudo_set_bonds_moving_average(
origin: T::RuntimeOrigin,
netuid: u16,
bonds_moving_average: u64,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_bonds_moving_average(netuid, bonds_moving_average);
log::info!(
"BondsMovingAverageSet( netuid: {:?} bonds_moving_average: {:?} ) ",
netuid,
bonds_moving_average
);
Self::deposit_event(Event::BondsMovingAverageSet(netuid, bonds_moving_average));
Ok(())
}
pub fn get_max_registrations_per_block(netuid: u16) -> u16 {
MaxRegistrationsPerBlock::<T>::get(netuid)
}
pub fn set_max_registrations_per_block(netuid: u16, max_registrations_per_block: u16) {
MaxRegistrationsPerBlock::<T>::insert(netuid, max_registrations_per_block);
}
pub fn do_sudo_set_max_registrations_per_block(
origin: T::RuntimeOrigin,
netuid: u16,
max_registrations_per_block: u16,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Self::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
Self::set_max_registrations_per_block(netuid, max_registrations_per_block);
log::info!(
"MaxRegistrationsPerBlock( netuid: {:?} max_registrations_per_block: {:?} ) ",
netuid,
max_registrations_per_block
);
Self::deposit_event(Event::MaxRegistrationsPerBlockSet(
netuid,