Skip to content

Commit a20dc22

Browse files
committed
formatting
1 parent 579a187 commit a20dc22

File tree

2 files changed

+56
-56
lines changed

2 files changed

+56
-56
lines changed

develop/parachains/maintenance/configure-asynchronous-backing.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ This can be found in the relay chain's runtime. You can see the Polkadot [`async
3535
This phase involves configuring your parachain's runtime `/runtime/src/lib.rs` to make use of async backing system.
3636

3737
1. Establish and ensure that constants for capacity ([`UNINCLUDED_SEGMENT_CAPACITY`](https://github.com/polkadot-fellows/runtimes/blob/d49a9f33d0ea85ce51c26c84a70b61624ec06901/system-parachains/constants/src/polkadot.rs#L42-L44){target=\_blank}) and velocity ([`BLOCK_PROCESSING_VELOCITY`](https://github.com/polkadot-fellows/runtimes/blob/d49a9f33d0ea85ce51c26c84a70b61624ec06901/system-parachains/constants/src/polkadot.rs#L45-L47){target=\_blank}) are both set to `1` in the runtime.
38+
3839
2. Establish and ensure the constant relay chain slot duration measured in milliseconds equal to `6000` in the runtime.
3940

4041
```rust title="lib.rs"
@@ -59,7 +60,7 @@ This phase involves configuring your parachain's runtime `/runtime/src/lib.rs` t
5960
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
6061
```
6162

62-
4. Configure `cumulus_pallet_parachain_system` in the runtime.
63+
4. Configure [`cumulus_pallet_parachain_system`](https://paritytech.github.io/polkadot-sdk/master/cumulus_pallet_parachain_system/index.html){target=\_blank} in the runtime.
6364

6465
- Define a [`FixedVelocityConsensusHook`](https://paritytech.github.io/polkadot-sdk/master/cumulus_pallet_aura_ext/consensus_hook/struct.FixedVelocityConsensusHook.html){target=\_blank} using our capacity, velocity, and relay slot duration constants.
6566
```rust title="lib.rs"
@@ -74,36 +75,36 @@ This phase involves configuring your parachain's runtime `/runtime/src/lib.rs` t
7475
- Use this to set the parachain system [`ConsensusHook`](https://paritytech.github.io/polkadot-sdk/master/cumulus_pallet_parachain_system/pallet/trait.Config.html#associatedtype.ConsensusHook){target=\_blank} property.
7576
```rust title="lib.rs"
7677
impl cumulus_pallet_parachain_system::Config for Runtime {
77-
..
78+
...
7879
type ConsensusHook = ConsensusHook;
79-
..
80+
...
8081
}
8182
```
8283

8384
- Set the parachain system property [`CheckAssociatedRelayNumber`](https://paritytech.github.io/polkadot-sdk/master/cumulus_pallet_parachain_system/pallet/trait.Config.html#associatedtype.CheckAssociatedRelayNumber){target=\_blank} to [`RelayNumberMonotonicallyIncreases`](https://paritytech.github.io/polkadot-sdk/master/cumulus_pallet_parachain_system/struct.RelayNumberMonotonicallyIncreases.html){target=\_blank}
8485
```rust title="lib.rs"
8586
impl cumulus_pallet_parachain_system::Config for Runtime {
86-
..
87+
...
8788
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
88-
..
89+
...
8990
}
9091
```
9192

9293
5. Configure [`pallet_aura`](https://paritytech.github.io/polkadot-sdk/master/pallet_aura/index.html){target=\_blank} in the runtime.
9394

94-
[`pallet_aura`]((https://paritytech.github.io/polkadot-sdk/master/pallet_aura/index.html){target=\_blank}) implements Authority Round (Aura) - a deterministic [consensus](https://docs.polkadot.com/polkadot-protocol/glossary/#consensus){target=\_blank} protocol where block production is limited to a rotating list of authorities that take turns creating blocks. [`pallet_aura`](https://paritytech.github.io/polkadot-sdk/master/pallet_aura/index.html){target=\_blank} uses [`pallet_timestamp`](https://paritytech.github.io/polkadot-sdk/master/pallet_timestamp/index.html){target=\_blank} to track consensus rounds (via [`slots`](https://paritytech.github.io/polkadot-sdk/master/pallet_aura/pallet/trait.Config.html#associatedtype.SlotDuration){target=\_blank}).
95+
[`pallet_aura`]((https://paritytech.github.io/polkadot-sdk/master/pallet_aura/index.html){target=\_blank}) implements Authority Round (Aura) - a deterministic [consensus](/polkadot-protocol/glossary/#consensus){target=\_blank} protocol where block production is limited to a rotating list of authorities that take turns creating blocks. [`pallet_aura`](https://paritytech.github.io/polkadot-sdk/master/pallet_aura/index.html){target=\_blank} uses [`pallet_timestamp`](https://paritytech.github.io/polkadot-sdk/master/pallet_timestamp/index.html){target=\_blank} to track consensus rounds (via [`slots`](https://paritytech.github.io/polkadot-sdk/master/pallet_aura/pallet/trait.Config.html#associatedtype.SlotDuration){target=\_blank}).
9596

9697
- Set [`AllowMultipleBlocksPerSlot`](https://paritytech.github.io/polkadot-sdk/master/pallet_aura/pallet/trait.Config.html#associatedtype.AllowMultipleBlocksPerSlot){target=\_blank} to `false`
97-
- We will set it to `true` when we activate async backing in phase 3
98+
- This will be set to `true` when we activate async backing in phase 3
9899

99100
- Define [`pallet_aura::SlotDuration`](https://paritytech.github.io/polkadot-sdk/master/pallet_aura/pallet/trait.Config.html#associatedtype.SlotDuration){target=\_blank} using our constant [`SLOT_DURATION`](https://github.com/polkadot-fellows/runtimes/blob/d49a9f33d0ea85ce51c26c84a70b61624ec06901/system-parachains/constants/src/lib.rs#L38-L40){target=\_blank}
100101
```rust title="lib.rs"
101102
impl pallet_aura::Config for Runtime {
102-
..
103+
...
103104
type AllowMultipleBlocksPerSlot = ConstBool<false>;
104105
#[cfg(feature = "experimental")]
105106
type SlotDuration = ConstU64<SLOT_DURATION>;
106-
..
107+
...
107108
}
108109
```
109110

@@ -119,14 +120,14 @@ This phase involves configuring your parachain's runtime `/runtime/src/lib.rs` t
119120

120121
- Add the dependency [`cumulus-primitives-aura`](https://paritytech.github.io/polkadot-sdk/master/cumulus_primitives_aura/index.html){target=\_blank} to the `runtime/Cargo.toml` file for your runtime
121122
```rust title="Cargo.toml"
122-
..
123+
...
123124
cumulus-primitives-aura = { path = "../../../../primitives/aura", default-features = false }
124-
..
125+
...
125126
```
126127

127128
- In the same file, add `"cumulus-primitives-aura/std",` to the `std` feature.
128129

129-
- Inside the [`impl_runtime_apis!`]((https://github.com/paritytech/polkadot-sdk/blob/6b17df5ae96f7970109ec3934c7d288f05baa23b/templates/parachain/runtime/src/apis.rs#L87-L91){target=\_blank}) block for your runtime, implement the [`cumulus_primitives_aura::AuraUnincludedSegmentApi`](https://paritytech.github.io/polkadot-sdk/master/cumulus_primitives_aura/trait.AuraUnincludedSegmentApi.html){target=\_blank} as shown below.
130+
- Inside the [`impl_runtime_apis!`](https://github.com/paritytech/polkadot-sdk/blob/6b17df5ae96f7970109ec3934c7d288f05baa23b/templates/parachain/runtime/src/apis.rs#L87-L91){target=\_blank} block for your runtime, implement the [`cumulus_primitives_aura::AuraUnincludedSegmentApi`](https://paritytech.github.io/polkadot-sdk/master/cumulus_primitives_aura/trait.AuraUnincludedSegmentApi.html){target=\_blank} as shown below.
130131
```rust title="apis.rs"
131132
impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
132133
fn can_build_upon(
@@ -138,7 +139,7 @@ This phase involves configuring your parachain's runtime `/runtime/src/lib.rs` t
138139
```
139140

140141
!!!note
141-
With a capacity of 1 we have an effective velocity of ½ even when velocity is configured to some larger value. This is because capacity will be filled after a single block is produced and will only be freed up after that block is included on the relay chain, which takes 2 relay blocks to accomplish. Thus with capacity 1 and velocity 1 we get the customary 12 second parachain block time.
142+
With a capacity of 1 you have an effective velocity of ½ even when velocity is configured to some larger value. This is because capacity will be filled after a single block is produced and will only be freed up after that block is included on the relay chain, which takes 2 relay blocks to accomplish. Thus with capacity 1 and velocity 1 you get the customary 12 second parachain block time.
142143

143144
8. If your `runtime/src/lib.rs` provides a [`CheckInherents`](https://paritytech.github.io/polkadot-sdk/master/cumulus_pallet_parachain_system/macro.register_validate_block.html){target=\_blank} type to [`register_validate_block`](https://paritytech.github.io/polkadot-sdk/master/cumulus_pallet_parachain_system/macro.register_validate_block.html), remove it. [`FixedVelocityConsensusHook`](https://paritytech.github.io/polkadot-sdk/master/cumulus_pallet_aura_ext/consensus_hook/struct.FixedVelocityConsensusHook.html){target=\_blank} makes it unnecessary. The following example shows how `register_validate_block` should look after removing `CheckInherents`.
144145

@@ -166,27 +167,27 @@ This phase consists of plugging in the new lookahead collator node.
166167

167168
```rust title="node/src/service.rs"
168169
sc_service::spawn_tasks(sc_service::SpawnTasksParams {
169-
..
170+
...
170171
backend: backend.clone(),
171-
..
172+
...
172173
})?;
173174
```
174175

175176
3. Add `backend` as a parameter to [`start_consensus()`](https://paritytech.github.io/polkadot-sdk/master/parachain_template_node/service/fn.start_consensus.html){target=\_blank} in `node/src/service.rs`
176177

177178
```rust title="node/src/service.rs"
178179
fn start_consensus(
179-
..
180+
...
180181
backend: Arc<ParachainBackend>,
181-
..
182+
...
182183
```
183184

184185
```rust title="node/src/service.rs"
185186
if validator {
186187
start_consensus(
187-
..
188+
...
188189
backend.clone(),
189-
..
190+
...
190191
)?;
191192
}
192193
```
@@ -206,16 +207,16 @@ This phase consists of plugging in the new lookahead collator node.
206207
- Increase [`authoring_duration`](https://github.com/paritytech/polkadot-sdk/blob/6b17df5ae96f7970109ec3934c7d288f05baa23b/templates/parachain/node/src/service.rs#L206-L225){target=\_blank} from 500 milliseconds to 2000
207208
```rust title="node/src/service.rs"
208209
let params = AuraParams {
209-
..
210+
...
210211
para_client: client.clone(),
211212
para_backend: backend.clone(),
212-
..
213+
...
213214
code_hash_provider: move |block_hash| {
214215
client.code_at(block_hash).ok().map(|c| ValidationCode::from(c).hash())
215216
},
216-
..
217+
...
217218
authoring_duration: Duration::from_millis(2000),
218-
..
219+
...
219220
};
220221
```
221222

@@ -235,8 +236,7 @@ This phase consists of plugging in the new lookahead collator node.
235236

236237
This phase consists of changes to your parachain's runtime that activate async backing feature.
237238

238-
1. Configure [`pallet_aura`](https://paritytech.github.io/polkadot-sdk/master/pallet_aura/index.html){target=\_blank}, setting [`AllowMultipleBlocksPerSlot`](https://paritytech.github.io/polkadot-sdk/master/pallet_aura/pallet/trait.Config.html#associatedtype.AllowMultipleBlocksPerSlot){target=\_blank} to true in
239-
`runtime/src/lib.rs`.
239+
1. Configure [`pallet_aura`](https://paritytech.github.io/polkadot-sdk/master/pallet_aura/index.html){target=\_blank}, setting [`AllowMultipleBlocksPerSlot`](https://paritytech.github.io/polkadot-sdk/master/pallet_aura/pallet/trait.Config.html#associatedtype.AllowMultipleBlocksPerSlot){target=\_blank} to true in `runtime/src/lib.rs`.
240240

241241
```rust title="runtime/src/lib.rs"
242242
impl pallet_aura::Config for Runtime {
@@ -266,7 +266,7 @@ This phase consists of changes to your parachain's runtime that activate async b
266266
3. Decrease [`MILLI_SECS_PER_BLOCK`](https://github.com/paritytech/polkadot-sdk/blob/6b17df5ae96f7970109ec3934c7d288f05baa23b/templates/parachain/runtime/src/lib.rs#L182-L194){target=\_blank} to 6000.
267267

268268
!!!note
269-
For a parachain which measures time in terms of its own block number rather than by relay block number it may be preferable to increase velocity. Changing block time may cause complications, requiring additional changes. See the section "Timing by Block Number".
269+
For a parachain which measures time in terms of its own block number rather than by relay block number it may be preferable to increase velocity. Changing block time may cause complications, requiring additional changes. See the section [Timing by Block Number](#timing-by-block-number){target=\_blank}.
270270

271271
```rust title="runtime/src/lib.rs"
272272
mod block_times {
@@ -297,9 +297,9 @@ This phase consists of changes to your parachain's runtime that activate async b
297297

298298
```rust title="runtime/src/lib.rs"
299299
impl pallet_timestamp::Config for Runtime {
300-
..
300+
...
301301
type MinimumPeriod = ConstU64<0>;
302-
..
302+
...
303303
}
304304
```
305305

0 commit comments

Comments
 (0)