Skip to content

Commit 579a187

Browse files
committed
formatting
1 parent 5be370d commit 579a187

File tree

2 files changed

+28
-47
lines changed

2 files changed

+28
-47
lines changed

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ description: Learn how to increase the efficiency and throughput of your paracha
1010
This guide is relevant for Cumulus-based parachain projects started in 2023 or before, whose backing process is synchronous where parablocks can only be built on the latest relay chain block. Async backing allows collators to build parablocks on older relay chain blocks and create pipelines of multiple pending parablocks. This parallel block generation increases efficiency and throughput.
1111

1212
!!!note
13-
If starting a new parachain project, please use an async backing compatible template such as
14-
the [parachain template](https://github.com/paritytech/polkadot-sdk-parachain-template){target=\_blank}.
15-
The rollout process for async backing has three phases. Phases 1 and 2 below put new
16-
infrastructure in place. Then we can simply turn on async backing in phase 3.
13+
If starting a new parachain project, please use an async backing compatible template such as the [parachain template](https://github.com/paritytech/polkadot-sdk-parachain-template){target=\_blank}. The rollout process for async backing has three phases. Phases 1 and 2 below put new infrastructure in place. Then we can simply turn on async backing in phase 3.
1714

1815
## Prerequisite
1916

@@ -65,8 +62,6 @@ This phase involves configuring your parachain's runtime `/runtime/src/lib.rs` t
6562
4. Configure `cumulus_pallet_parachain_system` in the runtime.
6663

6764
- 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.
68-
- 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.
69-
7065
```rust title="lib.rs"
7166
type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
7267
Runtime,
@@ -76,6 +71,7 @@ This phase involves configuring your parachain's runtime `/runtime/src/lib.rs` t
7671
>;
7772
```
7873

74+
- 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.
7975
```rust title="lib.rs"
8076
impl cumulus_pallet_parachain_system::Config for Runtime {
8177
..
@@ -84,8 +80,7 @@ This phase involves configuring your parachain's runtime `/runtime/src/lib.rs` t
8480
}
8581
```
8682

87-
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}
88-
83+
- 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}
8984
```rust title="lib.rs"
9085
impl cumulus_pallet_parachain_system::Config for Runtime {
9186
..
@@ -102,7 +97,6 @@ This phase involves configuring your parachain's runtime `/runtime/src/lib.rs` t
10297
- We will set it to `true` when we activate async backing in phase 3
10398

10499
- 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}
105-
106100
```rust title="lib.rs"
107101
impl pallet_aura::Config for Runtime {
108102
..
@@ -124,17 +118,15 @@ This phase involves configuring your parachain's runtime `/runtime/src/lib.rs` t
124118
7. Implement the [`AuraUnincludedSegmentApi`](https://paritytech.github.io/polkadot-sdk/master/cumulus_primitives_aura/trait.AuraUnincludedSegmentApi.html){target=\_blank}, which allows the collator client to query its runtime to determine whether it should author a block.
125119

126120
- 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
127-
128121
```rust title="Cargo.toml"
129122
..
130123
cumulus-primitives-aura = { path = "../../../../primitives/aura", default-features = false }
131124
..
132125
```
133126

134-
In the same file, add `"cumulus-primitives-aura/std",` to the `std` feature.
135-
136-
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.
127+
- In the same file, add `"cumulus-primitives-aura/std",` to the `std` feature.
137128

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.
138130
```rust title="apis.rs"
139131
impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
140132
fn can_build_upon(
@@ -212,7 +204,6 @@ This phase consists of plugging in the new lookahead collator node.
212204
- Add a [`para_backend`](https://github.com/paritytech/polkadot-sdk/blob/6b17df5ae96f7970109ec3934c7d288f05baa23b/templates/parachain/node/src/service.rs#L206-L225){target=\_blank} parameter after `para_client`, passing in our para backend
213205
- Provide a [`code_hash_provider`](https://github.com/paritytech/polkadot-sdk/blob/6b17df5ae96f7970109ec3934c7d288f05baa23b/templates/parachain/node/src/service.rs#L206-L225){target=\_blank} closure like that shown below
214206
- 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
215-
216207
```rust title="node/src/service.rs"
217208
let params = AuraParams {
218209
..
@@ -234,11 +225,10 @@ This phase consists of plugging in the new lookahead collator node.
234225
6. In [`start_consensus()`](https://github.com/paritytech/polkadot-sdk/blob/6b17df5ae96f7970109ec3934c7d288f05baa23b/templates/parachain/node/src/service.rs#L173) replace `basic_aura::run` with [`aura::run`](https://github.com/paritytech/polkadot-sdk/blob/6b17df5ae96f7970109ec3934c7d288f05baa23b/templates/parachain/node/src/service.rs#L226){target=\_blank}
235226

236227
```rust title="node/src/service.rs"
237-
let fut =
238-
aura::run::<Block, sp_consensus_aura::sr25519::AuthorityPair, _, _, _, _, _, _, _, _, _>(
239-
params,
240-
);
241-
task_manager.spawn_essential_handle().spawn("aura", None, fut);
228+
let fut = aura::run::<Block, sp_consensus_aura::sr25519::AuthorityPair, _, _, _, _, _, _, _, _>(
229+
params,
230+
);
231+
task_manager.spawn_essential_handle().spawn("aura", None, fut);
242232
```
243233

244234
## Phase 3 - Activate Async Backing
@@ -248,7 +238,7 @@ This phase consists of changes to your parachain's runtime that activate async b
248238
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
249239
`runtime/src/lib.rs`.
250240

251-
```rust title="runtime/src/lib.rs'
241+
```rust title="runtime/src/lib.rs"
252242
impl pallet_aura::Config for Runtime {
253243
type AuthorityId = AuraId;
254244
type DisabledValidators = ();
@@ -317,5 +307,4 @@ This phase consists of changes to your parachain's runtime that activate async b
317307

318308
With asynchronous backing it will be possible for parachains to opt for a block time of 6 seconds rather than 12 seconds. But modifying block duration isn't so simple for a parachain which was measuring time in terms of its own block number. It could result in expected and actual time not matching up, stalling the parachain.
319309

320-
One strategy to deal with this issue is to instead rely on relay chain block numbers for timing. Relay block number is kept track of by each parachain in [`pallet-parachain-system`](https://paritytech.github.io/polkadot-sdk/master/cumulus_pallet_parachain_system/index.html){target=\_blank} with the
321-
storage value [`LastRelaychainBlockNumber`](https://paritytech.github.io/polkadot-sdk/master/cumulus_pallet_parachain_system/pallet/type.LastRelayChainBlockNumber.html){target=\_blank}. This value can be obtained and used wherever timing based on block number is needed.
310+
One strategy to deal with this issue is to instead rely on relay chain block numbers for timing. Relay block number is kept track of by each parachain in [`pallet-parachain-system`](https://paritytech.github.io/polkadot-sdk/master/cumulus_pallet_parachain_system/index.html){target=\_blank} with the storage value [`LastRelaychainBlockNumber`](https://paritytech.github.io/polkadot-sdk/master/cumulus_pallet_parachain_system/pallet/type.LastRelayChainBlockNumber.html){target=\_blank}. This value can be obtained and used wherever timing based on block number is needed.

0 commit comments

Comments
 (0)