Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorg Async Backing #5176

Merged
merged 71 commits into from
Oct 5, 2023
Merged
Changes from 15 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
a680a26
added conditional rendering
filippoweb3 Sep 11, 2023
00b3bdb
edited sync backing part
filippoweb3 Sep 11, 2023
85e317f
minor edits
filippoweb3 Sep 11, 2023
112faa5
reorg text async
filippoweb3 Sep 11, 2023
db99038
rearranged text
filippoweb3 Sep 11, 2023
91935e2
grammar check
filippoweb3 Sep 11, 2023
5b0f39a
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 11, 2023
7e0be00
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 11, 2023
1dc698b
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 11, 2023
0a8f531
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 12, 2023
5723b28
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 12, 2023
148ed7d
added Bader's feedback
filippoweb3 Sep 12, 2023
b2764f8
added notes + high level prospective parachains
CrackTheCode016 Sep 12, 2023
8c53586
moved text around
filippoweb3 Sep 13, 2023
dcd4f94
minor addition
filippoweb3 Sep 13, 2023
d00e5b3
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 14, 2023
90e9552
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 14, 2023
e90a3a5
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 14, 2023
284b7a7
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 14, 2023
a388eab
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 14, 2023
5eb7041
minor edit
filippoweb3 Sep 14, 2023
80d8da5
Merge branch 'master' into reorg-async-backing
filippoweb3 Sep 14, 2023
7b03e18
clarifications
CrackTheCode016 Sep 20, 2023
f609a94
Merge branch 'reorg-async-backing' of github.com:w3f/polkadot-wiki in…
CrackTheCode016 Sep 20, 2023
7e46935
added sync backing graphics and description
filippoweb3 Sep 21, 2023
300ac38
added async backing diagrams
filippoweb3 Sep 21, 2023
44d2f76
more info description async backing
filippoweb3 Sep 21, 2023
94070fc
added second case async backing
filippoweb3 Sep 21, 2023
75de1eb
grammar check
filippoweb3 Sep 21, 2023
f583b47
minor edits
filippoweb3 Sep 21, 2023
55a6abd
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 22, 2023
a62eb30
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 22, 2023
135ef38
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 22, 2023
82656b6
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 22, 2023
c6e2e41
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 22, 2023
22c2229
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 22, 2023
9784d4b
updated figures
filippoweb3 Sep 22, 2023
fa2bb6f
minor edit async backing figure
filippoweb3 Sep 22, 2023
48eca0c
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 25, 2023
285154a
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 25, 2023
c5a373b
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 25, 2023
4c4d169
Bradley feedback pt1
filippoweb3 Sep 25, 2023
837e7dc
edits to sync backing section
filippoweb3 Sep 25, 2023
e30ed29
added new figures, modified text
filippoweb3 Sep 25, 2023
742db52
Bradley feedback pt2
filippoweb3 Sep 25, 2023
cd0c6fd
edits figure
filippoweb3 Sep 25, 2023
134fc0c
added Bradley's answers to Bader's questions
filippoweb3 Sep 25, 2023
f31cccb
more additions
filippoweb3 Sep 26, 2023
6b78e5e
Merge branch 'master' into reorg-async-backing
filippoweb3 Sep 26, 2023
e8ad5e5
additions references
filippoweb3 Sep 26, 2023
743db67
moved text around for better read
filippoweb3 Sep 26, 2023
e06b66f
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 27, 2023
3d8ea1e
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 27, 2023
b378bb0
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 27, 2023
6b422de
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 27, 2023
7f500f8
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 27, 2023
69ab29f
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 27, 2023
56908f3
Update docs/learn/learn-async-backing.md
filippoweb3 Sep 27, 2023
1ea1c8f
Bradley's feedback
filippoweb3 Sep 27, 2023
80d903f
minor edits
filippoweb3 Sep 27, 2023
b46e156
Sophia's feedback (no figures)
filippoweb3 Sep 27, 2023
208ab8d
sophia's feedback, figures
filippoweb3 Sep 28, 2023
985e382
major edits
filippoweb3 Sep 28, 2023
d4ad730
param error correction
filippoweb3 Sep 28, 2023
b6e2559
minor edits and reorg
filippoweb3 Sep 29, 2023
1eec716
updated figures
filippoweb3 Oct 1, 2023
42e2e46
minor addition
filippoweb3 Oct 1, 2023
268d3c3
Update docs/learn/learn-async-backing.md
filippoweb3 Oct 4, 2023
b4013fa
Shawn's feedback
filippoweb3 Oct 4, 2023
6a23e24
Merge branch 'master' into reorg-async-backing
filippoweb3 Oct 4, 2023
c989096
added new figure
filippoweb3 Oct 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 145 additions & 68 deletions docs/learn/learn-async-backing.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,103 +7,179 @@ keywords: [parachains, slots, backing, parablock]
slug: ../learn-async-backing
---

