Skip to content

Commit 20311a9

Browse files
docs/async_back: Align docs to latest behavior (paritytech#11387)
Tiny PR to update the async backing documentation / guidelines: - older params are no longer used `async_backing_params` - UNINCLUDED_SEGMENT_CAPACITY is now 3 - no need for `experimental` feature flags Closes: paritytech#8804 --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent a66398f commit 20311a9

2 files changed

Lines changed: 44 additions & 36 deletions

File tree

docs/sdk/src/guides/async_backing_guide.rs

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,34 @@
1616
//! ## Prerequisite
1717
//!
1818
//! The relay chain needs to have async backing enabled so double-check that the relay-chain
19-
//! configuration contains the following three parameters (especially when testing locally e.g. with
19+
//! configuration contains the following parameter (especially when testing locally e.g. with
2020
//! zombienet):
2121
//!
2222
//! ```json
23-
//! "async_backing_params": {
24-
//! "max_candidate_depth": 3,
25-
//! "allowed_ancestry_len": 2
26-
//! },
27-
//! "scheduling_lookahead": 2
23+
//! "scheduler_params": {
24+
//! "lookahead": 3
25+
//! }
2826
//! ```
2927
//!
30-
//! <div class="warning"><code>scheduling_lookahead</code> must be set to 2, otherwise parachain
28+
//! <div class="warning"><code>lookahead</code> must be set to at least 3, otherwise parachain
3129
//! block times will degrade to worse than with sync backing!</div>
3230
//!
31+
//! Note: `async_backing_params` (`max_candidate_depth` and `allowed_ancestry_len`) are no longer
32+
//! required to be explicitly configured. Async backing works with them set to their default values
33+
//! of 0.
34+
//!
3335
//! ## Phase 1 - Update Parachain Runtime
3436
//!
3537
//! This phase involves configuring your parachain’s runtime `/runtime/src/lib.rs` to make use of
3638
//! async backing system.
3739
//!
38-
//! 1. Establish and ensure constants for `capacity` and `velocity` are both set to 1 in the
39-
//! runtime.
40+
//! 1. Establish and ensure constants for `capacity` and `velocity` in the runtime.
4041
//! 2. Establish and ensure the constant relay chain slot duration measured in milliseconds equal to
4142
//! `6000` in the runtime.
4243
//! ```rust
4344
//! // Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the
4445
//! // relay chain.
45-
//! pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
46+
//! pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
4647
//! // How many parachain blocks are processed by the relay chain per parent. Limits the number of
4748
//! // blocks authored per slot.
4849
//! pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
@@ -85,15 +86,13 @@
8586
//!
8687
//! 5. Configure `pallet_aura` in the runtime.
8788
//!
88-
//! - Set `AllowMultipleBlocksPerSlot` to `false` (don't worry, we will set it to `true` when we
89-
//! activate async backing in phase 3).
89+
//! - Set `AllowMultipleBlocksPerSlot` to `true` to allow multiple blocks per slot.
9090
//!
9191
//! - Define `pallet_aura::SlotDuration` using our constant `SLOT_DURATION`
9292
//! ```ignore
9393
//! impl pallet_aura::Config for Runtime {
9494
//! ..
95-
//! type AllowMultipleBlocksPerSlot = ConstBool<false>;
96-
//! #[cfg(feature = "experimental")]
95+
//! type AllowMultipleBlocksPerSlot = ConstBool<true>;
9796
//! type SlotDuration = ConstU64<SLOT_DURATION>;
9897
//! ..
9998
//! }
@@ -118,11 +117,8 @@
118117
//! - Inside the `impl_runtime_apis!` block for your runtime, implement the
119118
//! `cumulus_primitives_aura::AuraUnincludedSegmentApi` as shown below.
120119
#![doc = docify::embed!("../../templates/parachain/runtime/src/apis.rs", impl_can_build_upon)]
121-
//! **Note:** With a capacity of 1 we have an effective velocity of ½ even when velocity is
122-
//! configured to some larger value. This is because capacity will be filled after a single block is
123-
//! produced and will only be freed up after that block is included on the relay chain, which takes
124-
//! 2 relay blocks to accomplish. Thus with capacity 1 and velocity 1 we get the customary 12 second
125-
//! parachain block time.
120+
//! **Note:** With the default capacity of 3 and velocity of 1, a single parachain block is
121+
//! authored per relay chain block, giving a 6 second parachain block time.
126122
//!
127123
//! 8. If your `runtime/src/lib.rs` provides a `CheckInherents` type to `register_validate_block`,
128124
//! remove it. `FixedVelocityConsensusHook` makes it unnecessary. The following example shows how
@@ -201,10 +197,10 @@
201197
//!
202198
//! This phase consists of changes to your parachain’s runtime that activate async backing feature.
203199
//!
204-
//! 1. Configure `pallet_aura`, setting `AllowMultipleBlocksPerSlot` to true in
205-
//! `runtime/src/lib.rs`.
200+
//! 1. Verify `pallet_aura` has `AllowMultipleBlocksPerSlot` set to `true` in `runtime/src/lib.rs`
201+
//! (this should already be done from Phase 1).
206202
#![doc = docify::embed!("../../templates/parachain/runtime/src/configs/mod.rs", aura_config)]
207-
//! 2. Increase the maximum `UNINCLUDED_SEGMENT_CAPACITY` in `runtime/src/lib.rs`.
203+
//! 2. Verify `UNINCLUDED_SEGMENT_CAPACITY` is set to at least `3` in `runtime/src/lib.rs`.
208204
#![doc = docify::embed!("../../templates/parachain/runtime/src/lib.rs", async_backing_params)]
209205
//! 3. Decrease `MILLISECS_PER_BLOCK` to 6000.
210206
//!
@@ -214,31 +210,31 @@
214210
#![doc = docify::embed!("../../templates/parachain/runtime/src/lib.rs", block_times)]
215211
//! 4. Update `MAXIMUM_BLOCK_WEIGHT` to reflect the increased time available for block production.
216212
#![doc = docify::embed!("../../templates/parachain/runtime/src/lib.rs", max_block_weight)]
217-
//! 5. Add a feature flagged alternative for `MinimumPeriod` in `pallet_timestamp`. The type should
218-
//! be `ConstU64<0>` with the feature flag experimental, and `ConstU64<{SLOT_DURATION / 2}>`
219-
//! without.
213+
//! 5. Set `MinimumPeriod` to `0` in `pallet_timestamp`. This is required to allow multiple blocks
214+
//! within the same slot.
220215
//! ```ignore
221216
//! impl pallet_timestamp::Config for Runtime {
222217
//! ..
223-
//! #[cfg(feature = "experimental")]
224218
//! type MinimumPeriod = ConstU64<0>;
225-
//! #[cfg(not(feature = "experimental"))]
226-
//! type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
227219
//! ..
228220
//! }
229221
//! ```
230222
//!
231223
//! ## Timing by Block Number
232224
//!
233-
//! With asynchronous backing it will be possible for parachains to opt for a block time of 6
234-
//! seconds rather than 12 seconds. But modifying block duration isn’t so simple for a parachain
235-
//! which was measuring time in terms of its own block number. It could result in expected and
236-
//! actual time not matching up, stalling the parachain.
225+
//! With asynchronous backing, parachains produce blocks every 6 seconds rather than 12 seconds.
226+
//! This means that any on-chain logic that derives time from parachain block numbers will see
227+
//! time move twice as fast. This could result in expected and actual time not matching up,
228+
//! potentially causing issues with vesting schedules, unlock periods, or other time-dependent
229+
//! logic.
230+
//!
231+
//! The recommended strategy is to rely on relay chain block numbers for timing instead of
232+
//! parachain block numbers. Relay block number is kept track of by each parachain in
233+
//! `pallet-parachain-system` with the storage value `LastRelayChainBlockNumber`. This value can
234+
//! be obtained and used wherever timing based on block number is needed.
237235
//!
238-
//! One strategy to deal with this issue is to instead rely on relay chain block numbers for timing.
239-
//! Relay block number is kept track of by each parachain in `pallet-parachain-system` with the
240-
//! storage value `LastRelayChainBlockNumber`. This value can be obtained and used wherever timing
241-
//! based on block number is needed.
236+
//! Alternatively, `pallet_timestamp` provides wall-clock time which is independent of block
237+
//! number and is not affected by changes in block time.
242238
243239
#![deny(rustdoc::broken_intra_doc_links)]
244240
#![deny(rustdoc::private_intra_doc_links)]

prdoc/pr_11387.prdoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
title: 'docs/async_back: Align docs to latest behavior'
2+
doc:
3+
- audience: Node Dev
4+
description: |-
5+
Tiny PR to update the async backing documentation / guidelines:
6+
- older params are no longer used `async_backing_params`
7+
- UNINCLUDED_SEGMENT_CAPACITY is now 3
8+
- no need for `experimental` feature flags
9+
10+
11+
Closes: https://github.com/paritytech/polkadot-sdk/issues/8804
12+
crates: []

0 commit comments

Comments
 (0)