Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pallets/admin-utils/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ impl pallet_subtensor::Config for Test {
type HotkeySwapOnSubnetInterval = HotkeySwapOnSubnetInterval;
type ProxyInterface = ();
type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval;
type GetCommitments = ();
}

parameter_types! {
Expand Down
5 changes: 0 additions & 5 deletions pallets/commitments/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ hex.workspace = true
sha2.workspace = true

log.workspace = true

pallet-subtensor.workspace = true
subtensor-runtime-common.workspace = true

[dev-dependencies]
Expand All @@ -57,7 +55,6 @@ std = [
"log/std",
"pallet-balances/std",
"pallet-drand/std",
"pallet-subtensor/std",
"rand_chacha/std",
"scale-info/std",
"sha2/std",
Expand All @@ -76,13 +73,11 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-drand/runtime-benchmarks",
"pallet-subtensor/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-balances/try-runtime",
"sp-runtime/try-runtime",
"pallet-drand/try-runtime",
"pallet-subtensor/try-runtime",
]
34 changes: 30 additions & 4 deletions pallets/commitments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
Expand Down Expand Up @@ -550,4 +552,28 @@ impl<T: Config> Pallet<T> {

Ok(total_weight)
}
pub fn get_commitments(netuid: NetUid) -> Vec<(T::AccountId, Vec<u8>)> {
let commitments: Vec<(T::AccountId, Vec<u8>)> =
<CommitmentOf<T> as IterableStorageDoubleMap<
NetUid,
T::AccountId,
Registration<BalanceOf<T>, T::MaxFields, BlockNumberFor<T>>,
>>::iter_prefix(netuid)
.map(|(account, registration)| {
let bytes = registration.encode();
(account, bytes)
})
.collect();
commitments
}
}

pub trait GetCommitments<AccountId> {
fn get_commitments(netuid: NetUid) -> Vec<(AccountId, Vec<u8>)>;
}

impl<AccountId> GetCommitments<AccountId> for () {
fn get_commitments(_netuid: NetUid) -> Vec<(AccountId, Vec<u8>)> {
Vec::new()
}
}
4 changes: 4 additions & 0 deletions pallets/subtensor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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"
]
Expand Down
4 changes: 4 additions & 0 deletions pallets/subtensor/src/macros/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -58,6 +59,9 @@ mod config {
/// Interface to allow interacting with the proxy pallet.
type ProxyInterface: crate::ProxyInterface<Self::AccountId>;

/// Interface to get commitments.
type GetCommitments: GetCommitments<Self::AccountId>;

/// =================================
/// ==== Initial Value Constants ====
/// =================================
Expand Down
32 changes: 31 additions & 1 deletion pallets/subtensor/src/rpc_info/metagraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,7 +110,7 @@ pub struct Metagraph<AccountId: TypeInfo + Encode + Decode> {
alpha_dividends_per_hotkey: Vec<(AccountId, Compact<AlphaCurrency>)>, // 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<AccountId: TypeInfo + Encode + Decode + Clone> {
// Subnet index
Expand Down Expand Up @@ -210,6 +211,8 @@ pub struct SelectiveMetagraph<AccountId: TypeInfo + Encode + Decode + Clone> {

// validators
validators: Option<Vec<Compact<u16>>>, // List of validators
// commitments
commitments: Option<Vec<(AccountId, Vec<Compact<u8>>)>>, // List of commitments
}

impl<AccountId> SelectiveMetagraph<AccountId>
Expand Down Expand Up @@ -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 => {}
};
}
Expand Down Expand Up @@ -451,6 +457,7 @@ where
tao_dividends_per_hotkey: None,
alpha_dividends_per_hotkey: None,
validators: None,
commitments: None,
}
}
}
Expand Down Expand Up @@ -529,6 +536,7 @@ pub enum SelectiveMetagraphIndex {
TaoDividendsPerHotkey,
AlphaDividendsPerHotkey,
Validators,
Commitments,
}

impl SelectiveMetagraphIndex {
Expand Down Expand Up @@ -607,6 +615,7 @@ impl SelectiveMetagraphIndex {
70 => Some(SelectiveMetagraphIndex::TaoDividendsPerHotkey),
71 => Some(SelectiveMetagraphIndex::AlphaDividendsPerHotkey),
72 => Some(SelectiveMetagraphIndex::Validators),
73 => Some(SelectiveMetagraphIndex::Commitments),
_ => None,
}
}
Expand Down Expand Up @@ -1367,6 +1376,7 @@ impl<T: Config> Pallet<T> {
}
}
Some(SelectiveMetagraphIndex::Validators) => Self::get_validators(netuid),
Some(SelectiveMetagraphIndex::Commitments) => Self::get_commitments(netuid),
None => SelectiveMetagraph {
// Subnet index
netuid: netuid.into(),
Expand Down Expand Up @@ -1413,6 +1423,25 @@ impl<T: Config> Pallet<T> {
..Default::default()
}
}

fn get_commitments(netuid: NetUid) -> SelectiveMetagraph<T::AccountId> {
let commitments = <T as Config>::GetCommitments::get_commitments(netuid);
let commitments: Vec<(T::AccountId, Vec<Compact<u8>>)> = commitments
.iter()
.map(|(account, commitment)| {
let compact_commitment = commitment
.iter()
.map(|c| Compact::from(*c))
.collect::<Vec<Compact<u8>>>();
(account.clone(), compact_commitment)
})
.collect();

SelectiveMetagraph {
commitments: Some(commitments),
..Default::default()
}
}
}

#[test]
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ impl crate::Config for Test {
type HotkeySwapOnSubnetInterval = HotkeySwapOnSubnetInterval;
type ProxyInterface = FakeProxier;
type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval;
type GetCommitments = ();
}

// Swap-related parameter types
Expand Down
1 change: 1 addition & 0 deletions pallets/transaction-fee/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ impl pallet_subtensor::Config for Test {
type HotkeySwapOnSubnetInterval = HotkeySwapOnSubnetInterval;
type ProxyInterface = ();
type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval;
type GetCommitments = ();
}

parameter_types! {
Expand Down
12 changes: 10 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1063,6 +1063,13 @@ impl OnMetadataCommitment<AccountId> for ResetBondsOnCommit {
fn on_metadata_commitment(_: NetUid, _: &AccountId) {}
}

pub struct GetCommitmentsStruct;
impl GetCommitments<AccountId> for GetCommitmentsStruct {
fn get_commitments(netuid: NetUid) -> Vec<(AccountId, Vec<u8>)> {
pallet_commitments::Pallet::<Runtime>::get_commitments(netuid)
}
}

impl pallet_commitments::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
Expand Down Expand Up @@ -1234,6 +1241,7 @@ impl pallet_subtensor::Config for Runtime {
type HotkeySwapOnSubnetInterval = HotkeySwapOnSubnetInterval;
type ProxyInterface = Proxier;
type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval;
type GetCommitments = GetCommitmentsStruct;
}

parameter_types! {
Expand Down
Loading