Skip to content
Merged
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
3 changes: 2 additions & 1 deletion pallets/admin-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ sp-io = { workspace = true }
sp-tracing = { workspace = true }
sp-consensus-aura = { workspace = true }
pallet-balances = { workspace = true, features = ["std"] }

pallet-scheduler = { workspace = true }
sp-std = { workspace = true }

[features]
default = ["std"]
Expand Down
40 changes: 35 additions & 5 deletions pallets/admin-utils/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

use frame_support::{
assert_ok, derive_impl, parameter_types,
traits::{Everything, Hooks},
traits::{Everything, Hooks, PrivilegeCmp},
weights,
};
use frame_system as system;
use frame_system::{limits, EnsureNever};
use frame_system::{limits, EnsureNever, EnsureRoot};
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::U256;
use sp_core::{ConstU64, H256};
use sp_runtime::{
traits::{BlakeTwo256, ConstU32, IdentityLookup},
BuildStorage, DispatchError,
BuildStorage, DispatchError, Perbill,
};

use sp_std::cmp::Ordering;
use sp_weights::Weight;
type Block = frame_system::mocking::MockBlock<Test>;

// Configure a mock runtime to test the pallet.
Expand All @@ -25,6 +26,7 @@ frame_support::construct_runtime!(
Balances: pallet_balances,
AdminUtils: pallet_admin_utils,
SubtensorModule: pallet_subtensor::{Pallet, Call, Storage, Event<T>, Error<T>},
Scheduler: pallet_scheduler,
}
);

Expand Down Expand Up @@ -126,7 +128,7 @@ impl pallet_subtensor::Config for Test {
type CouncilOrigin = EnsureNever<AccountId>;
type SenateMembers = ();
type TriumvirateInterface = ();

type Scheduler = Scheduler;
type InitialMinAllowedWeights = InitialMinAllowedWeights;
type InitialEmissionValue = InitialEmissionValue;
type InitialMaxWeightsLimit = InitialMaxWeightsLimit;
Expand Down Expand Up @@ -218,6 +220,34 @@ impl pallet_balances::Config for Test {
type RuntimeHoldReason = ();
}

pub struct OriginPrivilegeCmp;

impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {
fn cmp_privilege(_left: &OriginCaller, _right: &OriginCaller) -> Option<Ordering> {
None
}
}

parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *
BlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50;
pub const NoPreimagePostponement: Option<u32> = Some(10);
}

impl pallet_scheduler::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
type PalletsOrigin = OriginCaller;
type RuntimeCall = RuntimeCall;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<AccountId>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = pallet_scheduler::weights::SubstrateWeight<Test>;
type OriginPrivilegeCmp = OriginPrivilegeCmp;
type Preimages = ();
}

pub struct SubtensorIntrf;

