Skip to content

Commit

Permalink
Merge pull request #80 from agicommies/main
Browse files Browse the repository at this point in the history
refac: simplifying extrinsics
  • Loading branch information
Supremesource authored Aug 10, 2024
2 parents 7c6bb45 + 808a323 commit f221bbf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 112 deletions.
16 changes: 3 additions & 13 deletions pallets/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub mod pallet {
PalletId,
};
use frame_system::pallet_prelude::{ensure_signed, BlockNumberFor};
use pallet_subspace::DefaultKey;
use pallet_subspace::{global::GeneralBurnConfiguration, DefaultKey};
use sp_runtime::traits::AccountIdConversion;

const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
Expand Down Expand Up @@ -236,12 +236,7 @@ pub mod pallet {
maximum_set_weight_calls_per_epoch: u16,
vote_mode: VoteMode,
bonds_ma: u64,
min_burn: u64,
max_burn: u64,
target_registrations_interval: u16,
target_registrations_per_interval: u16,
max_registrations_per_interval: u16,
adjustment_alpha: u64,
module_burn_config: GeneralBurnConfiguration<T>,
min_validator_stake: u64,
max_allowed_validators: Option<u16>,
) -> DispatchResult {
Expand All @@ -261,12 +256,7 @@ pub mod pallet {
params.maximum_set_weight_calls_per_epoch = maximum_set_weight_calls_per_epoch;
params.governance_config.vote_mode = vote_mode;
params.bonds_ma = bonds_ma;
params.min_burn = min_burn;
params.max_burn = max_burn;
params.target_registrations_interval = target_registrations_interval;
params.target_registrations_per_interval = target_registrations_per_interval;
params.max_registrations_per_interval = max_registrations_per_interval;
params.adjustment_alpha = adjustment_alpha;
params.module_burn_config = module_burn_config;
params.min_validator_stake = min_validator_stake;
params.max_allowed_validators = max_allowed_validators;
Self::do_add_subnet_params_proposal(origin, netuid, data, params)
Expand Down
33 changes: 4 additions & 29 deletions pallets/subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,6 @@ pub mod pallet {
// TODO: not hardcode values here, get them from the storages instead,
// if they implement default already.
pub fn get() -> SubnetParams<T> {
let module_burn_defaults = GeneralBurnConfiguration::<T>::default_for(BurnType::Module);

SubnetParams {
name: BoundedVec::default(),
tempo: 100,
Expand All @@ -357,14 +355,7 @@ pub mod pallet {
bonds_ma: 900_000,

// registrations
min_burn: module_burn_defaults.min_burn,
max_burn: module_burn_defaults.max_burn,
target_registrations_interval: module_burn_defaults.target_registrations_interval,
target_registrations_per_interval: module_burn_defaults
.target_registrations_per_interval,
max_registrations_per_interval: module_burn_defaults.max_registrations_per_interval,
adjustment_alpha: module_burn_defaults.adjustment_alpha,

module_burn_config: GeneralBurnConfiguration::<T>::default_for(BurnType::Module),
min_validator_stake: DefaultMinValidatorStake::<T>::get(),
max_allowed_validators: None,
governance_config: GovernanceConfiguration {
Expand Down Expand Up @@ -399,13 +390,7 @@ pub mod pallet {
pub maximum_set_weight_calls_per_epoch: u16,
// consensus
pub bonds_ma: u64,
// registrations
pub min_burn: u64,
pub max_burn: u64,
pub target_registrations_interval: u16,
pub target_registrations_per_interval: u16,
pub max_registrations_per_interval: u16,
pub adjustment_alpha: u64,
pub module_burn_config: GeneralBurnConfiguration<T>,
pub min_validator_stake: u64,
pub max_allowed_validators: Option<u16>,
pub governance_config: GovernanceConfiguration,
Expand Down Expand Up @@ -1013,12 +998,7 @@ pub mod pallet {
maximum_set_weight_calls_per_epoch: u16,
vote_mode: VoteMode,
bonds_ma: u64,
min_burn: u64,
max_burn: u64,
target_registrations_interval: u16,
target_registrations_per_interval: u16,
max_registrations_per_interval: u16,
adjustment_alpha: u64,
module_burn_config: GeneralBurnConfiguration<T>,
min_validator_stake: u64,
max_allowed_validators: Option<u16>,
) -> DispatchResult {
Expand All @@ -1036,12 +1016,7 @@ pub mod pallet {
trust_ratio,
maximum_set_weight_calls_per_epoch,
bonds_ma,
min_burn,
max_burn,
target_registrations_interval,
target_registrations_per_interval,
max_registrations_per_interval,
adjustment_alpha,
module_burn_config,
min_validator_stake,
max_allowed_validators,
governance_config: GovernanceConfiguration {
Expand Down
21 changes: 2 additions & 19 deletions pallets/subspace/src/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,7 @@ impl<T: Config> SubnetChangeset<T> {
TrustRatio::<T>::insert(netuid, self.params.trust_ratio);
IncentiveRatio::<T>::insert(netuid, self.params.incentive_ratio);
BondsMovingAverage::<T>::insert(netuid, self.params.bonds_ma);
let burn_config: GeneralBurnConfiguration<T> = GeneralBurnConfiguration {
min_burn: self.params.min_burn,
max_burn: self.params.max_burn,
adjustment_alpha: self.params.adjustment_alpha,
target_registrations_interval: self.params.target_registrations_interval,
target_registrations_per_interval: self.params.target_registrations_per_interval,
max_registrations_per_interval: self.params.max_registrations_per_interval,
_pd: PhantomData,
};
burn_config.apply_module_burn(netuid)?;
self.params.module_burn_config.apply_module_burn(netuid)?;
MinValidatorStake::<T>::insert(netuid, self.params.min_validator_stake);
if self.params.maximum_set_weight_calls_per_epoch == 0 {
MaximumSetWeightCallsPerEpoch::<T>::remove(netuid);
Expand Down Expand Up @@ -169,8 +160,6 @@ impl<T: Config> SubnetChangeset<T> {

impl<T: Config> Pallet<T> {
pub fn subnet_params(netuid: u16) -> SubnetParams<T> {
let module_burn_config = ModuleBurnConfig::<T>::get(netuid);

SubnetParams {
founder: Founder::<T>::get(netuid),
founder_share: FounderShare::<T>::get(netuid),
Expand All @@ -188,13 +177,7 @@ impl<T: Config> Pallet<T> {
bonds_ma: BondsMovingAverage::<T>::get(netuid),

// Registrations
min_burn: module_burn_config.min_burn,
max_burn: module_burn_config.max_burn,
target_registrations_interval: module_burn_config.target_registrations_interval,
target_registrations_per_interval: module_burn_config.target_registrations_per_interval,
max_registrations_per_interval: module_burn_config.max_registrations_per_interval,
adjustment_alpha: module_burn_config.adjustment_alpha,

module_burn_config: ModuleBurnConfig::<T>::get(netuid),
min_validator_stake: MinValidatorStake::<T>::get(netuid),
max_allowed_validators: MaxAllowedValidators::<T>::get(netuid),
governance_config: T::get_subnet_governance_configuration(netuid),
Expand Down
14 changes: 2 additions & 12 deletions tests/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,7 @@ fn subnet_params_proposal_accepted() {
trust_ratio,
maximum_set_weight_calls_per_epoch,
bonds_ma,
min_burn,
max_burn,
target_registrations_interval,
target_registrations_per_interval,
max_registrations_per_interval,
adjustment_alpha,
module_burn_config,
min_validator_stake,
max_allowed_validators,
mut governance_config,
Expand Down Expand Up @@ -358,12 +353,7 @@ fn subnet_params_proposal_accepted() {
maximum_set_weight_calls_per_epoch,
governance_config.vote_mode,
bonds_ma,
min_burn,
max_burn,
target_registrations_interval,
target_registrations_per_interval,
max_registrations_per_interval,
adjustment_alpha,
module_burn_config,
min_validator_stake,
max_allowed_validators,
)
Expand Down
53 changes: 14 additions & 39 deletions tests/src/subspace/subnet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::mock::*;
use frame_support::assert_err;
use global::GeneralBurnConfiguration;
use pallet_governance::{GovernanceConfiguration, SubnetGovernanceConfig, VoteMode};
use pallet_subspace::*;
use sp_runtime::Percent;
Expand Down Expand Up @@ -59,10 +60,6 @@ fn subnet_update_changes_all_parameter_values() {
trust_ratio: 11,
maximum_set_weight_calls_per_epoch: 12,
bonds_ma: 13,
target_registrations_interval: 14,
target_registrations_per_interval: 15,
max_registrations_per_interval: 16,
adjustment_alpha: 17,
min_validator_stake: to_nano(50_000),
max_allowed_validators: Some(18),
governance_config: GovernanceConfiguration {
Expand All @@ -73,8 +70,15 @@ fn subnet_update_changes_all_parameter_values() {
max_proposal_reward_treasury_allocation: 21,
proposal_reward_interval: 22,
},
min_burn: 20000000000,
max_burn: 21000000000,
module_burn_config: GeneralBurnConfiguration {
min_burn: to_nano(15),
max_burn: to_nano(24),
target_registrations_interval: 25,
target_registrations_per_interval: 26,
max_registrations_per_interval: 27,
adjustment_alpha: 28,
..Default::default()
},
};

let SubnetParams {
Expand All @@ -92,19 +96,13 @@ fn subnet_update_changes_all_parameter_values() {
trust_ratio,
maximum_set_weight_calls_per_epoch,
bonds_ma,
min_burn,
max_burn,
target_registrations_interval,
target_registrations_per_interval,
max_registrations_per_interval,
adjustment_alpha,
module_burn_config,
min_validator_stake,
max_allowed_validators,

Check warning on line 101 in tests/src/subspace/subnet.rs

View workflow job for this annotation

GitHub Actions / check

unused variable: `max_allowed_validators`
governance_config,
} = params.clone();

SubnetChangeset::<Test>::update(netuid, params).unwrap().apply(netuid).unwrap();

assert_eq!(Founder::<Test>::get(netuid), founder);
assert_eq!(FounderShare::<Test>::get(netuid), founder_share);
assert_eq!(ImmunityPeriod::<Test>::get(netuid), immunity_period);
Expand All @@ -121,31 +119,13 @@ fn subnet_update_changes_all_parameter_values() {
Some(maximum_set_weight_calls_per_epoch)
);
assert_eq!(BondsMovingAverage::<Test>::get(netuid), bonds_ma);
assert_eq!(ModuleBurnConfig::<Test>::get(netuid).min_burn, min_burn);
assert_eq!(ModuleBurnConfig::<Test>::get(netuid).max_burn, max_burn);
assert_eq!(
ModuleBurnConfig::<Test>::get(netuid).target_registrations_interval,
target_registrations_interval
);
assert_eq!(
ModuleBurnConfig::<Test>::get(netuid).target_registrations_per_interval,
target_registrations_per_interval
);
assert_eq!(
ModuleBurnConfig::<Test>::get(netuid).max_registrations_per_interval,
max_registrations_per_interval
);
assert_eq!(
ModuleBurnConfig::<Test>::get(netuid).adjustment_alpha,
adjustment_alpha
);
assert_eq!(ModuleBurnConfig::<Test>::get(netuid), module_burn_config);
assert_eq!(MinValidatorStake::<Test>::get(netuid), min_validator_stake);
assert_eq!(MinValidatorStake::<Test>::get(netuid), min_validator_stake);

assert_eq!(
SubnetGovernanceConfig::<Test>::get(netuid),
governance_config
);

assert_eq!(SubspaceMod::get_total_subnets(), 1);
assert_eq!(N::<Test>::get(netuid), 1);
assert_eq!(SubnetMetadata::<Test>::get(netuid), metadata);
Expand Down Expand Up @@ -252,12 +232,7 @@ fn update_subnet_verifies_names_uniquiness_integrity() {
params.maximum_set_weight_calls_per_epoch,
params.governance_config.vote_mode,
params.bonds_ma,
params.min_burn,
params.max_burn,
params.target_registrations_interval,
params.target_registrations_per_interval,
params.max_registrations_per_interval,
params.adjustment_alpha,
params.module_burn_config,
params.min_validator_stake,
params.max_allowed_validators,
)
Expand Down

0 comments on commit f221bbf

Please sign in to comment.