import RPC from "./../../components/RPC-Connection";

:::info Learn about Parachain Consensus

To fully follow the material on this page, it is recommended to be familiar with the primary stages
of the [Parachain Protocol](./learn-parachains-protocol.md).

:::

## Synchronous Backing

Before diving into asynchronous backing it is important to understand what synchronous backing is
and what its main limitations are.

:::info What is backing?

**Backing** refers to the process in which a parablock is verified by a subset of validators who
determine the blocks validity. It is an important step in the validation process for parablocks, as
it is the first line of defense in ensuring valid state transitions are taking place. Validators who
back the parablock put their stake at risk, and if the block is found to be malicious, those
filippoweb3 marked this conversation as resolved.
Show resolved Hide resolved
validators are slashed.

:::

In synchronous backing, parablock validation is tightly coupled to the relay chain's progression on
a one-to-one basis. Every parablock must be generated and backed within a relay-chain block
(six-second window), and (if successfully backed) it will be included in a relay-chain block (often
referred to as the **parent** block, as the parablock anchors itself to it) after an additional six
filippoweb3 marked this conversation as resolved.
Show resolved Hide resolved
seconds. Thus, a parablock can be produced every 12 seconds because a new parablock can be produced
after the inclusion of the previous one.

The **contextual execution** of new parablocks are parablock ancestors included in the relay chain
filippoweb3 marked this conversation as resolved.
Show resolved Hide resolved
after 12 seconds, where contextual execution refers to the context built by included parablock
ancestors used by the parachains to generate new parablocks.

:::info It is important to note the clarification below
filippoweb3 marked this conversation as resolved.
Show resolved Hide resolved

- Not the entire parablock, but the **paraheader** is placed on the parent block on the relay chain.
- The relay chain does not access the entire state of a parachain but only the values that changed
during that block and the merkelized hashes of the unchanged values.
filippoweb3 marked this conversation as resolved.
Show resolved Hide resolved

:::

### Synchronous Backing Diagram
filippoweb3 marked this conversation as resolved.
Show resolved Hide resolved

FIGURE HERE?

A particular parablock, `P`, would only be valid for backing at relay chain parent `R` and
subsequently included at `R + 1` should it be backed successfully. Thus, a parablock is rushing to
be backed and included within a two-relay-chain-blocks window due to the inherent requirement for
synchrony between the parachain and relay chain. The next parablock `P + 1` will be valid for
backing at realy-chain block `R + 2`, i.e. two relay-chain blocks after the previously included
parablock.

The parablock generation and backing are bound together within a six-second window that limits the
amount of data a collator can add to each parablock. Essentially, a parablock is limited to the
requirement of being backed in six seconds, leaving little time for its generation and its
blockspace to be properly filled.
filippoweb3 marked this conversation as resolved.
Show resolved Hide resolved

## Asynchronous Backing

:::warning Disclaimer: Performance Measurements

Due to asynchronous backing not being fully implemented in a running production network, each
performance metric is not fully tested.

:::

### Pipelining
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can take out pipelining here, as we want to introduce what async backing is. Pipelining is a good way to describe it, but it isn't fully what async backing represents IMHO.

Suggested change
### Pipelining

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave it as it helped me to get the picture of what is happening and there are some parts linked to it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is indeed more to it than just pipelining, though that doesn't make it wrong to spend time hammering home the pipelining comparison. If the reader takes away any one thing, I'd have it be the notion of completing the backing and inclusion steps for different blocks at the same time.

Here's a useful extension of the pipelining comparison. Async backing doesn't just allow for pipelining within a single pipe. It laid the foundation for a large number of pipes (~10 cores) to run for the same parachain at the same time. In that way we have two distinct new forms of parallel computation.


