Skip to content

Commit 4ebbf92

Browse files
authored
Merge pull request #713 from opentensor/feat/scheduled_coldkey_swap_back
Schedule coldkey swap and dissolve network
2 parents 488e2cf + 51aa073 commit 4ebbf92

File tree

23 files changed

+861
-537
lines changed

23 files changed

+861
-537
lines changed

Cargo.lock

Lines changed: 32 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ members = [
3333
"pallets/collective",
3434
"pallets/registry",
3535
"runtime",
36+
"support/tools",
3637
"support/macros",
3738
"support/linting",
3839
]

pallets/admin-utils/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ sp-io = { workspace = true }
3737
sp-tracing = { workspace = true }
3838
sp-consensus-aura = { workspace = true }
3939
pallet-balances = { workspace = true, features = ["std"] }
40-
40+
pallet-scheduler = { workspace = true }
41+
sp-std = { workspace = true }
4142

4243
[features]
4344
default = ["std"]
@@ -50,12 +51,14 @@ std = [
5051
"pallet-subtensor/std",
5152
"sp-consensus-aura/std",
5253
"pallet-balances/std",
54+
"pallet-scheduler/std",
5355
"sp-runtime/std",
5456
"sp-tracing/std",
5557
"sp-weights/std",
5658
"log/std",
5759
"sp-core/std",
5860
"sp-io/std",
61+
"sp-std/std",
5962
"substrate-fixed/std",
6063
]
6164
runtime-benchmarks = [
@@ -64,12 +67,14 @@ runtime-benchmarks = [
6467
"frame-system/runtime-benchmarks",
6568
"pallet-balances/runtime-benchmarks",
6669
"sp-runtime/runtime-benchmarks",
67-
"pallet-subtensor/runtime-benchmarks"
70+
"pallet-subtensor/runtime-benchmarks",
71+
"pallet-scheduler/runtime-benchmarks",
6872
]
6973
try-runtime = [
7074
"frame-support/try-runtime",
7175
"frame-system/try-runtime",
7276
"pallet-balances/try-runtime",
77+
"pallet-scheduler/try-runtime",
7378
"sp-runtime/try-runtime",
7479
"pallet-subtensor/try-runtime"
7580
]

pallets/admin-utils/tests/mock.rs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22

33
use frame_support::{
44
assert_ok, derive_impl, parameter_types,
5-
traits::{Everything, Hooks},
5+
traits::{Everything, Hooks, PrivilegeCmp},
66
weights,
77
};
88
use frame_system as system;
9-
use frame_system::{limits, EnsureNever};
9+
use frame_system::{limits, EnsureNever, EnsureRoot};
1010
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
1111
use sp_core::U256;
1212
use sp_core::{ConstU64, H256};
1313
use sp_runtime::{
1414
traits::{BlakeTwo256, ConstU32, IdentityLookup},
15-
BuildStorage,
15+
BuildStorage, Perbill,
1616
};
17+
use sp_std::cmp::Ordering;
18+
use sp_weights::Weight;
1719

1820
type Block = frame_system::mocking::MockBlock<Test>;
1921

@@ -25,6 +27,7 @@ frame_support::construct_runtime!(
2527
Balances: pallet_balances,
2628
AdminUtils: pallet_admin_utils,
2729
SubtensorModule: pallet_subtensor::{Pallet, Call, Storage, Event<T>, Error<T>},
30+
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>},
2831
}
2932
);
3033

@@ -120,17 +123,20 @@ parameter_types! {
120123
pub const InitialLiquidAlphaOn: bool = false; // Default value for LiquidAlphaOn
121124
pub const InitialHotkeyEmissionTempo: u64 = 1;
122125
pub const InitialNetworkMaxStake: u64 = u64::MAX; // Maximum possible value for u64, this make the make stake infinity
126+
pub const InitialColdkeySwapScheduleDuration: u64 = 5 * 24 * 60 * 60 / 12; // 5 days
127+
pub const InitialDissolveNetworkScheduleDuration: u64 = 5 * 24 * 60 * 60 / 12; // 5 days
123128
}
124129

