Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Implement Lean BEEFY (#10882)
Browse files Browse the repository at this point in the history
Simplified BEEFY worker logic based on the invariant that GRANDPA
will always finalize 1st block of each new session, meaning BEEFY
worker is guaranteed to receive finality notification for the
BEEFY mandatory blocks.

Under these conditions the current design is as follows:
- session changes are detected based on BEEFY Digest present in
  BEEFY mandatory blocks,
- on each new session new `Rounds` of voting is created, with old
  rounds being dropped (for gossip rounds, last 3 are still alive
  so votes are still being gossiped),
- after processing finality for a block, the worker votes if
  a new voting target has become available as a result of said
  block finality processing,
- incoming votes as well as self-created votes are processed
  and signed commitments are created for completed BEEFY voting
  rounds,
- the worker votes if a new voting target becomes available
  once a round successfully completes.

On worker startup, the current validator set is retrieved from
the BEEFY pallet. If it is the genesis validator set, worker
starts voting right away considering Block #1 as session start.

Otherwise (not genesis), the worker will vote starting with
mandatory block of the next session.

Later on when we add the BEEFY initial-sync (catch-up) logic,
the worker will sync all past mandatory blocks Signed Commitments
and will be able to start voting right away.

BEEFY mandatory block is the block with header containing the BEEFY
`AuthoritiesChange` Digest, this block is guaranteed to be finalized
by GRANDPA.

This session-boundary block is signed by the ending-session's
validator set. Next blocks will be signed by the new session's
validator set. This behavior is consistent with what GRANDPA does
as well.

Also drop the limit N on active gossip rounds. In an adversarial
network, a bad actor could create and gossip N invalid votes with
round numbers larger than the current correct round number. This
would lead to votes for correct rounds to no longer be gossiped.

Add unit-tests for all components, including full voter consensus
tests.

Signed-off-by: Adrian Catangiu <adrian@parity.io>
Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
Co-authored-by: David Salami <Wizdave97>
  • Loading branch information
acatangiu and tomusdrw committed Mar 25, 2022
1 parent 318dea3 commit 411d9bb
Show file tree
Hide file tree
Showing 12 changed files with 1,815 additions and 568 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions client/beefy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ description = "BEEFY Client gadget for substrate"
[dependencies]
fnv = "1.0.6"
futures = "0.3"
futures-timer = "3.0.1"
hex = "0.4.2"
log = "0.4"
parking_lot = "0.12.0"
Expand All @@ -23,22 +24,31 @@ sp-api = { version = "4.0.0-dev", path = "../../primitives/api" }
sp-application-crypto = { version = "6.0.0", path = "../../primitives/application-crypto" }
sp-arithmetic = { version = "5.0.0", path = "../../primitives/arithmetic" }
sp-blockchain = { version = "4.0.0-dev", path = "../../primitives/blockchain" }
sp-consensus = { version = "0.10.0-dev", path = "../../primitives/consensus/common" }
sp-core = { version = "6.0.0", path = "../../primitives/core" }
sp-keystore = { version = "0.12.0", path = "../../primitives/keystore" }
sp-runtime = { version = "6.0.0", path = "../../primitives/runtime" }

sc-chain-spec = { version = "4.0.0-dev", path = "../../client/chain-spec" }
sc-utils = { version = "4.0.0-dev", path = "../utils" }
sc-client-api = { version = "4.0.0-dev", path = "../api" }
sc-finality-grandpa = { version = "0.10.0-dev", path = "../../client/finality-grandpa" }
sc-keystore = { version = "4.0.0-dev", path = "../keystore" }
sc-network = { version = "0.10.0-dev", path = "../network" }
sc-network-gossip = { version = "0.10.0-dev", path = "../network-gossip" }
sc-utils = { version = "4.0.0-dev", path = "../utils" }

beefy-primitives = { version = "4.0.0-dev", path = "../../primitives/beefy" }

[dev-dependencies]
sp-tracing = { version = "5.0.0", path = "../../primitives/tracing" }
sc-consensus = { version = "0.10.0-dev", path = "../consensus/common" }
sc-network-test = { version = "0.8.0", path = "../network/test" }

sp-finality-grandpa = { version = "4.0.0-dev", path = "../../primitives/finality-grandpa" }
sp-keyring = { version = "6.0.0", path = "../../primitives/keyring" }
sp-tracing = { version = "5.0.0", path = "../../primitives/tracing" }
substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/runtime/client" }

serde = "1.0.136"
strum = { version = "0.23", features = ["derive"] }
tokio = "1.15"
tempfile = "3.1.0"
Loading

0 comments on commit 411d9bb

Please sign in to comment.