Asynchronous backing is a feature that introduces
[pipelining](https://www.techtarget.com/whatis/definition/pipelining) to the parachain block
generation and validation process. It is analogous to the logical pipelining of processor
[generation](./learn-parachains-protocol.md), [backing](./learn-parachains-protocol.md) and
[inclusion](./learn-parachains-protocol.md). It is analogous to the logical pipelining of processor
filippoweb3 marked this conversation as resolved.
Show resolved Hide resolved
instruction in "traditional" architectures, where some instructions may be executed before others
are complete. Instructions may also be executed in parallel, enabling multiple parts of the
processor to be working on potentially different instructions at the same time.
processor to work on potentially different instructions simultaneously.

Bundles of state transitions represented as blocks may be processed similarly. In the context of
Polkadot, it aims to increase the throughput of the entire network.
{{ polkadot: Polkadot :polkadot }}{{ kusama: Kusama :kusama }}, pipelining aims to increase the
throughput of the entire network.

:::info
### Synchronous vs. Asynchronous Backing

In order to realize which exact processes this upgrade improves, it is recommended to be familiar
with the stages of parablock validation, which you may [read here](./learn-parachains-protocol.md).
Asynchronous Backing has three overarching goals:

:::
1. Decrease parachain block (parablock) validation time to **6 seconds** from **12 seconds**
2. **Increase the usable blockspace**, allowing more state changes per relay chain block.
filippoweb3 marked this conversation as resolved.
Show resolved Hide resolved
3. **Allow parablocks to be re-proposed** to the network if they are not included successfully on
the first attempt.

Asynchronous backing enables logical pipelining over the parablock
[**generation**](https://wiki.polkadot.network/docs/learn-parachains-protocol#collators),
[**backing**](https://wiki.polkadot.network/docs/learn-parachains-protocol#parachain-phase), and
[**inclusion**](https://wiki.polkadot.network/docs/learn-parachains-protocol#inclusion-pipeline)
processes. A parablock may be at different stages, but multiple parablocks can be processed
simultaneously (in parallel) if needed. Most notably, parablock N + 1 can be generated and backed
while its predecessor, parablock N, is undergoing inclusion on the relay chain. Processes can occur
while their ancestors are included on the relay chain.
In synchronous backing, parablock generation relies on the most recent relay-chain block. Each
parablock must be generated and go through the entire backing process in a single relay block. It
then proceeds to the inclusion process during the generation of the next relay-chain block.

This pipeline will allow [collators](./learn-parachains-protocol.md#collators) to include an
estimated ~3-5x more transactions/data while speeding up parachain block times from 12 to 6 seconds.
In short, Polkadot with asynchronous backing will deliver an estimated ~6-10x more blockspace to its
parachains.
Asynchronous backing brings the following changes to the parachain protocol:

Asynchronous Backing has three overarching goals:
- Parablock generation is now decoupled from the backing process, avoiding the previous 6-second
deadline through the backing process. This gives more time for collators to properly use
blockspace, decreasing the probability of generating empty parablocks.
- Parachains can generate blocks and have them placed into **unincluded segments** of parablock
ancestors (i.e. parablocks that are seconded but not yet backed by paravalidators and included in
the relay chain) rather than ancestors included in the relay chain state.
filippoweb3 marked this conversation as resolved.
Show resolved Hide resolved

1. Decrease parachain block (parablock) validation time to **6 seconds** from **12 seconds**
2. Increase the amount of usable blockspace, allowing more state changes per relay chain block.
3. Allow for parablocks to be re-proposed to the network if they are not included successfully on
the first attempt.
### Unincluded Segments

Asynchronous backing provides a form of **contextual execution**, which allows for more time for
parachain collators to fit more transactions and prepare block candidates for backing and inclusion.
**Contextual execution** refers to how a parablock can be built earlier using the context provided
by an _unincluded segment_ of recent block ancestors.
Unincluded segments are chains of candidate parablocks that are seconded but not yet backed and
included in the relay chain. Parablocks can be added to this unincluded segment without waiting for
the latest included parent block of the relay chain. The core functionality that asynchronous
backing brings is the ability to build on these unincluded segments of block ancestors rather than
ancestors included in the relay chain state.

**Unincluded segments** are chains of candidate blocks that are not yet included in the relay chain.
Parablocks can be added to this unincluded segment without waiting for the latest included parent
block of the relay chain. The core functionality that asynchronous backing brings is the ability to
build on these unincluded segments of block ancestors rather than ancestors included in the relay
chain state.
Compared to synchronous backing, contextual execution shift from being the parablock ancestors
included in the relay chain, to being being the latest ancestor parablock pushed into the unincluded
segment. This allows to start building parablocks earlier, giving plenty of time to parachain
collators to fit more transactions and prepare block candidates for backing and eventually
inclusion.

Currently, parablocks rely on the most recent relay chain block (often referred to as the **parent**
block, as the parablock anchors itself to it). Each parablock must be generated and go through the
entire backing process in a single relay block. It then proceeds to the availability + inclusion
process during the next block.
### Asynchronous Backing Diagram

:::info
FIGURE HERE?

It is important to note the following clarifications:
In asynchronous backing, parablock `P + 1` can begin the generation process soon after parablock `P`
has been generated and appended into the [unincluded segment](#unincluded-segments). Backing of
parablock ancestor `P - 1` (pushed to the unincluded segment before `P`) can happen as soon as `P`
is in the unincluded segment, available as execution context for the generation of parablock
`P + 1`. Inclusion of `P - 1` and backing of `P` can happen within the span of one relay chain block
(i.e. six-second time window) thanks to [pipelining](#pipelining).

1. The parablock is not placed on the relay chain in its entirety, but rather the **paraheader**
2. The relay chain does not access the entire state of a parachain but only the values that changed
during that block and the merkelized hashes of the unchanged values.
The execution context for the latest parablock is derived from the unincluded segment of block
ancestors upon which the newest parablock is built. These blocks can be prepared in anticipation of
being included later rather than keeping in sync with the relay chain's progress one-to-one. A
parablock can be in a different stage from another one being built if it abides by the parameters
set forth by the asynchronous backing configuration.

:::
Asynchronous backing will allow [collators](./learn-parachains-protocol.md#collators) to include an
estimated ~3-5x more data into parablocks while speeding up parachain block times from 12 to 6
seconds. Due to the 2x decrease in block time and the possibility of building blocks in advance to
fit more data, Polkadot with asynchronous backing will deliver an estimated ~6-10x more blockspace
to its parachains.

For more information on the validity and availability process, be sure to visit the
[parachain protocol](../learn/learn-parachains-protocol.md) page.
This combination of lower latency, higher storage per block, and a logical pipeline spanning
Polkadot's networking, runtime, and collation aspects will allow for higher, more robust throughput.

## Synchronous Backing on Polkadot
### Prospective Parachains

With synchronous backing, there was only about a single relay chain block (6-second window), to
complete the parablock candidate generation and backing process. This was tightly coupled to the
relay chain's progress, where blocks had to be created within this window.
Prospective parachains are essentially all unincluded segments from all parachains.

The main limitation of synchronous backing is that parablock validation is tightly coupled to the
relay chain's progression on a 1-1 basis, meaning every parablock must be generated and backed
within six seconds. This time limit reduces the amount of data a collator has time to add to each
block.
The
[prospective Parachains subsystem](https://paritytech.github.io/polkadot/book/node/backing/prospective-parachains.html),
is responsible for coordinating the state of various prospective parachain fragments. A fragment is
a prospective/potential parablock. More than one of these make up a
[**fragment tree**](https://paritytech.github.io/polkadot/book/node/backing/prospective-parachains.html#fragment-trees),
and represent the potential states of a parachain. Each of these fragments are anchored to a past
relay chain parent. This does not have to be the latest parent, as was before, but can be one in the
past.

A particular parablock, `P1`, would **only** be valid for backing at relay chain parent `R1 + 1` and
subsequently, be included at `R1 + 2` should it be backed successfully. Essentially, a parablock is
rushing to be backed and included within this two-block window due to the inherent requirement for
synchrony between the parachain and relay chain.
This subsystem also communicates with other subsystems in the validation process, such as the
Backing subsystem, once a candidate block has been seconded.

## Asynchronous Backing on Polkadot
### Further Benefits of Async Backing

With asynchronous backing, the window of time is customizable and will most likely sit around the
6-18 second range. It also introduces a parameter to aid in defining the maximum amount of ancestor
blocks, which allows for a parablock to be backed later in the future, enabling more computational
and storage time per block. The context for the latest parablock is derived from the unincluded
segment of block ancestors upon which the newest parablock is built.
Asynchronous backing also introduces a parameter to define the maximum number of ancestor blocks
within the unincluded segment. This allows for a parablock to be backed later, enabling more
computational and storage time per block. The decoupling of collation (candidate generation) and
backing also allows for more execution time, while citing a lower validation time.

These blocks can be prepared in anticipation of being included later rather than keeping in sync
with the relay chain's progress 1-1. The block can be in a different stage from another block being
built, as long as it abides by the parameters set forth by the asynchronous backing configuration.
There are two parameters that are controlled can be controlled by governance:

This combination of lower latency, higher storage per block, and a logical pipeline spanning
Polkadot's networking, runtime, and collation aspects will allow for higher, more robust throughput.
- [`allowed_ancestry_len`](https://github.com/paritytech/polkadot-sdk/blob/f204e3264f945c33b4cea18a49f7232c180b07c5/polkadot/primitives/src/vstaging/mod.rs#L54) -
How many ancestors of a relay parent are allowed to build candidates on top of.
- [`max_candidate_depth`](https://github.com/paritytech/polkadot-sdk/blob/f204e3264f945c33b4cea18a49f7232c180b07c5/polkadot/primitives/src/vstaging/mod.rs#L49) -
The maximum amount of candidates between the latest parablock and relay parent ancestor.

## Learn More

Expand All @@ -114,3 +190,4 @@ resources:
Rob Habermeier, Polkadot founder, details the plans for Polkadot for 2023.
- [Asynchronous Backing Spec & Tracking Issue](https://github.com/paritytech/polkadot/issues/3779) -
The implementation tracking issue for asynchronous backing
- [Prospective Parachains Subsystem - The Polkadot Parachain Host Implementers' Guide](https://paritytech.github.io/polkadot/book/node/backing/prospective-parachains.html)
Loading