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

Restructure codebase #26

Merged
merged 29 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9dcec21
Add block validation code
paulhauner Sep 26, 2018
84bb408
Split block validation tests into functions
paulhauner Sep 26, 2018
a8b08fb
Add first block validation benches
paulhauner Sep 26, 2018
debc642
Move attestation validation into iter.for_each
paulhauner Sep 26, 2018
05fe231
Fix bug with bitfield validation
paulhauner Sep 28, 2018
b92d88d
Add (untested) parallelization for att validation
paulhauner Sep 28, 2018
19ddbde
Refact block val. tests to be more modular
paulhauner Sep 28, 2018
8020b89
Refactor block val. benches to use test funtions
paulhauner Sep 28, 2018
13467ab
Tidy benches file
paulhauner Sep 28, 2018
7c88f94
Tidy comments in block validation
paulhauner Sep 29, 2018
e0e8aa9
Introduce "benches" feature
paulhauner Sep 29, 2018
bc27be1
Further development on block validation
paulhauner Sep 29, 2018
0b99951
Refactor block val. into "BlockValidationContext"
paulhauner Sep 29, 2018
385564d
Rename block_store functions
paulhauner Sep 30, 2018
5dd2361
Progress further with block validation
paulhauner Sep 30, 2018
9642c4b
Simplify block validation tests
paulhauner Sep 30, 2018
a87fe88
Fix bug in boolean bitfield
paulhauner Sep 30, 2018
496adc0
Fix bug in attestation val. bitfield checking
paulhauner Sep 30, 2018
77b48b9
Implement more tests for block validation
paulhauner Sep 30, 2018
29ed29c
Update benchmarks as per recent code changes
paulhauner Sep 30, 2018
b426c9e
Remove "benches" feature
paulhauner Sep 30, 2018
c3ec8a3
Introduce AttestationValidationContext
paulhauner Sep 30, 2018
4d1f730
Restructure block validation directory
paulhauner Sep 30, 2018
8f52858
Refactor validation tests into integration tests
paulhauner Oct 1, 2018
8e094b3
Implement framework for testing attestation val.
paulhauner Oct 1, 2018
6b7677a
Update block and attestation validation code
paulhauner Oct 1, 2018
cd3b2f5
Add test for attestation msg generation
paulhauner Oct 1, 2018
07bfd7e
Add tests for attestation_validation
paulhauner Oct 1, 2018
0fbe417
Heavily restructure repo
paulhauner Oct 2, 2018
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
18 changes: 12 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,20 @@ version = "0.0.1"
authors = ["Paul Hauner <paul@paulhauner.com>"]

[dependencies]
# TODO: remove "blake2" in favor of "blake2-rfc"
blake2 = "^0.7.1"
blake2-rfc = "0.2.18"
bls-aggregates = { git = "https://github.com/sigp/signature-schemes" }
boolean-bitfield = { path = "boolean-bitfield" }
bytes = ""
crypto-mac = "^0.6.2"
clap = "2.32.0"
db = { path = "lighthouse/db" }
dirs = "1.0.3"
ethereum-types = "0.4.0"
futures = "0.1.23"
network-libp2p = { path = "network-libp2p" }
rand = "0.3"
rocksdb = "0.10.1"
rlp = { git = "https://github.com/paritytech/parity-common" }
slog = "^2.2.3"
slog-term = "^2.4.0"
slog-async = "^2.3.0"
ssz = { path = "ssz" }
tokio = "0.1"

[dependencies.pairing]
Expand All @@ -35,3 +30,14 @@ ring = { git = "https://github.com/paritytech/ring" }
[[bin]]
path = "lighthouse/main.rs"
name = "lighthouse"

[workspace]
members = [
"beacon_chain/types",
"beacon_chain/utils/bls",
"beacon_chain/utils/boolean-bitfield",
"beacon_chain/utils/hashing",
"beacon_chain/utils/ssz",
"beacon_chain/utils/ssz_helpers",
"lighthouse/db",
]
11 changes: 11 additions & 0 deletions beacon_chain/types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "types"
version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"]

