Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/master' into ismail/absc…
Browse files Browse the repository at this point in the history
…issify_lite_node

# Conflicts:
#	light-node/src/state.rs
#	light-node/src/threshold.rs
#	tendermint-lite/src/lib.rs
#	tendermint-lite/src/main.rs
  • Loading branch information
liamsi committed Feb 8, 2020
2 parents 1124e4d + 994b457 commit 5244176
Show file tree
Hide file tree
Showing 33 changed files with 20,611 additions and 18,762 deletions.
189 changes: 145 additions & 44 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,147 @@
version: 2
version: 2.1

jobs:
build:
executors:
cargo-executor:
docker:
- image: rust:1
resource_class: large
cargo-audit-executor:
docker:
- image: circleci/rust
steps:
- checkout
- run:
name: rustfmt
command: |
cargo fmt --version
cargo fmt -- --check
- run:
name: clippy
command: |
if rustup component add clippy; then
cargo clippy --version
cargo clippy --all --all-targets -- -Dwarnings -Drust-2018-idioms
else
echo Skipping clippy
fi
- run:
name: build
command: |
rustc --version
cargo --version
cargo build
- run:
name: build --benches
command: |
rustc --version
cargo --version
cargo build --benches
- run:
name: build --release
command: |
rustc --version
cargo --version
cargo build --release
- run:
name: test
command: |
rustc --version
cargo --version
cargo test
- image: rust:1
resource_class: small

commands:
install_coverage_dependencies:
steps:
- run:
name: Install grcov and zip
command: |
apt-get update
apt-get install -y zip
cargo install --force grcov
print_version_info:
steps:
- run:
name: Version information
command: |
rustup --version
rustc --version
cargo --version
update_stable_toolchain:
steps:
- run:
name: Update toolchain
command: |
test -z "stable" || echo "stable" >rust-toolchain
rustup show active-toolchain
update_nightly_toolchain:
steps:
- run:
name: Update nightly toolchain
command: |
test -z "nightly" || echo "nightly" >rust-toolchain
rustup show active-toolchain
calculate_cargo_dependencies:
steps:
- run:
name: Calculate dependencies
command: test -e Cargo.lock || cargo generate-lockfile

jobs:
format:
description: Check proper formatting
executor: cargo-executor
steps:
- checkout
- update_stable_toolchain
- print_version_info
- calculate_cargo_dependencies
- run:
name: Check formatting
command: |
if rustup component add rustfmt; then
cargo fmt --all -- --check
else
echo Skipping rustfmt
fi
clippy:
description: Lint using clippy
executor: cargo-executor
steps:
- checkout
- update_stable_toolchain
- print_version_info
- calculate_cargo_dependencies
- run:
name: Run clippy checks
command: |
if rustup component add clippy; then
cargo clippy --all --all-targets -- -Dwarnings -Drust-2018-idioms
else
echo Skipping clippy
fi
test-stable:
description: Run all tests using the stable toolchain
executor: cargo-executor
steps:
- checkout
- update_stable_toolchain
- print_version_info
- calculate_cargo_dependencies
- run:
name: Build all targets
command: cargo build --all --all-targets
- run:
name: Run all tests
command: cargo test --all
audit:
description: Audit for vulnerable dependencies
executor: cargo-audit-executor
steps:
- checkout
- update_stable_toolchain
- print_version_info
- run:
name: Install Cargo Audit
command: |
cargo install --force cargo-audit
- run:
name: Run Cargo Audit
command: |
cargo audit
test-nightly-coverage:
description: Collect and upload test coverage using the nighly toolchain
executor: cargo-executor
steps:
- checkout
- update_nightly_toolchain
- print_version_info
- install_coverage_dependencies
- calculate_cargo_dependencies
- run:
name: Run tests with coverage env
command: |
export CARGO_INCREMENTAL=0
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads"
cargo clean
cargo test --all --verbose
- run:
name: Collect and upload test coverage
command: |
# Note: this currently only matches gc files in crates named *tendermint*.
# This is something to keep in mind if we create crates that do not have tendermint in
# their name.
zip -0 ccov.zip `find . \( -name "*tendermint*.gc*" \) -print`
grcov ccov.zip -s . -t lcov --llvm --branch --ignore-not-existing --ignore "/*" -o lcov.info
bash <(curl -s https://codecov.io/bash) -f lcov.info
rm -f lcov.info
rm -f ccov.zip
workflows:
commit-workflow:
jobs:
- format
- clippy
- test-stable
- test-nightly-coverage
- audit
23 changes: 23 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
codecov:
require_ci_to_pass: yes

ignore:

coverage:
precision: 1
round: down
# we should increase this to 70% ?
range: "50...100"

status:
project: true
patch: true
changes: true

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: yes
macro: no
25 changes: 10 additions & 15 deletions light-node/src/requester.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use tendermint::block;
use tendermint::lite;
use tendermint::block::signed_header::SignedHeader as TMCommit;
use tendermint::block::Header as TMHeader;
use tendermint::rpc;
use tendermint::validator;
use tendermint::{block, lite};

use core::future::Future;
use tendermint::lite::{Height, SignedHeader};
use tendermint::validator::Set;
use tokio::runtime::Builder;

/// RPCRequester wraps the Tendermint rpc::Client.
Expand All @@ -17,33 +20,26 @@ impl RPCRequester {
}
}

