Skip to content

Commit 00def43

Browse files
committed
Merge branch 'devnet-ready' into manual-sealing-for-aura-fix
2 parents d1db96a + e40090e commit 00def43

33 files changed

+373
-120
lines changed

.github/e2e.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: E2E Tests
2+
3+
on:
4+
workflow_dispatch:

pallets/subtensor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ rand_chacha.workspace = true
5656
pallet-crowdloan.workspace = true
5757
pallet-subtensor-proxy.workspace = true
5858
pallet-shield.workspace = true
59+
pallet-scheduler.workspace = true
5960

6061
[dev-dependencies]
6162
pallet-balances = { workspace = true, features = ["std"] }
62-
pallet-scheduler.workspace = true
6363
pallet-subtensor-proxy.workspace = true
6464
pallet-aura.workspace = true
6565
subtensor-runtime-common.workspace = true

pallets/subtensor/src/benchmarks.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,21 @@ mod pallet_benchmarks {
554554
_(RawOrigin::Signed(coldkey));
555555
}
556556

557+
#[benchmark]
558+
fn clear_coldkey_swap_announcement() {
559+
let coldkey: T::AccountId = account("coldkey", 0, 0);
560+
let new_coldkey: T::AccountId = account("new_coldkey", 0, 0);
561+
let new_coldkey_hash: T::Hash = <T as frame_system::Config>::Hashing::hash_of(&new_coldkey);
562+
let now = frame_system::Pallet::<T>::block_number();
563+
let delay = ColdkeySwapReannouncementDelay::<T>::get();
564+
565+
ColdkeySwapAnnouncements::<T>::insert(&coldkey, (now, new_coldkey_hash));
566+
frame_system::Pallet::<T>::set_block_number(now + delay);
567+
568+
#[extrinsic_call]
569+
_(RawOrigin::Signed(coldkey));
570+
}
571+
557572
#[benchmark]
558573
fn reset_coldkey_swap() {
559574
let coldkey: T::AccountId = account("old_coldkey", 0, 0);
@@ -586,7 +601,8 @@ mod pallet_benchmarks {
586601
let block_number: u64 = Subtensor::<T>::get_current_block_as_u64();
587602
let (nonce, work) =
588603
Subtensor::<T>::create_work_for_block_number(netuid, block_number, 3, &hotkey);
589-
let origin = T::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone()));
604+
let origin =
605+
<T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone()));
590606
assert_ok!(Subtensor::<T>::register(
591607
origin.clone(),
592608
netuid,

pallets/subtensor/src/coinbase/reveal_commits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<T: Config> Pallet<T> {
178178
// Apply weights
179179
// ------------------------------------------------------------------
180180
if let Err(e) = Self::do_set_mechanism_weights(
181-
T::RuntimeOrigin::signed(who.clone()),
181+
OriginFor::<T>::signed(who.clone()),
182182
netuid,
183183
MechId::from(mecid),
184184
uids,

pallets/subtensor/src/coinbase/root.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<T: Config> Pallet<T> {
7777
/// # Returns:
7878
/// * 'DispatchResult': A result type indicating success or failure of the registration.
7979
///
80-
pub fn do_root_register(origin: T::RuntimeOrigin, hotkey: T::AccountId) -> DispatchResult {
80+
pub fn do_root_register(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
8181
// --- 0. Get the unique identifier (UID) for the root network.
8282
let current_block_number: u64 = Self::get_current_block_as_u64();
8383
ensure!(

pallets/subtensor/src/epoch/run_epoch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ impl<T: Config> Pallet<T> {
15081508
}
15091509

15101510
pub fn do_set_alpha_values(
1511-
origin: T::RuntimeOrigin,
1511+
origin: OriginFor<T>,
15121512
netuid: NetUid,
15131513
alpha_low: u16,
15141514
alpha_high: u16,

pallets/subtensor/src/guards/check_coldkey_swap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ where
5151
Call::announce_coldkey_swap { .. }
5252
| Call::swap_coldkey_announced { .. }
5353
| Call::dispute_coldkey_swap { .. }
54+
| Call::clear_coldkey_swap_announcement { .. }
5455
)
5556
);
5657

pallets/subtensor/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub(crate) mod tests;
5656
// apparently this is stabilized since rust 1.36
5757
extern crate alloc;
5858

59+
pub type OriginFor<T> = <T as frame_system::Config>::RuntimeOrigin;
60+
5961
pub const MAX_CRV3_COMMIT_SIZE_BYTES: u32 = 5000;
6062

6163
pub const ALPHA_MAP_BATCH_SIZE: usize = 30;

pallets/subtensor/src/macros/config.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ mod config {
1414
/// Configure the pallet by specifying the parameters and types on which it depends.
1515
#[pallet::config]
1616
pub trait Config:
17-
frame_system::Config + pallet_drand::Config + pallet_crowdloan::Config
17+
frame_system::Config
18+
+ pallet_drand::Config
19+
+ pallet_crowdloan::Config
20+
+ pallet_scheduler::Config
1821
{
1922
/// call type
2023
type RuntimeCall: Parameter
21-
+ Dispatchable<RuntimeOrigin = Self::RuntimeOrigin>
24+
+ Dispatchable<RuntimeOrigin = OriginFor<Self>>
2225
+ From<Call<Self>>
2326
+ IsType<<Self as frame_system::Config>::RuntimeCall>
2427
+ From<frame_system::Call<Self>>;
2528

2629
/// A sudo-able call.
2730
type SudoRuntimeCall: Parameter
28-
+ UnfilteredDispatchable<RuntimeOrigin = Self::RuntimeOrigin>
31+
+ UnfilteredDispatchable<RuntimeOrigin = OriginFor<Self>>
2932
+ GetDispatchInfo;
3033

3134
/// Currency type that will be used to place deposits on neurons

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ mod dispatches {
241241
.saturating_add(T::DbWeight::get().reads(10_u64))
242242
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
243243
pub fn commit_weights(
244-
origin: T::RuntimeOrigin,
244+
origin: OriginFor<T>,
245245
netuid: NetUid,
246246
commit_hash: H256,
247247
) -> DispatchResult {
@@ -275,7 +275,7 @@ mod dispatches {
275275
.saturating_add(T::DbWeight::get().reads(7))
276276
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
277277
pub fn commit_mechanism_weights(
278-
origin: T::RuntimeOrigin,
278+
origin: OriginFor<T>,
279279
netuid: NetUid,
280280
mecid: MechId,
281281
commit_hash: H256,
@@ -359,7 +359,7 @@ mod dispatches {
359359
.saturating_add(T::DbWeight::get().reads(17_u64))
360360
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
361361
pub fn reveal_weights(
362-
origin: T::RuntimeOrigin,
362+
origin: OriginFor<T>,
363363
netuid: NetUid,
364364
uids: Vec<u16>,
365365
values: Vec<u16>,
@@ -414,7 +414,7 @@ mod dispatches {
414414
.saturating_add(T::DbWeight::get().reads(16))
415415
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
416416
pub fn reveal_mechanism_weights(
417-
origin: T::RuntimeOrigin,
417+
origin: OriginFor<T>,
418418
netuid: NetUid,
419419
mecid: MechId,
420420
uids: Vec<u16>,
@@ -512,7 +512,7 @@ mod dispatches {
512512
.saturating_add(T::DbWeight::get().reads(7_u64))
513513
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
514514
pub fn commit_crv3_mechanism_weights(
515-
origin: T::RuntimeOrigin,
515+
origin: OriginFor<T>,
516516
netuid: NetUid,
517517
mecid: MechId,
518518
commit: BoundedVec<u8, ConstU32<MAX_CRV3_COMMIT_SIZE_BYTES>>,
@@ -572,7 +572,7 @@ mod dispatches {
572572
.saturating_add(T::DbWeight::get().reads(17_u64))
573573
.saturating_add(T::DbWeight::get().writes(2_u64)), DispatchClass::Normal, Pays::No))]
574574
pub fn batch_reveal_weights(
575-
origin: T::RuntimeOrigin,
575+
origin: OriginFor<T>,
576576
netuid: NetUid,
577577
uids_list: Vec<Vec<u16>>,
578578
values_list: Vec<Vec<u16>>,
@@ -1339,7 +1339,7 @@ mod dispatches {
13391339
.saturating_add(T::DbWeight::get().reads(6))
13401340
.saturating_add(T::DbWeight::get().writes(31)), DispatchClass::Normal, Pays::Yes))]
13411341
pub fn set_children(
1342-
origin: T::RuntimeOrigin,
1342+
origin: OriginFor<T>,
13431343
hotkey: T::AccountId,
13441344
netuid: NetUid,
13451345
children: Vec<(u64, T::AccountId)>,
@@ -1558,7 +1558,7 @@ mod dispatches {
15581558
.saturating_add(T::DbWeight::get().reads(19_u64))
15591559
.saturating_add(T::DbWeight::get().writes(7_u64)), DispatchClass::Normal, Pays::Yes))]
15601560
pub fn move_stake(
1561-
origin: T::RuntimeOrigin,
1561+
origin: OriginFor<T>,
15621562
origin_hotkey: T::AccountId,
15631563
destination_hotkey: T::AccountId,
15641564
origin_netuid: NetUid,
@@ -1601,7 +1601,7 @@ mod dispatches {
16011601
.saturating_add(T::DbWeight::get().reads(16_u64))
16021602
.saturating_add(T::DbWeight::get().writes(6_u64)), DispatchClass::Normal, Pays::Yes))]
16031603
pub fn transfer_stake(
1604-
origin: T::RuntimeOrigin,
1604+
origin: OriginFor<T>,
16051605
destination_coldkey: T::AccountId,
16061606
hotkey: T::AccountId,
16071607
origin_netuid: NetUid,
@@ -1646,7 +1646,7 @@ mod dispatches {
16461646
Pays::Yes
16471647
))]
16481648
pub fn swap_stake(
1649-
origin: T::RuntimeOrigin,
1649+
origin: OriginFor<T>,
16501650
hotkey: T::AccountId,
16511651
origin_netuid: NetUid,
16521652
destination_netuid: NetUid,
@@ -1820,7 +1820,7 @@ mod dispatches {
18201820
Pays::Yes
18211821
))]
18221822
pub fn swap_stake_limit(
1823-
origin: T::RuntimeOrigin,
1823+
origin: OriginFor<T>,
18241824
hotkey: T::AccountId,
18251825
origin_netuid: NetUid,
18261826
destination_netuid: NetUid,
@@ -1853,10 +1853,7 @@ mod dispatches {
18531853
DispatchClass::Normal,
18541854
Pays::Yes
18551855
))]
1856-
pub fn try_associate_hotkey(
1857-
origin: T::RuntimeOrigin,
1858-
hotkey: T::AccountId,
1859-
) -> DispatchResult {
1856+
pub fn try_associate_hotkey(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
18601857
let coldkey = ensure_signed(origin)?;
18611858

18621859
let _ = Self::do_try_associate_hotkey(&coldkey, &hotkey);
@@ -1878,7 +1875,7 @@ mod dispatches {
18781875
DispatchClass::Normal,
18791876
Pays::Yes
18801877
))]
1881-
pub fn start_call(origin: T::RuntimeOrigin, netuid: NetUid) -> DispatchResult {
1878+
pub fn start_call(origin: OriginFor<T>, netuid: NetUid) -> DispatchResult {
18821879
Self::do_start_call(origin, netuid)?;
18831880
Ok(())
18841881
}
@@ -1915,7 +1912,7 @@ mod dispatches {
19151912
Pays::No
19161913
))]
19171914
pub fn associate_evm_key(
1918-
origin: T::RuntimeOrigin,
1915+
origin: OriginFor<T>,
19191916
netuid: NetUid,
19201917
evm_key: H160,
19211918
block_number: u64,
@@ -1941,7 +1938,7 @@ mod dispatches {
19411938
Pays::Yes
19421939
))]
19431940
pub fn recycle_alpha(
1944-
origin: T::RuntimeOrigin,
1941+
origin: OriginFor<T>,
19451942
hotkey: T::AccountId,
19461943
amount: AlphaBalance,
19471944
netuid: NetUid,
@@ -1966,7 +1963,7 @@ mod dispatches {
19661963
Pays::Yes
19671964
))]
19681965
pub fn burn_alpha(
1969-
origin: T::RuntimeOrigin,
1966+
origin: OriginFor<T>,
19701967
hotkey: T::AccountId,
19711968
amount: AlphaBalance,
19721969
netuid: NetUid,
@@ -1995,7 +1992,7 @@ mod dispatches {
19951992
.saturating_add(T::DbWeight::get().reads(30_u64))
19961993
.saturating_add(T::DbWeight::get().writes(13_u64)), DispatchClass::Normal, Pays::Yes))]
19971994
pub fn remove_stake_full_limit(
1998-
origin: T::RuntimeOrigin,
1995+
origin: OriginFor<T>,
19991996
hotkey: T::AccountId,
20001997
netuid: NetUid,
20011998
limit_price: Option<TaoBalance>,
@@ -2022,7 +2019,7 @@ mod dispatches {
20222019
#[pallet::call_index(110)]
20232020
#[pallet::weight(SubnetLeasingWeightInfo::<T>::do_register_leased_network(T::MaxContributors::get()))]
20242021
pub fn register_leased_network(
2025-
origin: T::RuntimeOrigin,
2022+
origin: OriginFor<T>,
20262023
emissions_share: Percent,
20272024
end_block: Option<BlockNumberFor<T>>,
20282025
) -> DispatchResultWithPostInfo {
@@ -2048,7 +2045,7 @@ mod dispatches {
20482045
#[pallet::call_index(111)]
20492046
#[pallet::weight(SubnetLeasingWeightInfo::<T>::do_terminate_lease(T::MaxContributors::get()))]
20502047
pub fn terminate_lease(
2051-
origin: T::RuntimeOrigin,
2048+
origin: OriginFor<T>,
20522049
lease_id: LeaseId,
20532050
hotkey: T::AccountId,
20542051
) -> DispatchResultWithPostInfo {
@@ -2121,7 +2118,7 @@ mod dispatches {
21212118
.saturating_add(T::DbWeight::get().reads(10_u64))
21222119
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
21232120
pub fn commit_timelocked_weights(
2124-
origin: T::RuntimeOrigin,
2121+
origin: OriginFor<T>,
21252122
netuid: NetUid,
21262123
commit: BoundedVec<u8, ConstU32<MAX_CRV3_COMMIT_SIZE_BYTES>>,
21272124
reveal_round: u64,
@@ -2152,7 +2149,7 @@ mod dispatches {
21522149
.saturating_add(T::DbWeight::get().reads(4_u64))
21532150
.saturating_add(T::DbWeight::get().writes(2_u64)), DispatchClass::Normal, Pays::Yes))]
21542151
pub fn set_coldkey_auto_stake_hotkey(
2155-
origin: T::RuntimeOrigin,
2152+
origin: OriginFor<T>,
21562153
netuid: NetUid,
21572154
hotkey: T::AccountId,
21582155
) -> DispatchResult {
@@ -2226,7 +2223,7 @@ mod dispatches {
22262223
.saturating_add(T::DbWeight::get().reads(9_u64))
22272224
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
22282225
pub fn commit_timelocked_mechanism_weights(
2229-
origin: T::RuntimeOrigin,
2226+
origin: OriginFor<T>,
22302227
netuid: NetUid,
22312228
mecid: MechId,
22322229
commit: BoundedVec<u8, ConstU32<MAX_CRV3_COMMIT_SIZE_BYTES>>,
@@ -2326,7 +2323,7 @@ mod dispatches {
23262323

23272324
/// --- Sets root claim number (sudo extrinsic). Zero disables auto-claim.
23282325
#[pallet::call_index(123)]
2329-
#[pallet::weight(Weight::from_parts(4_000_000, 0)
2326+
#[pallet::weight(Weight::from_parts(2_283_000, 0)
23302327
.saturating_add(T::DbWeight::get().reads(0_u64))
23312328
.saturating_add(T::DbWeight::get().writes(1_u64)))]
23322329
pub fn sudo_set_num_root_claims(origin: OriginFor<T>, new_value: u64) -> DispatchResult {
@@ -2397,8 +2394,8 @@ mod dispatches {
23972394

23982395
if let Some((when, _)) = ColdkeySwapAnnouncements::<T>::get(who.clone()) {
23992396
let reannouncement_delay = ColdkeySwapReannouncementDelay::<T>::get();
2400-
let new_when = when.saturating_add(reannouncement_delay);
2401-
ensure!(now >= new_when, Error::<T>::ColdkeySwapReannouncedTooEarly);
2397+
let min_when = when.saturating_add(reannouncement_delay);
2398+
ensure!(now >= min_when, Error::<T>::ColdkeySwapReannouncedTooEarly);
24022399
} else {
24032400
// Only charge the swap cost on the first announcement
24042401
let swap_cost = Self::get_key_swap_cost();
@@ -2596,13 +2593,38 @@ mod dispatches {
25962593
Pays::Yes
25972594
))]
25982595
pub fn add_stake_burn(
2599-
origin: T::RuntimeOrigin,
2596+
origin: OriginFor<T>,
26002597
hotkey: T::AccountId,
26012598
netuid: NetUid,
26022599
amount: TaoBalance,
26032600
limit: Option<TaoBalance>,
26042601
) -> DispatchResult {
26052602
Self::do_add_stake_burn(origin, hotkey, netuid, amount, limit)
26062603
}
2604+
2605+
/// Clears a coldkey swap announcement after the reannouncement delay if
2606+
/// it has not been disputed.
2607+
///
2608+
/// The `ColdkeySwapCleared` event is emitted on successful clear.
2609+
#[pallet::call_index(133)]
2610+
#[pallet::weight(Weight::from_parts(17_890_000, 0)
2611+
.saturating_add(T::DbWeight::get().reads(2))
2612+
.saturating_add(T::DbWeight::get().writes(1)))]
2613+
pub fn clear_coldkey_swap_announcement(origin: OriginFor<T>) -> DispatchResult {
2614+
let who = ensure_signed(origin)?;
2615+
let now = <frame_system::Pallet<T>>::block_number();
2616+
2617+
let Some((when, _)) = ColdkeySwapAnnouncements::<T>::get(who.clone()) else {
2618+
return Err(Error::<T>::ColdkeySwapAnnouncementNotFound.into());
2619+
};
2620+
let delay = ColdkeySwapReannouncementDelay::<T>::get();
2621+
let min_when = when.saturating_add(delay);
2622+
ensure!(now >= min_when, Error::<T>::ColdkeySwapClearTooEarly);
2623+
2624+
ColdkeySwapAnnouncements::<T>::remove(&who);
2625+
2626+
Self::deposit_event(Event::ColdkeySwapCleared { who });
2627+
Ok(())
2628+
}
26072629
}
26082630
}

0 commit comments

Comments
 (0)