[dependencies]
bls = { path = "../utils/bls" }
boolean-bitfield = { path = "../utils/boolean-bitfield" }
ethereum-types = "0.4.0"
rand = "0.3"
ssz = { path = "../utils/ssz" }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::utils::types::Hash256;
use super::Hash256;
use super::attestation_record::AttestationRecord;

pub struct ActiveState {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::utils::types::{ Hash256, Bitfield };
use super::{ Hash256, Bitfield };
use super::bls::{
AggregateSignature,
BLS_AGG_SIG_BYTE_SIZE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::utils::types::Hash256;
use super::Hash256;
use super::attestation_record::AttestationRecord;
use super::ssz::{ Encodable, SszStream };

Expand All @@ -13,6 +13,7 @@ pub const MIN_SSZ_BLOCK_LENGTH: usize = {
};
pub const MAX_SSZ_BLOCK_LENGTH: usize = MIN_SSZ_BLOCK_LENGTH + (1 << 24);

#[derive(Debug, PartialEq, Clone)]
pub struct Block {
pub parent_hash: Hash256,
pub slot_number: u64,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::utils::types::Hash256;
use super::Hash256;

#[derive(Clone)]
pub struct CrosslinkRecord {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::validator_record::ValidatorRecord;
use super::crosslink_record::CrosslinkRecord;
use super::shard_and_committee::ShardAndCommittee;
use super::ethereum_types::U256;
use super::utils::types::{ Hash256 };
use super::Hash256;


pub struct CrystallizedState {
Expand Down
49 changes: 49 additions & 0 deletions beacon_chain/types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
extern crate ethereum_types;
extern crate bls;
extern crate boolean_bitfield;
extern crate ssz;

pub mod active_state;
pub mod attestation_record;
pub mod crystallized_state;
pub mod chain_config;
pub mod block;
pub mod crosslink_record;
pub mod shard_and_committee;
pub mod validator_record;

use self::ethereum_types::{
H256,
H160,
U256
};
use self::boolean_bitfield::BooleanBitfield;
use std::collections::HashMap;

pub use active_state::ActiveState;
pub use attestation_record::AttestationRecord;
pub use crystallized_state::CrystallizedState;
pub use chain_config::ChainConfig;
pub use block::Block;
pub use crosslink_record::CrosslinkRecord;
pub use shard_and_committee::ShardAndCommittee;
pub use validator_record::ValidatorRecord;

pub type Hash256 = H256;
pub type Address = H160;
pub type EthBalance = U256;
pub type Bitfield = BooleanBitfield;

/// Maps a (slot, shard_id) to attestation_indices.
pub type AttesterMap = HashMap<(u64, u16), Vec<usize>>;

/// Maps a slot to a block proposer.
pub type ProposerMap = HashMap<u64, usize>;

#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
1 change: 1 addition & 0 deletions lighthouse/state/mod.rs → beacon_chain/types/src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ pub mod shard_and_committee;
pub mod validator_record;

use super::bls;
use super::db;
use super::utils;
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#[derive(Clone,Debug)]
pub struct ShardAndCommittee {
pub shard_id: u16,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
extern crate rand;

use super::utils::types::{ Hash256, Address, U256 };
use super::bls::{ PublicKey, Keypair };
use super::{
Hash256,
Address,
EthBalance,
};
use super::bls::{
PublicKey,
Keypair
};

pub struct ValidatorRecord {
pub pubkey: PublicKey,
pub withdrawal_shard: u16,
pub withdrawal_address: Address,
pub randao_commitment: Hash256,
pub balance: U256,
pub balance: EthBalance,
pub start_dynasty: u64,
pub end_dynasty: u64,
}
Expand All @@ -25,7 +30,7 @@ impl ValidatorRecord {
withdrawal_shard: 0,
withdrawal_address: Address::zero(),
randao_commitment: Hash256::zero(),
balance: U256::zero(),
balance: EthBalance::zero(),
start_dynasty: 0,
end_dynasty: 0,
};
Expand Down
7 changes: 7 additions & 0 deletions beacon_chain/utils/bls/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bls"
version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"]

[dependencies]
bls-aggregates = { git = "https://github.com/sigp/signature-schemes" }
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ pub use self::bls_aggregates::AggregatePublicKey;
pub use self::bls_aggregates::Signature;
pub use self::bls_aggregates::Keypair;
pub use self::bls_aggregates::PublicKey;
pub use self::bls_aggregates::SecretKey;

pub const BLS_AGG_SIG_BYTE_SIZE: usize = 97;
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ impl BooleanBitfield {
pub fn compute_length(bytes: &[u8]) -> usize {
for byte in (0..bytes.len()).rev() {
for bit in (0..8).rev() {
if byte & (1 << (bit as u8)) != 0 {
return (byte * 8) + bit
if bytes[byte] & (1 << (bit as u8)) != 0 {
return (byte * 8) + bit + 1
}
}
}
Expand Down Expand Up @@ -188,6 +188,25 @@ mod tests {
use super::*;
use ssz::Decodable;

#[test]
fn test_new_from_slice() {
let s = [0];
let b = BooleanBitfield::from(&s[..]);
assert_eq!(b.len, 0);

let s = [255];
let b = BooleanBitfield::from(&s[..]);
assert_eq!(b.len, 8);

let s = [0, 1];
let b = BooleanBitfield::from(&s[..]);
assert_eq!(b.len, 9);

let s = [31];
let b = BooleanBitfield::from(&s[..]);
assert_eq!(b.len, 5);
}

#[test]
fn test_ssz_encoding() {
let mut b = BooleanBitfield::new();
Expand All @@ -199,6 +218,7 @@ mod tests {
assert_eq!(stream.drain(), vec![0, 0, 0, 2, 0, 1]);
}

/*
#[test]
fn test_ssz_decoding() {
/*
Expand Down Expand Up @@ -227,6 +247,7 @@ mod tests {
let res = BooleanBitfield::ssz_decode(&input, 0);
assert_eq!(res, Err(ssz::DecodeError::TooShort));
}
*/

#[test]
fn test_new_bitfield_len() {
Expand Down
7 changes: 7 additions & 0 deletions beacon_chain/utils/hashing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "hashing"
version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"]

[dependencies]
blake2-rfc = "0.2.18"
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::blake2::blake2b::blake2b;
extern crate blake2_rfc;

use self::blake2_rfc::blake2b::blake2b;

pub fn canonical_hash(input: &[u8]) -> Vec<u8> {
let result = blake2b(64, &[], input);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ mod tests {
&vec![1],
2
);
assert_eq!(err, Err(DecodeError::OutOfBounds));
assert_eq!(err, Err(DecodeError::TooShort));

let err: Result<(u16,usize), DecodeError> = decode_ssz(
&vec![0, 0, 0, 0],
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions beacon_chain/utils/ssz_helpers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "ssz_helpers"
version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"]

[dependencies]
bls = { path = "../bls" }
hashing = { path = "../hashing" }
types = { path = "../../types" }
ssz = { path = "../ssz" }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::MIN_SSZ_ATTESTION_RECORD_LENGTH as MIN_LENGTH;
use super::types::attestation_record::MIN_SSZ_ATTESTION_RECORD_LENGTH as MIN_LENGTH;
use super::ssz::LENGTH_BYTES;
use super::ssz::decode::decode_length;

Expand Down Expand Up @@ -54,8 +54,8 @@ pub fn split_one_attestation(full_ssz: &[u8], index: usize)
#[cfg(test)]
mod tests {
use super::*;
use super::super::AttestationRecord;
use super::super::utils::types::{
use super::super::types::{
AttestationRecord,
Hash256,
Bitfield,
};
Expand Down
7 changes: 7 additions & 0 deletions beacon_chain/utils/ssz_helpers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extern crate bls;
extern crate hashing;
extern crate types;
extern crate ssz;

pub mod attestation_ssz_splitter;
pub mod ssz_block;
Loading