Skip to content

Commit

Permalink
refactor: improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
MohsenNz committed Jan 11, 2025
1 parent 5d77cae commit ea74ee7
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 67 deletions.
3 changes: 0 additions & 3 deletions pallets/jungochain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,6 @@ pub mod pallet {
#[pallet::type_value]
/// Default value for network rate limit.
pub fn DefaultNetworkRateLimit<T: Config>() -> u64 {
if cfg!(feature = "pow-faucet") {
return 0;
}
T::InitialNetworkRateLimit::get()
}
#[pallet::type_value]
Expand Down
134 changes: 70 additions & 64 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ type MemberCount = u32;

pub type Nonce = u32;

type CU16<const T: u16> = ConstU16<T>;
type CU32<const T: u32> = ConstU32<T>;
type CU64<const T: u64> = ConstU64<T>;

// Method used to calculate the fee of an extrinsic
pub const fn deposit(items: u32, bytes: u32) -> Balance {
pub const ITEMS_FEE: Balance = 2_000 * 10_000;
Expand Down Expand Up @@ -908,71 +912,68 @@ impl pallet_jungochain::Config for Runtime {
type Preimages = Preimage;
type InitialIssuance = ConstU64<0>;
// -- Per subnet
type InitialRho = ConstU16<10>;
type InitialKappa = ConstU16<32_767>; // 0.5 = 65535/2
type InitialBondsMovingAverage = ConstU64<900_000>;
type InitialMaxAllowedUids = ConstU16<4096>;
type InitialMinAllowedWeights = ConstU16<1024>;
type InitialEmissionValue = ConstU16<0>;
type InitialMaxWeightsLimit = ConstU16<1000>; // 1000/2^16 = 0.015
type InitialValidatorPruneLen = ConstU64<1>;
type InitialScalingLawPower = ConstU16<50>; // 0.5
type InitialTempo = ConstU16<DEFAULT_SUBNET_TEMPO>;
type InitialAdjustmentInterval = ConstU16<100>;
type InitialAdjustmentAlpha = ConstU64<0>; // no weight to previous value.
type InitialTargetRegistrationsPerInterval = ConstU16<2>;
type InitialImmunityPeriod = ConstU16<4096>;
type InitialActivityCutoff = ConstU16<5000>;
type InitialMaxRegistrationsPerBlock = ConstU16<1>;
type InitialMaxAllowedValidators = ConstU16<128>;
type InitialPruningScore = ConstU16<{ u16::MAX }>;
type InitialDefaultDelegateTake = ConstU16<11_796>; // 18% honest number.
type InitialDefaultChildKeyTake = ConstU16<0>; // Allow 0% childkey take
type InitialMinDelegateTake = ConstU16<0>; // Allow 0% delegate take
type InitialMinChildKeyTake = ConstU16<0>; // 0 %
type InitialWeightsVersionKey = ConstU64<0>;
type InitialDifficulty = ConstU64<10_000_000>;
type InitialMaxDifficulty = ConstU64<{ u64::MAX / 4 }>;
type InitialMinDifficulty = ConstU64<10_000_000>;
type InitialServingRateLimit = ConstU64<50>;
type InitialBurn = ConstU64<1_000_000_000>; // 1 tao
type InitialMaxBurn = ConstU64<100_000_000_000>; // 100 tao
type InitialMinBurn = ConstU64<1_000_000_000>; // 1 tao
type InitialRho = CU16<10>;
type InitialKappa = CU16<32_767>; // 0.5 = 65535/2
type InitialBondsMovingAverage = CU64<900_000>;
type InitialMaxAllowedUids = CU16<4096>;
type InitialMinAllowedWeights = CU16<1024>;
type InitialEmissionValue = CU16<0>;
type InitialMaxWeightsLimit = CU16<1000>; // 1000/2^16 = 0.015
type InitialValidatorPruneLen = CU64<1>;
type InitialScalingLawPower = CU16<50>; // 0.5
type InitialTempo = CU16<DEFAULT_SUBNET_TEMPO>;
type InitialAdjustmentInterval = CU16<100>;
type InitialAdjustmentAlpha = CU64<0>; // no weight to previous value.
type InitialTargetRegistrationsPerInterval = CU16<2>;
type InitialImmunityPeriod = CU16<4096>;
type InitialActivityCutoff = CU16<5000>;
type InitialMaxRegistrationsPerBlock = CU16<1>;
type InitialMaxAllowedValidators = CU16<128>;
type InitialPruningScore = CU16<{ u16::MAX }>;
type InitialDefaultDelegateTake = CU16<11_796>; // 18% honest number.
type InitialDefaultChildKeyTake = CU16<0>; // Allow 0% childkey take
type InitialMinDelegateTake = CU16<0>; // Allow 0% delegate take
type InitialMinChildKeyTake = CU16<0>; // 0 %
type InitialWeightsVersionKey = CU64<0>;
type InitialDifficulty = CU64<10_000_000>;
type InitialMaxDifficulty = CU64<{ u64::MAX / 4 }>;
type InitialMinDifficulty = CU64<10_000_000>;
type InitialServingRateLimit = CU64<50>;
type InitialBurn = CU64<{ 1 * JUNGO }>;
type InitialMaxBurn = CU64<{ 100 * JUNGO }>;
type InitialMinBurn = CU64<{ 1 * JUNGO }>;
// --
type KeySwapCost = ConstU64<1_000_000_000>;
type AlphaHigh = ConstU16<58982>; // Represents 0.9 as per the production default
type AlphaLow = ConstU16<45875>; // Represents 0.7 as per the production default
type KeySwapCost = CU64<1_000_000_000>;
type AlphaHigh = CU16<58982>; // Represents 0.9 as per the production default
type AlphaLow = CU16<45875>; // Represents 0.7 as per the production default
type LiquidAlphaOn = ConstBool<false>;
type RootTempo = ConstU16<ROOT_TEMPO>;

type InitialTxRateLimit = ConstU64<SUBTENSOR_INITIAL_TX_RATE_LIMIT>;
type InitialTxDelegateTakeRateLimit = ConstU64<216000>; // 30 days at 12 seconds per block ?
type InitialTxChildKeyTakeRateLimit = ConstU64<INITIAL_CHILDKEY_TAKE_RATELIMIT>;
type InitialMaxChildKeyTake = ConstU16<11_796>; // 18 %
type InitialRAORecycledForRegistration = ConstU64<0>; // 0 rao
type InitialSenateRequiredStakePercentage = ConstU64<1>; // 1 percent of total stake
type InitialNetworkImmunityPeriod = ConstU64<{ 7 * 7200 }>;
type InitialNetworkMinAllowedUids = ConstU16<128>;
type InitialNetworkMinLockCost = ConstU64<1_000_000_000_000>; // 1000 TAO
type InitialNetworkLockReductionInterval = ConstU64<{ 14 * 7200 }>;
type InitialSubnetOwnerCut = ConstU16<11_796>; // 18 percent
type InitialSubnetLimit = ConstU16<1024>;
type InitialFirstReservedNetuids = ConstU16<FIRST_RESERVED_NETUIDS>;
type InitialNetworkRateLimit = SubtensorInitialNetworkRateLimit;
type InitialTargetStakesPerInterval = ConstU64<1>;
type InitialHotkeyEmissionTempo = SubtensorInitialHotkeyEmissionTempo;
type InitialNetworkMaxStake = ConstU64<{ u64::MAX }>; // Maximum possible value for u64, this make the make stake infinity
type InitialColdkeySwapScheduleDuration = InitialColdkeySwapScheduleDuration;
type InitialDissolveNetworkScheduleDuration = InitialDissolveNetworkScheduleDuration;
type DefaultStakeInterval = ConstU64<DEFAULT_STAKE_INTERVAL>;
type DefaultWeightsSetRateLimit = ConstU64<DEFAULT_WEIGHTS_SET_RATE_LIMIT>;
}
parameter_types! {
pub const SubtensorInitialNetworkRateLimit : u64 = 7200;
pub const SubtensorInitialHotkeyEmissionTempo : u64 = 7200; // Drain every day.
pub const InitialColdkeySwapScheduleDuration : BlockNumber = 5 * DAYS;
pub const InitialDissolveNetworkScheduleDuration : BlockNumber = 5 * DAYS;
}
type RootTempo = CU16<ROOT_TEMPO>;

type InitialTxRateLimit = CU64<SUBTENSOR_INITIAL_TX_RATE_LIMIT>;
type InitialTxDelegateTakeRateLimit = CU64<{ 30 * DAYS as u64}>;
type InitialTxChildKeyTakeRateLimit = CU64<INITIAL_CHILDKEY_TAKE_RATELIMIT>;
type InitialMaxChildKeyTake = CU16<11_796>; // 18 %
type InitialRAORecycledForRegistration = CU64<0>; // 0 rao
type InitialSenateRequiredStakePercentage = CU64<1>; // 1 percent of total stake
type InitialNetworkImmunityPeriod = CU64<{ 7 * DAYS as u64 }>;
type InitialNetworkMinAllowedUids = CU16<128>;
type InitialNetworkMinLockCost = CU64<{ 1_000 * JUNGO }>; // 1000 JUNGO
type InitialNetworkLockReductionInterval = CU64<{ 14 * DAYS as u64 }>;
type InitialSubnetOwnerCut = CU16<11_796>; // 18 percent
type InitialSubnetLimit = CU16<1024>;
type InitialFirstReservedNetuids = CU16<FIRST_RESERVED_NETUIDS>;
type InitialNetworkRateLimit = CU64<NETWORK_RATE_LIMIT>;
type InitialTargetStakesPerInterval = CU64<1>;
type InitialHotkeyEmissionTempo = CU64<{ 1 * DAYS as u64 }>;
type InitialNetworkMaxStake = CU64<{ u64::MAX }>; // Maximum possible value for u64, this make the make stake infinity
type InitialColdkeySwapScheduleDuration = CU32<{ 5 * DAYS }>;
type InitialDissolveNetworkScheduleDuration = CU32<{ 5 * DAYS }>;
type DefaultStakeInterval = CU64<DEFAULT_STAKE_INTERVAL>;
type DefaultWeightsSetRateLimit = CU64<DEFAULT_WEIGHTS_SET_RATE_LIMIT>;
}

pub const JUNGO: Balance = 1_000_000_000;

#[cfg(not(feature = "fast-blocks"))]
pub const ROOT_TEMPO: u16 = 20 * MINUTES as u16; //100;
#[cfg(feature = "fast-blocks")]
Expand All @@ -982,7 +983,7 @@ pub const DEFAULT_SUBNET_TEMPO: u16 = ROOT_TEMPO - 1;
pub const DEFAULT_STAKE_INTERVAL: u64 = DEFAULT_SUBNET_TEMPO as u64;

#[cfg(not(feature = "fast-blocks"))]
pub const INITIAL_CHILDKEY_TAKE_RATELIMIT: u64 = 216000; // 30 days at 12 seconds per block
pub const INITIAL_CHILDKEY_TAKE_RATELIMIT: u64 = 30 * DAYS as u64;
#[cfg(feature = "fast-blocks")]
pub const INITIAL_CHILDKEY_TAKE_RATELIMIT: u64 = 5;

Expand All @@ -1001,6 +1002,11 @@ pub const FIRST_RESERVED_NETUIDS: u16 = 1000;
#[cfg(feature = "fast-blocks")]
pub const FIRST_RESERVED_NETUIDS: u16 = 1000;

#[cfg(not(feature = "fast-blocks"))]
pub const NETWORK_RATE_LIMIT: u64 = 10 * MINUTES as u64; // bittensor value was 1 * DAYS
#[cfg(feature = "fast-blocks")]
pub const NETWORK_RATE_LIMIT: u64 = 0;

type EnsureMajoritySenate =
pallet_collective::EnsureProportionMoreThan<AccountId, TriumvirateCollective, 1, 2>;

Expand Down

0 comments on commit ea74ee7

Please sign in to comment.