diff --git a/Cargo.lock b/Cargo.lock index f84f1c0839..edab4cd165 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7541,7 +7541,6 @@ dependencies = [ "log", "pallet-balances", "pallet-drand", - "pallet-subtensor", "parity-scale-codec", "rand_chacha 0.3.1", "scale-info", @@ -8133,6 +8132,7 @@ dependencies = [ "num-traits", "pallet-balances", "pallet-collective", + "pallet-commitments", "pallet-crowdloan", "pallet-drand", "pallet-membership", diff --git a/pallets/admin-utils/src/tests/mock.rs b/pallets/admin-utils/src/tests/mock.rs index 67099a1906..7bba7929dd 100644 --- a/pallets/admin-utils/src/tests/mock.rs +++ b/pallets/admin-utils/src/tests/mock.rs @@ -227,6 +227,7 @@ impl pallet_subtensor::Config for Test { type HotkeySwapOnSubnetInterval = HotkeySwapOnSubnetInterval; type ProxyInterface = (); type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval; + type GetCommitments = (); } parameter_types! { diff --git a/pallets/commitments/Cargo.toml b/pallets/commitments/Cargo.toml index bedc0d945c..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 d8c36079fd..6d0d826ab4 100644 --- a/pallets/commitments/src/lib.rs +++ b/pallets/commitments/src/lib.rs @@ -10,15 +10,15 @@ 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, Get}, }; +use frame_system::pallet_prelude::BlockNumberFor; +pub use pallet::*; use scale_info::prelude::collections::BTreeSet; use sp_runtime::SaturatedConversion; use sp_runtime::{Saturating, Weight, traits::Zero}; @@ -29,7 +29,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; @@ -550,4 +552,28 @@ impl Pallet { Ok(total_weight) } + 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 a63f63b599..ed40d8d36f 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -42,6 +42,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 @@ -78,6 +79,7 @@ std = [ "log/std", "num-traits/std", "pallet-balances/std", + "pallet-commitments/std", "pallet-collective/std", "pallet-drand/std", "pallet-membership/std", @@ -119,6 +121,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", @@ -140,6 +143,7 @@ try-runtime = [ "sp-runtime/try-runtime", "pallet-collective/try-runtime", "pallet-drand/try-runtime", + "pallet-commitments/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 b89fe8e865..eebff46c6e 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..1ad09d4bbb 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)) + .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/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index d011983383..28da96687a 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -458,6 +458,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 3248c45e60..8aca06dc5d 100644 --- a/pallets/transaction-fee/src/tests/mock.rs +++ b/pallets/transaction-fee/src/tests/mock.rs @@ -292,6 +292,7 @@ impl pallet_subtensor::Config for Test { type HotkeySwapOnSubnetInterval = HotkeySwapOnSubnetInterval; type ProxyInterface = (); type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval; + type GetCommitments = (); } parameter_types! { diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index cc9c02eca3..2f2b53f869 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; @@ -1063,6 +1063,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; @@ -1238,6 +1245,7 @@ impl pallet_subtensor::Config for Runtime { type HotkeySwapOnSubnetInterval = HotkeySwapOnSubnetInterval; type ProxyInterface = Proxier; type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval; + type GetCommitments = GetCommitmentsStruct; } parameter_types! {