From 3bc07c80c3faeef0d11cfb433c53a725186f478b Mon Sep 17 00:00:00 2001 From: Davirain Date: Wed, 16 Nov 2022 21:29:46 +0800 Subject: [PATCH 1/7] Change host_height, host_timestamp return Value --- .../clients/ics07_tendermint/client_state.rs | 6 ++-- crates/ibc/src/core/ics02_client/context.rs | 6 ++-- .../ics02_client/handler/create_client.rs | 4 +-- .../ics02_client/handler/update_client.rs | 6 ++-- .../ibc/src/core/ics03_connection/context.rs | 4 +-- .../ics03_connection/handler/conn_open_ack.rs | 4 +-- .../ics03_connection/handler/conn_open_try.rs | 4 +-- crates/ibc/src/core/ics04_channel/context.rs | 6 ++-- .../handler/chan_close_confirm.rs | 2 +- .../ics04_channel/handler/chan_close_init.rs | 2 +- .../handler/chan_open_confirm.rs | 2 +- .../core/ics04_channel/handler/recv_packet.rs | 6 ++-- crates/ibc/src/mock/context.rs | 32 +++++++++---------- .../ibc/src/relayer/ics18_relayer/context.rs | 2 +- crates/ibc/src/relayer/ics18_relayer/error.rs | 5 +++ crates/ibc/src/relayer/ics18_relayer/utils.rs | 4 +-- crates/ibc/src/test_utils.rs | 4 +-- 17 files changed, 52 insertions(+), 47 deletions(-) diff --git a/crates/ibc/src/clients/ics07_tendermint/client_state.rs b/crates/ibc/src/clients/ics07_tendermint/client_state.rs index 2167851a5..70d40fed7 100644 --- a/crates/ibc/src/clients/ics07_tendermint/client_state.rs +++ b/crates/ibc/src/clients/ics07_tendermint/client_state.rs @@ -402,7 +402,7 @@ impl Ics2ClientState for ClientState { untrusted_state, trusted_state, &options, - ctx.host_timestamp().into_tm_time().unwrap(), + ctx.host_timestamp()?.into_tm_time().unwrap(), ); match verdict { @@ -743,8 +743,8 @@ fn verify_delay_passed( height: Height, connection_end: &ConnectionEnd, ) -> Result<(), Ics02Error> { - let current_timestamp = ctx.host_timestamp(); - let current_height = ctx.host_height(); + let current_timestamp = ctx.host_timestamp().map_err(|e| Ics02Error::other(e.to_string()))?; + let current_height = ctx.host_height().map_err(|e| Ics02Error::other(e.to_string()))?; let client_id = connection_end.client_id(); let processed_time = ctx diff --git a/crates/ibc/src/core/ics02_client/context.rs b/crates/ibc/src/core/ics02_client/context.rs index 4ad9e9b7e..77d0aed88 100644 --- a/crates/ibc/src/core/ics02_client/context.rs +++ b/crates/ibc/src/core/ics02_client/context.rs @@ -51,14 +51,14 @@ pub trait ClientReader { ) -> Result>, Error>; /// Returns the current height of the local chain. - fn host_height(&self) -> Height; + fn host_height(&self) -> Result; /// Returns the current timestamp of the local chain. - fn host_timestamp(&self) -> Timestamp { + fn host_timestamp(&self) -> Result { let pending_consensus_state = self .pending_host_consensus_state() .expect("host must have pending consensus state"); - pending_consensus_state.timestamp() + Ok(pending_consensus_state.timestamp()) } /// Returns the `ConsensusState` of the host (local) chain at a specific height. diff --git a/crates/ibc/src/core/ics02_client/handler/create_client.rs b/crates/ibc/src/core/ics02_client/handler/create_client.rs index 0a9094f55..d81d6e7cc 100644 --- a/crates/ibc/src/core/ics02_client/handler/create_client.rs +++ b/crates/ibc/src/core/ics02_client/handler/create_client.rs @@ -57,8 +57,8 @@ pub fn process(ctx: &dyn ClientReader, msg: MsgCreateClient) -> HandlerResult( debug!("latest consensus state: {:?}", latest_consensus_state); - let now = ClientReader::host_timestamp(ctx); + let now = ClientReader::host_timestamp(ctx)?; let duration = now .duration_since(&latest_consensus_state.timestamp()) .ok_or_else(|| { @@ -86,8 +86,8 @@ pub fn process( client_id: client_id.clone(), client_state, consensus_state, - processed_time: ClientReader::host_timestamp(ctx), - processed_height: ctx.host_height(), + processed_time: ClientReader::host_timestamp(ctx)?, + processed_height: ctx.host_height()?, }); output.emit(IbcEvent::UpdateClient(UpdateClient::new( diff --git a/crates/ibc/src/core/ics03_connection/context.rs b/crates/ibc/src/core/ics03_connection/context.rs index 83ddb2e74..3e33775ed 100644 --- a/crates/ibc/src/core/ics03_connection/context.rs +++ b/crates/ibc/src/core/ics03_connection/context.rs @@ -28,11 +28,11 @@ pub trait ConnectionReader { fn decode_client_state(&self, client_state: Any) -> Result, Error>; /// Returns the current height of the local chain. - fn host_current_height(&self) -> Height; + fn host_current_height(&self) -> Result; #[deprecated(since = "0.20.0")] /// Returns the oldest height available on the local chain. - fn host_oldest_height(&self) -> Height; + fn host_oldest_height(&self) -> Result; /// Returns the prefix that the local chain uses in the KV store. fn commitment_prefix(&self) -> CommitmentPrefix; diff --git a/crates/ibc/src/core/ics03_connection/handler/conn_open_ack.rs b/crates/ibc/src/core/ics03_connection/handler/conn_open_ack.rs index 7e8405dd0..ebc41ed4c 100644 --- a/crates/ibc/src/core/ics03_connection/handler/conn_open_ack.rs +++ b/crates/ibc/src/core/ics03_connection/handler/conn_open_ack.rs @@ -19,10 +19,10 @@ pub(crate) fn process( ) -> HandlerResult { let mut output = HandlerOutput::builder(); - if msg.consensus_height_of_a_on_b > ctx_a.host_current_height() { + if msg.consensus_height_of_a_on_b > ctx_a.host_current_height()? { return Err(Error::invalid_consensus_height( msg.consensus_height_of_a_on_b, - ctx_a.host_current_height(), + ctx_a.host_current_height()?, )); } diff --git a/crates/ibc/src/core/ics03_connection/handler/conn_open_try.rs b/crates/ibc/src/core/ics03_connection/handler/conn_open_try.rs index 5846ba9c4..41d984567 100644 --- a/crates/ibc/src/core/ics03_connection/handler/conn_open_try.rs +++ b/crates/ibc/src/core/ics03_connection/handler/conn_open_try.rs @@ -24,11 +24,11 @@ pub(crate) fn process( ctx_b.validate_self_client(msg.client_state_of_b_on_a.clone())?; - if msg.consensus_height_of_b_on_a > ctx_b.host_current_height() { + if msg.consensus_height_of_b_on_a > ctx_b.host_current_height()? { // Fail if the consensus height is too advanced. return Err(Error::invalid_consensus_height( msg.consensus_height_of_b_on_a, - ctx_b.host_current_height(), + ctx_b.host_current_height()?, )); } diff --git a/crates/ibc/src/core/ics04_channel/context.rs b/crates/ibc/src/core/ics04_channel/context.rs index 16e6cfc30..dcfb35e71 100644 --- a/crates/ibc/src/core/ics04_channel/context.rs +++ b/crates/ibc/src/core/ics04_channel/context.rs @@ -113,14 +113,14 @@ pub trait ChannelReader { fn hash(&self, value: Vec) -> Vec; /// Returns the current height of the local chain. - fn host_height(&self) -> Height; + fn host_height(&self) -> Result; /// Returns the current timestamp of the local chain. - fn host_timestamp(&self) -> Timestamp { + fn host_timestamp(&self) -> Result { let pending_consensus_state = self .pending_host_consensus_state() .expect("host must have pending consensus state"); - pending_consensus_state.timestamp() + Ok(pending_consensus_state.timestamp()) } /// Returns the `ConsensusState` of the host (local) chain at a specific height. diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_close_confirm.rs b/crates/ibc/src/core/ics04_channel/handler/chan_close_confirm.rs index c1b65cca2..bd99e5070 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_close_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_close_confirm.rs @@ -133,7 +133,7 @@ mod tests { let client_id = ClientId::new(mock_client_type(), 24).unwrap(); let conn_id = ConnectionId::new(2); let default_context = MockContext::default(); - let client_consensus_state_height = default_context.host_height(); + let client_consensus_state_height = default_context.host_height().unwrap(); let conn_end = ConnectionEnd::new( ConnectionState::Open, diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_close_init.rs b/crates/ibc/src/core/ics04_channel/handler/chan_close_init.rs index c62faab62..829fd2b86 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_close_init.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_close_init.rs @@ -111,7 +111,7 @@ mod tests { let context = { let default_context = MockContext::default(); - let client_consensus_state_height = default_context.host_height(); + let client_consensus_state_height = default_context.host_height().unwrap(); default_context .with_client(&client_id, client_consensus_state_height) diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs b/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs index da9985951..bfa211be2 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs @@ -140,7 +140,7 @@ mod tests { let client_id = ClientId::new(mock_client_type(), 24).unwrap(); let conn_id = ConnectionId::new(2); let context = MockContext::default(); - let client_consensus_state_height = context.host_current_height().revision_height(); + let client_consensus_state_height = context.host_current_height().unwrap().revision_height(); // The connection underlying the channel we're trying to open. let conn_end = ConnectionEnd::new( diff --git a/crates/ibc/src/core/ics04_channel/handler/recv_packet.rs b/crates/ibc/src/core/ics04_channel/handler/recv_packet.rs index 2e3d75a76..1e4d999df 100644 --- a/crates/ibc/src/core/ics04_channel/handler/recv_packet.rs +++ b/crates/ibc/src/core/ics04_channel/handler/recv_packet.rs @@ -66,7 +66,7 @@ pub fn process( )); } - let latest_height = ChannelReader::host_height(ctx); + let latest_height = ChannelReader::host_height(ctx)?; if packet.timeout_height.has_expired(latest_height) { return Err(Error::low_packet_height( latest_height, @@ -74,7 +74,7 @@ pub fn process( )); } - let latest_timestamp = ChannelReader::host_timestamp(ctx); + let latest_timestamp = ChannelReader::host_timestamp(ctx)?; if let Expiry::Expired = latest_timestamp.check_expiry(&packet.timeout_timestamp) { return Err(Error::low_packet_timestamp()); } @@ -186,7 +186,7 @@ mod tests { let context = MockContext::default(); - let host_height = context.query_latest_height().increment(); + let host_height = context.query_latest_height().unwrap().increment(); let client_height = host_height.increment(); diff --git a/crates/ibc/src/mock/context.rs b/crates/ibc/src/mock/context.rs index 64c6e9448..54c919a40 100644 --- a/crates/ibc/src/mock/context.rs +++ b/crates/ibc/src/mock/context.rs @@ -845,12 +845,12 @@ impl ChannelReader for MockContext { sha2::Sha256::digest(value).to_vec() } - fn host_height(&self) -> Height { - self.latest_height() + fn host_height(&self) -> Result { + Ok(self.latest_height()) } - fn host_timestamp(&self) -> Timestamp { - ClientReader::host_timestamp(self) + fn host_timestamp(&self) -> Result { + ClientReader::host_timestamp(self).map_err(|e| Ics04Error::other(e.to_string())) } fn host_consensus_state(&self, height: Height) -> Result, Ics04Error> { @@ -1103,13 +1103,13 @@ impl ConnectionReader for MockContext { ClientReader::decode_client_state(self, client_state).map_err(Ics03Error::ics02_client) } - fn host_current_height(&self) -> Height { - self.latest_height() + fn host_current_height(&self) -> Result { + Ok(self.latest_height()) } - fn host_oldest_height(&self) -> Height { + fn host_oldest_height(&self) -> Result { // history must be non-empty, so `self.history[0]` is valid - self.history[0].height() + Ok(self.history[0].height()) } fn commitment_prefix(&self) -> CommitmentPrefix { @@ -1275,17 +1275,17 @@ impl ClientReader for MockContext { Ok(None) } - fn host_height(&self) -> Height { - self.latest_height() + fn host_height(&self) -> Result { + Ok(self.latest_height()) } - fn host_timestamp(&self) -> Timestamp { - self.history + fn host_timestamp(&self) -> Result { + Ok(self.history .last() .expect("history cannot be empty") .timestamp() .add(self.block_time) - .unwrap() + .unwrap()) } fn host_consensus_state(&self, height: Height) -> Result, Ics02Error> { @@ -1401,8 +1401,8 @@ impl ClientKeeper for MockContext { } impl Ics18Context for MockContext { - fn query_latest_height(&self) -> Height { - self.host_current_height() + fn query_latest_height(&self) -> Result { + self.host_current_height().map_err(|e| Ics18Error::ics03(e)) } fn query_client_full_state(&self, client_id: &ClientId) -> Option> { @@ -1411,7 +1411,7 @@ impl Ics18Context for MockContext { } fn query_latest_header(&self) -> Option> { - let block_ref = self.host_block(self.host_current_height()); + let block_ref = self.host_block(self.host_current_height().unwrap()); block_ref.cloned().map(Header::into_box) } diff --git a/crates/ibc/src/relayer/ics18_relayer/context.rs b/crates/ibc/src/relayer/ics18_relayer/context.rs index 50b4bc643..d8ea4f5c1 100644 --- a/crates/ibc/src/relayer/ics18_relayer/context.rs +++ b/crates/ibc/src/relayer/ics18_relayer/context.rs @@ -17,7 +17,7 @@ use crate::Height; /// types, light client, RPC client, etc.) pub trait Ics18Context { /// Returns the latest height of the chain. - fn query_latest_height(&self) -> Height; + fn query_latest_height(&self) -> Result; /// Returns this client state for the given `client_id` on this chain. /// Wrapper over the `/abci_query?path=..` endpoint. diff --git a/crates/ibc/src/relayer/ics18_relayer/error.rs b/crates/ibc/src/relayer/ics18_relayer/error.rs index e975de5a3..57b028148 100644 --- a/crates/ibc/src/relayer/ics18_relayer/error.rs +++ b/crates/ibc/src/relayer/ics18_relayer/error.rs @@ -1,5 +1,6 @@ use crate::core::ics24_host::identifier::ClientId; use crate::core::ics26_routing::error::Error as RoutingError; +use crate::core::ics03_connection; use crate::Height; use flex_error::define_error; @@ -34,5 +35,9 @@ define_error! { TransactionFailed [ RoutingError ] | _ | { "transaction processing by modules failed" }, + + Ics03 + [ ics03_connection::error::Error ] + | _ | { "ics03 connection error" } } } diff --git a/crates/ibc/src/relayer/ics18_relayer/utils.rs b/crates/ibc/src/relayer/ics18_relayer/utils.rs index a837d5bfe..7df858755 100644 --- a/crates/ibc/src/relayer/ics18_relayer/utils.rs +++ b/crates/ibc/src/relayer/ics18_relayer/utils.rs @@ -149,7 +149,7 @@ mod tests { .query_client_full_state(&client_on_b_for_a) .unwrap() .latest_height(); - assert_eq!(client_height_b, ctx_a.query_latest_height()); + assert_eq!(client_height_b, ctx_a.query_latest_height().unwrap()); // Update client on chain B to latest height of B. // - create the client update message with the latest header from B @@ -206,7 +206,7 @@ mod tests { .query_client_full_state(&client_on_a_for_b) .unwrap() .latest_height(); - assert_eq!(client_height_a, ctx_b.query_latest_height()); + assert_eq!(client_height_a, ctx_b.query_latest_height().unwrap()); } } } diff --git a/crates/ibc/src/test_utils.rs b/crates/ibc/src/test_utils.rs index b3e715826..3fb7d8065 100644 --- a/crates/ibc/src/test_utils.rs +++ b/crates/ibc/src/test_utils.rs @@ -428,8 +428,8 @@ impl ChannelReader for DummyTransferModule { sha2::Sha256::digest(value).to_vec() } - fn host_height(&self) -> Height { - Height::new(0, 1).unwrap() + fn host_height(&self) -> Result { + Height::new(0, 1).map_err(|e| Error::other(e.to_string())) } fn host_consensus_state(&self, _height: Height) -> Result, Error> { From 8e8262f138317f9a8c462cd4cca61e0e9ea3adcc Mon Sep 17 00:00:00 2001 From: Davirain Date: Wed, 16 Nov 2022 21:30:08 +0800 Subject: [PATCH 2/7] fmt code --- crates/ibc/src/clients/ics07_tendermint/client_state.rs | 8 ++++++-- .../src/core/ics04_channel/handler/chan_open_confirm.rs | 3 ++- crates/ibc/src/mock/context.rs | 3 ++- crates/ibc/src/relayer/ics18_relayer/error.rs | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/ibc/src/clients/ics07_tendermint/client_state.rs b/crates/ibc/src/clients/ics07_tendermint/client_state.rs index 70d40fed7..3d2888cb6 100644 --- a/crates/ibc/src/clients/ics07_tendermint/client_state.rs +++ b/crates/ibc/src/clients/ics07_tendermint/client_state.rs @@ -743,8 +743,12 @@ fn verify_delay_passed( height: Height, connection_end: &ConnectionEnd, ) -> Result<(), Ics02Error> { - let current_timestamp = ctx.host_timestamp().map_err(|e| Ics02Error::other(e.to_string()))?; - let current_height = ctx.host_height().map_err(|e| Ics02Error::other(e.to_string()))?; + let current_timestamp = ctx + .host_timestamp() + .map_err(|e| Ics02Error::other(e.to_string()))?; + let current_height = ctx + .host_height() + .map_err(|e| Ics02Error::other(e.to_string()))?; let client_id = connection_end.client_id(); let processed_time = ctx diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs b/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs index bfa211be2..4f7901d35 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs @@ -140,7 +140,8 @@ mod tests { let client_id = ClientId::new(mock_client_type(), 24).unwrap(); let conn_id = ConnectionId::new(2); let context = MockContext::default(); - let client_consensus_state_height = context.host_current_height().unwrap().revision_height(); + let client_consensus_state_height = + context.host_current_height().unwrap().revision_height(); // The connection underlying the channel we're trying to open. let conn_end = ConnectionEnd::new( diff --git a/crates/ibc/src/mock/context.rs b/crates/ibc/src/mock/context.rs index 54c919a40..9223610f5 100644 --- a/crates/ibc/src/mock/context.rs +++ b/crates/ibc/src/mock/context.rs @@ -1280,7 +1280,8 @@ impl ClientReader for MockContext { } fn host_timestamp(&self) -> Result { - Ok(self.history + Ok(self + .history .last() .expect("history cannot be empty") .timestamp() diff --git a/crates/ibc/src/relayer/ics18_relayer/error.rs b/crates/ibc/src/relayer/ics18_relayer/error.rs index 57b028148..d141358ca 100644 --- a/crates/ibc/src/relayer/ics18_relayer/error.rs +++ b/crates/ibc/src/relayer/ics18_relayer/error.rs @@ -1,6 +1,6 @@ +use crate::core::ics03_connection; use crate::core::ics24_host::identifier::ClientId; use crate::core::ics26_routing::error::Error as RoutingError; -use crate::core::ics03_connection; use crate::Height; use flex_error::define_error; @@ -35,7 +35,7 @@ define_error! { TransactionFailed [ RoutingError ] | _ | { "transaction processing by modules failed" }, - + Ics03 [ ics03_connection::error::Error ] | _ | { "ics03 connection error" } From d966f1baf122b9d21e2a0c241cbb18496c242dea Mon Sep 17 00:00:00 2001 From: Davirain Date: Wed, 16 Nov 2022 21:38:06 +0800 Subject: [PATCH 3/7] Create 242-change-return-value.md --- .changelog/unreleased/features/242-change-return-value.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/features/242-change-return-value.md diff --git a/.changelog/unreleased/features/242-change-return-value.md b/.changelog/unreleased/features/242-change-return-value.md new file mode 100644 index 000000000..fe8275db4 --- /dev/null +++ b/.changelog/unreleased/features/242-change-return-value.md @@ -0,0 +1,2 @@ +- Change host_height, host_timestamp return value in ics02, ics03, ics04 + ([#242](https://github.com/cosmos/ibc-rs/issues/242)) \ No newline at end of file From b0bd4305694ee19ab640483aa19dd1275e76a4bf Mon Sep 17 00:00:00 2001 From: Davirain Date: Thu, 17 Nov 2022 00:10:07 +0800 Subject: [PATCH 4/7] fix clippy --- crates/ibc/src/mock/context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ibc/src/mock/context.rs b/crates/ibc/src/mock/context.rs index 9223610f5..cc29103bf 100644 --- a/crates/ibc/src/mock/context.rs +++ b/crates/ibc/src/mock/context.rs @@ -1403,7 +1403,7 @@ impl ClientKeeper for MockContext { impl Ics18Context for MockContext { fn query_latest_height(&self) -> Result { - self.host_current_height().map_err(|e| Ics18Error::ics03(e)) + self.host_current_height().map_err(Ics18Error::ics03) } fn query_client_full_state(&self, client_id: &ClientId) -> Option> { From 4af036bb6da79c741da258ea83d181d002a24845 Mon Sep 17 00:00:00 2001 From: Davirain Date: Mon, 21 Nov 2022 09:25:09 +0800 Subject: [PATCH 5/7] update .changelog --- .../unreleased/breaking-changes/242-change-return-value.md | 2 ++ .changelog/unreleased/features/242-change-return-value.md | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 .changelog/unreleased/breaking-changes/242-change-return-value.md delete mode 100644 .changelog/unreleased/features/242-change-return-value.md diff --git a/.changelog/unreleased/breaking-changes/242-change-return-value.md b/.changelog/unreleased/breaking-changes/242-change-return-value.md new file mode 100644 index 000000000..b44d16f3a --- /dev/null +++ b/.changelog/unreleased/breaking-changes/242-change-return-value.md @@ -0,0 +1,2 @@ +- Change `host_height`, `host_timestamp` return value to a `Result` in `ClientReader`, `ConnectionReader`, and `ChannelReader` + ([#242](https://github.com/cosmos/ibc-rs/issues/242)) \ No newline at end of file diff --git a/.changelog/unreleased/features/242-change-return-value.md b/.changelog/unreleased/features/242-change-return-value.md deleted file mode 100644 index fe8275db4..000000000 --- a/.changelog/unreleased/features/242-change-return-value.md +++ /dev/null @@ -1,2 +0,0 @@ -- Change host_height, host_timestamp return value in ics02, ics03, ics04 - ([#242](https://github.com/cosmos/ibc-rs/issues/242)) \ No newline at end of file From 89663901b2672285b88b5b144ac46e6ac8a37071 Mon Sep 17 00:00:00 2001 From: Davirain Date: Mon, 21 Nov 2022 09:32:36 +0800 Subject: [PATCH 6/7] Change host_height, host_timestamp return value in ValidationContext --- .../unreleased/breaking-changes/242-change-return-value.md | 2 +- crates/ibc/src/clients/ics07_tendermint/client_state.rs | 2 +- crates/ibc/src/core/context.rs | 6 +++--- crates/ibc/src/core/ics02_client/handler/create_client.rs | 4 ++-- crates/ibc/src/core/ics02_client/handler/update_client.rs | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.changelog/unreleased/breaking-changes/242-change-return-value.md b/.changelog/unreleased/breaking-changes/242-change-return-value.md index b44d16f3a..f3e30b2d0 100644 --- a/.changelog/unreleased/breaking-changes/242-change-return-value.md +++ b/.changelog/unreleased/breaking-changes/242-change-return-value.md @@ -1,2 +1,2 @@ -- Change `host_height`, `host_timestamp` return value to a `Result` in `ClientReader`, `ConnectionReader`, and `ChannelReader` +- Change `host_height`, `host_timestamp` return value to a `Result` in `ClientReader`, `ConnectionReader`, `ChannelReader` and `ValidationContext` ([#242](https://github.com/cosmos/ibc-rs/issues/242)) \ No newline at end of file diff --git a/crates/ibc/src/clients/ics07_tendermint/client_state.rs b/crates/ibc/src/clients/ics07_tendermint/client_state.rs index 0f4dc956c..5280f85b5 100644 --- a/crates/ibc/src/clients/ics07_tendermint/client_state.rs +++ b/crates/ibc/src/clients/ics07_tendermint/client_state.rs @@ -574,7 +574,7 @@ impl Ics2ClientState for ClientState { untrusted_state, trusted_state, &options, - ctx.host_timestamp().into_tm_time().unwrap(), + ctx.host_timestamp()?.into_tm_time().unwrap(), ); match verdict { diff --git a/crates/ibc/src/core/context.rs b/crates/ibc/src/core/context.rs index f9c781034..4ec3654dc 100644 --- a/crates/ibc/src/core/context.rs +++ b/crates/ibc/src/core/context.rs @@ -90,14 +90,14 @@ pub trait ValidationContext { ) -> Result>, ClientError>; /// Returns the current height of the local chain. - fn host_height(&self) -> Height; + fn host_height(&self) -> Result; /// Returns the current timestamp of the local chain. - fn host_timestamp(&self) -> Timestamp { + fn host_timestamp(&self) -> Result { let pending_consensus_state = self .pending_host_consensus_state() .expect("host must have pending consensus state"); - pending_consensus_state.timestamp() + Ok(pending_consensus_state.timestamp()) } /// Returns the pending `ConsensusState` of the host (local) chain. diff --git a/crates/ibc/src/core/ics02_client/handler/create_client.rs b/crates/ibc/src/core/ics02_client/handler/create_client.rs index 33b1ed265..900eb5dd3 100644 --- a/crates/ibc/src/core/ics02_client/handler/create_client.rs +++ b/crates/ibc/src/core/ics02_client/handler/create_client.rs @@ -90,12 +90,12 @@ where ctx.store_update_time( client_id.clone(), client_state.latest_height(), - ctx.host_timestamp(), + ctx.host_timestamp()?, )?; ctx.store_update_height( client_id.clone(), client_state.latest_height(), - ctx.host_height(), + ctx.host_height()?, )?; ctx.emit_ibc_event(IbcEvent::CreateClient(CreateClient::new( diff --git a/crates/ibc/src/core/ics02_client/handler/update_client.rs b/crates/ibc/src/core/ics02_client/handler/update_client.rs index f5ff0c533..bb05601d5 100644 --- a/crates/ibc/src/core/ics02_client/handler/update_client.rs +++ b/crates/ibc/src/core/ics02_client/handler/update_client.rs @@ -56,7 +56,7 @@ where debug!("latest consensus state: {:?}", latest_consensus_state); - let now = ctx.host_timestamp(); + let now = ctx.host_timestamp()?; let duration = now .duration_since(&latest_consensus_state.timestamp()) .ok_or_else(|| { @@ -109,12 +109,12 @@ where ctx.store_update_time( client_id.clone(), client_state.latest_height(), - ctx.host_timestamp(), + ctx.host_timestamp()?, )?; ctx.store_update_height( client_id.clone(), client_state.latest_height(), - ctx.host_height(), + ctx.host_height()?, )?; { From bc84cef06ef24fe824c72ba6d7f33f78b8e73609 Mon Sep 17 00:00:00 2001 From: Davirain Date: Tue, 22 Nov 2022 15:25:46 +0800 Subject: [PATCH 7/7] update Ics18context to RelayerContext in mock/context.rs --- crates/ibc/src/mock/context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ibc/src/mock/context.rs b/crates/ibc/src/mock/context.rs index 109191a45..c5d0376fe 100644 --- a/crates/ibc/src/mock/context.rs +++ b/crates/ibc/src/mock/context.rs @@ -1401,7 +1401,7 @@ impl ClientKeeper for MockContext { } } -impl Ics18Context for MockContext { +impl RelayerContext for MockContext { fn query_latest_height(&self) -> Result { self.host_current_height().map_err(Ics18Error::ics03) }