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

BEEFY spec #682

Merged
merged 39 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f3266ef
rebased to main, added sections on beefy, and file on beefy analysis
bhargavbh Jul 12, 2023
124c8e0
added new row for BEEFY keys
bhargavbh Jul 12, 2023
f2f194d
MMR spec and interface contributed by Heverson
bhargavbh Jul 12, 2023
30cbe68
added mmr root merging direction to mmr definition
heversonbr Jul 13, 2023
152d022
updated mmr description
heversonbr Jul 13, 2023
da9b0b2
changes to mmr tree reverted.round selection added
bhargavbh Jul 19, 2023
d6cc7d7
Update chap-host-api.md
Noc2 Jul 12, 2023
9126dfb
Update chap-overview.md
Noc2 Jul 12, 2023
c935ae1
Update chap-runtime-api.md
Noc2 Jul 12, 2023
8fe7c91
Update chap-state.md
Noc2 Jul 12, 2023
92794c9
Update id-consensus.md
Noc2 Jul 14, 2023
b086bd6
Update sect-block-production.md
Noc2 Jul 14, 2023
e573c7d
Update id-extrinsics.md
Noc2 Jul 17, 2023
97664c4
Update part-polkadot-host.md
Noc2 Jul 17, 2023
770c1d7
Update id-glossary.md
Noc2 Jul 17, 2023
17a25b8
Update id-cryptography-encoding.md
Noc2 Jul 19, 2023
59537bb
Update id-weights.md
Noc2 Jul 20, 2023
ff5560c
Update sect-lightclient.md
Noc2 Jul 20, 2023
c19efc3
Update chapter-anv.md
Noc2 Jul 20, 2023
cdb284c
Update sect-metadata.md
Noc2 Jul 20, 2023
27009bf
Update sect-lightclient.md
Noc2 Jul 21, 2023
0e3b0e8
Update chapter-anv.md
Noc2 Jul 21, 2023
61a542a
incorporated Syeds review
bhargavbh Sep 22, 2023
7e06f3b
subsampling chart updated
bhargavbh Sep 26, 2023
9234004
Merge branch 'main' into bnb/beefy-spec
bhargavbh Oct 9, 2023
c56855f
tuned
bhargavbh Oct 2, 2023
89c186a
tuned; completed TODOs
bhargavbh Oct 9, 2023
7db0ab5
tuned; removed sequence charts; more appropriate location for them is…
bhargavbh Oct 9, 2023
f8e9c7d
Delete docs/sect-beefy.md
bhargavbh Oct 9, 2023
8528d9b
tuned
bhargavbh Oct 9, 2023
961d285
Update sect-finality.md
Noc2 Oct 10, 2023
fca4dcc
Update id-cryptography-encoding.md
Noc2 Oct 10, 2023
9eefc29
tuned; removed reference to ethereum transactions; motivation -> requ…
bhargavbh Oct 10, 2023
6b3a60b
Update sect-finality.md
Noc2 Oct 10, 2023
2e475ac
tuned; renamed definition header from commitment -> signed commitment
bhargavbh Oct 10, 2023
98f5fe4
added BEEFY consensus message, networking and gossip messages related…
bhargavbh Oct 10, 2023
82c13a0
consensus message defined
bhargavbh Oct 11, 2023
99f44da
tuned; fixed broken links; changed statements -> payloads in networki…
bhargavbh Oct 11, 2023
30d00b0
Update chap-networking.md
Noc2 Oct 11, 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
60 changes: 59 additions & 1 deletion docs/chap-networking.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Complete specification of the Polkadot networking protocol relies on the followi
## -sec-num- Node Identities {#id-node-identities}

