Skip to content

Commit 85657c5

Browse files
committed
fix conflict
2 parents ab5b272 + 71455aa commit 85657c5

File tree

14 files changed

+584
-741
lines changed

14 files changed

+584
-741
lines changed

docs/wasm-contracts.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ For general smart contract development on Subtensor, please refer to the officia
1414
- [ink! Getting Started Guide](https://use.ink/docs/v5/getting-started/setup)
1515
- [ink! Examples](https://github.com/use-ink/ink-examples/tree/v5.x.x)
1616

17+
> [!WARNING]
18+
> ink! `>= 6.0` drops support for `pallet-contracts`, please use `ink < 6.0`.
19+
> See: https://github.com/use-ink/ink/releases/tag/v6.0.0-alpha
20+
1721
## Subtensor-Specific Features
1822

1923
### Chain Extension

pallets/admin-utils/src/lib.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ pub mod pallet {
10151015
#[pallet::call_index(33)]
10161016
#[pallet::weight((
10171017
Weight::from_parts(2_875_000, 0)
1018+
.saturating_add(T::DbWeight::get().reads(0_u64))
10181019
.saturating_add(T::DbWeight::get().writes(1_u64)),
10191020
DispatchClass::Operational,
10201021
Pays::Yes
@@ -1146,7 +1147,9 @@ pub mod pallet {
11461147
/// The extrinsic will call the Subtensor pallet to set the weights min stake.
11471148
#[pallet::call_index(42)]
11481149
#[pallet::weight((
1149-
Weight::from_parts(5_000_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)),
1150+
Weight::from_parts(5_000_000, 0)
1151+
.saturating_add(T::DbWeight::get().reads(0_u64))
1152+
.saturating_add(T::DbWeight::get().writes(1_u64)),
11501153
DispatchClass::Operational,
11511154
Pays::Yes
11521155
))]
@@ -1189,7 +1192,9 @@ pub mod pallet {
11891192
/// The extrinsic will call the Subtensor pallet to set the rate limit for delegate take transactions.
11901193
#[pallet::call_index(45)]
11911194
#[pallet::weight((
1192-
Weight::from_parts(5_019_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)),
1195+
Weight::from_parts(5_019_000, 0)
1196+
.saturating_add(T::DbWeight::get().reads(0_u64))
1197+
.saturating_add(T::DbWeight::get().writes(1_u64)),
11931198
DispatchClass::Operational,
11941199
Pays::Yes
11951200
))]
@@ -1210,7 +1215,9 @@ pub mod pallet {
12101215
/// The extrinsic will call the Subtensor pallet to set the minimum delegate take.
12111216
#[pallet::call_index(46)]
12121217
#[pallet::weight((
1213-
Weight::from_parts(7_214_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)),
1218+
Weight::from_parts(7_214_000, 0)
1219+
.saturating_add(T::DbWeight::get().reads(0_u64))
1220+
.saturating_add(T::DbWeight::get().writes(1_u64)),
12141221
DispatchClass::Operational,
12151222
Pays::Yes
12161223
))]
@@ -1266,6 +1273,7 @@ pub mod pallet {
12661273
#[pallet::call_index(50)]
12671274
#[pallet::weight((
12681275
Weight::from_parts(18_300_000, 0)
1276+
.saturating_add(T::DbWeight::get().reads(2_u64))
12691277
.saturating_add(T::DbWeight::get().writes(1_u64)),
12701278
DispatchClass::Normal,
12711279
Pays::Yes
@@ -1340,6 +1348,7 @@ pub mod pallet {
13401348
#[pallet::call_index(54)]
13411349
#[pallet::weight((
13421350
Weight::from_parts(5_000_000, 0)
1351+
.saturating_add(T::DbWeight::get().reads(0_u64))
13431352
.saturating_add(T::DbWeight::get().writes(1_u64)),
13441353
DispatchClass::Operational,
13451354
Pays::Yes
@@ -1377,6 +1386,7 @@ pub mod pallet {
13771386
#[pallet::call_index(55)]
13781387
#[pallet::weight((
13791388
Weight::from_parts(5_000_000, 0)
1389+
.saturating_add(T::DbWeight::get().reads(0_u64))
13801390
.saturating_add(T::DbWeight::get().writes(1_u64)),
13811391
DispatchClass::Operational,
13821392
Pays::Yes
@@ -1510,6 +1520,7 @@ pub mod pallet {
15101520
#[pallet::call_index(61)]
15111521
#[pallet::weight((
15121522
Weight::from_parts(20_460_000, 0)
1523+
.saturating_add(T::DbWeight::get().reads(2_u64))
15131524
.saturating_add(T::DbWeight::get().writes(1_u64)),
15141525
DispatchClass::Normal,
15151526
Pays::Yes
@@ -1582,7 +1593,8 @@ pub mod pallet {
15821593
#[pallet::call_index(62)]
15831594
#[pallet::weight((
15841595
Weight::from_parts(10_020_000, 3507)
1585-
.saturating_add(T::DbWeight::get().reads(1_u64)),
1596+
.saturating_add(T::DbWeight::get().reads(1_u64))
1597+
.saturating_add(T::DbWeight::get().writes(0_u64)),
15861598
DispatchClass::Operational,
15871599
Pays::Yes
15881600
))]
@@ -1616,6 +1628,7 @@ pub mod pallet {
16161628
#[pallet::call_index(63)]
16171629
#[pallet::weight((
16181630
Weight::from_parts(3_000_000, 0)
1631+
.saturating_add(T::DbWeight::get().reads(0_u64))
16191632
.saturating_add(T::DbWeight::get().writes(1_u64)),
16201633
DispatchClass::Operational,
16211634
Pays::Yes
@@ -1669,6 +1682,7 @@ pub mod pallet {
16691682
#[pallet::call_index(65)]
16701683
#[pallet::weight((
16711684
Weight::from_parts(6_201_000, 0)
1685+
.saturating_add(T::DbWeight::get().reads(0_u64))
16721686
.saturating_add(T::DbWeight::get().writes(1_u64)),
16731687
DispatchClass::Operational,
16741688
Pays::Yes
@@ -1755,6 +1769,7 @@ pub mod pallet {
17551769
#[pallet::call_index(69)]
17561770
#[pallet::weight((
17571771
Weight::from_parts(20_460_000, 0)
1772+
.saturating_add(T::DbWeight::get().reads(2_u64))
17581773
.saturating_add(T::DbWeight::get().writes(1_u64)),
17591774
DispatchClass::Normal,
17601775
Pays::Yes
@@ -1792,7 +1807,8 @@ pub mod pallet {
17921807
/// This function has a fixed weight of 0 and is classified as an operational transaction that does not incur any fees.
17931808
#[pallet::call_index(70)]
17941809
#[pallet::weight((
1795-
Weight::from_parts(22_340_000, 0)
1810+
Weight::from_parts(32_930_000, 0)
1811+
.saturating_add(T::DbWeight::get().reads(2_u64))
17961812
.saturating_add(T::DbWeight::get().writes(1_u64)),
17971813
DispatchClass::Normal,
17981814
Pays::Yes
@@ -1880,6 +1896,7 @@ pub mod pallet {
18801896
#[pallet::call_index(66)]
18811897
#[pallet::weight((
18821898
Weight::from_parts(17_980_000, 0)
1899+
.saturating_add(T::DbWeight::get().reads(2_u64))
18831900
.saturating_add(T::DbWeight::get().writes(1_u64)),
18841901
DispatchClass::Operational,
18851902
Pays::Yes

pallets/subtensor/src/coinbase/subnet_emissions.rs

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use alloc::collections::BTreeMap;
44
use safe_math::FixedExt;
55
use substrate_fixed::transcendental::{exp, ln};
66
use substrate_fixed::types::{I32F32, I64F64, U64F64, U96F32};
7+
use subtensor_swap_interface::SwapHandler;
78

89
impl<T: Config> Pallet<T> {
910
pub fn get_subnet_block_emissions(
@@ -50,6 +51,7 @@ impl<T: Config> Pallet<T> {
5051

5152
// Update SubnetEmaTaoFlow if needed and return its value for
5253
// the current block
54+
#[allow(dead_code)]
5355
fn get_ema_flow(netuid: NetUid) -> I64F64 {
5456
let current_block: u64 = Self::get_current_block_as_u64();
5557

@@ -73,8 +75,12 @@ impl<T: Config> Pallet<T> {
7375
last_block_ema
7476
}
7577
} else {
76-
// Initialize EMA flow, set S(current_block) = 0
77-
let ema_flow = I64F64::saturating_from_num(0);
78+
// Initialize EMA flow, set S(current_block) = min(price, ema_price) * init_factor
79+
let init_factor = I64F64::saturating_from_num(1_000_000_000);
80+
let moving_price = I64F64::saturating_from_num(Self::get_moving_alpha_price(netuid));
81+
let current_price =
82+
I64F64::saturating_from_num(T::SwapInterface::current_alpha_price(netuid));
83+
let ema_flow = init_factor.saturating_mul(moving_price.min(current_price));
7884
SubnetEmaTaoFlow::<T>::insert(netuid, (current_block, ema_flow));
7985
ema_flow
8086
}
@@ -83,6 +89,7 @@ impl<T: Config> Pallet<T> {
8389
// Either the minimal EMA flow L = min{Si}, or an artificial
8490
// cut off at some higher value A (TaoFlowCutoff)
8591
// L = max {A, min{min{S[i], 0}}}
92+
#[allow(dead_code)]
8693
fn get_lower_limit(ema_flows: &BTreeMap<NetUid, I64F64>) -> I64F64 {
8794
let zero = I64F64::saturating_from_num(0);
8895
let min_flow = ema_flows
@@ -174,6 +181,7 @@ impl<T: Config> Pallet<T> {
174181
}
175182

176183
// Implementation of shares that uses TAO flow
184+
#[allow(dead_code)]
177185
fn get_shares_flow(subnets_to_emit_to: &[NetUid]) -> BTreeMap<NetUid, U64F64> {
178186
// Get raw flows
179187
let ema_flows = subnets_to_emit_to
@@ -206,7 +214,14 @@ impl<T: Config> Pallet<T> {
206214
offset_flows
207215
}
208216

217+
// Combines ema price method and tao flow method linearly over FlowHalfLife blocks
218+
pub(crate) fn get_shares(subnets_to_emit_to: &[NetUid]) -> BTreeMap<NetUid, U64F64> {
219+
Self::get_shares_flow(subnets_to_emit_to)
220+
// Self::get_shares_price_ema(subnets_to_emit_to)
221+
}
222+
209223
// DEPRECATED: Implementation of shares that uses EMA prices will be gradually deprecated
224+
#[allow(dead_code)]
210225
fn get_shares_price_ema(subnets_to_emit_to: &[NetUid]) -> BTreeMap<NetUid, U64F64> {
211226
// Get sum of alpha moving prices
212227
let total_moving_prices = subnets_to_emit_to
@@ -233,61 +248,4 @@ impl<T: Config> Pallet<T> {
233248
})
234249
.collect::<BTreeMap<NetUid, U64F64>>()
235250
}
236-
237-
// Combines ema price method and tao flow method linearly over FlowHalfLife blocks
238-
pub(crate) fn get_shares(subnets_to_emit_to: &[NetUid]) -> BTreeMap<NetUid, U64F64> {
239-
let current_block: u64 = Self::get_current_block_as_u64();
240-
241-
// Weight of tao flow method
242-
let period = FlowHalfLife::<T>::get();
243-
let one = U64F64::saturating_from_num(1);
244-
let zero = U64F64::saturating_from_num(0);
245-
let tao_flow_weight = if let Some(start_block) = FlowFirstBlock::<T>::get() {
246-
if (current_block > start_block) && (current_block < start_block.saturating_add(period))
247-
{
248-
// Combination period in progress
249-
let start_fixed = U64F64::saturating_from_num(start_block);
250-
let current_fixed = U64F64::saturating_from_num(current_block);
251-
let period_fixed = U64F64::saturating_from_num(period);
252-
current_fixed
253-
.saturating_sub(start_fixed)
254-
.safe_div(period_fixed)
255-
} else if current_block >= start_block.saturating_add(period) {
256-
// Over combination period
257-
one
258-
} else {
259-
// Not yet in combination period
260-
zero
261-
}
262-
} else {
263-
zero
264-
};
265-
266-
// Get shares for each method as needed
267-
let shares_flow = if tao_flow_weight > zero {
268-
Self::get_shares_flow(subnets_to_emit_to)
269-
} else {
270-
BTreeMap::new()
271-
};
272-
273-
let shares_prices = if tao_flow_weight < one {
274-
Self::get_shares_price_ema(subnets_to_emit_to)
275-
} else {
276-
BTreeMap::new()
277-
};
278-
279-
// Combine
280-
let mut shares_combined = BTreeMap::new();
281-
for netuid in subnets_to_emit_to.iter() {
282-
let share_flow = shares_flow.get(netuid).unwrap_or(&zero);
283-
let share_prices = shares_prices.get(netuid).unwrap_or(&zero);
284-
shares_combined.insert(
285-
*netuid,
286-
share_flow.saturating_mul(tao_flow_weight).saturating_add(
287-
share_prices.saturating_mul(one.saturating_sub(tao_flow_weight)),
288-
),
289-
);
290-
}
291-
shares_combined
292-
}
293251
}

pallets/subtensor/src/lib.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ pub mod pallet {
8888
use frame_system::pallet_prelude::*;
8989
use pallet_drand::types::RoundNumber;
9090
use runtime_common::prod_or_fast;
91-
use safe_math::FixedExt;
9291
use sp_core::{ConstU32, H160, H256};
9392
use sp_runtime::traits::{Dispatchable, TrailingZeroInput};
9493
use sp_std::collections::btree_map::BTreeMap;
@@ -1445,7 +1444,7 @@ pub mod pallet {
14451444
#[pallet::type_value]
14461445
/// Default value for flow normalization exponent.
14471446
pub fn DefaultFlowNormExponent<T: Config>() -> U64F64 {
1448-
U64F64::saturating_from_num(15).safe_div(U64F64::saturating_from_num(10))
1447+
U64F64::saturating_from_num(1)
14491448
}
14501449
#[pallet::storage]
14511450
/// --- ITEM --> Flow Normalization Exponent (p)
@@ -1455,7 +1454,7 @@ pub mod pallet {
14551454
/// Default value for flow EMA smoothing.
14561455
pub fn DefaultFlowEmaSmoothingFactor<T: Config>() -> u64 {
14571456
// Example values:
1458-
// half-life factor value i64 normalized
1457+
// half-life factor value i64 normalized (x 2^63)
14591458
// 216000 (1 month) --> 0.000003209009576 ( 29_597_889_189_277)
14601459
// 50400 (1 week) --> 0.000013752825678 (126_847_427_788_335)
14611460
29_597_889_189_277
@@ -1469,9 +1468,6 @@ pub mod pallet {
14691468
/// --- ITEM --> Flow EMA smoothing factor (flow alpha), u64 normalized
14701469
pub type FlowEmaSmoothingFactor<T: Config> =
14711470
StorageValue<_, u64, ValueQuery, DefaultFlowEmaSmoothingFactor<T>>;
1472-
#[pallet::storage]
1473-
/// --- ITEM --> Block when TAO flow calculation starts(ed)
1474-
pub type FlowFirstBlock<T: Config> = StorageValue<_, u64, OptionQuery>;
14751471

14761472
/// ============================
14771473
/// ==== Global Parameters =====
@@ -2227,9 +2223,9 @@ pub mod pallet {
22272223
pub type RootClaimed<T: Config> = StorageNMap<
22282224
_,
22292225
(
2226+
NMapKey<Identity, NetUid>, // subnet
22302227
NMapKey<Blake2_128Concat, T::AccountId>, // hot
22312228
NMapKey<Blake2_128Concat, T::AccountId>, // cold
2232-
NMapKey<Identity, NetUid>, // subnet
22332229
),
22342230
u128,
22352231
ValueQuery,

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,8 @@ mod dispatches {
712712
///
713713
#[pallet::call_index(2)]
714714
#[pallet::weight((Weight::from_parts(340_800_000, 0)
715-
.saturating_add(T::DbWeight::get().reads(24_u64))
716-
.saturating_add(T::DbWeight::get().writes(15)), DispatchClass::Normal, Pays::Yes))]
715+
.saturating_add(T::DbWeight::get().reads(25_u64))
716+
.saturating_add(T::DbWeight::get().writes(16_u64)), DispatchClass::Normal, Pays::Yes))]
717717
pub fn add_stake(
718718
origin: OriginFor<T>,
719719
hotkey: T::AccountId,
@@ -1587,8 +1587,8 @@ mod dispatches {
15871587
/// - Thrown if key has hit transaction rate limit
15881588
#[pallet::call_index(84)]
15891589
#[pallet::weight((Weight::from_parts(358_500_000, 0)
1590-
.saturating_add(T::DbWeight::get().reads(39_u64))
1591-
.saturating_add(T::DbWeight::get().writes(24_u64)), DispatchClass::Normal, Pays::Yes))]
1590+
.saturating_add(T::DbWeight::get().reads(41_u64))
1591+
.saturating_add(T::DbWeight::get().writes(26_u64)), DispatchClass::Normal, Pays::Yes))]
15921592
pub fn unstake_all_alpha(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
15931593
Self::do_unstake_all_alpha(origin, hotkey)
15941594
}
@@ -1701,8 +1701,8 @@ mod dispatches {
17011701
#[pallet::call_index(87)]
17021702
#[pallet::weight((
17031703
Weight::from_parts(351_300_000, 0)
1704-
.saturating_add(T::DbWeight::get().reads(35_u64))
1705-
.saturating_add(T::DbWeight::get().writes(22_u64)),
1704+
.saturating_add(T::DbWeight::get().reads(37_u64))
1705+
.saturating_add(T::DbWeight::get().writes(24_u64)),
17061706
DispatchClass::Normal,
17071707
Pays::Yes
17081708
))]
@@ -1766,8 +1766,8 @@ mod dispatches {
17661766
///
17671767
#[pallet::call_index(88)]
17681768
#[pallet::weight((Weight::from_parts(402_900_000, 0)
1769-
.saturating_add(T::DbWeight::get().reads(24_u64))
1770-
.saturating_add(T::DbWeight::get().writes(15)), DispatchClass::Normal, Pays::Yes))]
1769+
.saturating_add(T::DbWeight::get().reads(25_u64))
1770+
.saturating_add(T::DbWeight::get().writes(16_u64)), DispatchClass::Normal, Pays::Yes))]
17711771
pub fn add_stake_limit(
17721772
origin: OriginFor<T>,
17731773
hotkey: T::AccountId,
@@ -1830,8 +1830,8 @@ mod dispatches {
18301830
///
18311831
#[pallet::call_index(89)]
18321832
#[pallet::weight((Weight::from_parts(377_400_000, 0)
1833-
.saturating_add(T::DbWeight::get().reads(28_u64))
1834-
.saturating_add(T::DbWeight::get().writes(14)), DispatchClass::Normal, Pays::Yes))]
1833+
.saturating_add(T::DbWeight::get().reads(29_u64))
1834+
.saturating_add(T::DbWeight::get().writes(15_u64)), DispatchClass::Normal, Pays::Yes))]
18351835
pub fn remove_stake_limit(
18361836
origin: OriginFor<T>,
18371837
hotkey: T::AccountId,
@@ -1874,8 +1874,8 @@ mod dispatches {
18741874
#[pallet::call_index(90)]
18751875
#[pallet::weight((
18761876
Weight::from_parts(411_500_000, 0)
1877-
.saturating_add(T::DbWeight::get().reads(35_u64))
1878-
.saturating_add(T::DbWeight::get().writes(22_u64)),
1877+
.saturating_add(T::DbWeight::get().reads(37_u64))
1878+
.saturating_add(T::DbWeight::get().writes(24_u64)),
18791879
DispatchClass::Normal,
18801880
Pays::Yes
18811881
))]
@@ -2052,8 +2052,8 @@ mod dispatches {
20522052
/// Without limit_price it remove all the stake similar to `remove_stake` extrinsic
20532053
#[pallet::call_index(103)]
20542054
#[pallet::weight((Weight::from_parts(395_300_000, 10142)
2055-
.saturating_add(T::DbWeight::get().reads(28_u64))
2056-
.saturating_add(T::DbWeight::get().writes(14_u64)), DispatchClass::Normal, Pays::Yes))]
2055+
.saturating_add(T::DbWeight::get().reads(29_u64))
2056+
.saturating_add(T::DbWeight::get().writes(15_u64)), DispatchClass::Normal, Pays::Yes))]
20572057
pub fn remove_stake_full_limit(
20582058
origin: T::RuntimeOrigin,
20592059
hotkey: T::AccountId,
@@ -2210,7 +2210,7 @@ mod dispatches {
22102210
#[pallet::call_index(114)]
22112211
#[pallet::weight((Weight::from_parts(29_930_000, 0)
22122212
.saturating_add(T::DbWeight::get().reads(4_u64))
2213-
.saturating_add(T::DbWeight::get().writes(2_u64)), DispatchClass::Normal, Pays::No))]
2213+
.saturating_add(T::DbWeight::get().writes(2_u64)), DispatchClass::Normal, Pays::Yes))]
22142214
pub fn set_coldkey_auto_stake_hotkey(
22152215
origin: T::RuntimeOrigin,
22162216
netuid: NetUid,

0 commit comments

Comments
 (0)