Skip to content

Commit

Permalink
Cleanup errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hu55a1n1 committed Nov 4, 2022
1 parent cd75fb1 commit b90d5e2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
23 changes: 15 additions & 8 deletions crates/ibc/src/clients/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@ impl ClientState {
let trusted_val_hash = header.trusted_validator_set.hash();

if consensus_state.next_validators_hash != trusted_val_hash {
return Err(Ics02Error::client_specific(format!("trusted validators {:?}, does not hash to latest trusted validators. Expected: {:?}, got: {:?}", header.trusted_validator_set, consensus_state.next_validators_hash, trusted_val_hash)));
return Err(Error::misbehaviour_trusted_validator_hash_mismatch(
header.trusted_validator_set.clone(),
consensus_state.next_validators_hash,
trusted_val_hash,
)
.into());
}

Ok(())
Expand All @@ -285,7 +290,13 @@ impl ClientState {
})?;

if duration_since_consensus_state >= self.trusting_period {
return Err(Ics02Error::client_specific(format!("current timestamp minus the latest consensus state timestamp is greater than or equal to the trusting period ({:?} >= {:?})", duration_since_consensus_state, self.trusting_period)));
return Err(
Error::misbehaviour_consensus_state_timestamp_gte_trusting_period(
duration_since_consensus_state,
self.trusting_period,
)
.into(),
);
}

let _chain_id = self
Expand Down Expand Up @@ -542,16 +553,12 @@ impl Ics2ClientState for ClientState {
if header_1.signed_header.commit.block_id.hash
== header_2.signed_header.commit.block_id.hash
{
return Err(Ics02Error::client_specific(
"headers block hashes are equal".to_string(),
));
return Err(Error::misbehaviour_headers_block_hashes_equal().into());
}
} else {
// BFT time violation
if header_1.signed_header.header.time > header_2.signed_header.header.time {
return Err(Ics02Error::client_specific(
"headers are not at same height and are monotonically increasing".to_string(),
));
return Err(Error::misbehaviour_headers_not_at_same_height().into());
}
}

Expand Down
33 changes: 30 additions & 3 deletions crates/ibc/src/clients/ics07_tendermint/error.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use crate::prelude::*;

use flex_error::{define_error, TraceError};

use crate::core::ics02_client::error::Error as Ics02Error;
use crate::core::ics24_host::error::ValidationError;
use crate::core::ics24_host::identifier::ClientId;
use crate::timestamp::{Timestamp, TimestampOverflowError};

use crate::Height;

use core::time::Duration;

use flex_error::{define_error, TraceError};
use tendermint::account::Id;
use tendermint::hash::Hash;
use tendermint::Error as TendermintError;
use tendermint_light_client_verifier::errors::VerificationErrorDetail as LightClientErrorDetail;
use tendermint_light_client_verifier::types::ValidatorSet;

define_error! {
#[derive(Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -290,6 +292,31 @@ define_error! {
| e | {
format_args!("the client is frozen: frozen_height={0} target_height={1}", e.frozen_height, e.target_height)
},

MisbehaviourHeadersBlockHashesEqual
|_| { "headers block hashes are equal" },

MisbehaviourHeadersNotAtSameHeight
|_| { "headers are not at same height and are monotonically increasing" },

MisbehaviourTrustedValidatorHashMismatch
{
trusted_validator_set: ValidatorSet,
next_validators_hash: Hash,
trusted_val_hash: Hash,
}
| e | {
format_args!("trusted validators {:?}, does not hash to latest trusted validators. Expected: {:?}, got: {:?}", e.trusted_validator_set, e.next_validators_hash, e.trusted_val_hash)
},

MisbehaviourConsensusStateTimestampGteTrustingPeriod
{
duration_since_consensus_state: Duration,
trusting_period: Duration,
}
| e | {
format_args!("current timestamp minus the latest consensus state timestamp is greater than or equal to the trusting period ({:?} >= {:?})", e.duration_since_consensus_state, e.trusting_period)
},
}
}

Expand Down

0 comments on commit b90d5e2

Please sign in to comment.