Like any other distributed system, each Polkadot Host node has a unique global identifier. This identifier, called `PeerId`, serves as a singular reference to a particular node within the overall network.
In Polkadot each node is required to maintain its own pair of ED25519 cryptographic keys from which the `PeerId` [is derived](https://pl-launchpad.io/curriculum/libp2p/connections/#peer-identity).
In Polkadot, each node is required to maintain its own pair of ED25519 cryptographic keys from which the `PeerId` [is derived](https://pl-launchpad.io/curriculum/libp2p/connections/#peer-identity).

The Polkadot node’s `PeerId` is structured based on the [libp2p specification](https://docs.libp2p.io/concepts/peer-id/) but does not fully conform to the specification. In particular, it does not support [CID](https://github.com/multiformats/cid) and the only supported key type is ED25519. The `PeerId` is built by hashing the [encoded public key](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#keys) with [multihash](https://github.com/multiformats/multihash) and represented as follows:

Expand Down Expand Up @@ -197,6 +197,13 @@ The prefixes on those substreams are known as protocol identifiers and are used
For backward compatibility reasons, `/paritytech/grandpa/1` is also a valid substream for those messages.
:::

- `/91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3/beefy/1` - a substream/notification protocol which sends signed BEEFY payloads, as described in [Section -sec-num-ref-](sect-finality#sect-grandpa-beefy), to connected peers. This is a *Notification* substream.

The messages are specified in [Section -sec-num-ref-](chap-networking#sect-msg-grandpa-beefy).

:::info
For backward compatibility reasons, `/paritytech/beefy/1` is also a valid substream for those messages.
:::

## -sec-num- Network Messages {#sect-network-messages}

Expand Down Expand Up @@ -698,3 +705,54 @@ This message is the sub-component of the GRANDPA Gossip message ([Definition -de


:::
### -sec-num- GRANDPA BEEFY {#sect-msg-grandpa-beefy}

This section defines the messages required for the BEEFY protocol ([Section -sec-num-ref-](sect-finality#sect-grandpa-beefy)). Those messages are sent over the `/91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3/beefy/1` substream.
###### Definition -def-num- Commitment {#defn-grandpa-beefy-commitment}
:::definition
A **commitment**, ${C}$, contains the information extracted from the finalized block at height ${H}_{{i}}{\left({B}_{{\text{last}}}\right)}$ as specified in the message body and a datastructure of the following format:
$$
{C}={\left({R}_{{h}},{H}_{{i}}{\left({B}_{{\text{last}}}\right)},\text{id}_{{{\mathbb{{V}}}}}\right)}
$$
**where**
- ${R}_{{h}}$ is the MMR root of all the block header hashes leading up to the latest, finalized block.
- ${H}_{{i}}{\left({B}_{{\text{last}}}\right)}$ is the block number this commitment is for. Namely the latest, finalized block.
- $\text{id}_{{{\mathbb{{V}}}}}$ is the current authority set Id ([Definition -def-num-ref-](sect-finality#defn-authority-set-id)).
:::
###### Definition -def-num- Vote Message {#defn-msg-beefy-gossip}
:::definition
A **vote message**, ${M}_{{v}}$, is direct vote created by the Polkadot Host on every BEEFY round and is gossiped to its peers. The message is a datastructure of the following format:
$$
{M}_{{v}}=\text{Enc}_{{\text{SC}}}{\left({C},{{A}_{{\text{id}}}^{{\text{bfy}}}},{A}_{{\text{sig}}}\right)}
$$
**where**
- ${C}$ is the BEEFY commitment ([Definition -def-num-ref-](chap-networking#defn-grandpa-beefy-commitment)).
- ${{A}_{{\text{id}}}^{{\text{bfy}}}}$ is the ECDSA public key of the Polkadot Host.
- ${A}_{{\text{sig}}}$ is the signature created with ${{A}_{{\text{id}}}^{{\text{bfy}}}}$ by signing the payload ${R}_{{h}}$ in ${C}$.
:::
###### Definition -def-num- Signed Commitment {#defn-grandpa-beefy-signed-commitment}
:::definition
A **signed commitment**, ${M}_{{\text{sc}}}$, is a datastructure of the following format:
$$
{M}_{{\text{SC}}}=\text{Enc}_{{\text{SC}}}{\left({C},{S}_{{n}}\right)}
$$
$$
{S}_{{n}}={\left({{A}_{{0}}^{{\text{sig}}}},\ldots{{A}_{{n}}^{{\text{sig}}}}\right)}
$$
**where**
- ${C}$ is the BEEFY commitment ([Definition -def-num-ref-](chap-networking#defn-grandpa-beefy-commitment)).
- ${S}_{{n}}$ is an array where its exact size matches the number of validators in the current authority set as specified by $\text{id}_{{{\mathbb{{V}}}}}$ ([Definition -def-num-ref-](sect-finality#defn-authority-set-id)) in ${C}$. Individual items are of the type *Option* ([Definition -def-num-ref-](id-cryptography-encoding#defn-option-type)), which can contain a signature of a validator which signed the same payload (${R}_{{h}}$ in ${C}$) and is active in the current authority set. It’s critical that the signatures are sorted based on their corresponding public key entry in the authority set.
For example, the signature of the validator at index 3 in the authority set must be placed at index *3* in ${S}_{{n}}$. If not signature is available for that validator, then the *Option* variant is *None* inserted ([Definition -def-num-ref-](id-cryptography-encoding#defn-option-type)). This sorting allows clients to map public keys to their corresponding signatures.
:::
###### Definition -def-num- Signed Commitment Witness {#defn-grandpa-beefy-signed-commitment-witness}
:::definition
A **signed commitment witness**, ${{M}_{{\text{SC}}}^{{w}}}$, is a light version of the signed BEEFY commitment ([Definition -def-num-ref-](chap-networking#defn-grandpa-beefy-signed-commitment)). Instead of containing the entire list of signatures, it only claims which validator signed the payload.
The message is a datastructure of the following format:
$$
{{M}_{{\text{SC}}}^{{w}}}=\text{Enc}_{{\text{SC}}}{\left({C},{V}_{{{0},\ldots{n}}},{R}_{{\text{sig}}}\right)}
$$
**where**
- ${C}$ is the BEEFY commitment ([Definition -def-num-ref-](chap-networking#defn-grandpa-beefy-commitment)).
- ${V}_{{{0},\ldots{n}}}$ is an array where its exact size matches the number of validators in the current authority set as specified by $\text{id}_{{{\mathbb{{V}}}}}$ in ${C}$. Individual items are booleans which indicate whether the validator has signed the payload (*true*) or not (*false*). It’s critical that the boolean indicators are sorted based on their corresponding public key entry in the authority set.
For example, the boolean indicator of the validator at index 3 in the authority set must be placed at index *3* in ${V}_{{n}}$. This sorting allows clients to map public keys to their corresponding boolean indicators.
- ${R}_{{\text{sig}}}$ is the MMR root of the signatures in the original signed BEEFY commitment ([Definition -def-num-ref-](chap-networking#defn-grandpa-beefy-signed-commitment)).
1 change: 1 addition & 0 deletions docs/chap-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ $$
$t = 4$ **Consensus Message**, contains scale-encoded message $m$ from the Runtime to the consensus engine. The receiving engine is determined by the *id* identifier:
- *id* = BABE: a message to BABE engine ([Definition -def-num-ref-](sect-block-production#defn-consensus-message-babe))
- *id* = FRNK: a message to GRANDPA engine ([Definition -def-num-ref-](sect-finality#defn-consensus-message-grandpa))
- *id* = BEEF: a message to BEEFY engine ([Definition -def-num-ref-](sect-finality#defn-consensus-message-beefy))


$t = 5$ **Seal**, is produced by the consensus engine and proves the authorship of the block producer. The engine used for this is provided through *id* (at the moment, `BABE`), while $m$ contains the scale-encoded signature ([Definition -def-num-ref-](sect-block-production#defn-block-signature)) of the block producer. In particular, the Seal digest item must be the last item in the digest array and must be stripped off by the Polkadot Host before the block is submitted to any Runtime function, including for validation. The Seal must be added back to the digest afterward.
Expand Down
Loading