Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refac(pallets/subspace): group burn related values into BurnConfig #100

Merged
merged 4 commits into from
May 13, 2024
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
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

[Unreleased]

Spec version: `114`

- Deleted, or moved useless code and values of:
- Burn rate
- Min Stake
- The following storage values were deleted and are now accessible through `BurnConfig`:
- `MinBurn`
- `MaxBurn`
- `AdjustmentAlpha`
- `TargetRegistrationsInterval`
- `TargetRegistrationsPerInterval`
- The storage value `RemovedSubnets` is now called `SubnetGaps`

## Version 1.7.3

Expand Down
132 changes: 62 additions & 70 deletions pallets/subspace/src/global.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,61 @@
use super::*;
use frame_support::pallet_prelude::DispatchResult;
use sp_arithmetic::per_things::Percent;
use sp_core::Get;
use sp_runtime::DispatchError;

#[derive(Clone, TypeInfo, Decode, Encode, PartialEq, Eq, frame_support::DebugNoBound)]
#[scale_info(skip_type_params(T))]
pub struct BurnConfiguration<T: Config> {
/// min burn the adjustment algorithm can set
pub min_burn: u64,
/// max burn the adjustment algorithm can set
pub max_burn: u64,
/// the steepness with which the burn curve will increase
/// every interval
pub adjustment_alpha: u64,
/// interval in blocks for the burn to be adjusted
pub adjustment_interval: u16,
/// the number of registrations expected per interval, if
/// below, burn gets decreased, it is increased otherwise
pub expected_registrations: u16,
pub _pd: PhantomData<T>,
}

impl<T: Config> Default for BurnConfiguration<T> {
fn default() -> Self {
Self {
min_burn: 4_000_000_000,
max_burn: 250_000_000_000,
adjustment_alpha: u64::MAX / 2,
adjustment_interval: DefaultTempo::<T>::get() * 2,
expected_registrations: DefaultTempo::<T>::get(),
_pd: PhantomData,
}
}
}

impl<T: Config> BurnConfiguration<T> {
pub fn apply(self) -> Result<(), DispatchError> {
ensure!(self.min_burn >= 100_000_000, Error::<T>::InvalidMinBurn);

ensure!(self.max_burn > self.min_burn, Error::<T>::InvalidMaxBurn);

ensure!(
self.expected_registrations > 0,
Error::<T>::InvalidTargetRegistrationsPerInterval
);

ensure!(
self.adjustment_interval > 0,
Error::<T>::InvalidTargetRegistrationsInterval
);

BurnConfig::<T>::set(self);

Ok(())
}
}

