Skip to content

Commit 9c2b057

Browse files
paritytech-release-backport-bot[bot]sigurpolgithub-actions[bot]
authored
[unstable2507] Backport #9632 (#9654)
Backport #9632 into `unstable2507` from sigurpol. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. **NOTE: A breaking change is necessary to add support for the new extrinsic to lazily prune era and to let runtime configure `MaxPruningItems`. This is why the semver check below has been bypassed.** Being the branch `unstable`, this should be acceptable. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> --------- Co-authored-by: Paolo La Camera <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent fcb5d29 commit 9c2b057

File tree

14 files changed

+2874
-962
lines changed

14 files changed

+2874
-962
lines changed

cumulus/parachains/runtimes/assets/asset-hub-westend/src/staking.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ parameter_types! {
264264
pub const MaxNominations: u32 = <NposCompactSolution16 as frame_election_provider_support::NposSolution>::LIMIT as u32;
265265
pub storage PlanningEraOffset: u32 = prod_or_fast!(2, 1);
266266
pub const MaxEraDuration: u64 = RelaySessionDuration::get() as u64 * RELAY_CHAIN_SLOT_DURATION_MILLIS as u64 * SessionsPerEra::get() as u64;
267+
pub MaxPruningItems: u32 = 100;
267268
}
268269

269270
impl pallet_staking_async::Config for Runtime {
@@ -296,6 +297,7 @@ impl pallet_staking_async::Config for Runtime {
296297
type PlanningEraOffset = PlanningEraOffset;
297298
type RcClientInterface = StakingRcClient;
298299
type MaxEraDuration = MaxEraDuration;
300+
type MaxPruningItems = MaxPruningItems;
299301
}
300302

301303
impl pallet_staking_async_rc_client::Config for Runtime {

cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_staking_async.rs

Lines changed: 208 additions & 112 deletions
Large diffs are not rendered by default.

prdoc/pr_9632.prdoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
title: 'staking-async: implement lazy era pruning extrinsic'
2+
doc:
3+
- audience: Runtime User
4+
description: |-
5+
Move era pruning from automatic unbounded deletions to a permissionless lazy pruning system.
6+
The new system processes era pruning across multiple blocks using a state machine pattern, ensuring storage operations remain bounded and preventing PoV size exhaustion.
7+
8+
crates:
9+
- name: pallet-staking-async
10+
bump: major
11+
validate: false
12+
- name: asset-hub-westend-runtime
13+
bump: minor
14+
- name: pallet-staking-async-parachain-runtime
15+
bump: minor

substrate/frame/staking-async/ahm-test/src/ah/mock.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ parameter_types! {
316316
pub static SlashDeferredDuration: u32 = 2;
317317
pub static SessionsPerEra: u32 = 6;
318318
pub static PlanningEraOffset: u32 = 2;
319+
pub MaxPruningItems: u32 = 100;
319320
}
320321

321322
impl pallet_staking_async::Config for Runtime {
@@ -341,6 +342,7 @@ impl pallet_staking_async::Config for Runtime {
341342
type Slash = ();
342343
type SlashDeferDuration = SlashDeferredDuration;
343344
type MaxEraDuration = ();
345+
type MaxPruningItems = MaxPruningItems;
344346

345347
type HistoryDepth = ConstU32<7>;
346348
type MaxControllersInDeprecationBatch = ();

substrate/frame/staking-async/runtimes/parachain/src/staking.rs

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ parameter_types! {
251251
// frequently. On Kusama and Polkadot, a higher value like 7 × ideal_era_duration is more
252252
// appropriate.
253253
pub const MaxEraDuration: u64 = RelaySessionDuration::get() as u64 * RELAY_CHAIN_SLOT_DURATION_MILLIS as u64 * SessionsPerEra::get() as u64;
254+
pub MaxPruningItems: u32 = 100;
254255
}
255256

256257
impl pallet_staking_async::Config for Runtime {
@@ -278,9 +279,10 @@ impl pallet_staking_async::Config for Runtime {
278279
type HistoryDepth = frame_support::traits::ConstU32<84>;
279280
type MaxControllersInDeprecationBatch = MaxControllersInDeprecationBatch;
280281
type EventListeners = (NominationPools, DelegatedStaking);
281-
type WeightInfo = weights::pallet_staking_async::WeightInfo<Runtime>;
282+
type WeightInfo = pallet_staking_async::weights::SubstrateWeight<Runtime>;
282283
type MaxInvulnerables = frame_support::traits::ConstU32<20>;
283284
type MaxEraDuration = MaxEraDuration;
285+
type MaxPruningItems = MaxPruningItems;
284286
type PlanningEraOffset =
285287
pallet_staking_async::PlanningEraOffsetOf<Self, RelaySessionDuration, ConstU32<10>>;
286288
type RcClientInterface = StakingRcClient;
@@ -481,41 +483,3 @@ where
481483
UncheckedExtrinsic::new_bare(call)
482484
}
483485
}
484-
485-
#[cfg(test)]
486-
mod tests {
487-
use super::*;
488-
use frame_support::weights::constants::{WEIGHT_PROOF_SIZE_PER_KB, WEIGHT_REF_TIME_PER_MILLIS};
489-
use pallet_staking_async::WeightInfo;
490-
491-
fn weight_diff(block: Weight, op: Weight) {
492-
log::info!(
493-
target: "runtime",
494-
"ref_time: {:?}ms {:.4} of total",
495-
op.ref_time() / WEIGHT_REF_TIME_PER_MILLIS,
496-
op.ref_time() as f64 / block.ref_time() as f64
497-
);
498-
log::info!(
499-
target: "runtime",
500-
"proof_size: {:?}kb {:.4} of total",
501-
op.proof_size() / WEIGHT_PROOF_SIZE_PER_KB,
502-
op.proof_size() as f64 / block.proof_size() as f64
503-
);
504-
}
505-
506-
#[test]
507-
fn polkadot_prune_era() {
508-
sp_tracing::try_init_simple();
509-
let prune_era = <Runtime as pallet_staking_async::Config>::WeightInfo::prune_era(600);
510-
let block_weight = <Runtime as frame_system::Config>::BlockWeights::get().max_block;
511-
weight_diff(block_weight, prune_era);
512-
}
513-
514-
#[test]
515-
fn kusama_prune_era() {
516-
sp_tracing::try_init_simple();
517-
let prune_era = <Runtime as pallet_staking_async::Config>::WeightInfo::prune_era(1000);
518-
let block_weight = <Runtime as frame_system::Config>::BlockWeights::get().max_block;
519-
weight_diff(block_weight, prune_era);
520-
}
521-
}

0 commit comments

Comments
 (0)