Skip to content

Commit 9de9f7c

Browse files
committed
allow for reannouncement in tx ext
1 parent be0e7dd commit 9de9f7c

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,6 +2381,7 @@ mod dispatches {
23812381
let new_when = when.saturating_add(reannouncement_delay);
23822382
ensure!(now >= new_when, Error::<T>::ColdkeySwapReannouncedTooEarly);
23832383
} else {
2384+
// Only charge the swap cost on the first announcement
23842385
let swap_cost = Self::get_key_swap_cost();
23852386
Self::charge_swap_cost(&who, swap_cost)?;
23862387
}

pallets/subtensor/src/tests/swap_coldkey.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,12 +1272,15 @@ fn test_remove_coldkey_swap_announcement_with_bad_origin_fails() {
12721272
}
12731273

12741274
#[test]
1275-
fn test_subtensor_extension_rejects_any_call_that_is_not_swap_coldkey_announced() {
1275+
fn test_subtensor_extension_rejects_any_call_that_is_not_announce_or_swap() {
12761276
new_test_ext(0).execute_with(|| {
12771277
let netuid = NetUid::from(1);
12781278
let who = U256::from(0);
12791279
let new_coldkey = U256::from(1);
1280+
let another_coldkey = U256::from(3);
12801281
let new_coldkey_hash = <Test as frame_system::Config>::Hashing::hash_of(&new_coldkey);
1282+
let another_coldkey_hash =
1283+
<Test as frame_system::Config>::Hashing::hash_of(&another_coldkey);
12811284
let hotkey = U256::from(2);
12821285
let stake = DefaultMinStake::<Test>::get().to_u64();
12831286
assert_ne!(hotkey, who);
@@ -1380,6 +1383,14 @@ fn test_subtensor_extension_rejects_any_call_that_is_not_swap_coldkey_announced(
13801383
);
13811384
}
13821385

1386+
// Reannounce coldkey swap should succeed
1387+
let call = RuntimeCall::SubtensorModule(SubtensorCall::announce_coldkey_swap {
1388+
new_coldkey_hash: another_coldkey_hash,
1389+
});
1390+
let info = call.get_dispatch_info();
1391+
let ext = SubtensorTransactionExtension::<Test>::new();
1392+
assert_ok!(ext.dispatch_transaction(RuntimeOrigin::signed(who).into(), call, &info, 0, 0));
1393+
13831394
// Swap coldkey announced should succeed
13841395
let call =
13851396
RuntimeCall::SubtensorModule(SubtensorCall::swap_coldkey_announced { new_coldkey });

pallets/subtensor/src/transaction_extension.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ where
119119
if ColdkeySwapAnnouncements::<T>::contains_key(who)
120120
&& !matches!(
121121
call.is_sub_type(),
122-
Some(Call::swap_coldkey_announced { .. })
122+
Some(Call::announce_coldkey_swap { .. })
123+
| Some(Call::swap_coldkey_announced { .. })
123124
)
124125
{
125126
return Err(CustomTransactionError::ColdkeySwapAnnounced.into());

0 commit comments

Comments
 (0)