From 126f87432dd3287c5a341bc22ae3bc52cab289a8 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 13 Sep 2024 12:46:33 -0500 Subject: [PATCH] Rename HostError InvalidData and MissingData variants --- .../ics02-client/src/handler/update_client.rs | 7 ++++--- .../ics02-client/src/handler/upgrade_client.rs | 4 ++-- .../cosmos/src/validate_self_client.rs | 16 ++++++++-------- ibc-core/ics24-host/src/context.rs | 2 +- ibc-core/ics24-host/types/src/error.rs | 8 ++++---- ibc-testkit/src/testapp/ibc/core/client_ctx.rs | 8 ++++---- ibc-testkit/src/testapp/ibc/core/core_ctx.rs | 18 +++++++++--------- .../tests/core/ics02_client/upgrade_client.rs | 2 +- .../core/ics03_connection/conn_open_ack.rs | 4 ++-- 9 files changed, 35 insertions(+), 34 deletions(-) diff --git a/ibc-core/ics02-client/src/handler/update_client.rs b/ibc-core/ics02-client/src/handler/update_client.rs index 10d16504a..1f8bdae14 100644 --- a/ibc-core/ics02-client/src/handler/update_client.rs +++ b/ibc-core/ics02-client/src/handler/update_client.rs @@ -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, diff --git a/ibc-core/ics02-client/src/handler/upgrade_client.rs b/ibc-core/ics02-client/src/handler/upgrade_client.rs index 195ca4da8..300540212 100644 --- a/ibc-core/ics02-client/src/handler/upgrade_client.rs +++ b/ibc-core/ics02-client/src/handler/upgrade_client.rs @@ -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() ), diff --git a/ibc-core/ics24-host/cosmos/src/validate_self_client.rs b/ibc-core/ics24-host/cosmos/src/validate_self_client.rs index 4528d917d..d1f4dd162 100644 --- a/ibc-core/ics24-host/cosmos/src/validate_self_client.rs +++ b/ibc-core/ics24-host/cosmos/src/validate_self_client.rs @@ -33,7 +33,7 @@ pub trait ValidateSelfClientContext { let self_chain_id = self.chain_id(); 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 @@ -45,7 +45,7 @@ pub trait ValidateSelfClientContext { let self_revision_number = self_chain_id.revision_number(); 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, @@ -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, @@ -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(), @@ -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(), })? }; 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(), @@ -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 ({:?})", client_state_of_host_on_counterparty.unbonding_period, client_state_of_host_on_counterparty.trusting_period @@ -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(), diff --git a/ibc-core/ics24-host/src/context.rs b/ibc-core/ics24-host/src/context.rs index 46bbc6a30..4a11b276b 100644 --- a/ibc-core/ics24-host/src/context.rs +++ b/ibc-core/ics24-host/src/context.rs @@ -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(), }) } diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index 4a7336ae7..7e0e5563a 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -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}` diff --git a/ibc-testkit/src/testapp/ibc/core/client_ctx.rs b/ibc-testkit/src/testapp/ibc/core/client_ctx.rs index cc4d06f83..afc7e7611 100644 --- a/ibc-testkit/src/testapp/ibc/core/client_ctx.rs +++ b/ibc-testkit/src/testapp/ibc/core/client_ctx.rs @@ -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(), }) }) @@ -115,7 +115,7 @@ where }) }) .transpose() - .map_err(|e| HostError::MissingData { + .map_err(|e| HostError::MissingState { description: e.to_string(), })?; @@ -154,7 +154,7 @@ where }) }) .transpose() - .map_err(|e| HostError::MissingData { + .map_err(|e| HostError::MissingState { description: e.to_string(), })?; @@ -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(), })?; let consensus_state = self diff --git a/ibc-testkit/src/testapp/ibc/core/core_ctx.rs b/ibc-testkit/src/testapp/ibc/core/core_ctx.rs index faefd28c9..93b17319b 100644 --- a/ibc-testkit/src/testapp/ibc/core/core_ctx.rs +++ b/ibc-testkit/src/testapp/ibc/core/core_ctx.rs @@ -42,7 +42,7 @@ where fn host_height(&self) -> Result { Height::new(*self.revision_number.lock(), self.store.current_height()).map_err(|e| { - HostError::InvalidData { + HostError::InvalidState { description: e.to_string(), } }) @@ -57,7 +57,7 @@ where fn client_counter(&self) -> Result { self.client_counter .get(StoreHeight::Pending, &NextClientSequencePath) - .ok_or(HostError::MissingData { + .ok_or(HostError::MissingState { description: "missing client counter".to_string(), }) } @@ -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(), }) } @@ -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, @@ -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(), @@ -119,7 +119,7 @@ where fn connection_end(&self, conn_id: &ConnectionId) -> Result { 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()), }) } @@ -133,7 +133,7 @@ where fn connection_counter(&self) -> Result { self.conn_counter .get(StoreHeight::Pending, &NextConnectionSequencePath) - .ok_or(HostError::MissingData { + .ok_or(HostError::MissingState { description: "missing connection counter".to_string(), }) } @@ -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(), })?; let client_state = self @@ -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(), }) }) diff --git a/tests-integration/tests/core/ics02_client/upgrade_client.rs b/tests-integration/tests/core/ics02_client/upgrade_client.rs index ed09d154a..7ec273f15 100644 --- a/tests-integration/tests/core/ics02_client/upgrade_client.rs +++ b/tests-integration/tests/core/ics02_client/upgrade_client.rs @@ -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() diff --git a/tests-integration/tests/core/ics03_connection/conn_open_ack.rs b/tests-integration/tests/core/ics03_connection/conn_open_ack.rs index 45e4bc395..29b87495d 100644 --- a/tests-integration/tests/core/ics03_connection/conn_open_ack.rs +++ b/tests-integration/tests/core/ics03_connection/conn_open_ack.rs @@ -127,7 +127,7 @@ fn conn_open_ack_validate(fxt: &Fixture, 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 { @@ -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()