Skip to content

Commit

Permalink
Merge pull request #1 from paritytech/rh-vote-graph
Browse files Browse the repository at this point in the history
Vote Graph and GHOST-hunting
  • Loading branch information
rphmeier authored Aug 14, 2018
2 parents 3186e05 + e8454bb commit 39a73f4
Show file tree
Hide file tree
Showing 5 changed files with 612 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true
[*]
indent_style=tab
indent_size=tab
tab_width=4
end_of_line=lf
charset=utf-8
trim_trailing_whitespace=true
max_line_length=120
insert_final_newline=true

[*.yml]
indent_style=space
indent_size=2
tab_width=8
end_of_line=lf
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "finality-afg"
version = "0.1.0"
description = "PBFT-based finality gadget for blockchains"
authors = ["Parity Technologies <[email protected]>"]

[dependencies]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# finality-afg
finality gadget for blockchains, based on PBFT

Implementation in Rust.
67 changes: 67 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2018 Parity Technologies (UK) Ltd.
// This file is part of finality-afg.

// finality-afg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// finality-afg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with finality-afg. If not, see <http://www.gnu.org/licenses/>.

//! Finality gadget for blockchains.
//!
//! https://hackmd.io/svMTltnGQsSR1GCjRKOPbw
mod vote_graph;

use std::fmt;

/// A prevote for a block and its ancestors.
pub struct Prevote<H> {
round: u64,
target: H,
weight: usize,
}

/// A precommit for a block and its ancestors.
pub struct Precommit<H> {
round: u64,
target: H,
weight: usize,
}

#[derive(Clone, PartialEq, Debug)]
pub enum Error {
BlockNotInSubtree,
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::BlockNotInSubtree => write!(f, "Block not in subtree of base"),
}
}
}

impl ::std::error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::BlockNotInSubtree => "Block not in subtree of base",
}
}
}

/// Chain context necessary for implementation of the finality gadget.
pub trait Chain<H> {
/// Get the ancestry of a block up to but not including the base hash.
/// Should be in reverse order from `block`'s parent.
///
/// If the block is not a descendent of `base`, returns an error.
fn ancestry(&self, base: H, block: H) -> Result<Vec<H>, Error>;
}
Loading

0 comments on commit 39a73f4

Please sign in to comment.