125130
impl pallet_subtensor::Config for Test {
126131
type RuntimeEvent = RuntimeEvent;
132+
type RuntimeCall = RuntimeCall;
127133
type Currency = Balances;
128134
type InitialIssuance = InitialIssuance;
129135
type SudoRuntimeCall = TestRuntimeCall;
130136
type CouncilOrigin = EnsureNever<AccountId>;
131137
type SenateMembers = ();
132138
type TriumvirateInterface = ();
133-
139+
type Scheduler = Scheduler;
134140
type InitialMinAllowedWeights = InitialMinAllowedWeights;
135141
type InitialEmissionValue = InitialEmissionValue;
136142
type InitialMaxWeightsLimit = InitialMaxWeightsLimit;
@@ -181,6 +187,9 @@ impl pallet_subtensor::Config for Test {
181187
type LiquidAlphaOn = InitialLiquidAlphaOn;
182188
type InitialHotkeyEmissionTempo = InitialHotkeyEmissionTempo;
183189
type InitialNetworkMaxStake = InitialNetworkMaxStake;
190+
type Preimages = ();
191+
type InitialColdkeySwapScheduleDuration = InitialColdkeySwapScheduleDuration;
192+
type InitialDissolveNetworkScheduleDuration = InitialDissolveNetworkScheduleDuration;
184193
}
185194

186195
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
@@ -226,6 +235,14 @@ impl pallet_balances::Config for Test {
226235
type RuntimeHoldReason = ();
227236
}
228237

238+
pub struct OriginPrivilegeCmp;
239+
240+
impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {
241+
fn cmp_privilege(_left: &OriginCaller, _right: &OriginCaller) -> Option<Ordering> {
242+
None
243+
}
244+
}
245+
229246
impl pallet_admin_utils::Config for Test {
230247
type RuntimeEvent = RuntimeEvent;
231248
type AuthorityId = AuraId;
@@ -235,6 +252,26 @@ impl pallet_admin_utils::Config for Test {
235252
type WeightInfo = ();
236253
}
237254

255+
parameter_types! {
256+
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *
257+
BlockWeights::get().max_block;
258+
pub const MaxScheduledPerBlock: u32 = 50;
259+
pub const NoPreimagePostponement: Option<u32> = Some(10);
260+
}
261+
262+
impl pallet_scheduler::Config for Test {
263+
type RuntimeOrigin = RuntimeOrigin;
264+
type RuntimeEvent = RuntimeEvent;
265+
type PalletsOrigin = OriginCaller;
266+
type RuntimeCall = RuntimeCall;
267+
type MaximumWeight = MaximumSchedulerWeight;
268+
type ScheduleOrigin = EnsureRoot<AccountId>;
269+
type MaxScheduledPerBlock = MaxScheduledPerBlock;
270+
type WeightInfo = pallet_scheduler::weights::SubstrateWeight<Test>;
271+
type OriginPrivilegeCmp = OriginPrivilegeCmp;
272+
type Preimages = ();
273+
}
274+
238275
// Build genesis storage according to the mock runtime.
239276
pub fn new_test_ext() -> sp_io::TestExternalities {
240277
sp_tracing::try_init_simple();

pallets/subtensor/Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ num-traits = { version = "0.2.19", default-features = false, features = ["libm"]
4949

5050
[dev-dependencies]
5151
pallet-balances = { workspace = true, features = ["std"] }
52+
pallet-scheduler = { workspace = true }
5253
sp-version = { workspace = true }
5354
# Substrate
5455
sp-tracing = { workspace = true }
5556
parity-util-mem = { workspace = true, features = ["primitive-types"] }
5657
rand = { workspace = true }
5758
sp-core = { workspace = true }
59+
sp-std = { workspace = true }
60+
pallet-preimage = { workspace = true }
5861

5962
[features]
6063
default = ["std"]
@@ -68,6 +71,8 @@ std = [
6871
"pallet-membership/std",
6972
"substrate-fixed/std",
7073
"pallet-balances/std",
74+
"pallet-preimage/std",
75+
"pallet-scheduler/std",
7176
"pallet-transaction-payment/std",
7277
"pallet-utility/std",
7378
"sp-core/std",
@@ -94,13 +99,17 @@ runtime-benchmarks = [
9499
"pallet-membership/runtime-benchmarks",
95100
"pallet-utility/runtime-benchmarks",
96101
"sp-runtime/runtime-benchmarks",
97-
"pallet-collective/runtime-benchmarks"
102+
"pallet-collective/runtime-benchmarks",
103+
"pallet-preimage/runtime-benchmarks",
104+
"pallet-scheduler/runtime-benchmarks",
98105
]
99106
try-runtime = [
100107
"frame-support/try-runtime",
101108
"frame-system/try-runtime",
102109
"pallet-balances/try-runtime",
103110
"pallet-membership/try-runtime",
111+
"pallet-preimage/try-runtime",
112+
"pallet-scheduler/try-runtime",
104113
"pallet-transaction-payment/try-runtime",
105114
"pallet-utility/try-runtime",
106115
"sp-runtime/try-runtime",

pallets/subtensor/rpc/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ sp-runtime = { workspace = true }
2626

2727
# local packages
2828

29-
subtensor-custom-rpc-runtime-api = { version = "0.0.2", path = "../runtime-api", default-features = false }
30-
pallet-subtensor = { version = "4.0.0-dev", path = "../../subtensor", default-features = false }
29+
subtensor-custom-rpc-runtime-api = { path = "../runtime-api", default-features = false }
30+
pallet-subtensor = { path = "../../subtensor", default-features = false }
3131

3232
[features]
3333
default = ["std"]

0 commit comments

Comments
 (0)