Skip to content

Commit f8cb94c

Browse files
paritytech-release-backport-bot[bot]bkonturgithub-actions[bot]
authored
[stable2506] Backport #9514 (#9522)
Backport #9514 into `stable2506` from bkontur. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> Co-authored-by: Branislav Kontur <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent bb71a69 commit f8cb94c

File tree

5 files changed

+113
-57
lines changed

5 files changed

+113
-57
lines changed

polkadot/runtime/parachains/src/paras/benchmarking.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ mod benchmarks {
288288
let code = ValidationCode(vec![0; 32]);
289289
let new_code_hash = code.hash();
290290
let valid_period = BlockNumberFor::<T>::from(1_000_000_u32);
291+
ParaLifecycles::<T>::insert(&para_id, ParaLifecycle::Parachain);
291292

292293
#[extrinsic_call]
293294
_(RawOrigin::Root, para_id, new_code_hash, valid_period);

polkadot/runtime/parachains/src/paras/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,11 +1297,13 @@ pub mod pallet {
12971297
valid_period: BlockNumberFor<T>,
12981298
) -> DispatchResult {
12991299
T::AuthorizeCurrentCodeOrigin::ensure_origin(origin, &para)?;
1300+
// The requested para must be a valid para (neither onboarding nor offboarding).
1301+
ensure!(Self::is_valid_para(para), Error::<T>::NotRegistered);
13001302

13011303
let now = frame_system::Pallet::<T>::block_number();
13021304
let expire_at = now.saturating_add(valid_period);
13031305

1304-
// insert authorized code hash and make sure to overwrite existing one for a para.
1306+
// Insert the authorized code hash and ensure it overwrites the existing one for a para.
13051307
AuthorizedCodeHash::<T>::insert(
13061308
&para,
13071309
AuthorizedCodeHashAndExpiry::from((new_code_hash, expire_at)),
@@ -1324,7 +1326,7 @@ pub mod pallet {
13241326
para: ParaId,
13251327
new_code: ValidationCode,
13261328
) -> DispatchResultWithPostInfo {
1327-
// no need to ensure, anybody can do this
1329+
// no need to ensure anybody can do this
13281330

13291331
// Ensure `new_code` is authorized
13301332
let _ = Self::validate_code_is_authorized(&new_code, &para)?;
@@ -1586,6 +1588,7 @@ impl<T: Config> Pallet<T> {
15861588
UpgradeGoAheadSignal::<T>::remove(&para);
15871589
UpgradeRestrictionSignal::<T>::remove(&para);
15881590
ParaLifecycles::<T>::remove(&para);
1591+
AuthorizedCodeHash::<T>::remove(&para);
15891592
let removed_future_code_hash = FutureCodeHash::<T>::take(&para);
15901593
if let Some(removed_future_code_hash) = removed_future_code_hash {
15911594
Self::decrease_code_ref(&removed_future_code_hash);

polkadot/runtime/parachains/src/paras/tests.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,11 @@ fn full_parachain_cleanup_storage() {
945945
run_to_block(7, None);
946946
assert_eq!(frame_system::Pallet::<Test>::block_number(), 7);
947947
Paras::note_new_head(para_id, Default::default(), expected_at);
948+
AuthorizedCodeHash::<Test>::insert(
949+
&para_id,
950+
AuthorizedCodeHashAndExpiry::from((ValidationCode(vec![7]).hash(), 1000)),
951+
);
952+
assert!(AuthorizedCodeHash::<Test>::get(&para_id).is_some());
948953

949954
assert_ok!(Paras::schedule_para_cleanup(para_id));
950955

@@ -968,6 +973,7 @@ fn full_parachain_cleanup_storage() {
968973
assert!(FutureCodeUpgrades::<Test>::get(&para_id).is_none());
969974
assert!(FutureCodeHash::<Test>::get(&para_id).is_none());
970975
assert!(Paras::current_code(&para_id).is_none());
976+
assert!(AuthorizedCodeHash::<Test>::get(&para_id).is_none());
971977

972978
// run to do the final cleanup
973979
let cleaned_up_at = 8 + code_retention_period + 1;
@@ -2173,7 +2179,33 @@ fn authorize_force_set_current_code_hash_works() {
21732179
DispatchError::BadOrigin,
21742180
);
21752181

2176-
// root can authorize
2182+
// para not registered
2183+
ParaLifecycles::<Test>::insert(&para_a, ParaLifecycle::Onboarding);
2184+
assert!(!Paras::is_valid_para(para_a));
2185+
assert_err!(
2186+
Paras::authorize_force_set_current_code_hash(
2187+
RuntimeOrigin::root(),
2188+
para_a,
2189+
code_1_hash,
2190+
valid_period
2191+
),
2192+
Error::<Test>::NotRegistered,
2193+
);
2194+
ParaLifecycles::<Test>::insert(&para_a, ParaLifecycle::OffboardingParachain);
2195+
assert!(!Paras::is_valid_para(para_a));
2196+
assert_err!(
2197+
Paras::authorize_force_set_current_code_hash(
2198+
RuntimeOrigin::root(),
2199+
para_a,
2200+
code_1_hash,
2201+
valid_period
2202+
),
2203+
Error::<Test>::NotRegistered,
2204+
);
2205+
2206+
// root can authorize for registered para
2207+
ParaLifecycles::<Test>::insert(&para_a, ParaLifecycle::Parachain);
2208+
assert!(Paras::is_valid_para(para_a));
21772209
System::set_block_number(1);
21782210
assert_ok!(Paras::authorize_force_set_current_code_hash(
21792211
RuntimeOrigin::root(),
@@ -2185,6 +2217,8 @@ fn authorize_force_set_current_code_hash_works() {
21852217
AuthorizedCodeHash::<Test>::get(&para_a),
21862218
Some((code_1_hash, 1 + valid_period).into())
21872219
);
2220+
ParaLifecycles::<Test>::insert(&para_b, ParaLifecycle::Parachain);
2221+
assert!(Paras::is_valid_para(para_b));
21882222
System::set_block_number(5);
21892223
assert_ok!(Paras::authorize_force_set_current_code_hash(
21902224
RuntimeOrigin::root(),

polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_paras.rs

Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
//! Autogenerated weights for `polkadot_runtime_parachains::paras`
1818
//!
1919
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
20-
//! DATE: 2025-03-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
20+
//! DATE: 2025-08-19, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
2121
//! WORST CASE MAP SIZE: `1000000`
22-
//! HOSTNAME: `299f3957073a`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
22+
//! HOSTNAME: `1d17579cdeaf`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
2323
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024
2424
2525
// Executed Command:
@@ -68,11 +68,11 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
6868
// Proof Size summary in bytes:
6969
// Measured: `8309`
7070
// Estimated: `11774`
71-
// Minimum execution time: 38_137_000 picoseconds.
72-
Weight::from_parts(38_981_000, 0)
71+
// Minimum execution time: 36_757_000 picoseconds.
72+
Weight::from_parts(37_351_000, 0)
7373
.saturating_add(Weight::from_parts(0, 11774))
74-
// Standard Error: 129
75-
.saturating_add(Weight::from_parts(13_542, 0).saturating_mul(c.into()))
74+
// Standard Error: 5
75+
.saturating_add(Weight::from_parts(2_469, 0).saturating_mul(c.into()))
7676
.saturating_add(T::DbWeight::get().reads(4))
7777
.saturating_add(T::DbWeight::get().writes(6))
7878
}
@@ -83,11 +83,11 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
8383
// Proof Size summary in bytes:
8484
// Measured: `0`
8585
// Estimated: `0`
86-
// Minimum execution time: 6_970_000 picoseconds.
87-
Weight::from_parts(7_230_000, 0)
86+
// Minimum execution time: 7_337_000 picoseconds.
87+
Weight::from_parts(21_463_534, 0)
8888
.saturating_add(Weight::from_parts(0, 0))
89-
// Standard Error: 42
90-
.saturating_add(Weight::from_parts(4_548, 0).saturating_mul(s.into()))
89+
// Standard Error: 2
90+
.saturating_add(Weight::from_parts(929, 0).saturating_mul(s.into()))
9191
.saturating_add(T::DbWeight::get().writes(1))
9292
}
9393
/// Storage: `Paras::MostRecentContext` (r:0 w:1)
@@ -96,8 +96,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
9696
// Proof Size summary in bytes:
9797
// Measured: `0`
9898
// Estimated: `0`
99-
// Minimum execution time: 3_539_000 picoseconds.
100-
Weight::from_parts(3_836_000, 0)
99+
// Minimum execution time: 3_744_000 picoseconds.
100+
Weight::from_parts(3_970_000, 0)
101101
.saturating_add(Weight::from_parts(0, 0))
102102
.saturating_add(T::DbWeight::get().writes(1))
103103
}
@@ -124,11 +124,11 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
124124
// Proof Size summary in bytes:
125125
// Measured: `8452`
126126
// Estimated: `11917`
127-
// Minimum execution time: 52_993_000 picoseconds.
128-
Weight::from_parts(53_656_000, 0)
127+
// Minimum execution time: 52_945_000 picoseconds.
128+
Weight::from_parts(53_953_000, 0)
129129
.saturating_add(Weight::from_parts(0, 11917))
130-
// Standard Error: 132
131-
.saturating_add(Weight::from_parts(13_454, 0).saturating_mul(c.into()))
130+
// Standard Error: 3
131+
.saturating_add(Weight::from_parts(2_449, 0).saturating_mul(c.into()))
132132
.saturating_add(T::DbWeight::get().reads(8))
133133
.saturating_add(T::DbWeight::get().writes(7))
134134
}
@@ -145,11 +145,11 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
145145
// Proof Size summary in bytes:
146146
// Measured: `268`
147147
// Estimated: `3733`
148-
// Minimum execution time: 14_784_000 picoseconds.
149-
Weight::from_parts(15_216_000, 0)
148+
// Minimum execution time: 15_247_000 picoseconds.
149+
Weight::from_parts(35_253_573, 0)
150150
.saturating_add(Weight::from_parts(0, 3733))
151-
// Standard Error: 42
152-
.saturating_add(Weight::from_parts(4_570, 0).saturating_mul(s.into()))
151+
// Standard Error: 2
152+
.saturating_add(Weight::from_parts(935, 0).saturating_mul(s.into()))
153153
.saturating_add(T::DbWeight::get().reads(1))
154154
.saturating_add(T::DbWeight::get().writes(3))
155155
}
@@ -161,8 +161,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
161161
// Proof Size summary in bytes:
162162
// Measured: `4312`
163163
// Estimated: `7777`
164-
// Minimum execution time: 24_300_000 picoseconds.
165-
Weight::from_parts(25_154_000, 0)
164+
// Minimum execution time: 22_007_000 picoseconds.
165+
Weight::from_parts(22_746_000, 0)
166166
.saturating_add(Weight::from_parts(0, 7777))
167167
.saturating_add(T::DbWeight::get().reads(2))
168168
.saturating_add(T::DbWeight::get().writes(1))
@@ -180,11 +180,11 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
180180
// Proof Size summary in bytes:
181181
// Measured: `683`
182182
// Estimated: `4148`
183-
// Minimum execution time: 91_676_000 picoseconds.
184-
Weight::from_parts(93_066_000, 0)
183+
// Minimum execution time: 91_762_000 picoseconds.
184+
Weight::from_parts(92_492_215, 0)
185185
.saturating_add(Weight::from_parts(0, 4148))
186-
// Standard Error: 127
187-
.saturating_add(Weight::from_parts(12_834, 0).saturating_mul(c.into()))
186+
// Standard Error: 5
187+
.saturating_add(Weight::from_parts(1_951, 0).saturating_mul(c.into()))
188188
.saturating_add(T::DbWeight::get().reads(4))
189189
.saturating_add(T::DbWeight::get().writes(3))
190190
}
@@ -196,8 +196,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
196196
// Proof Size summary in bytes:
197197
// Measured: `28`
198198
// Estimated: `3493`
199-
// Minimum execution time: 6_886_000 picoseconds.
200-
Weight::from_parts(7_123_000, 0)
199+
// Minimum execution time: 7_076_000 picoseconds.
200+
Weight::from_parts(7_394_000, 0)
201201
.saturating_add(Weight::from_parts(0, 3493))
202202
.saturating_add(T::DbWeight::get().reads(1))
203203
.saturating_add(T::DbWeight::get().writes(1))
@@ -212,8 +212,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
212212
// Proof Size summary in bytes:
213213
// Measured: `26706`
214214
// Estimated: `30171`
215-
// Minimum execution time: 114_157_000 picoseconds.
216-
Weight::from_parts(120_289_000, 0)
215+
// Minimum execution time: 112_839_000 picoseconds.
216+
Weight::from_parts(116_733_000, 0)
217217
.saturating_add(Weight::from_parts(0, 30171))
218218
.saturating_add(T::DbWeight::get().reads(3))
219219
.saturating_add(T::DbWeight::get().writes(1))
@@ -234,8 +234,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
234234
// Proof Size summary in bytes:
235235
// Measured: `27360`
236236
// Estimated: `30825`
237-
// Minimum execution time: 727_795_000 picoseconds.
238-
Weight::from_parts(754_623_000, 0)
237+
// Minimum execution time: 753_885_000 picoseconds.
238+
Weight::from_parts(780_076_000, 0)
239239
.saturating_add(Weight::from_parts(0, 30825))
240240
.saturating_add(T::DbWeight::get().reads(5))
241241
.saturating_add(T::DbWeight::get().writes(103))
@@ -250,8 +250,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
250250
// Proof Size summary in bytes:
251251
// Measured: `27338`
252252
// Estimated: `30803`
253-
// Minimum execution time: 110_002_000 picoseconds.
254-
Weight::from_parts(117_296_000, 0)
253+
// Minimum execution time: 109_551_000 picoseconds.
254+
Weight::from_parts(115_723_000, 0)
255255
.saturating_add(Weight::from_parts(0, 30803))
256256
.saturating_add(T::DbWeight::get().reads(3))
257257
.saturating_add(T::DbWeight::get().writes(1))
@@ -270,8 +270,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
270270
// Proof Size summary in bytes:
271271
// Measured: `26728`
272272
// Estimated: `30193`
273-
// Minimum execution time: 585_996_000 picoseconds.
274-
Weight::from_parts(609_200_000, 0)
273+
// Minimum execution time: 617_998_000 picoseconds.
274+
Weight::from_parts(637_103_000, 0)
275275
.saturating_add(Weight::from_parts(0, 30193))
276276
.saturating_add(T::DbWeight::get().reads(5))
277277
.saturating_add(T::DbWeight::get().writes(3))
@@ -286,30 +286,38 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
286286
// Proof Size summary in bytes:
287287
// Measured: `26706`
288288
// Estimated: `30171`
289-
// Minimum execution time: 106_306_000 picoseconds.
290-
Weight::from_parts(113_807_000, 0)
289+
// Minimum execution time: 108_309_000 picoseconds.
290+
Weight::from_parts(112_880_000, 0)
291291
.saturating_add(Weight::from_parts(0, 30171))
292292
.saturating_add(T::DbWeight::get().reads(3))
293293
.saturating_add(T::DbWeight::get().writes(1))
294294
}
295-
295+
/// Storage: `Paras::UpgradeCooldowns` (r:1 w:1)
296+
/// Proof: `Paras::UpgradeCooldowns` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
297+
/// Storage: `Paras::UpgradeRestrictionSignal` (r:0 w:1)
298+
/// Proof: `Paras::UpgradeRestrictionSignal` (`max_values`: None, `max_size`: None, mode: `Measured`)
296299
fn remove_upgrade_cooldown() -> Weight {
297-
// JUST COPIED AND WILL BE UPDATED NEXT TIME
298-
Weight::from_parts(107_759_000, 0)
299-
.saturating_add(Weight::from_parts(0, 30171))
300-
.saturating_add(T::DbWeight::get().reads(3))
301-
.saturating_add(T::DbWeight::get().writes(1))
300+
// Proof Size summary in bytes:
301+
// Measured: `267`
302+
// Estimated: `1752`
303+
// Minimum execution time: 33_402_000 picoseconds.
304+
Weight::from_parts(34_573_000, 0)
305+
.saturating_add(Weight::from_parts(0, 1752))
306+
.saturating_add(T::DbWeight::get().reads(1))
307+
.saturating_add(T::DbWeight::get().writes(2))
302308
}
303-
309+
/// Storage: `Paras::ParaLifecycles` (r:1 w:0)
310+
/// Proof: `Paras::ParaLifecycles` (`max_values`: None, `max_size`: None, mode: `Measured`)
304311
/// Storage: `Paras::AuthorizedCodeHash` (r:0 w:1)
305312
/// Proof: `Paras::AuthorizedCodeHash` (`max_values`: None, `max_size`: None, mode: `Measured`)
306313
fn authorize_force_set_current_code_hash() -> Weight {
307314
// Proof Size summary in bytes:
308-
// Measured: `0`
309-
// Estimated: `0`
310-
// Minimum execution time: 8_112_000 picoseconds.
311-
Weight::from_parts(8_401_000, 0)
312-
.saturating_add(Weight::from_parts(0, 0))
315+
// Measured: `61`
316+
// Estimated: `3526`
317+
// Minimum execution time: 13_133_000 picoseconds.
318+
Weight::from_parts(13_801_000, 0)
319+
.saturating_add(Weight::from_parts(0, 3526))
320+
.saturating_add(T::DbWeight::get().reads(1))
313321
.saturating_add(T::DbWeight::get().writes(1))
314322
}
315323
/// Storage: `Paras::AuthorizedCodeHash` (r:1 w:1)
@@ -325,11 +333,11 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::paras::WeightInfo for
325333
// Proof Size summary in bytes:
326334
// Measured: `132`
327335
// Estimated: `3597`
328-
// Minimum execution time: 32_733_000 picoseconds.
329-
Weight::from_parts(33_172_000, 0)
336+
// Minimum execution time: 32_802_000 picoseconds.
337+
Weight::from_parts(33_769_000, 0)
330338
.saturating_add(Weight::from_parts(0, 3597))
331-
// Standard Error: 133
332-
.saturating_add(Weight::from_parts(14_731, 0).saturating_mul(c.into()))
339+
// Standard Error: 10
340+
.saturating_add(Weight::from_parts(3_966, 0).saturating_mul(c.into()))
333341
.saturating_add(T::DbWeight::get().reads(3))
334342
.saturating_add(T::DbWeight::get().writes(4))
335343
}

prdoc/pr_9514.prdoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
title: 'Paras: Clean up `AuthorizedCodeHash` when offboarding'
2+
doc:
3+
- audience: Runtime Dev
4+
description: This PR updates the `Paras` pallet to clear entries in `AuthorizedCodeHash`
5+
as part of the offboarding process.
6+
crates:
7+
- name: polkadot-runtime-parachains
8+
bump: patch
9+
- name: westend-runtime
10+
bump: patch

0 commit comments

Comments
 (0)