Skip to content

Commit b6a76e2

Browse files
authored
Merge pull request #1565 from opentensor/fix/roman/netuid-in-SelectiveMetagraph
Add netuid to `SelectiveMetagraphIndex` object
2 parents 1e568eb + 614543e commit b6a76e2

File tree

2 files changed

+83
-77
lines changed

2 files changed

+83
-77
lines changed

pallets/subtensor/src/rpc_info/metagraph.rs

Lines changed: 82 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ where
213213
{
214214
pub fn merge_value(&mut self, other: &Self, metagraph_index: usize) {
215215
match SelectiveMetagraphIndex::from_index(metagraph_index) {
216-
// Name and symbol
216+
Some(SelectiveMetagraphIndex::Netuid) => self.netuid = other.netuid,
217217
Some(SelectiveMetagraphIndex::Name) => self.name = other.name.clone(),
218218
Some(SelectiveMetagraphIndex::Symbol) => self.symbol = other.symbol.clone(),
219219
Some(SelectiveMetagraphIndex::Identity) => self.identity = other.identity.clone(),
@@ -450,6 +450,7 @@ where
450450
}
451451

452452
pub enum SelectiveMetagraphIndex {
453+
Netuid,
453454
Name,
454455
Symbol,
455456
Identity,
@@ -526,77 +527,78 @@ pub enum SelectiveMetagraphIndex {
526527
impl SelectiveMetagraphIndex {
527528
fn from_index(index: usize) -> Option<Self> {
528529
match index {
529-
0 => Some(SelectiveMetagraphIndex::Name),
530-
1 => Some(SelectiveMetagraphIndex::Symbol),
531-
2 => Some(SelectiveMetagraphIndex::Identity),
532-
3 => Some(SelectiveMetagraphIndex::NetworkRegisteredAt),
533-
4 => Some(SelectiveMetagraphIndex::OwnerHotkey),
534-
5 => Some(SelectiveMetagraphIndex::OwnerColdkey),
535-
6 => Some(SelectiveMetagraphIndex::Block),
536-
7 => Some(SelectiveMetagraphIndex::Tempo),
537-
8 => Some(SelectiveMetagraphIndex::LastStep),
538-
9 => Some(SelectiveMetagraphIndex::BlocksSinceLastStep),
539-
10 => Some(SelectiveMetagraphIndex::SubnetEmission),
540-
11 => Some(SelectiveMetagraphIndex::AlphaIn),
541-
12 => Some(SelectiveMetagraphIndex::AlphaOut),
542-
13 => Some(SelectiveMetagraphIndex::TaoIn),
543-
14 => Some(SelectiveMetagraphIndex::AlphaOutEmission),
544-
15 => Some(SelectiveMetagraphIndex::AlphaInEmission),
545-
16 => Some(SelectiveMetagraphIndex::TaoInEmission),
546-
17 => Some(SelectiveMetagraphIndex::PendingAlphaEmission),
547-
18 => Some(SelectiveMetagraphIndex::PendingRootEmission),
548-
19 => Some(SelectiveMetagraphIndex::SubnetVolume),
549-
20 => Some(SelectiveMetagraphIndex::MovingPrice),
550-
21 => Some(SelectiveMetagraphIndex::Rho),
551-
22 => Some(SelectiveMetagraphIndex::Kappa),
552-
23 => Some(SelectiveMetagraphIndex::MinAllowedWeights),
553-
24 => Some(SelectiveMetagraphIndex::MaxWeightsLimit),
554-
25 => Some(SelectiveMetagraphIndex::WeightsVersion),
555-
26 => Some(SelectiveMetagraphIndex::WeightsRateLimit),
556-
27 => Some(SelectiveMetagraphIndex::ActivityCutoff),
557-
28 => Some(SelectiveMetagraphIndex::MaxValidators),
558-
29 => Some(SelectiveMetagraphIndex::NumUids),
559-
30 => Some(SelectiveMetagraphIndex::MaxUids),
560-
31 => Some(SelectiveMetagraphIndex::Burn),
561-
32 => Some(SelectiveMetagraphIndex::Difficulty),
562-
33 => Some(SelectiveMetagraphIndex::RegistrationAllowed),
563-
34 => Some(SelectiveMetagraphIndex::PowRegistrationAllowed),
564-
35 => Some(SelectiveMetagraphIndex::ImmunityPeriod),
565-
36 => Some(SelectiveMetagraphIndex::MinDifficulty),
566-
37 => Some(SelectiveMetagraphIndex::MaxDifficulty),
567-
38 => Some(SelectiveMetagraphIndex::MinBurn),
568-
39 => Some(SelectiveMetagraphIndex::MaxBurn),
569-
40 => Some(SelectiveMetagraphIndex::AdjustmentAlpha),
570-
41 => Some(SelectiveMetagraphIndex::AdjustmentInterval),
571-
42 => Some(SelectiveMetagraphIndex::TargetRegsPerInterval),
572-
43 => Some(SelectiveMetagraphIndex::MaxRegsPerBlock),
573-
44 => Some(SelectiveMetagraphIndex::ServingRateLimit),
574-
45 => Some(SelectiveMetagraphIndex::CommitRevealWeightsEnabled),
575-
46 => Some(SelectiveMetagraphIndex::CommitRevealPeriod),
576-
47 => Some(SelectiveMetagraphIndex::LiquidAlphaEnabled),
577-
48 => Some(SelectiveMetagraphIndex::AlphaHigh),
578-
49 => Some(SelectiveMetagraphIndex::AlphaLow),
579-
50 => Some(SelectiveMetagraphIndex::BondsMovingAvg),
580-
51 => Some(SelectiveMetagraphIndex::Hotkeys),
581-
52 => Some(SelectiveMetagraphIndex::Coldkeys),
582-
53 => Some(SelectiveMetagraphIndex::Identities),
583-
54 => Some(SelectiveMetagraphIndex::Axons),
584-
55 => Some(SelectiveMetagraphIndex::Active),
585-
56 => Some(SelectiveMetagraphIndex::ValidatorPermit),
586-
57 => Some(SelectiveMetagraphIndex::PruningScore),
587-
58 => Some(SelectiveMetagraphIndex::LastUpdate),
588-
59 => Some(SelectiveMetagraphIndex::Emission),
589-
60 => Some(SelectiveMetagraphIndex::Dividends),
590-
61 => Some(SelectiveMetagraphIndex::Incentives),
591-
62 => Some(SelectiveMetagraphIndex::Consensus),
592-
63 => Some(SelectiveMetagraphIndex::Trust),
593-
64 => Some(SelectiveMetagraphIndex::Rank),
594-
65 => Some(SelectiveMetagraphIndex::BlockAtRegistration),
595-
66 => Some(SelectiveMetagraphIndex::AlphaStake),
596-
67 => Some(SelectiveMetagraphIndex::TaoStake),
597-
68 => Some(SelectiveMetagraphIndex::TotalStake),
598-
69 => Some(SelectiveMetagraphIndex::TaoDividendsPerHotkey),
599-
70 => Some(SelectiveMetagraphIndex::AlphaDividendsPerHotkey),
530+
0 => Some(SelectiveMetagraphIndex::Netuid),
531+
1 => Some(SelectiveMetagraphIndex::Name),
532+
2 => Some(SelectiveMetagraphIndex::Symbol),
533+
3 => Some(SelectiveMetagraphIndex::Identity),
534+
4 => Some(SelectiveMetagraphIndex::NetworkRegisteredAt),
535+
5 => Some(SelectiveMetagraphIndex::OwnerHotkey),
536+
6 => Some(SelectiveMetagraphIndex::OwnerColdkey),
537+
7 => Some(SelectiveMetagraphIndex::Block),
538+
8 => Some(SelectiveMetagraphIndex::Tempo),
539+
9 => Some(SelectiveMetagraphIndex::LastStep),
540+
10 => Some(SelectiveMetagraphIndex::BlocksSinceLastStep),
541+
11 => Some(SelectiveMetagraphIndex::SubnetEmission),
542+
12 => Some(SelectiveMetagraphIndex::AlphaIn),
543+
13 => Some(SelectiveMetagraphIndex::AlphaOut),
544+
14 => Some(SelectiveMetagraphIndex::TaoIn),
545+
15 => Some(SelectiveMetagraphIndex::AlphaOutEmission),
546+
16 => Some(SelectiveMetagraphIndex::AlphaInEmission),
547+
17 => Some(SelectiveMetagraphIndex::TaoInEmission),
548+
18 => Some(SelectiveMetagraphIndex::PendingAlphaEmission),
549+
19 => Some(SelectiveMetagraphIndex::PendingRootEmission),
550+
20 => Some(SelectiveMetagraphIndex::SubnetVolume),
551+
21 => Some(SelectiveMetagraphIndex::MovingPrice),
552+
22 => Some(SelectiveMetagraphIndex::Rho),
553+
23 => Some(SelectiveMetagraphIndex::Kappa),
554+
24 => Some(SelectiveMetagraphIndex::MinAllowedWeights),
555+
25 => Some(SelectiveMetagraphIndex::MaxWeightsLimit),
556+
26 => Some(SelectiveMetagraphIndex::WeightsVersion),
557+
27 => Some(SelectiveMetagraphIndex::WeightsRateLimit),
558+
28 => Some(SelectiveMetagraphIndex::ActivityCutoff),
559+
29 => Some(SelectiveMetagraphIndex::MaxValidators),
560+
30 => Some(SelectiveMetagraphIndex::NumUids),
561+
31 => Some(SelectiveMetagraphIndex::MaxUids),
562+
32 => Some(SelectiveMetagraphIndex::Burn),
563+
33 => Some(SelectiveMetagraphIndex::Difficulty),
564+
34 => Some(SelectiveMetagraphIndex::RegistrationAllowed),
565+
35 => Some(SelectiveMetagraphIndex::PowRegistrationAllowed),
566+
36 => Some(SelectiveMetagraphIndex::ImmunityPeriod),
567+
37 => Some(SelectiveMetagraphIndex::MinDifficulty),
568+
38 => Some(SelectiveMetagraphIndex::MaxDifficulty),
569+
39 => Some(SelectiveMetagraphIndex::MinBurn),
570+
40 => Some(SelectiveMetagraphIndex::MaxBurn),
571+
41 => Some(SelectiveMetagraphIndex::AdjustmentAlpha),
572+
42 => Some(SelectiveMetagraphIndex::AdjustmentInterval),
573+
43 => Some(SelectiveMetagraphIndex::TargetRegsPerInterval),
574+
44 => Some(SelectiveMetagraphIndex::MaxRegsPerBlock),
575+
45 => Some(SelectiveMetagraphIndex::ServingRateLimit),
576+
46 => Some(SelectiveMetagraphIndex::CommitRevealWeightsEnabled),
577+
47 => Some(SelectiveMetagraphIndex::CommitRevealPeriod),
578+
48 => Some(SelectiveMetagraphIndex::LiquidAlphaEnabled),
579+
49 => Some(SelectiveMetagraphIndex::AlphaHigh),
580+
50 => Some(SelectiveMetagraphIndex::AlphaLow),
581+
51 => Some(SelectiveMetagraphIndex::BondsMovingAvg),
582+
52 => Some(SelectiveMetagraphIndex::Hotkeys),
583+
53 => Some(SelectiveMetagraphIndex::Coldkeys),
584+
54 => Some(SelectiveMetagraphIndex::Identities),
585+
55 => Some(SelectiveMetagraphIndex::Axons),
586+
56 => Some(SelectiveMetagraphIndex::Active),
587+
57 => Some(SelectiveMetagraphIndex::ValidatorPermit),
588+
58 => Some(SelectiveMetagraphIndex::PruningScore),
589+
59 => Some(SelectiveMetagraphIndex::LastUpdate),
590+
60 => Some(SelectiveMetagraphIndex::Emission),
591+
61 => Some(SelectiveMetagraphIndex::Dividends),
592+
62 => Some(SelectiveMetagraphIndex::Incentives),
593+
63 => Some(SelectiveMetagraphIndex::Consensus),
594+
64 => Some(SelectiveMetagraphIndex::Trust),
595+
65 => Some(SelectiveMetagraphIndex::Rank),
596+
66 => Some(SelectiveMetagraphIndex::BlockAtRegistration),
597+
67 => Some(SelectiveMetagraphIndex::AlphaStake),
598+
68 => Some(SelectiveMetagraphIndex::TaoStake),
599+
69 => Some(SelectiveMetagraphIndex::TotalStake),
600+
70 => Some(SelectiveMetagraphIndex::TaoDividendsPerHotkey),
601+
71 => Some(SelectiveMetagraphIndex::AlphaDividendsPerHotkey),
600602
_ => None,
601603
}
602604
}
@@ -724,7 +726,7 @@ impl<T: Config> Pallet<T> {
724726
coldkeys, // coldkey per UID
725727
axons, // Axon information per UID.
726728
identities,
727-
active: Active::<T>::get(netuid), // Avtive per UID
729+
active: Active::<T>::get(netuid), // Active per UID
728730
validator_permit: ValidatorPermit::<T>::get(netuid), // Val permit per UID
729731
pruning_score: PruningScores::<T>::get(netuid)
730732
.into_iter()
@@ -808,6 +810,10 @@ impl<T: Config> Pallet<T> {
808810
) -> SelectiveMetagraph<T::AccountId> {
809811
match SelectiveMetagraphIndex::from_index(metagraph_index as usize) {
810812
// Name and symbol
813+
Some(SelectiveMetagraphIndex::Netuid) => SelectiveMetagraph {
814+
netuid: netuid.into(),
815+
..Default::default()
816+
},
811817
Some(SelectiveMetagraphIndex::Name) => SelectiveMetagraph {
812818
netuid: netuid.into(),
813819
name: Some(
@@ -1166,7 +1172,7 @@ impl<T: Config> Pallet<T> {
11661172
},
11671173
Some(SelectiveMetagraphIndex::ValidatorPermit) => SelectiveMetagraph {
11681174
netuid: netuid.into(),
1169-
active: Some(ValidatorPermit::<T>::get(netuid)),
1175+
validator_permit: Some(ValidatorPermit::<T>::get(netuid)),
11701176
..Default::default()
11711177
},
11721178

@@ -1451,11 +1457,11 @@ fn test_selective_metagraph() {
14511457
metagraph.merge_value(&metagraph_name, wrong_index);
14521458
assert!(metagraph.name.is_none());
14531459

1454-
let name_index: usize = 0;
1460+
let name_index: usize = 1;
14551461
metagraph.merge_value(&metagraph_name, name_index);
14561462
assert!(metagraph.name.is_some());
14571463

1458-
let alph_low_index: usize = 49;
1464+
let alph_low_index: usize = 50;
14591465
let metagraph_alpha_low = SelectiveMetagraph::<u32> {
14601466
netuid: 0_u16.into(),
14611467
alpha_low: Some(0_u16.into()),

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
207207
// `spec_version`, and `authoring_version` are the same between Wasm and native.
208208
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
209209
// the compatible custom types.
210-
spec_version: 263,
210+
spec_version: 264,
211211
impl_version: 1,
212212
apis: RUNTIME_API_VERSIONS,
213213
transaction_version: 1,

0 commit comments

Comments
 (0)