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

Vote Graph and GHOST-hunting #1

Merged
merged 7 commits into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 <admin@parity.io>"]

[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