Skip to content

Commit

Permalink
Rename HostError InvalidData and MissingData variants
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchen1991 committed Sep 13, 2024
1 parent 35f7844 commit 126f874
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 34 deletions.
7 changes: 4 additions & 3 deletions ibc-core/ics02-client/src/handler/update_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ where

{
let event = {
let consensus_height = consensus_heights.first().ok_or(HostError::MissingData {
description: "missing updated height in client update state".to_string(),
})?;
let consensus_height =
consensus_heights.first().ok_or(HostError::MissingState {
description: "missing updated height in client update state".to_string(),
})?;

IbcEvent::UpdateClient(UpdateClient::new(
client_id,
Expand Down
4 changes: 2 additions & 2 deletions ibc-core/ics02-client/src/handler/upgrade_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ where
);
let old_consensus_state = client_val_ctx
.consensus_state(&old_client_cons_state_path)
.map_err(|_| HostError::MissingData {
.map_err(|_| HostError::MissingState {
description: format!(
"missing consensus state for client {0} at height {1}",
"missing consensus state for client {} at height {}",
client_id,
old_client_state.latest_height()
),

Check warning on line 46 in ibc-core/ics02-client/src/handler/upgrade_client.rs

View check run for this annotation

Codecov / codecov/patch

ibc-core/ics02-client/src/handler/upgrade_client.rs#L42-L46

Added lines #L42 - L46 were not covered by tests
Expand Down
16 changes: 8 additions & 8 deletions ibc-core/ics24-host/cosmos/src/validate_self_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub trait ValidateSelfClientContext {
let self_chain_id = self.chain_id();

Check warning on line 34 in ibc-core/ics24-host/cosmos/src/validate_self_client.rs

View check run for this annotation

Codecov / codecov/patch

ibc-core/ics24-host/cosmos/src/validate_self_client.rs#L34

Added line #L34 was not covered by tests
if self_chain_id != &client_state_of_host_on_counterparty.chain_id {
return Err(HostError::InvalidData {
return Err(HostError::InvalidState {
description: format!(
"invalid chain ID: expected {}, actual {}",
self_chain_id, client_state_of_host_on_counterparty.chain_id
Expand All @@ -45,7 +45,7 @@ pub trait ValidateSelfClientContext {
let self_revision_number = self_chain_id.revision_number();

Check warning on line 46 in ibc-core/ics24-host/cosmos/src/validate_self_client.rs

View check run for this annotation

Codecov / codecov/patch

ibc-core/ics24-host/cosmos/src/validate_self_client.rs#L46

Added line #L46 was not covered by tests
if self_revision_number != latest_height.revision_number() {
return Err(HostError::InvalidData {
return Err(HostError::InvalidState {
description: format!(
"mismatched client revision numbers; expected {}, actual {}",
self_revision_number,
Expand All @@ -55,7 +55,7 @@ pub trait ValidateSelfClientContext {
}

if latest_height >= self.host_current_height() {
return Err(HostError::InvalidData {
return Err(HostError::InvalidState {
description: format!(
"client latest height {} should be less than chain height {}",
latest_height,
Expand All @@ -65,7 +65,7 @@ pub trait ValidateSelfClientContext {
}

if self.proof_specs() != &client_state_of_host_on_counterparty.proof_specs {
return Err(HostError::InvalidData {
return Err(HostError::InvalidState {
description: format!(
"invalid client proof specs; expected {:?}, actual {:?}",
self.proof_specs(),
Expand All @@ -81,13 +81,13 @@ pub trait ValidateSelfClientContext {
trust_level.numerator(),
trust_level.denominator(),
)
.map_err(|e| HostError::InvalidData {
.map_err(|e| HostError::InvalidState {
description: e.to_string(),

Check warning on line 85 in ibc-core/ics24-host/cosmos/src/validate_self_client.rs

View check run for this annotation

Codecov / codecov/patch

ibc-core/ics24-host/cosmos/src/validate_self_client.rs#L84-L85

Added lines #L84 - L85 were not covered by tests
})?
};

if self.unbonding_period() != client_state_of_host_on_counterparty.unbonding_period {
return Err(HostError::InvalidData {
return Err(HostError::InvalidState {
description: format!(
"invalid unbonding period; expected {:?}, actual {:?}",
self.unbonding_period(),
Expand All @@ -99,7 +99,7 @@ pub trait ValidateSelfClientContext {
if client_state_of_host_on_counterparty.unbonding_period
< client_state_of_host_on_counterparty.trusting_period
{
return Err(HostError::InvalidData { description: format!(
return Err(HostError::InvalidState { description: format!(
"invalid counterparty client state: unbonding period must be greater than trusting period; unbonding period ({:?}) < trusting period ({:?})",

Check warning on line 103 in ibc-core/ics24-host/cosmos/src/validate_self_client.rs

View check run for this annotation

Codecov / codecov/patch

ibc-core/ics24-host/cosmos/src/validate_self_client.rs#L102-L103

Added lines #L102 - L103 were not covered by tests
client_state_of_host_on_counterparty.unbonding_period,
client_state_of_host_on_counterparty.trusting_period
Expand All @@ -109,7 +109,7 @@ pub trait ValidateSelfClientContext {
if !client_state_of_host_on_counterparty.upgrade_path.is_empty()
&& self.upgrade_path() != client_state_of_host_on_counterparty.upgrade_path
{
return Err(HostError::InvalidData {
return Err(HostError::InvalidState {
description: format!(
"invalid upgrade path; expected {:?}, actual {:?}",
self.upgrade_path(),
Expand Down
2 changes: 1 addition & 1 deletion ibc-core/ics24-host/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub trait ValidationContext {
&self.get_compatible_versions(),
counterparty_candidate_versions,
)
.map_err(|e| HostError::MissingData {
.map_err(|e| HostError::MissingState {
description: e.to_string(),

Check warning on line 90 in ibc-core/ics24-host/src/context.rs

View check run for this annotation

Codecov / codecov/patch

ibc-core/ics24-host/src/context.rs#L90

Added line #L90 was not covered by tests
})
}
Expand Down
8 changes: 4 additions & 4 deletions ibc-core/ics24-host/types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use prost::DecodeError as ProstError;
pub enum HostError {
/// application module error: `{description}`
AppModule { description: String },
/// invalid data: `{description}`
InvalidData { description: String },
/// missing data: `{description}`
MissingData { description: String },
/// invalid state: `{description}`
InvalidState { description: String },
/// missing state: `{description}`
MissingState { description: String },
/// failed to update store: `{description}`
FailedToUpdateStore { description: String },
/// failed to store data: `{description}`
Expand Down
8 changes: 4 additions & 4 deletions ibc-testkit/src/testapp/ibc/core/client_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where
consensus_path.revision_number,
consensus_path.revision_height,
)
.map_err(|e| HostError::InvalidData {
.map_err(|e| HostError::InvalidState {
description: e.to_string(),

Check warning on line 80 in ibc-testkit/src/testapp/ibc/core/client_ctx.rs

View check run for this annotation

Codecov / codecov/patch

ibc-testkit/src/testapp/ibc/core/client_ctx.rs#L80

Added line #L80 was not covered by tests
})
})
Expand Down Expand Up @@ -115,7 +115,7 @@ where
})
})
.transpose()
.map_err(|e| HostError::MissingData {
.map_err(|e| HostError::MissingState {
description: e.to_string(),

Check warning on line 119 in ibc-testkit/src/testapp/ibc/core/client_ctx.rs

View check run for this annotation

Codecov / codecov/patch

ibc-testkit/src/testapp/ibc/core/client_ctx.rs#L119

Added line #L119 was not covered by tests
})?;

Expand Down Expand Up @@ -154,7 +154,7 @@ where
})
})
.transpose()
.map_err(|e| HostError::MissingData {
.map_err(|e| HostError::MissingState {
description: e.to_string(),

Check warning on line 158 in ibc-testkit/src/testapp/ibc/core/client_ctx.rs

View check run for this annotation

Codecov / codecov/patch

ibc-testkit/src/testapp/ibc/core/client_ctx.rs#L158

Added line #L158 was not covered by tests
})?;

Expand Down Expand Up @@ -185,7 +185,7 @@ where
client_cons_state_path.revision_number,
client_cons_state_path.revision_height,
)
.map_err(|e| HostError::InvalidData {
.map_err(|e| HostError::InvalidState {
description: e.to_string(),

Check warning on line 189 in ibc-testkit/src/testapp/ibc/core/client_ctx.rs

View check run for this annotation

Codecov / codecov/patch

ibc-testkit/src/testapp/ibc/core/client_ctx.rs#L189

Added line #L189 was not covered by tests
})?;
let consensus_state = self
Expand Down
18 changes: 9 additions & 9 deletions ibc-testkit/src/testapp/ibc/core/core_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where

fn host_height(&self) -> Result<Height, HostError> {
Height::new(*self.revision_number.lock(), self.store.current_height()).map_err(|e| {
HostError::InvalidData {
HostError::InvalidState {
description: e.to_string(),
}

Check warning on line 47 in ibc-testkit/src/testapp/ibc/core/core_ctx.rs

View check run for this annotation

Codecov / codecov/patch

ibc-testkit/src/testapp/ibc/core/core_ctx.rs#L45-L47

Added lines #L45 - L47 were not covered by tests
})
Expand All @@ -57,7 +57,7 @@ where
fn client_counter(&self) -> Result<u64, HostError> {
self.client_counter
.get(StoreHeight::Pending, &NextClientSequencePath)
.ok_or(HostError::MissingData {
.ok_or(HostError::MissingState {
description: "missing client counter".to_string(),
})
}
Expand All @@ -68,7 +68,7 @@ where
consensus_states_binding
.get(&height.revision_height())
.cloned()
.ok_or(HostError::MissingData {
.ok_or(HostError::MissingState {
description: ClientError::MissingLocalConsensusState(*height).to_string(),
})
}
Expand All @@ -91,7 +91,7 @@ where
.latest_height()
.revision_number()
{
return Err(HostError::InvalidData {
return Err(HostError::InvalidState {
description: format!(
"client is not in the same revision as the chain. expected: {}, got: {}",
self_revision_number,
Expand All @@ -104,7 +104,7 @@ where

let host_current_height = latest_height.increment();
if client_state_of_host_on_counterparty.latest_height() >= host_current_height {
return Err(HostError::InvalidData {
return Err(HostError::InvalidState {
description: format!(
"invalid counterparty client state: client latest height {} should be less than chain height {}",
client_state_of_host_on_counterparty.latest_height(),
Expand All @@ -119,7 +119,7 @@ where
fn connection_end(&self, conn_id: &ConnectionId) -> Result<ConnectionEnd, HostError> {
self.connection_end_store
.get(StoreHeight::Pending, &ConnectionPath::new(conn_id))
.ok_or(HostError::MissingData {
.ok_or(HostError::MissingState {
description: format!("missing connection end for connection {}", conn_id.clone()),
})
}
Expand All @@ -133,7 +133,7 @@ where
fn connection_counter(&self) -> Result<u64, HostError> {
self.conn_counter
.get(StoreHeight::Pending, &NextConnectionSequencePath)
.ok_or(HostError::MissingData {
.ok_or(HostError::MissingState {
description: "missing connection counter".to_string(),
})
}
Expand Down Expand Up @@ -338,7 +338,7 @@ where
consensus_path.revision_number,
consensus_path.revision_height,
)
.map_err(|e| HostError::InvalidData {
.map_err(|e| HostError::InvalidState {
description: e.to_string(),
})?;

Check warning on line 343 in ibc-testkit/src/testapp/ibc/core/core_ctx.rs

View check run for this annotation

Codecov / codecov/patch

ibc-testkit/src/testapp/ibc/core/core_ctx.rs#L340-L343

Added lines #L340 - L343 were not covered by tests
let client_state = self
Expand Down Expand Up @@ -374,7 +374,7 @@ where
consensus_path.revision_number,
consensus_path.revision_height,
)
.map_err(|e| HostError::InvalidData {
.map_err(|e| HostError::InvalidState {
description: e.to_string(),
})

Check warning on line 379 in ibc-testkit/src/testapp/ibc/core/core_ctx.rs

View check run for this annotation

Codecov / codecov/patch

ibc-testkit/src/testapp/ibc/core/core_ctx.rs#L376-L379

Added lines #L376 - L379 were not covered by tests
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn msg_upgrade_client_healthy() {
#[test]
fn upgrade_client_fail_nonexisting_client() {
let fxt = msg_upgrade_client_fixture(Ctx::Default, Msg::Default);
let expected_err = HandlerError::Host(HostError::MissingData {
let expected_err = HandlerError::Host(HostError::MissingState {
description: format!(
"missing client state for client {0}",
fxt.msg.client_id.clone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn conn_open_ack_validate(fxt: &Fixture<MsgConnectionOpenAck>, expect: Expect) {
let cons_state_height = fxt.msg.consensus_height_of_a_on_b;

match res.unwrap_err() {
HandlerError::Host(HostError::MissingData { ref description }) => {
HandlerError::Host(HostError::MissingState { ref description }) => {
assert!(description.contains(right_connection_id.to_string().as_str()))
}
HandlerError::Connection(ConnectionError::InsufficientConsensusHeight {
Expand Down Expand Up @@ -188,7 +188,7 @@ fn conn_open_ack_healthy() {
#[test]
fn conn_open_ack_no_connection() {
let fxt = conn_open_ack_fixture(Ctx::New);
let expected_err = HandlerError::Host(HostError::MissingData {
let expected_err = HandlerError::Host(HostError::MissingState {
description: format!(
"missing connection end for connection {}",
fxt.msg.conn_id_on_a.clone()
Expand Down

0 comments on commit 126f874

Please sign in to comment.