Skip to content

Commit

Permalink
Shivani/detect faulty vals (#163)
Browse files Browse the repository at this point in the history
* detects faulty validator

* fixed error kind and added test

* fixing messes

* Delete .gitignore

* global gitignore failed here

* removed reason string and added commit link to generator
  • Loading branch information
Shivani912 authored Mar 6, 2020
1 parent 6df2a92 commit efadd8b
Show file tree
Hide file tree
Showing 4 changed files with 13,738 additions and 13,699 deletions.
4 changes: 4 additions & 0 deletions tendermint/src/lite/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ pub enum Kind {
/// the implementation, if any.
#[error("Implementation specific error")]
ImplementationSpecific,

/// This is returned when a faulty i.e misbehaving full node is found
#[error("Found faulty full node")]
FaultyFullNode,
}

impl Kind {
Expand Down
20 changes: 14 additions & 6 deletions tendermint/src/lite_impl/signed_header.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! [`lite::SignedHeader`] implementation for [`block::signed_header::SignedHeader`].

use crate::lite::error::{Error, Kind};
use crate::lite::ValidatorSet;
use crate::validator::Set;
use crate::{block, hash, lite, vote};
use anomaly::fail;
Expand Down Expand Up @@ -53,36 +54,43 @@ impl lite::Commit for block::signed_header::SignedHeader {
fn validate(&self, vals: &Self::ValidatorSet) -> Result<(), Error> {
if self.commit.precommits.len() != vals.validators().len() {
fail!(
lite::error::Kind::ImplementationSpecific,
Kind::ImplementationSpecific,
"pre-commit length: {} doesn't match validator length: {}",
self.commit.precommits.len(),
vals.validators().len()
);
}

// make sure each vote is for the correct header
for precommit_opt in self.commit.precommits.iter() {
match precommit_opt {
Some(precommit) => {
// make sure each vote is for the correct header
if let Some(header_hash) = precommit.header_hash() {
if header_hash != self.header_hash() {
fail!(
lite::error::Kind::ImplementationSpecific,
Kind::ImplementationSpecific,
"validator({}) voted for header {}, but current header is {}",
precommit.validator_address,
header_hash,
self.header_hash()
);
}
}

// returns FaultyFullNode error if it detects a signer isn't present in the validator set
if vals.validator(precommit.validator_address) == None {
let reason = format!(
"Found a faulty signer ({}) not present in the validator set ({})",
precommit.validator_address,
vals.hash()
);
fail!(Kind::FaultyFullNode, reason);
}
}
None => (),
}
}

// TODO: check here if all the votes are from correct validators
// TODO: return error kind "InvalidValidator" if we find a vote from a validator not in the val set

Ok(())
}
}
Expand Down
2 changes: 2 additions & 0 deletions tendermint/tests/lite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ impl MockRequester {
}
}

// Link to the commit that generated below JSON test files:
// https://github.com/Shivani912/tendermint/commit/f7d16ab59b55a4f1a5cdbfa6b0c24467aa88fdb2
const TEST_FILES_PATH: &str = "./tests/support/lite/";
fn read_json_fixture(name: &str) -> String {
fs::read_to_string(PathBuf::from(TEST_FILES_PATH).join(name.to_owned() + ".json")).unwrap()
Expand Down
Loading

0 comments on commit efadd8b

Please sign in to comment.