impl pallet_admin_utils::SubtensorInterface<AccountId, Balance, RuntimeOrigin> for SubtensorIntrf {
Expand Down
6 changes: 3 additions & 3 deletions pallets/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,9 +951,9 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
///
/// If not `approved`:
/// - one event deposited.
/// Two removals, one mutation.
/// Computation and i/o `O(P)` where:
/// - `P` is number of active proposals
/// - Two removals, one mutation.
/// - Computation and i/o `O(P)` where:
/// - `P` is number of active proposals
fn do_approve_proposal(
seats: MemberCount,
yes_votes: MemberCount,
Expand Down
2 changes: 2 additions & 0 deletions pallets/subtensor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ num-traits = { version = "0.2.19", default-features = false, features = ["libm"]

[dev-dependencies]
pallet-balances = { workspace = true, features = ["std"] }
pallet-scheduler = { workspace = true }
sp-version = { workspace = true }
# Substrate
sp-tracing = { workspace = true }
parity-util-mem = { workspace = true, features = ["primitive-types"] }
rand = { workspace = true }
sp-core = { workspace = true }
sp-std = { workspace = true }

[features]
default = ["std"]
Expand Down
9 changes: 8 additions & 1 deletion pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub mod pallet {
use frame_support::{
dispatch::GetDispatchInfo,
pallet_prelude::{DispatchResult, StorageMap, ValueQuery, *},
traits::{tokens::fungible, UnfilteredDispatchable},
traits::{tokens::fungible, OriginTrait, UnfilteredDispatchable},
};
use frame_system::pallet_prelude::*;
use sp_core::H256;
Expand All @@ -78,6 +78,13 @@ pub mod pallet {
#[cfg(feature = "std")]
use sp_std::prelude::Box;

/// Origin for the pallet
pub type PalletsOriginOf<T> =
<<T as frame_system::Config>::RuntimeOrigin as OriginTrait>::PalletsOrigin;

/// Call type for the pallet
pub type CallOf<T> = <T as frame_system::Config>::RuntimeCall;

/// Tracks version for migrations. Should be monotonic with respect to the
/// order of migrations. (i.e. always increasing)
const STORAGE_VERSION: StorageVersion = StorageVersion::new(7);
Expand Down
11 changes: 1 addition & 10 deletions pallets/subtensor/src/macros/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,7 @@ mod config {
type TriumvirateInterface: crate::CollectiveInterface<Self::AccountId, Self::Hash, u32>;

/// The scheduler type used for scheduling delayed calls.
type Scheduler: ScheduleNamed<BlockNumberFor<Self>, Call<Self>, Self::RuntimeOrigin>;

/// The hashing system (algorithm) being used in the runtime, matching the Scheduler's Hasher.
type Hasher: Hash<
Output = <<Self::Scheduler as ScheduleNamed<
BlockNumberFor<Self>,
Call<Self>,
Self::RuntimeOrigin,
>>::Hasher as Hash>::Output,
>;
type Scheduler: ScheduleNamed<BlockNumberFor<Self>, CallOf<Self>, PalletsOriginOf<Self>>;

/// =================================
/// ==== Initial Value Constants ====
Expand Down
7 changes: 6 additions & 1 deletion pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,12 @@ mod dispatches {
)
.using_encoded(sp_io::hashing::blake2_256);

let hash = T::Hasher::hash(&call.encode());
let hash = <T::Scheduler as ScheduleNamed<
BlockNumberFor<T>,
CallOf<T>,
PalletsOriginOf<T>,
>>::Hasher::hash_of(&call);

let len = call.using_encoded(|e| e.len() as u32);

T::Scheduler::schedule_named(
Expand Down
34 changes: 32 additions & 2 deletions pallets/subtensor/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use frame_support::weights::constants::RocksDbWeight;
use frame_support::weights::Weight;
use frame_support::{
assert_ok, parameter_types,
traits::{Everything, Hooks},
traits::{Everything, Hooks, PrivilegeCmp},
};
use frame_system as system;
use frame_system::{limits, EnsureNever, EnsureRoot, RawOrigin};
Expand All @@ -17,6 +17,7 @@ use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
use sp_std::cmp::Ordering;

type Block = frame_system::mocking::MockBlock<Test>;

Expand All @@ -32,6 +33,7 @@ frame_support::construct_runtime!(
SenateMembers: pallet_membership::<Instance2>::{Pallet, Call, Storage, Event<T>, Config<T>},
SubtensorModule: pallet_subtensor::{Pallet, Call, Storage, Event<T>},
Utility: pallet_utility::{Pallet, Call, Storage, Event},
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>},
}
);

Expand Down Expand Up @@ -336,7 +338,7 @@ impl pallet_subtensor::Config for Test {
type CouncilOrigin = frame_system::EnsureSigned<AccountId>;
type SenateMembers = ManageSenateMembers;
type TriumvirateInterface = TriumvirateVotes;

type Scheduler = Scheduler;
type InitialMinAllowedWeights = InitialMinAllowedWeights;
type InitialEmissionValue = InitialEmissionValue;
type InitialMaxWeightsLimit = InitialMaxWeightsLimit;
Expand Down Expand Up @@ -385,6 +387,34 @@ impl pallet_subtensor::Config for Test {
type InitialNetworkMaxStake = InitialNetworkMaxStake;
}

pub struct OriginPrivilegeCmp;

impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {
fn cmp_privilege(_left: &OriginCaller, _right: &OriginCaller) -> Option<Ordering> {
None
}
}

parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *
BlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50;
pub const NoPreimagePostponement: Option<u32> = Some(10);
}

impl pallet_scheduler::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
type PalletsOrigin = OriginCaller;
type RuntimeCall = RuntimeCall;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<AccountId>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = pallet_scheduler::weights::SubstrateWeight<Test>;
type OriginPrivilegeCmp = OriginPrivilegeCmp;
type Preimages = ();
}

impl pallet_utility::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
Expand Down
18 changes: 1 addition & 17 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub mod check_nonce;
mod migrations;

use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::traits::schedule::v3::Named as ScheduleNamed;
use frame_support::{
dispatch::DispatchResultWithPostInfo,
genesis_builder_helper::{build_config, create_default_config},
Expand Down Expand Up @@ -840,19 +839,6 @@ impl pallet_commitments::Config for Runtime {
type RateLimit = CommitmentRateLimit;
}

impl pallet_scheduler::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type PalletsOrigin = OriginCaller;
type RuntimeCall = RuntimeCall;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<AccountId>;
type MaxScheduledPerBlock = ConstU32<50>;
type WeightInfo = pallet_scheduler::weights::SubstrateWeight<Runtime>;
type OriginPrivilegeCmp = EqualPrivilegeOnly;
type Preimages = Preimage;
}

// Configure the pallet subtensor.
parameter_types! {
pub const SubtensorInitialRho: u16 = 10;
Expand Down Expand Up @@ -912,9 +898,7 @@ impl pallet_subtensor::Config for Runtime {
type CouncilOrigin = EnsureMajoritySenate;
type SenateMembers = ManageSenateMembers;
type TriumvirateInterface = TriumvirateVotes;
type Scheduler = pallet_scheduler::Pallet<Runtime>;
type Hasher = BlakeTwo256;

type Scheduler = Scheduler;
type InitialRho = SubtensorInitialRho;
type InitialKappa = SubtensorInitialKappa;
type InitialMaxAllowedUids = SubtensorInitialMaxAllowedUids;
Expand Down