From b5b6278f321d5a679ddc3918d70a211019721b1d Mon Sep 17 00:00:00 2001 From: open-junius Date: Wed, 27 Aug 2025 15:31:20 +0800 Subject: [PATCH 1/8] add commitments data into metagraph --- Cargo.lock | 2 +- pallets/commitments/Cargo.toml | 8 ++--- pallets/commitments/src/lib.rs | 36 ++++++++++++++++++--- pallets/subtensor/Cargo.toml | 4 +++ pallets/subtensor/src/macros/config.rs | 4 +++ pallets/subtensor/src/rpc_info/metagraph.rs | 32 +++++++++++++++++- runtime/src/lib.rs | 12 +++++-- 7 files changed, 85 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7d65c7aac9..d7ec1b6845 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7557,7 +7557,6 @@ dependencies = [ "log", "pallet-balances", "pallet-drand", - "pallet-subtensor", "parity-scale-codec", "rand_chacha 0.3.1", "scale-info", @@ -8151,6 +8150,7 @@ dependencies = [ "num-traits", "pallet-balances", "pallet-collective", + "pallet-commitments", "pallet-crowdloan", "pallet-drand", "pallet-membership", diff --git a/pallets/commitments/Cargo.toml b/pallets/commitments/Cargo.toml index bedc0d945c..351af75061 100644 --- a/pallets/commitments/Cargo.toml +++ b/pallets/commitments/Cargo.toml @@ -36,7 +36,7 @@ sha2.workspace = true log.workspace = true -pallet-subtensor.workspace = true +# pallet-subtensor.workspace = true subtensor-runtime-common.workspace = true [dev-dependencies] @@ -57,7 +57,7 @@ std = [ "log/std", "pallet-balances/std", "pallet-drand/std", - "pallet-subtensor/std", + # "pallet-subtensor/std", "rand_chacha/std", "scale-info/std", "sha2/std", @@ -76,7 +76,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-drand/runtime-benchmarks", - "pallet-subtensor/runtime-benchmarks", + # "pallet-subtensor/runtime-benchmarks", ] try-runtime = [ "frame-support/try-runtime", @@ -84,5 +84,5 @@ try-runtime = [ "pallet-balances/try-runtime", "sp-runtime/try-runtime", "pallet-drand/try-runtime", - "pallet-subtensor/try-runtime", + # "pallet-subtensor/try-runtime", ] diff --git a/pallets/commitments/src/lib.rs b/pallets/commitments/src/lib.rs index 34192b6fa2..579e9dacab 100644 --- a/pallets/commitments/src/lib.rs +++ b/pallets/commitments/src/lib.rs @@ -10,12 +10,12 @@ mod mock; pub mod types; pub mod weights; -pub use pallet::*; -pub use types::*; -pub use weights::WeightInfo; - use ark_serialize::CanonicalDeserialize; +use codec::Encode; +use frame_support::IterableStorageDoubleMap; use frame_support::{BoundedVec, traits::Currency}; +use frame_system::pallet_prelude::BlockNumberFor; +pub use pallet::*; use scale_info::prelude::collections::BTreeSet; use sp_runtime::SaturatedConversion; use sp_runtime::{Saturating, traits::Zero}; @@ -26,7 +26,9 @@ use tle::{ stream_ciphers::AESGCMStreamCipherProvider, tlock::{TLECiphertext, tld}, }; +pub use types::*; use w3f_bls::EngineBLS; +pub use weights::WeightInfo; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; @@ -130,7 +132,7 @@ pub mod pallet { /// Identity data by account #[pallet::storage] #[pallet::getter(fn commitment_of)] - pub(super) type CommitmentOf = StorageDoubleMap< + pub type CommitmentOf = StorageDoubleMap< _, Identity, NetUid, @@ -537,4 +539,28 @@ impl Pallet { Ok(()) } + pub fn get_commitments(netuid: NetUid) -> Vec<(T::AccountId, Vec)> { + let commitments: Vec<(T::AccountId, Vec)> = + as IterableStorageDoubleMap< + NetUid, + T::AccountId, + Registration, T::MaxFields, BlockNumberFor>, + >>::iter_prefix(netuid) + .map(|(account, registration)| { + let bytes = registration.encode(); + (account, bytes) + }) + .collect(); + commitments + } +} + +pub trait GetCommitments { + fn get_commitments(netuid: NetUid) -> Vec<(AccountId, Vec)>; +} + +impl GetCommitments for () { + fn get_commitments(_netuid: NetUid) -> Vec<(AccountId, Vec)> { + Vec::new() + } } diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index 44d873c8a6..6734ba6883 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -47,6 +47,7 @@ runtime-common.workspace = true subtensor-runtime-common = { workspace = true, features = ["approx"] } pallet-drand.workspace = true +pallet-commitments.workspace = true pallet-collective.workspace = true pallet-membership.workspace = true hex-literal.workspace = true @@ -87,6 +88,7 @@ std = [ "ndarray/std", "num-traits/std", "pallet-balances/std", + "pallet-commitments/std", "pallet-collective/std", "pallet-drand/std", "pallet-membership/std", @@ -132,6 +134,7 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-collective/runtime-benchmarks", + "pallet-commitments/runtime-benchmarks", "pallet-drand/runtime-benchmarks", "pallet-membership/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", @@ -156,6 +159,7 @@ try-runtime = [ "sp-runtime/try-runtime", "pallet-collective/try-runtime", "pallet-drand/try-runtime", + "pallet-commitments/try-runtime", "pallet-proxy/try-runtime", "pallet-crowdloan/try-runtime", "runtime-common/try-runtime" diff --git a/pallets/subtensor/src/macros/config.rs b/pallets/subtensor/src/macros/config.rs index 3479ad8101..8a794a550c 100644 --- a/pallets/subtensor/src/macros/config.rs +++ b/pallets/subtensor/src/macros/config.rs @@ -6,6 +6,7 @@ use frame_support::pallet_macros::pallet_section; #[pallet_section] mod config { + use pallet_commitments::GetCommitments; use subtensor_swap_interface::SwapHandler; /// Configure the pallet by specifying the parameters and types on which it depends. @@ -58,6 +59,9 @@ mod config { /// Interface to allow interacting with the proxy pallet. type ProxyInterface: crate::ProxyInterface; + /// Interface to get commitments. + type GetCommitments: GetCommitments; + /// ================================= /// ==== Initial Value Constants ==== /// ================================= diff --git a/pallets/subtensor/src/rpc_info/metagraph.rs b/pallets/subtensor/src/rpc_info/metagraph.rs index 7f9dc46bee..45a6614ba3 100644 --- a/pallets/subtensor/src/rpc_info/metagraph.rs +++ b/pallets/subtensor/src/rpc_info/metagraph.rs @@ -4,6 +4,7 @@ use crate::epoch::math::*; use codec::Compact; use frame_support::IterableStorageDoubleMap; use frame_support::pallet_prelude::{Decode, Encode}; +use pallet_commitments::GetCommitments; use substrate_fixed::types::I64F64; use substrate_fixed::types::I96F32; use subtensor_macros::freeze_struct; @@ -109,7 +110,7 @@ pub struct Metagraph { alpha_dividends_per_hotkey: Vec<(AccountId, Compact)>, // List of dividend payout in alpha via subnet. } -#[freeze_struct("7604bd3817c55848")] +#[freeze_struct("56156d51c66190e8")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct SelectiveMetagraph { // Subnet index @@ -210,6 +211,8 @@ pub struct SelectiveMetagraph { // validators validators: Option>>, // List of validators + // commitments + commitments: Option>)>>, // List of commitments } impl SelectiveMetagraph @@ -367,6 +370,9 @@ where self.alpha_dividends_per_hotkey = other.alpha_dividends_per_hotkey.clone() } Some(SelectiveMetagraphIndex::Validators) => self.validators = other.validators.clone(), + Some(SelectiveMetagraphIndex::Commitments) => { + self.commitments = other.commitments.clone() + } None => {} }; } @@ -451,6 +457,7 @@ where tao_dividends_per_hotkey: None, alpha_dividends_per_hotkey: None, validators: None, + commitments: None, } } } @@ -529,6 +536,7 @@ pub enum SelectiveMetagraphIndex { TaoDividendsPerHotkey, AlphaDividendsPerHotkey, Validators, + Commitments, } impl SelectiveMetagraphIndex { @@ -607,6 +615,7 @@ impl SelectiveMetagraphIndex { 70 => Some(SelectiveMetagraphIndex::TaoDividendsPerHotkey), 71 => Some(SelectiveMetagraphIndex::AlphaDividendsPerHotkey), 72 => Some(SelectiveMetagraphIndex::Validators), + 73 => Some(SelectiveMetagraphIndex::Commitments), _ => None, } } @@ -1367,6 +1376,7 @@ impl Pallet { } } Some(SelectiveMetagraphIndex::Validators) => Self::get_validators(netuid), + Some(SelectiveMetagraphIndex::Commitments) => Self::get_commitments(netuid), None => SelectiveMetagraph { // Subnet index netuid: netuid.into(), @@ -1413,6 +1423,25 @@ impl Pallet { ..Default::default() } } + + fn get_commitments(netuid: NetUid) -> SelectiveMetagraph { + let commitments = ::GetCommitments::get_commitments(netuid); + let commitments: Vec<(T::AccountId, Vec>)> = commitments + .iter() + .map(|(account, commitment)| { + let compact_commitment = commitment + .iter() + .map(|c| Compact::from(c.clone())) + .collect::>>(); + (account.clone(), compact_commitment) + }) + .collect(); + + SelectiveMetagraph { + commitments: Some(commitments), + ..Default::default() + } + } } #[test] @@ -1492,6 +1521,7 @@ fn test_selective_metagraph() { tao_dividends_per_hotkey: None, alpha_dividends_per_hotkey: None, validators: None, + commitments: None, }; // test init value diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 60687d3a30..b78bf0b206 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -83,13 +83,13 @@ pub use frame_support::{ }; pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; +use pallet_commitments::GetCommitments; pub use pallet_timestamp::Call as TimestampCall; use pallet_transaction_payment::{ConstFeeMultiplier, Multiplier}; -use subtensor_transaction_fee::{SubtensorTxFeeHandler, TransactionFeeHandler}; - #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; pub use sp_runtime::{Perbill, Permill}; +use subtensor_transaction_fee::{SubtensorTxFeeHandler, TransactionFeeHandler}; use core::marker::PhantomData; @@ -1068,6 +1068,13 @@ impl OnMetadataCommitment for ResetBondsOnCommit { fn on_metadata_commitment(_: NetUid, _: &AccountId) {} } +pub struct GetCommitmentsStruct; +impl GetCommitments for GetCommitmentsStruct { + fn get_commitments(netuid: NetUid) -> Vec<(AccountId, Vec)> { + pallet_commitments::Pallet::::get_commitments(netuid) + } +} + impl pallet_commitments::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; @@ -1239,6 +1246,7 @@ impl pallet_subtensor::Config for Runtime { type HotkeySwapOnSubnetInterval = HotkeySwapOnSubnetInterval; type ProxyInterface = Proxier; type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval; + type GetCommitments = GetCommitmentsStruct; } parameter_types! { From 7e370319dd8799396e3439f68996b0994cab35d3 Mon Sep 17 00:00:00 2001 From: open-junius Date: Wed, 27 Aug 2025 15:41:10 +0800 Subject: [PATCH 2/8] commit Cargo.lock --- pallets/subtensor/src/rpc_info/metagraph.rs | 2 +- pallets/subtensor/src/tests/mock.rs | 1 + pallets/transaction-fee/src/tests/mock.rs | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pallets/subtensor/src/rpc_info/metagraph.rs b/pallets/subtensor/src/rpc_info/metagraph.rs index 45a6614ba3..1ad09d4bbb 100644 --- a/pallets/subtensor/src/rpc_info/metagraph.rs +++ b/pallets/subtensor/src/rpc_info/metagraph.rs @@ -1431,7 +1431,7 @@ impl Pallet { .map(|(account, commitment)| { let compact_commitment = commitment .iter() - .map(|c| Compact::from(c.clone())) + .map(|c| Compact::from(*c)) .collect::>>(); (account.clone(), compact_commitment) }) diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index 8aa6fe6cdd..f298f4743c 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -454,6 +454,7 @@ impl crate::Config for Test { type HotkeySwapOnSubnetInterval = HotkeySwapOnSubnetInterval; type ProxyInterface = FakeProxier; type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval; + type GetCommitments = (); } // Swap-related parameter types diff --git a/pallets/transaction-fee/src/tests/mock.rs b/pallets/transaction-fee/src/tests/mock.rs index c2f5caa432..8db3fd9155 100644 --- a/pallets/transaction-fee/src/tests/mock.rs +++ b/pallets/transaction-fee/src/tests/mock.rs @@ -288,6 +288,7 @@ impl pallet_subtensor::Config for Test { type HotkeySwapOnSubnetInterval = HotkeySwapOnSubnetInterval; type ProxyInterface = (); type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval; + type GetCommitments = (); } parameter_types! { From f8807763a6e6a1a8b1d53d38d26c15f19ce864c5 Mon Sep 17 00:00:00 2001 From: open-junius Date: Wed, 27 Aug 2025 15:41:54 +0800 Subject: [PATCH 3/8] cargo clippy --- pallets/admin-utils/src/tests/mock.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pallets/admin-utils/src/tests/mock.rs b/pallets/admin-utils/src/tests/mock.rs index 35934bc846..c90b1d56c0 100644 --- a/pallets/admin-utils/src/tests/mock.rs +++ b/pallets/admin-utils/src/tests/mock.rs @@ -223,6 +223,7 @@ impl pallet_subtensor::Config for Test { type HotkeySwapOnSubnetInterval = HotkeySwapOnSubnetInterval; type ProxyInterface = (); type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval; + type GetCommitments = (); } parameter_types! { From 31d9118053ba763e62ee991fc118a70a19a53b3d Mon Sep 17 00:00:00 2001 From: open-junius Date: Wed, 27 Aug 2025 15:50:00 +0800 Subject: [PATCH 4/8] bump runtime --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index b78bf0b206..65c46b96f6 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 306, + spec_version: 307, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From a4ed4838ad40407a692ebeb778034ac82e105a19 Mon Sep 17 00:00:00 2001 From: open-junius Date: Wed, 27 Aug 2025 17:26:28 +0800 Subject: [PATCH 5/8] convert unused code change --- pallets/commitments/Cargo.toml | 5 ----- pallets/commitments/src/lib.rs | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/pallets/commitments/Cargo.toml b/pallets/commitments/Cargo.toml index 351af75061..d2873673bc 100644 --- a/pallets/commitments/Cargo.toml +++ b/pallets/commitments/Cargo.toml @@ -35,8 +35,6 @@ hex.workspace = true sha2.workspace = true log.workspace = true - -# pallet-subtensor.workspace = true subtensor-runtime-common.workspace = true [dev-dependencies] @@ -57,7 +55,6 @@ std = [ "log/std", "pallet-balances/std", "pallet-drand/std", - # "pallet-subtensor/std", "rand_chacha/std", "scale-info/std", "sha2/std", @@ -76,7 +73,6 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-drand/runtime-benchmarks", - # "pallet-subtensor/runtime-benchmarks", ] try-runtime = [ "frame-support/try-runtime", @@ -84,5 +80,4 @@ try-runtime = [ "pallet-balances/try-runtime", "sp-runtime/try-runtime", "pallet-drand/try-runtime", - # "pallet-subtensor/try-runtime", ] diff --git a/pallets/commitments/src/lib.rs b/pallets/commitments/src/lib.rs index 579e9dacab..fbce46f710 100644 --- a/pallets/commitments/src/lib.rs +++ b/pallets/commitments/src/lib.rs @@ -132,7 +132,7 @@ pub mod pallet { /// Identity data by account #[pallet::storage] #[pallet::getter(fn commitment_of)] - pub type CommitmentOf = StorageDoubleMap< + pub(super) type CommitmentOf = StorageDoubleMap< _, Identity, NetUid, From a04425fdf770a6c0c852fd87984a03b2ed6ac2a9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 27 Aug 2025 11:24:00 +0000 Subject: [PATCH 6/8] auto-update benchmark weights --- pallets/subtensor/src/macros/dispatches.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 35439479ab..7dc0aad8fb 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -120,9 +120,9 @@ mod dispatches { /// - On failure for each failed item in the batch. /// #[pallet::call_index(80)] - #[pallet::weight((Weight::from_parts(95_160_000, 0) - .saturating_add(T::DbWeight::get().reads(14)) - .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] + #[pallet::weight((Weight::from_parts(19_580_000, 0) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(0_u64)), DispatchClass::Normal, Pays::No))] pub fn batch_set_weights( origin: OriginFor, netuids: Vec>, From 5d8926fd5ef93f68b3c4d959a77a629ca1191870 Mon Sep 17 00:00:00 2001 From: open-junius Date: Tue, 2 Sep 2025 20:39:53 +0800 Subject: [PATCH 7/8] bump version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 65c46b96f6..9892ae3f9c 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 307, + spec_version: 308, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From c60f7d8e33850e571ea473db7b8cb61747a3de04 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 2 Sep 2025 14:49:01 +0000 Subject: [PATCH 8/8] auto-update benchmark weights --- pallets/subtensor/src/macros/dispatches.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 46b4aaf92b..d59b0415d0 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -120,9 +120,9 @@ mod dispatches { /// - On failure for each failed item in the batch. /// #[pallet::call_index(80)] - #[pallet::weight((Weight::from_parts(19_330_000, 0) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(0_u64)), DispatchClass::Normal, Pays::No))] + #[pallet::weight((Weight::from_parts(94_280_000, 0) + .saturating_add(T::DbWeight::get().reads(14_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)), DispatchClass::Normal, Pays::No))] pub fn batch_set_weights( origin: OriginFor, netuids: Vec>,