24 releases (10 breaking)

✓ Uses Rust 2018 edition

0.11.2 Mar 19, 2020
0.11.0 Jan 16, 2020
0.10.2 Dec 10, 2019
0.10.1 Nov 26, 2019
0.4.0 Nov 23, 2018

#6 in Cryptocurrencies

Download history 1511/week @ 2019-12-09 1152/week @ 2019-12-16 445/week @ 2019-12-23 589/week @ 2019-12-30 1312/week @ 2020-01-06 1823/week @ 2020-01-13 1273/week @ 2020-01-20 1458/week @ 2020-01-27 1487/week @ 2020-02-03 1528/week @ 2020-02-10 1475/week @ 2020-02-17 1359/week @ 2020-02-24 1154/week @ 2020-03-02 1655/week @ 2020-03-09 2024/week @ 2020-03-16 1733/week @ 2020-03-23

5,685 downloads per month
Used in sc-finality-grandpa

Apache-2.0

205KB
4.5K SLoC

finality-grandpa

crates.io link Build Status Code coverage

GRANDPA, GHOST-based Recursive ANcestor Deriving Prefix Agreement, is a finality gadget for blockchains, implemented in Rust. It allows a set of nodes to come to BFT agreement on what is the canonical chain, which is produced by some external block production mechanism. It works under the assumption of a partially synchronous network model and with the presence of up to 1/3 Byzantine nodes.

Build & Test

The only dependency required to build and run the tests is to have a stable version of Rust installed.

git clone https://github.com/paritytech/finality-grandpa
cd finality-grandpa
cargo build
cargo test

Usage

Add this to your Cargo.toml:

[dependencies]
finality-grandpa = "0.10"

Features:

  • derive-codec - Derive Decode/Encode instances of parity-scale-codec for all the protocol messages.
  • test-helpers - Expose some opaque types for testing purposes.

Integration

This crate only implements the state machine for the GRANDPA protocol. In order to use this crate it is necessary to implement some traits to do the integration which are responsible for providing access to the underyling blockchain and setting up all the network communication.

Chain

The Chain trait allows the GRANDPA voter to check ancestry of a given block and also to query the best block in a given chain (which will be used for voting on).

Environment

The Environment trait defines the types that will be used for the input and output stream to receive and broadcast messages. It is also responsible for setting these up for a given round (through round_data), as well as timers which are used for timeouts in the protocol.

The trait exposes callbacks for the full lifecycle of a round:

  • proposed
  • prevoted
  • precommitted
  • completed

As well as callbacks for notifying about block finality and voter misbehavior (equivocations).

Substrate

The main user of this crate is Substrate and should be the main resource used to look into how the integration is done. The substrate-finality-grandpa crate should have most of the relevant integration code.

Most importantly this crate does not deal with authority set changes. It assumes that the set of authorities is always the same. Authority set handoffs are handled in Substrate by listening to signals emitted on the underlying blockchain.

Resources

License

Usage is provided under the Apache License (Version 2.0). See LICENSE for the full details.

Dependencies

~0.9–1.6MB
~30K SLoC