impl lite::types::Requester for RPCRequester {
type SignedHeader = block::signed_header::SignedHeader;
type ValidatorSet = validator::Set;
type TMSignedHeader = SignedHeader<TMCommit, TMHeader>;

impl lite::types::Requester<TMCommit, TMHeader> for RPCRequester {
/// Request the signed header at height h.
/// If h==0, request the latest signed header.
/// TODO: use an enum instead of h==0.
fn signed_header<H>(&self, h: H) -> Result<Self::SignedHeader, lite::Error>
where
H: Into<block::Height>,
{
fn signed_header(&self, h: Height) -> Result<TMSignedHeader, lite::Error> {
let height: block::Height = h.into();
let r = match height.value() {
0 => block_on(self.client.latest_commit()),
_ => block_on(self.client.commit(height)),
};
match r {
Ok(response) => Ok(response.signed_header),
Ok(response) => Ok(response.signed_header.into()),
Err(_error) => Err(lite::Error::RequestFailed),
}
}

/// Request the validator set at height h.
fn validator_set<H>(&self, h: H) -> Result<Self::ValidatorSet, lite::Error>
where
H: Into<block::Height>,
{
fn validator_set(&self, h: Height) -> Result<Set, lite::Error> {
let r = block_on(self.client.validators(h));
match r {
Ok(response) => Ok(validator::Set::new(response.validators)),
Expand All @@ -66,7 +62,6 @@ mod tests {
use super::*;
use tendermint::lite::types::Header as LiteHeader;
use tendermint::lite::types::Requester as LiteRequester;
use tendermint::lite::types::SignedHeader as LiteSignedHeader;
use tendermint::lite::types::ValidatorSet as LiteValSet;
use tendermint::rpc;

Expand Down
30 changes: 0 additions & 30 deletions light-node/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,30 +0,0 @@
use tendermint::lite::TrustedState;
use tendermint::{block::signed_header::SignedHeader, validator::Set};

#[derive(Clone)]
pub struct State {
last_header: SignedHeader,
vals: Set,
}

impl TrustedState for State {
type LastHeader = SignedHeader;
type ValidatorSet = Set;

fn new(last_header: &Self::LastHeader, vals: &Self::ValidatorSet) -> Self {
State {
last_header: last_header.clone(),
vals: vals.clone(),
}
}

// height H-1
fn last_header(&self) -> &Self::LastHeader {
&self.last_header
}

// height H
fn validators(&self) -> &Self::ValidatorSet {
&self.vals
}
}
21 changes: 10 additions & 11 deletions light-node/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::state::State;
use tendermint::block::Height;
use tendermint::lite::{Error, Header, SignedHeader, Store, TrustedState};
use tendermint::lite::{Error, Header, Height, TrustedState};

use std::collections::HashMap;
use tendermint::block;

pub type State = TrustedState<block::signed_header::SignedHeader, block::header::Header>;

#[derive(Default)]
pub struct MemStore {
Expand All @@ -13,25 +14,23 @@ pub struct MemStore {
impl MemStore {
pub fn new() -> MemStore {
MemStore {
height: Height::from(0),
height: 0,
store: HashMap::new(),
}
}
}

impl Store for MemStore {
type TrustedState = State;

fn add(&mut self, trusted: &Self::TrustedState) -> Result<(), Error> {
impl MemStore {
pub fn add(&mut self, trusted: State) -> Result<(), Error> {
let height = trusted.last_header().header().height();
self.height = height;
self.store.insert(height, trusted.clone());
self.store.insert(height, trusted);
Ok(())
}

fn get(&self, h: Height) -> Result<&Self::TrustedState, Error> {
pub fn get(&self, h: Height) -> Result<&State, Error> {
let mut height = h;
if h.value() == 0 {
if h == 0 {
height = self.height
}
match self.store.get(&height) {
Expand Down
11 changes: 0 additions & 11 deletions light-node/src/threshold.rs
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
use tendermint::lite::TrustThreshold;

pub struct TrustThresholdOneThird {}
impl TrustThreshold for TrustThresholdOneThird {}

pub struct TrustThresholdTwoThirds {}
impl TrustThreshold for TrustThresholdTwoThirds {
fn is_enough_power(&self, signed_voting_power: u64, total_voting_power: u64) -> bool {
signed_voting_power * 3 > total_voting_power * 2
}
}
Empty file added tendermint-lite/src/lib.rs
Empty file.
Loading

0 comments on commit 5244176

Please sign in to comment.