Create the fork-choice crate.

- Adds the naive fork choice (longest chain) rule.
- Adds basic documentation for the crate.
This commit is contained in:
Age Manning 2019-02-05 15:55:29 +11:00
parent da1498fc45
commit 8109fad7bf
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93
7 changed files with 29 additions and 4 deletions

View File

@ -3,7 +3,7 @@ members = [
"eth2/attester", "eth2/attester",
"eth2/block_producer", "eth2/block_producer",
"eth2/genesis", "eth2/genesis",
"eth2/naive_fork_choice", "eth2/fork_choice",
"eth2/types", "eth2/types",
"eth2/utils/bls", "eth2/utils/bls",
"eth2/utils/boolean-bitfield", "eth2/utils/boolean-bitfield",

View File

@ -1,10 +1,11 @@
[package] [package]
name = "naive_fork_choice" name = "fork_choice"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Age Manning <Age@AgeManning.com>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
db = { path = "../../beacon_node/db" } db = { path = "../../beacon_node/db" }
ssz = { path = "../utils/ssz" } ssz = { path = "../utils/ssz" }
types = { path = "../types" } types = { path = "../types" }

View File

View File

@ -0,0 +1,24 @@
//! This crate stores the various implementations of fork-choice rules that can be used for the
//! beacon blockchain.
//!
//! There are four implementations. One is the naive longest chain rule (primarily for testing
//! purposes). The other three are proposed implementations of the LMD-GHOST fork-choice rule with various forms of optimisation.
//!
//! The current implementations are:
//! - [`longest-chain`]: Simplistic longest-chain fork choice - primarily for testing, **not for
//! production**.
//! - [`basic_lmd_ghost`]: This is a simple and very inefficient implementation given in the ethereum 2.0
//! specifications (https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#get_block_root).
//! - [`optimised_lmd_ghost`]: This is an optimised version of the naive implementation as proposed
//! by Vitalik. The reference implementation can be found at: https://github.com/ethereum/research/blob/master/ghost/ghost.py
//! - [`protolambda_lmd_ghost`]: Another optimised version of LMD-GHOST designed by @protolambda.
//! The go implementation can be found here: https://github.com/protolambda/lmd-ghost.
//!
//! [`basic_lmd_ghost`]: struct.BasicLmdGhost.html
//! [`optimised_lmd_ghost`]: struct.OptimisedLmdGhost.html
//! [`protolambda_lmd_ghost`]: struct.ProtolambdaLmdGhost.html
pub mod basic_lmd_ghost;
pub mod longest_chain;
pub mod optimised_lmd_ghost;
pub mod protolambda_lmd_ghost;

View File

@ -14,7 +14,7 @@ pub enum ForkChoiceError {
DBError(String), DBError(String),
} }
pub fn naive_fork_choice<T>( pub fn longest_chain<T>(
head_block_hashes: &[Hash256], head_block_hashes: &[Hash256],
block_store: &Arc<BeaconBlockStore<T>>, block_store: &Arc<BeaconBlockStore<T>>,
) -> Result<Option<usize>, ForkChoiceError> ) -> Result<Option<usize>, ForkChoiceError>