impl<T: Config> Pallet<T> {
pub fn global_params() -> GlobalParams<T> {
Expand All @@ -16,11 +71,7 @@ impl<T: Config> Pallet<T> {
floor_delegation_fee: Self::get_floor_delegation_fee(),
// burn & registrations
max_registrations_per_block: Self::get_max_registrations_per_block(),
target_registrations_per_interval: Self::get_target_registrations_per_interval(),
target_registrations_interval: Self::get_target_registrations_interval(),
min_burn: Self::get_min_burn(),
max_burn: Self::get_max_burn(),
adjustment_alpha: Self::get_adjustment_alpha(),

// weights
max_allowed_weights: Self::get_max_allowed_weights_global(),
subnet_stake_threshold: Self::get_subnet_stake_threshold(),
Expand All @@ -33,6 +84,8 @@ impl<T: Config> Pallet<T> {
in percent of the overall network stake */
// s0
general_subnet_application_cost: Self::get_general_subnet_application_cost(),

burn_config: BurnConfig::<T>::get(),
}
}

Expand Down Expand Up @@ -81,31 +134,11 @@ impl<T: Config> Pallet<T> {
Error::<T>::InvalidMaxRegistrationsPerBlock
);

ensure!(
params.target_registrations_interval > 0,
Error::<T>::InvalidTargetRegistrationsInterval
);

ensure!(
params.unit_emission <= old_params.unit_emission,
Error::<T>::InvalidUnitEmission
);

// Make sure that the burn is at least 0.1 $ COMAI, it can't be
// zero, because the whole dynamic burn system would get broken.
ensure!(params.min_burn >= 100_000_000, Error::<T>::InvalidMinBurn);

// Make sure that the maximum burn is larger than minimum burn
ensure!(
params.max_burn > params.min_burn,
Error::<T>::InvalidMaxBurn
);

ensure!(
params.target_registrations_per_interval > 0,
Error::<T>::InvalidTargetRegistrationsPerInterval
);

ensure!(
params.max_allowed_weights > 0,
Error::<T>::InvalidMaxAllowedWeights
Expand Down Expand Up @@ -143,13 +176,8 @@ impl<T: Config> Pallet<T> {
Self::set_floor_delegation_fee(params.floor_delegation_fee);
// burn & registrations
Self::set_max_registrations_per_block(params.max_registrations_per_block);
Self::set_target_registrations_per_interval(params.target_registrations_per_interval);
Self::set_target_registrations_interval(params.target_registrations_interval);
Self::set_min_burn(params.min_burn);
Self::set_max_burn(params.max_burn);
Self::set_min_weight_stake(params.min_weight_stake);
Self::set_subnet_stake_threshold(params.subnet_stake_threshold);
Self::set_adjustment_alpha(params.adjustment_alpha);
Self::set_floor_delegation_fee(params.floor_delegation_fee);
Self::set_curator(params.curator);
FloorFounderShare::<T>::put(params.floor_founder_share);
Expand All @@ -162,6 +190,9 @@ impl<T: Config> Pallet<T> {
Self::set_proposal_cost(params.proposal_cost);
Self::set_proposal_expiration(params.proposal_expiration);
Self::set_proposal_participation_threshold(params.proposal_participation_threshold);

// burn
params.burn_config.apply().expect("invalid burn configuration");
}

pub fn get_curator() -> T::AccountId {
Expand All @@ -172,14 +203,6 @@ impl<T: Config> Pallet<T> {
Curator::<T>::put(curator)
}

pub fn get_target_registrations_per_interval() -> u16 {
TargetRegistrationsPerInterval::<T>::get()
}

pub fn set_target_registrations_per_interval(target_interval: u16) {
TargetRegistrationsPerInterval::<T>::put(target_interval)
}

pub fn get_min_weight_stake() -> u64 {
MinWeightStake::<T>::get()
}
Expand Down Expand Up @@ -212,6 +235,7 @@ impl<T: Config> Pallet<T> {
}

// Proposals

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esse comment aqui dawg

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matue-pelado

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PAISAO

pub fn get_proposal_cost() -> u64 {
ProposalCost::<T>::get()
}
Expand Down Expand Up @@ -248,14 +272,6 @@ impl<T: Config> Pallet<T> {
MaxRegistrationsPerBlock::<T>::set(max_registrations_per_block);
}

pub fn get_target_registrations_interval() -> u16 {
TargetRegistrationsInterval::<T>::get()
}

pub fn set_target_registrations_interval(target_registrations_interval: u16) {
TargetRegistrationsInterval::<T>::set(target_registrations_interval);
}

pub fn get_global_max_name_length() -> u16 {
MaxNameLength::<T>::get()
}
Expand All @@ -281,30 +297,6 @@ impl<T: Config> Pallet<T> {
global_n
}

pub fn get_min_burn() -> u64 {
MinBurn::<T>::get()
}

pub fn set_min_burn(min_burn: u64) {
MinBurn::<T>::put(min_burn);
}

pub fn get_max_burn() -> u64 {
MaxBurn::<T>::get()
}

pub fn set_max_burn(max_burn: u64) {
MaxBurn::<T>::put(max_burn);
}

pub fn get_adjustment_alpha() -> u64 {
AdjustmentAlpha::<T>::get()
}

pub fn set_adjustment_alpha(adjustment_alpha: u64) {
AdjustmentAlpha::<T>::put(adjustment_alpha);
}

// Whitelist management
pub fn is_in_legit_whitelist(account_id: &T::AccountId) -> bool {
LegitWhitelist::<T>::contains_key(account_id)
Expand Down
70 changes: 19 additions & 51 deletions pallets/subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub use step::yuma;
// =========================
// ==== Pallet Imports =====
// =========================
mod global;
pub mod global;
mod math;
pub mod module;
mod profit_share;
Expand Down Expand Up @@ -62,11 +62,12 @@ pub mod pallet {
use frame_support::{pallet_prelude::*, traits::Currency, Identity};
use frame_system::pallet_prelude::*;

use global::BurnConfiguration;
use module::ModuleChangeset;
use sp_arithmetic::per_things::Percent;
pub use sp_std::{vec, vec::Vec};

const STORAGE_VERSION: StorageVersion = StorageVersion::new(7);
const STORAGE_VERSION: StorageVersion = StorageVersion::new(8);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
Expand Down Expand Up @@ -95,36 +96,22 @@ pub mod pallet {
// ============================
// ==== Global Variables ====
// ============================

#[pallet::storage]
pub type BurnConfig<T: Config> = StorageValue<_, BurnConfiguration<T>, ValueQuery>;

#[pallet::type_value]
pub fn DefaultUnitEmission<T: Config>() -> u64 {
23148148148
}
#[pallet::storage] // --- ITEM ( unit_emission )
pub(super) type UnitEmission<T> = StorageValue<_, u64, ValueQuery, DefaultUnitEmission<T>>;

#[pallet::type_value]
pub fn DefaultMinBurn<T: Config>() -> u64 {
4_000_000_000 // 4 $COMAI
}
#[pallet::storage] // --- MinBurn
pub type MinBurn<T> = StorageValue<_, u64, ValueQuery, DefaultMinBurn<T>>;

#[pallet::type_value]
pub fn DefaultMaxBurn<T: Config>() -> u64 {
250_000_000_000 // 250 $COMAI
}

#[pallet::type_value]
pub fn DefaultAdjustmentAlpha<T: Config>() -> u64 {
u64::MAX / 2
}

#[pallet::storage] // --- adjusment alpha
pub type AdjustmentAlpha<T> = StorageValue<_, u64, ValueQuery, DefaultAdjustmentAlpha<T>>;

#[pallet::storage] // --- MaxBurn
pub type MaxBurn<T> = StorageValue<_, u64, ValueQuery, DefaultMaxBurn<T>>;

#[pallet::type_value]
pub fn DefaultSubnetStakeThreshold<T: Config>() -> Percent {
Percent::from_percent(5)
Expand Down Expand Up @@ -235,22 +222,6 @@ pub mod pallet {
pub type MaxRegistrationsPerBlock<T> =
StorageValue<_, u16, ValueQuery, DefaultMaxRegistrationsPerBlock<T>>;

#[pallet::type_value]
pub fn DefaultTargetRegistrationsPerInterval<T: Config>() -> u16 {
DefaultTargetRegistrationsInterval::<T>::get() / 2
}
#[pallet::storage] // --- ITEM( global_target_registrations_interval )
pub type TargetRegistrationsPerInterval<T> =
StorageValue<_, u16, ValueQuery, DefaultTargetRegistrationsPerInterval<T>>;

#[pallet::type_value] // --- ITEM( global_target_registrations_interval ) Measured in the number of blocks
pub fn DefaultTargetRegistrationsInterval<T: Config>() -> u16 {
DefaultTempo::<T>::get() * 2 // 2 times the epoch
}
#[pallet::storage] // --- ITEM( global_target_registrations_interval )
pub type TargetRegistrationsInterval<T> =
StorageValue<_, u16, ValueQuery, DefaultTargetRegistrationsInterval<T>>;

#[pallet::type_value]
pub fn DefaultMinDelegationFeeGlobal<T: Config>() -> Percent {
Percent::from_percent(5u8)
Expand Down Expand Up @@ -301,22 +272,15 @@ pub mod pallet {
pub max_allowed_weights: u16, // max number of weights per module

// mins
pub min_burn: u64, // min burn required
pub max_burn: u64, // max burn allowed
pub floor_delegation_fee: Percent, // min delegation fee
pub min_weight_stake: u64, // min weight stake required

// other
pub target_registrations_per_interval: u16, // desired number of registrations per interval
pub target_registrations_interval: u16, /* the number of blocks that defines the
* registration interval */
pub adjustment_alpha: u64, // adjustment alpha
pub unit_emission: u64, // emission per block
pub unit_emission: u64, // emission per block
pub curator: T::AccountId,

pub subnet_stake_threshold: Percent,

// porposals
// proposals
pub proposal_cost: u64,
pub proposal_expiration: u32,
pub proposal_participation_threshold: Percent,
Expand All @@ -325,6 +289,8 @@ pub mod pallet {

// founder share
pub floor_founder_share: u8,

pub burn_config: BurnConfiguration<T>,
}

pub struct DefaultSubnetParams<T: Config>(sp_std::marker::PhantomData<((), T)>);
Expand Down Expand Up @@ -606,7 +572,7 @@ pub mod pallet {
>;

#[pallet::storage] // --- MAP( netuid ) --> lowest_subnet
pub type RemovedSubnets<T> = StorageValue<_, BTreeSet<u16>, ValueQuery>;
pub type SubnetGaps<T> = StorageValue<_, BTreeSet<u16>, ValueQuery>;

// TOTAL STAKE PER SUBNET
#[pallet::storage] // --- MAP ( netuid ) --> subnet_total_stake
Expand Down Expand Up @@ -1212,21 +1178,23 @@ pub mod pallet {
params.max_allowed_modules = max_allowed_modules;
params.max_registrations_per_block = max_registrations_per_block;
params.max_allowed_weights = max_allowed_weights;
params.max_burn = max_burn;
params.min_burn = min_burn;
params.floor_delegation_fee = floor_delegation_fee;
params.floor_founder_share = floor_founder_share;
params.min_weight_stake = min_weight_stake;
params.target_registrations_per_interval = target_registrations_per_interval;
params.target_registrations_interval = target_registrations_interval;
params.adjustment_alpha = adjustment_alpha;
params.unit_emission = unit_emission;
params.curator = curator;
params.subnet_stake_threshold = subnet_stake_threshold;
params.proposal_cost = proposal_cost;
params.proposal_expiration = proposal_expiration;
params.proposal_participation_threshold = proposal_participation_threshold;
params.general_subnet_application_cost = general_subnet_application_cost;

params.burn_config.min_burn = min_burn;
params.burn_config.max_burn = max_burn;
params.burn_config.adjustment_alpha = adjustment_alpha;
params.burn_config.adjustment_interval = target_registrations_interval;
params.burn_config.expected_registrations = target_registrations_per_interval;

Self::do_add_global_proposal(origin, params)
}

Expand Down
Loading
Loading