diff --git a/Cargo.lock b/Cargo.lock index 90c2fb86fb..964c583e13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1550,9 +1550,9 @@ dependencies = [ [[package]] name = "crossbeam-queue" -version = "0.3.11" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" dependencies = [ "crossbeam-utils", ] @@ -2187,9 +2187,9 @@ checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" dependencies = [ "crunchy", "fixed-hash", - "impl-codec 0.6.0", + "impl-codec", "impl-rlp", - "impl-serde 0.4.0", + "impl-serde", "scale-info", "tiny-keccak", ] @@ -2220,12 +2220,12 @@ checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" dependencies = [ "ethbloom", "fixed-hash", - "impl-codec 0.6.0", + "impl-codec", "impl-rlp", - "impl-serde 0.4.0", - "primitive-types 0.12.2", + "impl-serde", + "primitive-types", "scale-info", - "uint 0.9.5", + "uint", ] [[package]] @@ -2269,7 +2269,7 @@ dependencies = [ "evm-runtime", "log", "parity-scale-codec", - "primitive-types 0.12.2", + "primitive-types", "rlp", "scale-info", "serde", @@ -2283,7 +2283,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d1da6cedc5cedb4208e59467106db0d1f50db01b920920589f8e672c02fdc04f" dependencies = [ "parity-scale-codec", - "primitive-types 0.12.2", + "primitive-types", "scale-info", "serde", ] @@ -2297,7 +2297,7 @@ dependencies = [ "environmental", "evm-core", "evm-runtime", - "primitive-types 0.12.2", + "primitive-types", ] [[package]] @@ -2309,7 +2309,7 @@ dependencies = [ "auto_impl", "environmental", "evm-core", - "primitive-types 0.12.2", + "primitive-types", "sha3", ] @@ -2694,7 +2694,7 @@ version = "1.0.0-dev" source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "hex", - "impl-serde 0.4.0", + "impl-serde", "libsecp256k1", "log", "parity-scale-codec", @@ -3876,26 +3876,6 @@ dependencies = [ "parity-scale-codec", ] -[[package]] -name = "impl-codec" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67aa010c1e3da95bf151bd8b4c059b2ed7e75387cdb969b4f8f2723a43f9941" -dependencies = [ - "parity-scale-codec", -] - -[[package]] -name = "impl-num-traits" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "803d15461ab0dcc56706adf266158acbc44ccf719bf7d0af30705f58b90a4b8c" -dependencies = [ - "integer-sqrt", - "num-traits", - "uint 0.10.0", -] - [[package]] name = "impl-rlp" version = "0.3.0" @@ -3914,15 +3894,6 @@ dependencies = [ "serde", ] -[[package]] -name = "impl-serde" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a143eada6a1ec4aefa5049037a26a6d597bfd64f8c026d07b77133e02b7dd0b" -dependencies = [ - "serde", -] - [[package]] name = "impl-trait-for-tuples" version = "0.2.2" @@ -4459,7 +4430,7 @@ dependencies = [ "sha2 0.10.8", "smallvec", "thiserror", - "uint 0.9.5", + "uint", "unsigned-varint 0.7.2", "void", ] @@ -4921,7 +4892,7 @@ dependencies = [ "tokio-util", "tracing", "trust-dns-resolver", - "uint 0.9.5", + "uint", "unsigned-varint 0.8.0", "url", "webpki", @@ -6664,7 +6635,7 @@ dependencies = [ "lru 0.8.1", "parity-util-mem-derive", "parking_lot 0.12.3", - "primitive-types 0.12.2", + "primitive-types", "smallvec", "winapi", ] @@ -6906,7 +6877,7 @@ dependencies = [ "libc", "log", "polkavm-assembler", - "polkavm-common 0.9.0", + "polkavm-common", "polkavm-linux-raw", ] @@ -6928,28 +6899,13 @@ dependencies = [ "log", ] -[[package]] -name = "polkavm-common" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f0dbafef4ab6ceecb4982ac3b550df430ef4f9fdbf07c108b7d4f91a0682fce" - [[package]] name = "polkavm-derive" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae8c4bea6f3e11cd89bb18bcdddac10bd9a24015399bd1c485ad68a985a19606" dependencies = [ - "polkavm-derive-impl-macro 0.9.0", -] - -[[package]] -name = "polkavm-derive" -version = "0.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "206caf322dfc02144510ad8360ff2051e5072f0874dcab3b410f78cdd52d0ebb" -dependencies = [ - "polkavm-derive-impl-macro 0.17.0", + "polkavm-derive-impl-macro", ] [[package]] @@ -6958,19 +6914,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c4fdfc49717fb9a196e74a5d28e0bc764eb394a2c803eb11133a31ac996c60c" dependencies = [ - "polkavm-common 0.9.0", - "proc-macro2", - "quote", - "syn 2.0.90", -] - -[[package]] -name = "polkavm-derive-impl" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42565aed4adbc4034612d0b17dea8db3681fb1bd1aed040d6edc5455a9f478a1" -dependencies = [ - "polkavm-common 0.17.0", + "polkavm-common", "proc-macro2", "quote", "syn 2.0.90", @@ -6982,17 +6926,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ - "polkavm-derive-impl 0.9.0", - "syn 2.0.90", -] - -[[package]] -name = "polkavm-derive-impl-macro" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d9838e95241b0bce4fe269cdd4af96464160505840ed5a8ac8536119ba19e2" -dependencies = [ - "polkavm-derive-impl 0.17.0", + "polkavm-derive-impl", "syn 2.0.90", ] @@ -7006,7 +6940,7 @@ dependencies = [ "hashbrown 0.14.5", "log", "object 0.32.2", - "polkavm-common 0.9.0", + "polkavm-common", "regalloc2 0.9.3", "rustc-demangle", ] @@ -7143,23 +7077,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" dependencies = [ "fixed-hash", - "impl-codec 0.6.0", + "impl-codec", "impl-rlp", - "impl-serde 0.4.0", + "impl-serde", "scale-info", - "uint 0.9.5", -] - -[[package]] -name = "primitive-types" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d15600a7d856470b7d278b3fe0e311fe28c2526348549f8ef2ff7db3299c87f5" -dependencies = [ - "fixed-hash", - "impl-codec 0.7.0", - "impl-num-traits", - "uint 0.10.0", + "uint", ] [[package]] @@ -9405,9 +9327,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" dependencies = [ "serde_derive", ] @@ -9442,9 +9364,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" dependencies = [ "proc-macro2", "quote", @@ -9936,7 +9858,7 @@ dependencies = [ "futures", "hash-db", "hash256-std-hasher", - "impl-serde 0.4.0", + "impl-serde", "itertools 0.11.0", "k256", "libsecp256k1", @@ -9946,7 +9868,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.3", "paste", - "primitive-types 0.12.2", + "primitive-types", "rand", "scale-info", "schnorrkel", @@ -9970,7 +9892,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#44766de645c741fd03d159fca7f17cd6e99c33e3" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -10066,7 +9988,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#44766de645c741fd03d159fca7f17cd6e99c33e3" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "proc-macro2", "quote", @@ -10076,7 +9998,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#44766de645c741fd03d159fca7f17cd6e99c33e3" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "environmental", "parity-scale-codec", @@ -10129,7 +10051,7 @@ dependencies = [ "libsecp256k1", "log", "parity-scale-codec", - "polkavm-derive 0.9.1", + "polkavm-derive", "rustversion", "secp256k1", "sp-core", @@ -10254,13 +10176,13 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#44766de645c741fd03d159fca7f17cd6e99c33e3" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "bytes", "impl-trait-for-tuples", "parity-scale-codec", - "polkavm-derive 0.17.1", - "primitive-types 0.13.1", + "polkavm-derive", + "primitive-types", "sp-externalities 0.25.0", "sp-runtime-interface-proc-macro 17.0.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", @@ -10278,8 +10200,8 @@ dependencies = [ "bytes", "impl-trait-for-tuples", "parity-scale-codec", - "polkavm-derive 0.9.1", - "primitive-types 0.12.2", + "polkavm-derive", + "primitive-types", "sp-externalities 0.29.0", "sp-runtime-interface-proc-macro 18.0.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409)", @@ -10292,7 +10214,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#44766de645c741fd03d159fca7f17cd6e99c33e3" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "Inflector", "expander", @@ -10394,14 +10316,14 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#44766de645c741fd03d159fca7f17cd6e99c33e3" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#44766de645c741fd03d159fca7f17cd6e99c33e3" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ - "impl-serde 0.5.0", + "impl-serde", "parity-scale-codec", "ref-cast", "serde", @@ -10413,7 +10335,7 @@ name = "sp-storage" version = "21.0.0" source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409#87971b3e92721bdf10bf40b410eaae779d494ca0" dependencies = [ - "impl-serde 0.4.0", + "impl-serde", "parity-scale-codec", "ref-cast", "serde", @@ -10435,7 +10357,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#44766de645c741fd03d159fca7f17cd6e99c33e3" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "parity-scale-codec", "tracing", @@ -10505,7 +10427,7 @@ name = "sp-version" version = "37.0.0" source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409#87971b3e92721bdf10bf40b410eaae779d494ca0" dependencies = [ - "impl-serde 0.4.0", + "impl-serde", "parity-scale-codec", "parity-wasm", "scale-info", @@ -10531,7 +10453,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#44766de645c741fd03d159fca7f17cd6e99c33e3" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -11705,18 +11627,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "uint" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909988d098b2f738727b161a106cfc7cab00c539c2687a8836f8e565976fb53e" -dependencies = [ - "byteorder", - "crunchy", - "hex", - "static_assertions", -] - [[package]] name = "unicode-bidi" version = "0.3.17" diff --git a/pallets/subtensor/rpc/src/lib.rs b/pallets/subtensor/rpc/src/lib.rs index 5b4c7777af..cdbcebcacb 100644 --- a/pallets/subtensor/rpc/src/lib.rs +++ b/pallets/subtensor/rpc/src/lib.rs @@ -55,6 +55,10 @@ pub trait SubtensorCustomApi { fn get_all_dynamic_info(&self, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getDynamicInfo")] fn get_dynamic_info(&self, netuid: u16, at: Option) -> RpcResult>; + #[method(name = "subnetInfo_getAllMetagraphs")] + fn get_all_metagraphs(&self, at: Option) -> RpcResult>; + #[method(name = "subnetInfo_getMetagraph")] + fn get_metagraph(&self, netuid: u16, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getSubnetState")] fn get_subnet_state(&self, netuid: u16, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getLockCost")] @@ -223,6 +227,13 @@ where }) } + fn get_all_metagraphs(&self, at: Option<::Hash>) -> RpcResult> { + let api = self.client.runtime_api(); + let at = at.unwrap_or_else(|| self.client.info().best_hash); + api.get_all_metagraphs(at) + .map_err(|e| Error::RuntimeError(format!("Unable to get metagraps: {:?}", e)).into()) + } + fn get_dynamic_info( &self, netuid: u16, @@ -235,6 +246,18 @@ where }) } + fn get_metagraph( + &self, + netuid: u16, + at: Option<::Hash>, + ) -> RpcResult> { + let api = self.client.runtime_api(); + let at = at.unwrap_or_else(|| self.client.info().best_hash); + api.get_metagraph(at, netuid).map_err(|e| { + Error::RuntimeError(format!("Unable to get dynamic subnets info: {:?}", e)).into() + }) + } + fn get_subnet_state( &self, netuid: u16, diff --git a/pallets/subtensor/runtime-api/src/lib.rs b/pallets/subtensor/runtime-api/src/lib.rs index 85adada680..cdcd6ed390 100644 --- a/pallets/subtensor/runtime-api/src/lib.rs +++ b/pallets/subtensor/runtime-api/src/lib.rs @@ -25,6 +25,8 @@ sp_api::decl_runtime_apis! { fn get_subnets_info_v2() -> Vec; fn get_subnet_hyperparams(netuid: u16) -> Vec; fn get_all_dynamic_info() -> Vec; + fn get_all_metagraphs() -> Vec; + fn get_metagraph(netuid: u16) -> Vec; fn get_dynamic_info(netuid: u16) -> Vec; fn get_subnet_state(netuid: u16) -> Vec; } diff --git a/pallets/subtensor/src/rpc_info/metagraph.rs b/pallets/subtensor/src/rpc_info/metagraph.rs new file mode 100644 index 0000000000..091c7e259c --- /dev/null +++ b/pallets/subtensor/src/rpc_info/metagraph.rs @@ -0,0 +1,287 @@ +use super::*; +extern crate alloc; +use crate::epoch::math::*; +use codec::Compact; +use frame_support::pallet_prelude::{Decode, Encode}; +use substrate_fixed::types::I64F64; +use subtensor_macros::freeze_struct; + +#[freeze_struct("eff674535ea437ae")] +#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] +pub struct Metagraph { + // Subnet index + netuid: Compact, + + // Name and symbol + name: Vec>, // name + symbol: Vec>, // token symbol + identity: Option, // identity information. + network_registered_at: Compact, // block at registration + + // Keys for owner. + owner_hotkey: T::AccountId, // hotkey + owner_coldkey: T::AccountId, // coldkey. + + // Tempo terms. + block: Compact, // block at call. + tempo: Compact, // epoch tempo + last_step: Compact, // last epoch + blocks_since_last_step: Compact, // blocks since last epoch. + + // Subnet emission terms + subnet_emission: Compact, // subnet emission via stao + alpha_in: Compact, // amount of alpha in reserve + alpha_out: Compact, // amount of alpha outstanding + tao_in: Compact, // amount of tao injected per block + alpha_out_emission: Compact, // amount injected in alpha reserves per block + alpha_in_emission: Compact, // amount injected outstanding per block + tao_in_emission: Compact, // amount of tao injected per block + pending_alpha_emission: Compact, // pending alpha to be distributed + pending_root_emission: Compact, // panding tao for root divs to be distributed + + // Hparams for epoch + rho: Compact, // subnet rho param + kappa: Compact, // subnet kappa param + + // Validator params + min_allowed_weights: Compact, // min allowed weights per val + max_weights_limit: Compact, // max allowed weights per val + weights_version: Compact, // allowed weights version + weights_rate_limit: Compact, // rate limit on weights. + activity_cutoff: Compact, // validator weights cut off period in blocks + max_validators: Compact, // max allowed validators. + + // Registration + num_uids: Compact, + max_uids: Compact, + burn: Compact, // current burn cost.. + difficulty: Compact, // current difficulty. + registration_allowed: bool, // allows registrations. + pow_registration_allowed: bool, // pow registration enabled. + immunity_period: Compact, // subnet miner immunity period + min_difficulty: Compact, // min pow difficulty + max_difficulty: Compact, // max pow difficulty + min_burn: Compact, // min tao burn + max_burn: Compact, // max tao burn + adjustment_alpha: Compact, // adjustment speed for registration params. + adjustment_interval: Compact, // pow and burn adjustment interval + target_regs_per_interval: Compact, // target registrations per interval + max_regs_per_block: Compact, // max registrations per block. + serving_rate_limit: Compact, // axon serving rate limit + + // CR + commit_reveal_weights_enabled: bool, // Is CR enabled. + commit_reveal_period: Compact, // Commit reveal interval + + // Bonds + liquid_alpha_enabled: bool, // Bonds liquid enabled. + alpha_high: Compact, // Alpha param high + alpha_low: Compact, // Alpha param low + bonds_moving_avg: Compact, // Bonds moving avg + + // Metagraph info. + hotkeys: Vec, // hotkey per UID + coldkeys: Vec, // coldkey per UID + identities: Vec, // coldkeys identities + axons: Vec, // UID axons. + active: Vec, // Avtive per UID + validator_permit: Vec, // Val permit per UID + pruning_score: Vec>, // Pruning per UID + last_update: Vec>, // Last update per UID + emission: Vec>, // Emission per UID + dividends: Vec>, // Dividends per UID + incentives: Vec>, // Mining incentives per UID + consensus: Vec>, // Consensus per UID + trust: Vec>, // Trust per UID + rank: Vec>, // Rank per UID + block_at_registration: Vec>, // Reg block per UID + alpha_stake: Vec>, // Alpha staked per UID + tao_stake: Vec>, // TAO staked per UID + total_stake: Vec>, // Total stake per UID + + // Dividend break down. + tao_dividends_per_hotkey: Vec<(T::AccountId, Compact)>, // List of dividend payouts in tao via root. + alpha_dividends_per_hotkey: Vec<(T::AccountId, Compact)>, // List of dividend payout in alpha via subnet. +} + +impl Pallet { + pub fn get_metagraph(netuid: u16) -> Option> { + if !Self::if_subnet_exist(netuid) { + return None; + } + + let n: u16 = Self::get_subnetwork_n(netuid); + let mut hotkeys: Vec = vec![]; + let mut coldkeys: Vec = vec![]; + let mut block_at_registration: Vec> = vec![]; + let mut identities: Vec = vec![]; + let mut axons: Vec = vec![]; + for uid in 0..n { + let hotkey = Keys::::get(netuid, uid); + let coldkey = Owner::::get(hotkey.clone()); + hotkeys.push(hotkey.clone()); + coldkeys.push(coldkey.clone()); + block_at_registration.push(BlockAtRegistration::::get(netuid, uid).into()); + identities.push(Identities::::get(coldkey.clone())?); + axons.push(Self::get_axon_info(netuid, &hotkey)); + } + let mut tao_dividends_per_hotkey: Vec<(T::AccountId, Compact)> = vec![]; + let mut alpha_dividends_per_hotkey: Vec<(T::AccountId, Compact)> = vec![]; + for hotkey in hotkeys.clone() { + let tao_divs = TaoDividendsPerSubnet::::get(netuid, hotkey.clone()); + let alpha_divs = AlphaDividendsPerSubnet::::get(netuid, hotkey.clone()); + tao_dividends_per_hotkey.push((hotkey.clone(), tao_divs.into())); + alpha_dividends_per_hotkey.push((hotkey.clone(), alpha_divs.into())); + } + let current_block: u64 = Pallet::::get_current_block_as_u64(); + let last_step = LastMechansimStepBlock::::get(netuid); + let blocks_since_last_step: u64 = current_block.saturating_sub(last_step); + let (total_stake_fl, alpha_stake_fl, tao_stake_fl): ( + Vec, + Vec, + Vec, + ) = Self::get_stake_weights_for_network(netuid); + Some(Metagraph { + // Subnet index + netuid: netuid.into(), // subnet index. + + // Name and symbol + name: Self::get_name_for_subnet(netuid) + .into_iter() + .map(Compact) + .collect(), // Name + symbol: Self::get_symbol_for_subnet(netuid) + .into_iter() + .map(Compact) + .collect(), // Symbol. + identity: SubnetIdentities::::get(netuid), // identity information. + network_registered_at: NetworkRegisteredAt::::get(netuid).into(), // block at registration + + // Keys for owner. + owner_hotkey: SubnetOwnerHotkey::::get(netuid), // Owner hotkey + owner_coldkey: SubnetOwner::::get(netuid), // Owner Coldkey + + // Tempo terms. + block: current_block.into(), // Block at call. + tempo: Self::get_tempo(netuid).into(), // epoch tempo + last_step: LastMechansimStepBlock::::get(netuid).into(), // last epoch + blocks_since_last_step: blocks_since_last_step.into(), // blocks since last epoch. + + // Subnet emission terms + subnet_emission: EmissionValues::::get(netuid).into(), // subnet emission via stao + alpha_in: SubnetAlphaIn::::get(netuid).into(), // amount of alpha in reserve + alpha_out: SubnetAlphaOut::::get(netuid).into(), // amount of alpha outstanding + tao_in: SubnetTAO::::get(netuid).into(), // amount of tao injected per block + alpha_out_emission: SubnetAlphaOutEmission::::get(netuid).into(), // amount injected in alpha reserves per block + alpha_in_emission: SubnetAlphaInEmission::::get(netuid).into(), // amount injected outstanding per block + tao_in_emission: SubnetTaoInEmission::::get(netuid).into(), // amount of tao injected per block + pending_alpha_emission: PendingEmission::::get(netuid).into(), // pending alpha to be distributed + pending_root_emission: PendingRootDivs::::get(netuid).into(), // panding tao for root divs to be distributed + + // Hparams for epoch + rho: Self::get_rho(netuid).into(), // subnet rho param + kappa: Self::get_kappa(netuid).into(), // subnet kappa param + + // Validator params + min_allowed_weights: Self::get_min_allowed_weights(netuid).into(), // min allowed weights per val + max_weights_limit: Self::get_max_weight_limit(netuid).into(), // max allowed weight + weights_version: Self::get_weights_version_key(netuid).into(), // allowed weights version + weights_rate_limit: Self::get_weights_set_rate_limit(netuid).into(), // rate limit on weights. + activity_cutoff: Self::get_activity_cutoff(netuid).into(), // validator weights cut off period in blocks + max_validators: Self::get_max_allowed_validators(netuid).into(), // max allowed validators. + + // Registration + num_uids: Self::get_subnetwork_n(netuid).into(), + max_uids: Self::get_max_allowed_uids(netuid).into(), + registration_allowed: Self::get_network_registration_allowed(netuid), // allows registrations. + pow_registration_allowed: Self::get_network_pow_registration_allowed(netuid), // allows pow registrations. + difficulty: Self::get_difficulty_as_u64(netuid).into(), // current difficulty. + burn: Self::get_burn_as_u64(netuid).into(), + immunity_period: Self::get_immunity_period(netuid).into(), // subnet miner immunity period + min_difficulty: Self::get_min_difficulty(netuid).into(), // min pow difficulty + max_difficulty: Self::get_max_difficulty(netuid).into(), // max pow difficulty + min_burn: Self::get_min_burn_as_u64(netuid).into(), // min tao burn + max_burn: Self::get_max_burn_as_u64(netuid).into(), // max tao burn + adjustment_alpha: Self::get_adjustment_alpha(netuid).into(), // adjustment speed for registration params. + adjustment_interval: Self::get_adjustment_interval(netuid).into(), // pow and burn adjustment interval + target_regs_per_interval: Self::get_target_registrations_per_interval(netuid).into(), // target registrations per interval + max_regs_per_block: Self::get_max_registrations_per_block(netuid).into(), // max registrations per block. + serving_rate_limit: Self::get_serving_rate_limit(netuid).into(), // axon serving rate limit + + // CR + commit_reveal_weights_enabled: Self::get_commit_reveal_weights_enabled(netuid), // Is CR enabled. + commit_reveal_period: Self::get_reveal_period(netuid).into(), // Commit reveal interval + + // Bonds + liquid_alpha_enabled: Self::get_liquid_alpha_enabled(netuid), // Bonds liquid enabled. + alpha_high: Self::get_alpha_values(netuid).1.into(), // Alpha param high + alpha_low: Self::get_alpha_values(netuid).0.into(), // Alpha param low + bonds_moving_avg: Self::get_bonds_moving_average(netuid).into(), // Bonds moving avg + + // Metagraph info. + hotkeys, // hotkey per UID + coldkeys, // coldkey per UID + axons, // Axon information per UID. + identities, + active: Active::::get(netuid), // Avtive per UID + validator_permit: ValidatorPermit::::get(netuid), // Val permit per UID + pruning_score: PruningScores::::get(netuid) + .into_iter() + .map(Compact::from) + .collect(), // Pruning per UID + last_update: LastUpdate::::get(netuid) + .into_iter() + .map(Compact::from) + .collect(), // Last update per UID + emission: Emission::::get(netuid) + .into_iter() + .map(Compact::from) + .collect(), // Emission per UID + dividends: Dividends::::get(netuid) + .into_iter() + .map(Compact::from) + .collect(), // Dividends per UID + incentives: Incentive::::get(netuid) + .into_iter() + .map(Compact::from) + .collect(), // Mining incentives per UID + consensus: Consensus::::get(netuid) + .into_iter() + .map(Compact::from) + .collect(), // Consensus per UID + trust: Trust::::get(netuid) + .into_iter() + .map(Compact::from) + .collect(), // Trust per UID + rank: Rank::::get(netuid) + .into_iter() + .map(Compact::from) + .collect(), // Rank per UID + block_at_registration, // Reg block per UID + alpha_stake: alpha_stake_fl + .iter() + .map(|xi| Compact::from(fixed64_to_u64(*xi))) + .collect::>>(), // Alpha staked per UID + tao_stake: tao_stake_fl + .iter() + .map(|xi| Compact::from(fixed64_to_u64(*xi))) + .collect::>>(), // TAO staked per UID + total_stake: total_stake_fl + .iter() + .map(|xi| Compact::from(fixed64_to_u64(*xi))) + .collect::>>(), // Total stake per UID + + // Dividend break down. + tao_dividends_per_hotkey, + alpha_dividends_per_hotkey, + }) + } + pub fn get_all_metagraphs() -> Vec>> { + let netuids: Vec = Self::get_all_subnet_netuids(); + let mut metagraphs = Vec::>>::new(); + for netuid in netuids.clone().iter() { + metagraphs.push(Self::get_metagraph(*netuid)); + } + metagraphs + } +} diff --git a/pallets/subtensor/src/rpc_info/mod.rs b/pallets/subtensor/src/rpc_info/mod.rs index 4c224050ec..13b2e9cbb4 100644 --- a/pallets/subtensor/src/rpc_info/mod.rs +++ b/pallets/subtensor/src/rpc_info/mod.rs @@ -1,6 +1,7 @@ use super::*; pub mod delegate_info; pub mod dynamic_info; +pub mod metagraph; pub mod neuron_info; pub mod show_subnet; pub mod stake_info; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 128d2b8f39..5c3688a510 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -2112,6 +2112,16 @@ impl_runtime_apis! { } } + fn get_metagraph(netuid: u16) -> Vec { + let _result = SubtensorModule::get_metagraph(netuid); + if _result.is_some() { + let result = _result.expect("Could not get Metagraph."); + result.encode() + } else { + vec![] + } + } + fn get_subnet_state(netuid: u16) -> Vec { let _result = SubtensorModule::get_subnet_state(netuid); if _result.is_some() { @@ -2122,6 +2132,11 @@ impl_runtime_apis! { } } + fn get_all_metagraphs() -> Vec { + let result = SubtensorModule::get_all_metagraphs(); + result.encode() + } + fn get_all_dynamic_info() -> Vec { let result = SubtensorModule::get_all_dynamic_info(); result.encode()