-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathlib.rs
2368 lines (2253 loc) · 87.9 KB
/
lib.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
#![cfg_attr(not(feature = "std"), no_std)]
#![recursion_limit = "512"]
#![allow(clippy::too_many_arguments)]
// Edit this file to define custom logic or remove it if it is not needed.
// Learn more about FRAME and the core library of Substrate FRAME pallets:
// <https://docs.substrate.io/reference/frame-pallets/>
pub use pallet::*;
use frame_system::{self as system, ensure_signed};
use frame_support::{
dispatch::{self, DispatchInfo, DispatchResult, DispatchResultWithPostInfo, PostDispatchInfo},
ensure,
pallet_macros::import_section,
traits::{IsSubType, tokens::fungible},
};
use codec::{Decode, Encode};
use frame_support::sp_runtime::transaction_validity::InvalidTransaction;
use frame_support::sp_runtime::transaction_validity::ValidTransaction;
use pallet_balances::Call as BalancesCall;
// use pallet_scheduler as Scheduler;
use scale_info::TypeInfo;
use sp_core::Get;
use sp_runtime::{
DispatchError,
traits::{DispatchInfoOf, Dispatchable, PostDispatchInfoOf, SignedExtension},
transaction_validity::{TransactionValidity, TransactionValidityError},
};
use sp_std::marker::PhantomData;
// ============================
// ==== Benchmark Imports =====
// ============================
mod benchmarks;
// =========================
// ==== Pallet Imports =====
// =========================
pub mod coinbase;
pub mod epoch;
pub mod macros;
pub mod migrations;
pub mod rpc_info;
pub mod staking;
pub mod subnets;
pub mod swap;
pub mod utils;
use crate::utils::rate_limiting::TransactionType;
use macros::{config, dispatches, errors, events, genesis, hooks};
#[cfg(test)]
mod tests;
// apparently this is stabilized since rust 1.36
extern crate alloc;
pub const MAX_CRV3_COMMIT_SIZE_BYTES: u32 = 5000;
#[deny(missing_docs)]
#[import_section(errors::errors)]
#[import_section(events::events)]
#[import_section(dispatches::dispatches)]
#[import_section(genesis::genesis)]
#[import_section(hooks::hooks)]
#[import_section(config::config)]
#[frame_support::pallet]
pub mod pallet {
use crate::migrations;
use frame_support::{
BoundedVec,
dispatch::GetDispatchInfo,
pallet_prelude::{DispatchResult, StorageMap, ValueQuery, *},
traits::{
OriginTrait, QueryPreimage, StorePreimage, UnfilteredDispatchable, tokens::fungible,
},
};
use frame_system::pallet_prelude::*;
use pallet_drand::types::RoundNumber;
use sp_core::{ConstU32, H256};
use sp_runtime::traits::{Dispatchable, TrailingZeroInput};
use sp_std::collections::vec_deque::VecDeque;
use sp_std::vec;
use sp_std::vec::Vec;
use substrate_fixed::types::{I96F32, U64F64};
use subtensor_macros::freeze_struct;
#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
#[cfg(feature = "std")]
use sp_std::prelude::Box;
/// Origin for the pallet
pub type PalletsOriginOf<T> =
<<T as frame_system::Config>::RuntimeOrigin as OriginTrait>::PalletsOrigin;
/// Call type for the pallet
pub type CallOf<T> = <T as frame_system::Config>::RuntimeCall;
/// Tracks version for migrations. Should be monotonic with respect to the
/// order of migrations. (i.e. always increasing)
const STORAGE_VERSION: StorageVersion = StorageVersion::new(7);
/// Minimum balance required to perform a coldkey swap
pub const MIN_BALANCE_TO_PERFORM_COLDKEY_SWAP: u64 = 100_000_000; // 0.1 TAO in RAO
#[pallet::pallet]
#[pallet::without_storage_info]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);
/// Alias for the account ID.
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
/// Struct for Axon.
pub type AxonInfoOf = AxonInfo;
/// local one
pub type LocalCallOf<T> = <T as Config>::RuntimeCall;
/// Data structure for Axon information.
#[crate::freeze_struct("3545cfb0cac4c1f5")]
#[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)]
pub struct AxonInfo {
/// Axon serving block.
pub block: u64,
/// Axon version
pub version: u32,
/// Axon u128 encoded ip address of type v6 or v4.
pub ip: u128,
/// Axon u16 encoded port.
pub port: u16,
/// Axon ip type, 4 for ipv4 and 6 for ipv6.
pub ip_type: u8,
/// Axon protocol. TCP, UDP, other.
pub protocol: u8,
/// Axon proto placeholder 1.
pub placeholder1: u8,
/// Axon proto placeholder 2.
pub placeholder2: u8,
}
/// Struct for NeuronCertificate.
pub type NeuronCertificateOf = NeuronCertificate;
/// Data structure for NeuronCertificate information.
#[freeze_struct("1c232be200d9ec6c")]
#[derive(Decode, Encode, Default, TypeInfo, PartialEq, Eq, Clone, Debug)]
pub struct NeuronCertificate {
/// The neuron TLS public key
pub public_key: BoundedVec<u8, ConstU32<64>>,
/// The algorithm used to generate the public key
pub algorithm: u8,
}
impl TryFrom<Vec<u8>> for NeuronCertificate {
type Error = ();
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
if value.len() > 65 {
return Err(());
}
// take the first byte as the algorithm
let algorithm = value.first().ok_or(())?;
// and the rest as the public_key
let certificate = value.get(1..).ok_or(())?.to_vec();
Ok(Self {
public_key: BoundedVec::try_from(certificate).map_err(|_| ())?,
algorithm: *algorithm,
})
}
}
/// Struct for Prometheus.
pub type PrometheusInfoOf = PrometheusInfo;
/// Data structure for Prometheus information.
#[crate::freeze_struct("5dde687e63baf0cd")]
#[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)]
pub struct PrometheusInfo {
/// Prometheus serving block.
pub block: u64,
/// Prometheus version.
pub version: u32,
/// Prometheus u128 encoded ip address of type v6 or v4.
pub ip: u128,
/// Prometheus u16 encoded port.
pub port: u16,
/// Prometheus ip type, 4 for ipv4 and 6 for ipv6.
pub ip_type: u8,
}
/// Struct for ChainIdentities. (DEPRECATED for V2)
pub type ChainIdentityOf = ChainIdentity;
/// Data structure for Chain Identities. (DEPRECATED for V2)
#[crate::freeze_struct("bbfd00438dbe2b58")]
#[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)]
pub struct ChainIdentity {
/// The name of the chain identity
pub name: Vec<u8>,
/// The URL associated with the chain identity
pub url: Vec<u8>,
/// The image representation of the chain identity
pub image: Vec<u8>,
/// The Discord information for the chain identity
pub discord: Vec<u8>,
/// A description of the chain identity
pub description: Vec<u8>,
/// Additional information about the chain identity
pub additional: Vec<u8>,
}
/// Struct for ChainIdentities.
pub type ChainIdentityOfV2 = ChainIdentityV2;
/// Data structure for Chain Identities.
#[crate::freeze_struct("ad72a270be7b59d7")]
#[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)]
pub struct ChainIdentityV2 {
/// The name of the chain identity
pub name: Vec<u8>,
/// The URL associated with the chain identity
pub url: Vec<u8>,
/// The github repository associated with the identity
pub github_repo: Vec<u8>,
/// The image representation of the chain identity
pub image: Vec<u8>,
/// The Discord information for the chain identity
pub discord: Vec<u8>,
/// A description of the chain identity
pub description: Vec<u8>,
/// Additional information about the chain identity
pub additional: Vec<u8>,
}
/// Struct for SubnetIdentities. (DEPRECATED for V2)
pub type SubnetIdentityOf = SubnetIdentity;
/// Data structure for Subnet Identities. (DEPRECATED for V2)
#[crate::freeze_struct("f448dc3dad763108")]
#[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)]
pub struct SubnetIdentity {
/// The name of the subnet
pub subnet_name: Vec<u8>,
/// The github repository associated with the chain identity
pub github_repo: Vec<u8>,
/// The subnet's contact
pub subnet_contact: Vec<u8>,
}
/// Struct for SubnetIdentitiesV2.
pub type SubnetIdentityOfV2 = SubnetIdentityV2;
/// Data structure for Subnet Identities
#[crate::freeze_struct("e002be4cd05d7b3e")]
#[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)]
pub struct SubnetIdentityV2 {
/// The name of the subnet
pub subnet_name: Vec<u8>,
/// The github repository associated with the subnet
pub github_repo: Vec<u8>,
/// The subnet's contact
pub subnet_contact: Vec<u8>,
/// The subnet's website
pub subnet_url: Vec<u8>,
/// The subnet's discord
pub discord: Vec<u8>,
/// The subnet's description
pub description: Vec<u8>,
/// Additional information about the subnet
pub additional: Vec<u8>,
}
/// ============================
/// ==== Staking + Accounts ====
/// ============================
#[pallet::type_value]
/// Default value for zero.
pub fn DefaultZeroU64<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default value for zero.
pub fn DefaultZeroU128<T: Config>() -> u128 {
0
}
#[pallet::type_value]
/// Default value for zero.
pub fn DefaultZeroU16<T: Config>() -> u16 {
0
}
#[pallet::type_value]
/// Default value for false.
pub fn DefaultFalse<T: Config>() -> bool {
false
}
#[pallet::type_value]
/// Default value for false.
pub fn DefaultTrue<T: Config>() -> bool {
true
}
#[pallet::type_value]
/// Total Rao in circulation.
pub fn TotalSupply<T: Config>() -> u64 {
21_000_000_000_000_000
}
#[pallet::type_value]
/// Default Delegate Take.
pub fn DefaultDelegateTake<T: Config>() -> u16 {
T::InitialDefaultDelegateTake::get()
}
#[pallet::type_value]
/// Default childkey take.
pub fn DefaultChildKeyTake<T: Config>() -> u16 {
T::InitialDefaultChildKeyTake::get()
}
#[pallet::type_value]
/// Default minimum delegate take.
pub fn DefaultMinDelegateTake<T: Config>() -> u16 {
T::InitialMinDelegateTake::get()
}
#[pallet::type_value]
/// Default minimum childkey take.
pub fn DefaultMinChildKeyTake<T: Config>() -> u16 {
T::InitialMinChildKeyTake::get()
}
#[pallet::type_value]
/// Default maximum childkey take.
pub fn DefaultMaxChildKeyTake<T: Config>() -> u16 {
T::InitialMaxChildKeyTake::get()
}
#[pallet::type_value]
/// Default account take.
pub fn DefaultAccountTake<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default value for global weight.
pub fn DefaultTaoWeight<T: Config>() -> u64 {
T::InitialTaoWeight::get()
}
#[pallet::type_value]
/// Default emission per block.
pub fn DefaultBlockEmission<T: Config>() -> u64 {
1_000_000_000
}
#[pallet::type_value]
/// Default allowed delegation.
pub fn DefaultAllowsDelegation<T: Config>() -> bool {
false
}
#[pallet::type_value]
/// Default total issuance.
pub fn DefaultTotalIssuance<T: Config>() -> u64 {
T::InitialIssuance::get()
}
#[pallet::type_value]
/// Default account, derived from zero trailing bytes.
pub fn DefaultAccount<T: Config>() -> T::AccountId {
T::AccountId::decode(&mut TrailingZeroInput::zeroes())
.expect("trailing zeroes always produce a valid account ID; qed")
}
// pub fn DefaultStakeInterval<T: Config>() -> u64 {
// 360
// } (DEPRECATED)
#[pallet::type_value]
/// Default account linkage
pub fn DefaultAccountLinkage<T: Config>() -> Vec<(u64, T::AccountId)> {
vec![]
}
#[pallet::type_value]
/// Default pending childkeys
pub fn DefaultPendingChildkeys<T: Config>() -> (Vec<(u64, T::AccountId)>, u64) {
(vec![], 0)
}
#[pallet::type_value]
/// Default account linkage
pub fn DefaultProportion<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default accumulated emission for a hotkey
pub fn DefaultAccumulatedEmission<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default last adjustment block.
pub fn DefaultLastAdjustmentBlock<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default last adjustment block.
pub fn DefaultRegistrationsThisBlock<T: Config>() -> u16 {
0
}
#[pallet::type_value]
/// Default registrations this block.
pub fn DefaultBurn<T: Config>() -> u64 {
T::InitialBurn::get()
}
#[pallet::type_value]
/// Default burn token.
pub fn DefaultMinBurn<T: Config>() -> u64 {
T::InitialMinBurn::get()
}
#[pallet::type_value]
/// Default min burn token.
pub fn DefaultMaxBurn<T: Config>() -> u64 {
T::InitialMaxBurn::get()
}
#[pallet::type_value]
/// Default max burn token.
pub fn DefaultDifficulty<T: Config>() -> u64 {
T::InitialDifficulty::get()
}
#[pallet::type_value]
/// Default difficulty value.
pub fn DefaultMinDifficulty<T: Config>() -> u64 {
T::InitialMinDifficulty::get()
}
#[pallet::type_value]
/// Default min difficulty value.
pub fn DefaultMaxDifficulty<T: Config>() -> u64 {
T::InitialMaxDifficulty::get()
}
#[pallet::type_value]
/// Default max difficulty value.
pub fn DefaultMaxRegistrationsPerBlock<T: Config>() -> u16 {
T::InitialMaxRegistrationsPerBlock::get()
}
#[pallet::type_value]
/// Default max registrations per block.
pub fn DefaultRAORecycledForRegistration<T: Config>() -> u64 {
T::InitialRAORecycledForRegistration::get()
}
#[pallet::type_value]
/// Default number of networks.
pub fn DefaultN<T: Config>() -> u16 {
0
}
#[pallet::type_value]
/// Default value for modality.
pub fn DefaultModality<T: Config>() -> u16 {
0
}
#[pallet::type_value]
/// Default value for hotkeys.
pub fn DefaultHotkeys<T: Config>() -> Vec<u16> {
vec![]
}
#[pallet::type_value]
/// Default value if network is added.
pub fn DefaultNeworksAdded<T: Config>() -> bool {
false
}
#[pallet::type_value]
/// Default value for network member.
pub fn DefaultIsNetworkMember<T: Config>() -> bool {
false
}
#[pallet::type_value]
/// Default value for registration allowed.
pub fn DefaultRegistrationAllowed<T: Config>() -> bool {
false
}
#[pallet::type_value]
/// Default value for network registered at.
pub fn DefaultNetworkRegisteredAt<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default value for network immunity period.
pub fn DefaultNetworkImmunityPeriod<T: Config>() -> u64 {
T::InitialNetworkImmunityPeriod::get()
}
#[pallet::type_value]
/// Default value for network last registered.
pub fn DefaultNetworkLastRegistered<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default value for network min allowed UIDs.
pub fn DefaultNetworkMinAllowedUids<T: Config>() -> u16 {
T::InitialNetworkMinAllowedUids::get()
}
#[pallet::type_value]
/// Default value for network min lock cost.
pub fn DefaultNetworkMinLockCost<T: Config>() -> u64 {
T::InitialNetworkMinLockCost::get()
}
#[pallet::type_value]
/// Default value for network lock reduction interval.
pub fn DefaultNetworkLockReductionInterval<T: Config>() -> u64 {
T::InitialNetworkLockReductionInterval::get()
}
#[pallet::type_value]
/// Default value for subnet owner cut.
pub fn DefaultSubnetOwnerCut<T: Config>() -> u16 {
T::InitialSubnetOwnerCut::get()
}
#[pallet::type_value]
/// Default value for network rate limit.
pub fn DefaultNetworkRateLimit<T: Config>() -> u64 {
if cfg!(feature = "pow-faucet") {
return 0;
}
T::InitialNetworkRateLimit::get()
}
#[pallet::type_value]
/// Default value for pending emission.
pub fn DefaultPendingEmission<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default value for blocks since last step.
pub fn DefaultBlocksSinceLastStep<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default value for last mechanism step block.
pub fn DefaultLastMechanismStepBlock<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default value for subnet owner.
pub fn DefaultSubnetOwner<T: Config>() -> T::AccountId {
T::AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes())
.expect("trailing zeroes always produce a valid account ID; qed")
}
#[pallet::type_value]
/// Default value for subnet locked.
pub fn DefaultSubnetLocked<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default value for network tempo
pub fn DefaultTempo<T: Config>() -> u16 {
T::InitialTempo::get()
}
#[pallet::type_value]
/// Default value for weights set rate limit.
pub fn DefaultWeightsSetRateLimit<T: Config>() -> u64 {
100
}
#[pallet::type_value]
/// Default block number at registration.
pub fn DefaultBlockAtRegistration<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default value for rho parameter.
pub fn DefaultRho<T: Config>() -> u16 {
T::InitialRho::get()
}
#[pallet::type_value]
/// Default value for kappa parameter.
pub fn DefaultKappa<T: Config>() -> u16 {
T::InitialKappa::get()
}
#[pallet::type_value]
/// Default maximum allowed UIDs.
pub fn DefaultMaxAllowedUids<T: Config>() -> u16 {
T::InitialMaxAllowedUids::get()
}
#[pallet::type_value]
/// Default immunity period.
pub fn DefaultImmunityPeriod<T: Config>() -> u16 {
T::InitialImmunityPeriod::get()
}
#[pallet::type_value]
/// Default activity cutoff.
pub fn DefaultActivityCutoff<T: Config>() -> u16 {
T::InitialActivityCutoff::get()
}
#[pallet::type_value]
/// Default maximum weights limit.
pub fn DefaultMaxWeightsLimit<T: Config>() -> u16 {
T::InitialMaxWeightsLimit::get()
}
#[pallet::type_value]
/// Default weights version key.
pub fn DefaultWeightsVersionKey<T: Config>() -> u64 {
T::InitialWeightsVersionKey::get()
}
#[pallet::type_value]
/// Default minimum allowed weights.
pub fn DefaultMinAllowedWeights<T: Config>() -> u16 {
T::InitialMinAllowedWeights::get()
}
#[pallet::type_value]
/// Default maximum allowed validators.
pub fn DefaultMaxAllowedValidators<T: Config>() -> u16 {
T::InitialMaxAllowedValidators::get()
}
#[pallet::type_value]
/// Default adjustment interval.
pub fn DefaultAdjustmentInterval<T: Config>() -> u16 {
T::InitialAdjustmentInterval::get()
}
#[pallet::type_value]
/// Default bonds moving average.
pub fn DefaultBondsMovingAverage<T: Config>() -> u64 {
T::InitialBondsMovingAverage::get()
}
/// Default bonds penalty.
#[pallet::type_value]
pub fn DefaultBondsPenalty<T: Config>() -> u16 {
T::InitialBondsPenalty::get()
}
#[pallet::type_value]
/// Default validator prune length.
pub fn DefaultValidatorPruneLen<T: Config>() -> u64 {
T::InitialValidatorPruneLen::get()
}
#[pallet::type_value]
/// Default scaling law power.
pub fn DefaultScalingLawPower<T: Config>() -> u16 {
T::InitialScalingLawPower::get()
}
#[pallet::type_value]
/// Default target registrations per interval.
pub fn DefaultTargetRegistrationsPerInterval<T: Config>() -> u16 {
T::InitialTargetRegistrationsPerInterval::get()
}
#[pallet::type_value]
/// Default adjustment alpha.
pub fn DefaultAdjustmentAlpha<T: Config>() -> u64 {
T::InitialAdjustmentAlpha::get()
}
#[pallet::type_value]
/// Default minimum stake for weights.
pub fn DefaultStakeThreshold<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default Reveal Period Epochs
pub fn DefaultRevealPeriodEpochs<T: Config>() -> u64 {
1
}
#[pallet::type_value]
/// Value definition for vector of u16.
pub fn EmptyU16Vec<T: Config>() -> Vec<u16> {
vec![]
}
#[pallet::type_value]
/// Value definition for vector of u64.
pub fn EmptyU64Vec<T: Config>() -> Vec<u64> {
vec![]
}
#[pallet::type_value]
/// Value definition for vector of bool.
pub fn EmptyBoolVec<T: Config>() -> Vec<bool> {
vec![]
}
#[pallet::type_value]
/// Value definition for bonds with type vector of (u16, u16).
pub fn DefaultBonds<T: Config>() -> Vec<(u16, u16)> {
vec![]
}
#[pallet::type_value]
/// Value definition for weights with vector of (u16, u16).
pub fn DefaultWeights<T: Config>() -> Vec<(u16, u16)> {
vec![]
}
#[pallet::type_value]
/// Default value for key with type T::AccountId derived from trailing zeroes.
pub fn DefaultKey<T: Config>() -> T::AccountId {
T::AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes())
.expect("trailing zeroes always produce a valid account ID; qed")
}
// pub fn DefaultHotkeyEmissionTempo<T: Config>() -> u64 {
// T::InitialHotkeyEmissionTempo::get()
// } (DEPRECATED)
#[pallet::type_value]
/// Default value for rate limiting
pub fn DefaultTxRateLimit<T: Config>() -> u64 {
T::InitialTxRateLimit::get()
}
#[pallet::type_value]
/// Default value for delegate take rate limiting
pub fn DefaultTxDelegateTakeRateLimit<T: Config>() -> u64 {
T::InitialTxDelegateTakeRateLimit::get()
}
#[pallet::type_value]
/// Default value for chidlkey take rate limiting
pub fn DefaultTxChildKeyTakeRateLimit<T: Config>() -> u64 {
T::InitialTxChildKeyTakeRateLimit::get()
}
#[pallet::type_value]
/// Default value for last extrinsic block.
pub fn DefaultLastTxBlock<T: Config>() -> u64 {
0
}
#[pallet::type_value]
/// Default value for serving rate limit.
pub fn DefaultServingRateLimit<T: Config>() -> u64 {
T::InitialServingRateLimit::get()
}
#[pallet::type_value]
/// Default value for weight commit/reveal enabled.
pub fn DefaultCommitRevealWeightsEnabled<T: Config>() -> bool {
false
}
#[pallet::type_value]
/// Senate requirements
pub fn DefaultSenateRequiredStakePercentage<T: Config>() -> u64 {
T::InitialSenateRequiredStakePercentage::get()
}
#[pallet::type_value]
/// -- ITEM (switches liquid alpha on)
pub fn DefaultLiquidAlpha<T: Config>() -> bool {
false
}
#[pallet::type_value]
/// (alpha_low: 0.7, alpha_high: 0.9)
pub fn DefaultAlphaValues<T: Config>() -> (u16, u16) {
(45875, 58982)
}
#[pallet::type_value]
/// Default value for coldkey swap schedule duration
pub fn DefaultColdkeySwapScheduleDuration<T: Config>() -> BlockNumberFor<T> {
T::InitialColdkeySwapScheduleDuration::get()
}
#[pallet::type_value]
/// Default value for applying pending items (e.g. childkeys).
pub fn DefaultPendingCooldown<T: Config>() -> u64 {
if cfg!(feature = "fast-blocks") {
return 15;
}
7_200
}
#[pallet::type_value]
/// Default minimum stake.
pub fn DefaultMinStake<T: Config>() -> u64 {
500_000
}
#[pallet::type_value]
/// Default staking fee.
pub fn DefaultStakingFee<T: Config>() -> u64 {
50_000
}
#[pallet::type_value]
/// Default unicode vector for tau symbol.
pub fn DefaultUnicodeVecU8<T: Config>() -> Vec<u8> {
b"\xF0\x9D\x9C\x8F".to_vec() // Unicode for tau (𝜏)
}
#[pallet::type_value]
/// Default value for dissolve network schedule duration
pub fn DefaultDissolveNetworkScheduleDuration<T: Config>() -> BlockNumberFor<T> {
T::InitialDissolveNetworkScheduleDuration::get()
}
#[pallet::type_value]
/// Default moving alpha for the moving price.
pub fn DefaultMovingAlpha<T: Config>() -> I96F32 {
// Moving average take 30 days to reach 50% of the price
// and 3.5 months to reach 90%.
I96F32::saturating_from_num(0.000003)
}
#[pallet::type_value]
/// Default subnet moving price.
pub fn DefaultMovingPrice<T: Config>() -> I96F32 {
I96F32::saturating_from_num(0.0)
}
#[pallet::type_value]
/// Default value for Share Pool variables
pub fn DefaultSharePoolZero<T: Config>() -> U64F64 {
U64F64::saturating_from_num(0)
}
#[pallet::type_value]
/// Default value for minimum liquidity in pool
pub fn DefaultMinimumPoolLiquidity<T: Config>() -> I96F32 {
I96F32::saturating_from_num(10_000_000)
}
#[pallet::storage]
pub type ColdkeySwapScheduleDuration<T: Config> =
StorageValue<_, BlockNumberFor<T>, ValueQuery, DefaultColdkeySwapScheduleDuration<T>>;
#[pallet::storage]
pub type DissolveNetworkScheduleDuration<T: Config> =
StorageValue<_, BlockNumberFor<T>, ValueQuery, DefaultDissolveNetworkScheduleDuration<T>>;
#[pallet::storage]
pub type SenateRequiredStakePercentage<T> =
StorageValue<_, u64, ValueQuery, DefaultSenateRequiredStakePercentage<T>>;
/// ============================
/// ==== Staking Variables ====
/// ============================
/// The Subtensor [`TotalIssuance`] represents the total issuance of tokens on the Bittensor network.
///
/// It is comprised of three parts:
/// - The total amount of issued tokens, tracked in the TotalIssuance of the Balances pallet
/// - The total amount of tokens staked in the system, tracked in [`TotalStake`]
/// - The total amount of tokens locked up for subnet reg, tracked in [`TotalSubnetLocked`] attained by iterating over subnet lock.
///
/// Eventually, Bittensor should migrate to using Holds afterwhich time we will not require this
/// separate accounting.
#[pallet::storage]
/// --- ITEM --> Global weight
pub type TaoWeight<T> = StorageValue<_, u64, ValueQuery, DefaultTaoWeight<T>>;
#[pallet::storage]
/// --- ITEM ( default_delegate_take )
pub type MaxDelegateTake<T> = StorageValue<_, u16, ValueQuery, DefaultDelegateTake<T>>;
#[pallet::storage]
/// --- ITEM ( min_delegate_take )
pub type MinDelegateTake<T> = StorageValue<_, u16, ValueQuery, DefaultMinDelegateTake<T>>;
#[pallet::storage]
/// --- ITEM ( default_childkey_take )
pub type MaxChildkeyTake<T> = StorageValue<_, u16, ValueQuery, DefaultMaxChildKeyTake<T>>;
#[pallet::storage]
/// --- ITEM ( min_childkey_take )
pub type MinChildkeyTake<T> = StorageValue<_, u16, ValueQuery, DefaultMinChildKeyTake<T>>;
#[pallet::storage]
/// MAP ( hot ) --> cold | Returns the controlling coldkey for a hotkey.
pub type Owner<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, T::AccountId, ValueQuery, DefaultAccount<T>>;
#[pallet::storage]
/// MAP ( hot ) --> take | Returns the hotkey delegation take. And signals that this key is open for delegation.
pub type Delegates<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, u16, ValueQuery, DefaultDelegateTake<T>>;
#[pallet::storage]
/// DMAP ( hot, netuid ) --> take | Returns the hotkey childkey take for a specific subnet
pub type ChildkeyTake<T: Config> = StorageDoubleMap<
_,
Blake2_128Concat,
T::AccountId, // First key: hotkey
Identity,
u16, // Second key: netuid
u16, // Value: take
ValueQuery,
>;
#[pallet::storage]
/// DMAP ( netuid, parent ) --> (Vec<(proportion,child)>, cool_down_block)
pub type PendingChildKeys<T: Config> = StorageDoubleMap<
_,
Identity,
u16,
Blake2_128Concat,
T::AccountId,
(Vec<(u64, T::AccountId)>, u64),
ValueQuery,
DefaultPendingChildkeys<T>,
>;
#[pallet::storage]
/// DMAP ( parent, netuid ) --> Vec<(proportion,child)>
pub type ChildKeys<T: Config> = StorageDoubleMap<
_,
Blake2_128Concat,
T::AccountId,
Identity,
u16,
Vec<(u64, T::AccountId)>,
ValueQuery,
DefaultAccountLinkage<T>,
>;
#[pallet::storage]
/// DMAP ( child, netuid ) --> Vec<(proportion,parent)>
pub type ParentKeys<T: Config> = StorageDoubleMap<
_,
Blake2_128Concat,
T::AccountId,
Identity,
u16,
Vec<(u64, T::AccountId)>,
ValueQuery,
DefaultAccountLinkage<T>,
>;
#[pallet::storage] // --- DMAP ( netuid, hotkey ) --> u64 | Last total dividend this hotkey got on tempo.
pub type AlphaDividendsPerSubnet<T: Config> = StorageDoubleMap<
_,
Identity,
u16,
Blake2_128Concat,
T::AccountId,
u64,
ValueQuery,
DefaultZeroU64<T>,
>;
#[pallet::storage] // --- DMAP ( netuid, hotkey ) --> u64 | Last total root dividend paid to this hotkey on this subnet.
pub type TaoDividendsPerSubnet<T: Config> = StorageDoubleMap<
_,
Identity,
u16,
Blake2_128Concat,
T::AccountId,
u64,
ValueQuery,
DefaultZeroU64<T>,
>;
/// ==================
/// ==== Coinbase ====
/// ==================
#[pallet::storage]
/// --- ITEM ( global_block_emission )
pub type BlockEmission<T> = StorageValue<_, u64, ValueQuery, DefaultBlockEmission<T>>;
#[pallet::storage]
/// --- DMap ( hot, netuid ) --> emission | last hotkey emission on network.
pub type LastHotkeyEmissionOnNetuid<T: Config> = StorageDoubleMap<
_,
Blake2_128Concat,
T::AccountId,
Identity,
u16,
u64,
ValueQuery,
DefaultZeroU64<T>,
>;
#[pallet::storage]
/// --- NMAP ( hot, cold, netuid ) --> last_emission_on_hot_cold_net | Returns the last_emission_update_on_hot_cold_net
pub type LastHotkeyColdkeyEmissionOnNetuid<T: Config> = StorageNMap<
_,
(
NMapKey<Blake2_128Concat, T::AccountId>, // hot
NMapKey<Blake2_128Concat, T::AccountId>, // cold
NMapKey<Identity, u16>, // subnet
),
u64, // Stake
ValueQuery,
>;
/// ==========================
/// ==== Staking Counters ====
/// ==========================
/// The Subtensor [`TotalIssuance`] represents the total issuance of tokens on the Bittensor network.
///
/// It is comprised of three parts:
/// - The total amount of issued tokens, tracked in the TotalIssuance of the Balances pallet
/// - The total amount of tokens staked in the system, tracked in [`TotalStake`]
/// - The total amount of tokens locked up for subnet reg, tracked in [`TotalSubnetLocked`] attained by iterating over subnet lock.
///
/// Eventually, Bittensor should migrate to using Holds afterwhich time we will not require this
/// separate accounting.
#[pallet::storage] // --- ITEM ( total_issuance )
pub type TotalIssuance<T> = StorageValue<_, u64, ValueQuery, DefaultTotalIssuance<T>>;
#[pallet::storage] // --- ITEM ( total_stake )
pub type TotalStake<T> = StorageValue<_, u64, ValueQuery>;
#[pallet::storage] // --- ITEM ( dynamic_block ) -- block when dynamic was turned on.
pub type DynamicBlock<T> = StorageValue<_, u64, ValueQuery>;
#[pallet::storage] // --- ITEM ( moving_alpha ) -- subnet moving alpha.
pub type SubnetMovingAlpha<T> = StorageValue<_, I96F32, ValueQuery, DefaultMovingAlpha<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> moving_price | The subnet moving price.
pub type SubnetMovingPrice<T: Config> =
StorageMap<_, Identity, u16, I96F32, ValueQuery, DefaultMovingPrice<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> total_volume | The total amount of TAO bought and sold since the start of the network.
pub type SubnetVolume<T: Config> =
StorageMap<_, Identity, u16, u128, ValueQuery, DefaultZeroU128<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> tao_in_subnet | Returns the amount of TAO in the subnet.
pub type SubnetTAO<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> alpha_in_emission | Returns the amount of alph in emission into the pool per block.
pub type SubnetAlphaInEmission<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> alpha_out_emission | Returns the amount of alpha out emission into the network per block.
pub type SubnetAlphaOutEmission<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> tao_in_emission | Returns the amount of tao emitted into this subent on the last block.
pub type SubnetTaoInEmission<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> alpha_sell_per_block | Alpha sold per block.
pub type SubnetAlphaEmissionSell<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> total_stake_at_moment_of_subnet_registration
pub type TotalStakeAtDynamic<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> alpha_supply_in_pool | Returns the amount of alpha in the pool.
pub type SubnetAlphaIn<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> alpha_supply_in_subnet | Returns the amount of alpha in the subnet.
pub type SubnetAlphaOut<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
#[pallet::storage] // --- MAP ( cold ) --> Vec<hot> | Maps coldkey to hotkeys that stake to it
pub type StakingHotkeys<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, Vec<T::AccountId>, ValueQuery>;
#[pallet::storage] // --- MAP ( cold ) --> Vec<hot> | Returns the vector of hotkeys controlled by this coldkey.
pub type OwnedHotkeys<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, Vec<T::AccountId>, ValueQuery>;
#[pallet::storage] // --- DMAP ( cold ) --> () | Maps coldkey to if a coldkey swap is scheduled.
pub type ColdkeySwapScheduled<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, (), ValueQuery>;
#[pallet::storage] // --- DMAP ( hot, netuid ) --> alpha | Returns the total amount of alpha a hotkey owns.
pub type TotalHotkeyAlpha<T: Config> = StorageDoubleMap<
_,
Blake2_128Concat,
T::AccountId,
Identity,