|
16 | 16 | //! ## Prerequisite |
17 | 17 | //! |
18 | 18 | //! 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 |
20 | 20 | //! zombienet): |
21 | 21 | //! |
22 | 22 | //! ```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 | +//! } |
28 | 26 | //! ``` |
29 | 27 | //! |
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 |
31 | 29 | //! block times will degrade to worse than with sync backing!</div> |
32 | 30 | //! |
| 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 | +//! |
33 | 35 | //! ## Phase 1 - Update Parachain Runtime |
34 | 36 | //! |
35 | 37 | //! This phase involves configuring your parachain’s runtime `/runtime/src/lib.rs` to make use of |
36 | 38 | //! async backing system. |
37 | 39 | //! |
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. |
40 | 41 | //! 2. Establish and ensure the constant relay chain slot duration measured in milliseconds equal to |
41 | 42 | //! `6000` in the runtime. |
42 | 43 | //! ```rust |
43 | 44 | //! // Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the |
44 | 45 | //! // relay chain. |
45 | | -//! pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; |
| 46 | +//! pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3; |
46 | 47 | //! // How many parachain blocks are processed by the relay chain per parent. Limits the number of |
47 | 48 | //! // blocks authored per slot. |
48 | 49 | //! pub const BLOCK_PROCESSING_VELOCITY: u32 = 1; |
|
85 | 86 | //! |
86 | 87 | //! 5. Configure `pallet_aura` in the runtime. |
87 | 88 | //! |
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. |
90 | 90 | //! |
91 | 91 | //! - Define `pallet_aura::SlotDuration` using our constant `SLOT_DURATION` |
92 | 92 | //! ```ignore |
93 | 93 | //! impl pallet_aura::Config for Runtime { |
94 | 94 | //! .. |
95 | | -//! type AllowMultipleBlocksPerSlot = ConstBool<false>; |
96 | | -//! #[cfg(feature = "experimental")] |
| 95 | +//! type AllowMultipleBlocksPerSlot = ConstBool<true>; |
97 | 96 | //! type SlotDuration = ConstU64<SLOT_DURATION>; |
98 | 97 | //! .. |
99 | 98 | //! } |
|
118 | 117 | //! - Inside the `impl_runtime_apis!` block for your runtime, implement the |
119 | 118 | //! `cumulus_primitives_aura::AuraUnincludedSegmentApi` as shown below. |
120 | 119 | #![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. |
126 | 122 | //! |
127 | 123 | //! 8. If your `runtime/src/lib.rs` provides a `CheckInherents` type to `register_validate_block`, |
128 | 124 | //! remove it. `FixedVelocityConsensusHook` makes it unnecessary. The following example shows how |
|
201 | 197 | //! |
202 | 198 | //! This phase consists of changes to your parachain’s runtime that activate async backing feature. |
203 | 199 | //! |
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). |
206 | 202 | #![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`. |
208 | 204 | #![doc = docify::embed!("../../templates/parachain/runtime/src/lib.rs", async_backing_params)] |
209 | 205 | //! 3. Decrease `MILLISECS_PER_BLOCK` to 6000. |
210 | 206 | //! |
|
214 | 210 | #![doc = docify::embed!("../../templates/parachain/runtime/src/lib.rs", block_times)] |
215 | 211 | //! 4. Update `MAXIMUM_BLOCK_WEIGHT` to reflect the increased time available for block production. |
216 | 212 | #![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. |
220 | 215 | //! ```ignore |
221 | 216 | //! impl pallet_timestamp::Config for Runtime { |
222 | 217 | //! .. |
223 | | -//! #[cfg(feature = "experimental")] |
224 | 218 | //! type MinimumPeriod = ConstU64<0>; |
225 | | -//! #[cfg(not(feature = "experimental"))] |
226 | | -//! type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>; |
227 | 219 | //! .. |
228 | 220 | //! } |
229 | 221 | //! ``` |
230 | 222 | //! |
231 | 223 | //! ## Timing by Block Number |
232 | 224 | //! |
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. |
237 | 235 | //! |
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. |
242 | 238 |
|
243 | 239 | #![deny(rustdoc::broken_intra_doc_links)] |
244 | 240 | #![deny(rustdoc::private_intra_doc_links)] |
0 commit comments