Skip to content

Commit e1b4db2

Browse files
Clean up ibc-core and ibc-clients error types (#1317)
* Clean up pass of ClientError type * Clean up pass of ics24 errors * Clean up pass of ics23 errors * Clean up pass of ics07 errors * Clean up ChannelError type * Clean up PacketError type * Better organize error variants * cargo nightly fmt * Update error variant in integration tests * Fix ics23 tests * Fix typo in doc comment * Update cw-check Cargo.lock * Clean up ics08 error * Cargo nightly fmt * Change single-field error variants to tuple structs * Propogate error variant changes * Propogate error variant changes * Clean up PacketError type * Clean up IdentifierError type * Clean up ics26 RouterError * Clean up ics03 ConnectionError * Fix error variant naming * Fix error variant naming * Remove redundant Other error variant * Clarify tendermint client error naming * Rename tendermint client Error to TendermintClientError * Rename wasm light client Error to WasmClientError * Rename ics25-handler Error to HandlerError * Remove unused HandlerError * Remove TendermintClientError::InvalidHeader error for more specific variant * Rename LightClientVerifierError variant to FailedToVerifyHeader * Rename ConsensusStateTimestampGteTrustingPeriod to InsufficientTrustingPeriod * Remove redundant ChannelError::FailedToParseSequence variant * Rename ChannelError::FailedChannelVerification to FailedProofVerification * Replace incorrect usages of FailedPacketVerification * Define From<CommitmentError> for ClientError impl * Add IdentifierError::FailedToParse variant * Replace InvalidPrefix error usage * Fix doc comment typo * Improve ChannelError variant names * Add PacketError::InvalidPathPrefix variant * Remove unnecessary PacketError variant * Add error variants used by basecoin * nit: remove unnecessary map_err in verify_(non_)membership * imp: define EmptyCommitmentRoot * nit: remove MissingHostHeight * fix: remove unnecessary map_err(PacketError::Channel) * Remove a TODO --------- Co-authored-by: Farhad Shabani <[email protected]>
1 parent 0d98ebf commit e1b4db2

File tree

85 files changed

+886
-1174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+886
-1174
lines changed

ci/cw-check/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ibc-clients/ics07-tendermint/src/client_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! Rust). As such, this module also includes some trait implementations that
99
//! serve to pass through traits implemented on the wrapped `ClientState` type.
1010
11-
use ibc_client_tendermint_types::error::Error;
11+
use ibc_client_tendermint_types::error::TendermintClientError;
1212
use ibc_client_tendermint_types::proto::v1::ClientState as RawTmClientState;
1313
use ibc_client_tendermint_types::ClientState as ClientStateType;
1414
use ibc_core_client::types::error::ClientError;
@@ -44,7 +44,7 @@ impl ClientState {
4444
impl Protobuf<RawTmClientState> for ClientState {}
4545

4646
impl TryFrom<RawTmClientState> for ClientState {
47-
type Error = Error;
47+
type Error = TendermintClientError;
4848

4949
fn try_from(raw: RawTmClientState) -> Result<Self, Self::Error> {
5050
Ok(Self(ClientStateType::try_from(raw)?))

ibc-clients/ics07-tendermint/src/client_state/common.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl ClientStateCommon for ClientState {
6767
let (upgrade_path_prefix, upgrade_path) = match upgrade_path.len() {
6868
0 => {
6969
return Err(UpgradeClientError::InvalidUpgradePath {
70-
reason: "no upgrade path has been set".to_string(),
70+
description: "no upgrade path has been set".to_string(),
7171
}
7272
.into());
7373
}
@@ -78,7 +78,7 @@ impl ClientStateCommon for ClientState {
7878
),
7979
_ => {
8080
return Err(UpgradeClientError::InvalidUpgradePath {
81-
reason: "upgrade path is too long".to_string(),
81+
description: "upgrade path is too long".to_string(),
8282
}
8383
.into());
8484
}
@@ -162,15 +162,11 @@ pub fn verify_consensus_state(
162162
let tm_consensus_state = TmConsensusState::try_from(consensus_state)?;
163163

164164
if tm_consensus_state.root().is_empty() {
165-
return Err(ClientError::Other {
166-
description: "empty commitment root".into(),
167-
});
165+
Err(CommitmentError::EmptyCommitmentRoot)?;
168166
};
169167

170168
if consensus_state_status(&tm_consensus_state, host_timestamp, trusting_period)?.is_expired() {
171-
return Err(ClientError::ClientNotActive {
172-
status: Status::Expired,
173-
});
169+
return Err(ClientError::InvalidStatus(Status::Expired));
174170
}
175171

176172
Ok(())
@@ -214,8 +210,8 @@ pub fn validate_proof_height(
214210

215211
if latest_height < proof_height {
216212
return Err(ClientError::InvalidProofHeight {
217-
latest_height,
218-
proof_height,
213+
actual: latest_height,
214+
expected: proof_height,
219215
});
220216
}
221217

@@ -258,7 +254,7 @@ pub fn verify_upgrade_client<H: HostFunctionsProvider>(
258254
// the upgrade height This condition checks both the revision number and
259255
// the height
260256
if latest_height >= upgraded_tm_client_state_height {
261-
Err(UpgradeClientError::LowUpgradeHeight {
257+
Err(UpgradeClientError::InsufficientUpgradeHeight {
262258
upgraded_height: upgraded_tm_client_state_height,
263259
client_height: latest_height,
264260
})?
@@ -301,17 +297,16 @@ pub fn verify_membership<H: HostFunctionsProvider>(
301297
value: Vec<u8>,
302298
) -> Result<(), ClientError> {
303299
if prefix.is_empty() {
304-
return Err(ClientError::Ics23Verification(
305-
CommitmentError::EmptyCommitmentPrefix,
306-
));
300+
Err(CommitmentError::EmptyCommitmentPrefix)?;
307301
}
308302

309303
let merkle_path = MerklePath::new(vec![prefix.as_bytes().to_vec().into(), path]);
310-
let merkle_proof = MerkleProof::try_from(proof).map_err(ClientError::InvalidCommitmentProof)?;
311304

312-
merkle_proof
313-
.verify_membership::<H>(proof_specs, root.clone().into(), merkle_path, value, 0)
314-
.map_err(ClientError::Ics23Verification)
305+
let merkle_proof = MerkleProof::try_from(proof)?;
306+
307+
merkle_proof.verify_membership::<H>(proof_specs, root.clone().into(), merkle_path, value, 0)?;
308+
309+
Ok(())
315310
}
316311

317312
/// Verify that the given value does not belong in the client's merkle proof.
@@ -327,9 +322,10 @@ pub fn verify_non_membership<H: HostFunctionsProvider>(
327322
path: PathBytes,
328323
) -> Result<(), ClientError> {
329324
let merkle_path = MerklePath::new(vec![prefix.as_bytes().to_vec().into(), path]);
330-
let merkle_proof = MerkleProof::try_from(proof).map_err(ClientError::InvalidCommitmentProof)?;
331325

332-
merkle_proof
333-
.verify_non_membership::<H>(proof_specs, root.clone().into(), merkle_path)
334-
.map_err(ClientError::Ics23Verification)
326+
let merkle_proof = MerkleProof::try_from(proof)?;
327+
328+
merkle_proof.verify_non_membership::<H>(proof_specs, root.clone().into(), merkle_path)?;
329+
330+
Ok(())
335331
}

ibc-clients/ics07-tendermint/src/client_state/misbehaviour.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ibc_client_tendermint_types::error::{Error, IntoResult};
1+
use ibc_client_tendermint_types::error::{IntoResult, TendermintClientError};
22
use ibc_client_tendermint_types::{
33
ConsensusState as ConsensusStateType, Header as TmHeader, Misbehaviour as TmMisbehaviour,
44
};
@@ -101,14 +101,11 @@ where
101101

102102
let duration_since_consensus_state =
103103
current_timestamp.duration_since(&trusted_timestamp).ok_or(
104-
ClientError::InvalidConsensusStateTimestamp {
105-
time1: trusted_timestamp,
106-
time2: current_timestamp,
107-
},
104+
ClientError::InvalidConsensusStateTimestamp(trusted_timestamp),
108105
)?;
109106

110107
if duration_since_consensus_state >= options.trusting_period {
111-
return Err(Error::ConsensusStateTimestampGteTrustingPeriod {
108+
return Err(TendermintClientError::InsufficientTrustingPeriod {
112109
duration_since_consensus_state,
113110
trusting_period: options.trusting_period,
114111
}

ibc-clients/ics07-tendermint/src/client_state/update_client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ibc_client_tendermint_types::error::{Error, IntoResult};
1+
use ibc_client_tendermint_types::error::{IntoResult, TendermintClientError};
22
use ibc_client_tendermint_types::{ConsensusState as ConsensusStateType, Header as TmHeader};
33
use ibc_core_client::context::{Convertible, ExtClientValidationContext};
44
use ibc_core_client::types::error::ClientError;
@@ -63,10 +63,10 @@ where
6363
.trusted_height
6464
.revision_height()
6565
.try_into()
66-
.map_err(|_| ClientError::ClientSpecific {
67-
description: Error::InvalidHeaderHeight {
68-
height: header.trusted_height.revision_height(),
69-
}
66+
.map_err(|_| ClientError::FailedHeaderVerification {
67+
description: TendermintClientError::InvalidHeaderHeight(
68+
header.trusted_height.revision_height(),
69+
)
7070
.to_string(),
7171
})?,
7272
next_validators: &header.trusted_next_validator_set,

ibc-clients/ics07-tendermint/src/client_state/validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,5 +278,5 @@ where
278278
&& subject_proof_specs == &substitute_proof_specs
279279
&& subject_upgrade_path == &substitute_upgrade_path)
280280
.then_some(())
281-
.ok_or(ClientError::ClientRecoveryStateMismatch)
281+
.ok_or(ClientError::MismatchedClientRecoveryStates)
282282
}

ibc-clients/ics07-tendermint/src/consensus_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! implementations that serve to pass through traits implemented on the wrapped
77
//! `ConsensusState` type.
88
9-
use ibc_client_tendermint_types::error::Error;
9+
use ibc_client_tendermint_types::error::TendermintClientError;
1010
use ibc_client_tendermint_types::proto::v1::ConsensusState as RawTmConsensusState;
1111
use ibc_client_tendermint_types::ConsensusState as ConsensusStateType;
1212
use ibc_core_client::context::consensus_state::ConsensusState as ConsensusStateTrait;
@@ -52,7 +52,7 @@ impl From<ConsensusState> for ConsensusStateType {
5252
impl Protobuf<RawTmConsensusState> for ConsensusState {}
5353

5454
impl TryFrom<RawTmConsensusState> for ConsensusState {
55-
type Error = Error;
55+
type Error = TendermintClientError;
5656

5757
fn try_from(raw: RawTmConsensusState) -> Result<Self, Self::Error> {
5858
Ok(Self(ConsensusStateType::try_from(raw)?))

0 commit comments

Comments
 (0)