From 96f31238507b0c0b5fc1c51ae2bc182fb96c5198 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Wed, 11 Oct 2023 14:28:11 -0700 Subject: [PATCH] imp: tracks ibc-rs pr915 --- Cargo.lock | 6 +- Cargo.toml | 4 +- crates/app/src/abci/v0_37/impls.rs | 2 +- crates/app/src/modules/ibc/client_contexts.rs | 84 +++++++++++++++++-- crates/app/src/modules/ibc/impls.rs | 70 +--------------- crates/app/src/modules/upgrade/impls.rs | 2 +- 6 files changed, 89 insertions(+), 79 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b6569260..258adebc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1103,7 +1103,7 @@ dependencies = [ [[package]] name = "ibc" version = "0.45.0" -source = "git+https://github.com/cosmos/ibc-rs?rev=518737a#518737a7a3538df5e4c09b68a0787e332c4c0951" +source = "git+https://github.com/cosmos/ibc-rs?rev=3711e75#3711e7502eb9283a4a329e1c740c349dd3aeeaa1" dependencies = [ "bytes", "derive_more", @@ -1130,7 +1130,7 @@ dependencies = [ [[package]] name = "ibc-derive" version = "0.3.0" -source = "git+https://github.com/cosmos/ibc-rs?rev=518737a#518737a7a3538df5e4c09b68a0787e332c4c0951" +source = "git+https://github.com/cosmos/ibc-rs?rev=3711e75#3711e7502eb9283a4a329e1c740c349dd3aeeaa1" dependencies = [ "darling", "proc-macro2", @@ -1158,7 +1158,7 @@ dependencies = [ [[package]] name = "ibc-query" version = "0.45.0" -source = "git+https://github.com/cosmos/ibc-rs?rev=518737a#518737a7a3538df5e4c09b68a0787e332c4c0951" +source = "git+https://github.com/cosmos/ibc-rs?rev=3711e75#3711e7502eb9283a4a329e1c740c349dd3aeeaa1" dependencies = [ "displaydoc", "ibc", diff --git a/Cargo.toml b/Cargo.toml index 8ab6fa84..3d86f4d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,8 @@ base64 = { version = "0.21", default-features = false, features = ["alloc"] } displaydoc = { version = "0.2", default-features = false } derive_more = { version = "0.99.17", default-features = false, features = ["from", "into", "display"] } ed25519 = { version = "2.1.0", default-features = false } -ibc = { git ="https://github.com/cosmos/ibc-rs", rev = "518737a" } -ibc-query = { git ="https://github.com/cosmos/ibc-rs", rev = "518737a" } +ibc = { git ="https://github.com/cosmos/ibc-rs", rev = "3711e75" } +ibc-query = { git ="https://github.com/cosmos/ibc-rs", rev = "3711e75" } ibc-proto = { version = "0.35.0", default-features = false } ics23 = { version = "0.10.1", default-features = false } prost = { version = "0.11.6", default-features = false } diff --git a/crates/app/src/abci/v0_37/impls.rs b/crates/app/src/abci/v0_37/impls.rs index 146fda12..c343956d 100644 --- a/crates/app/src/abci/v0_37/impls.rs +++ b/crates/app/src/abci/v0_37/impls.rs @@ -9,7 +9,7 @@ use basecoin_store::utils::SharedRwExt; use cosmrs::tx::SignerInfo; use cosmrs::tx::SignerPublicKey; use cosmrs::Tx; -use ibc::Any; +use ibc::proto::Any; use prost::Message; use serde_json::Value; use std::fmt::{Debug, Write}; diff --git a/crates/app/src/modules/ibc/client_contexts.rs b/crates/app/src/modules/ibc/client_contexts.rs index e3990ee1..e55a666b 100644 --- a/crates/app/src/modules/ibc/client_contexts.rs +++ b/crates/app/src/modules/ibc/client_contexts.rs @@ -7,19 +7,59 @@ use ibc::clients::ics07_tendermint::client_state::ClientState as TmClientState; use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; use ibc::clients::ics07_tendermint::{CommonContext, ValidationContext as TmValidationContext}; use ibc::core::ics02_client::error::ClientError; -use ibc::core::ics02_client::ClientExecutionContext; +use ibc::core::ics02_client::{ClientExecutionContext, ClientValidationContext}; use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ics24_host::path::{ClientConsensusStatePath, ClientStatePath, Path}; use ibc::core::timestamp::Timestamp; use ibc::core::{ContextError, ValidationContext}; +use ibc::Height as IbcHeight; use std::fmt::Debug; +impl ClientValidationContext for IbcContext +where + S: Store + Debug, +{ + /// Returns the time when the client state for the given [`ClientId`] was updated with a header for the given [`IbcHeight`] + fn client_update_time( + &self, + client_id: &ClientId, + height: &IbcHeight, + ) -> Result { + let processed_timestamp = self + .client_processed_times + .get(&(client_id.clone(), *height)) + .cloned() + .ok_or(ClientError::ProcessedTimeNotFound { + client_id: client_id.clone(), + height: *height, + })?; + Ok(processed_timestamp) + } + + /// Returns the height when the client state for the given [`ClientId`] was updated with a header for the given [`IbcHeight`] + fn client_update_height( + &self, + client_id: &ClientId, + height: &IbcHeight, + ) -> Result { + let processed_height = self + .client_processed_heights + .get(&(client_id.clone(), *height)) + .cloned() + .ok_or(ClientError::ProcessedHeightNotFound { + client_id: client_id.clone(), + height: *height, + })?; + Ok(processed_height) + } +} + impl ClientExecutionContext for IbcContext where S: Store + Debug, { - type ClientValidationContext = Self; + type V = Self; type AnyClientState = TmClientState; @@ -57,6 +97,34 @@ where })?; Ok(()) } + + /// Called upon successful client update. + /// Implementations are expected to use this to record the specified time as the time at which + /// this update (or header) was processed. + fn store_update_time( + &mut self, + client_id: ClientId, + height: IbcHeight, + timestamp: Timestamp, + ) -> Result<(), ContextError> { + self.client_processed_times + .insert((client_id, height), timestamp); + Ok(()) + } + + /// Called upon successful client update. + /// Implementations are expected to use this to record the specified height as the height at + /// at which this update (or header) was processed. + fn store_update_height( + &mut self, + client_id: ClientId, + height: IbcHeight, + host_height: IbcHeight, + ) -> Result<(), ContextError> { + self.client_processed_heights + .insert((client_id, height), host_height); + Ok(()) + } } impl CommonContext for IbcContext @@ -66,6 +134,14 @@ where type ConversionError = &'static str; type AnyConsensusState = AnyConsensusState; + fn host_timestamp(&self) -> Result { + ValidationContext::host_timestamp(self) + } + + fn host_height(&self) -> Result { + ValidationContext::host_height(self) + } + fn consensus_state( &self, client_cons_state_path: &ClientConsensusStatePath, @@ -78,10 +154,6 @@ impl TmValidationContext for IbcContext where S: Store + Debug, { - fn host_timestamp(&self) -> Result { - ValidationContext::host_timestamp(self) - } - fn next_consensus_state( &self, client_id: &ClientId, diff --git a/crates/app/src/modules/ibc/impls.rs b/crates/app/src/modules/ibc/impls.rs index 69d92e3c..cfb85b20 100644 --- a/crates/app/src/modules/ibc/impls.rs +++ b/crates/app/src/modules/ibc/impls.rs @@ -304,9 +304,9 @@ where /// Counter for channels channel_counter: u64, /// Tracks the processed time for client updates - client_processed_times: HashMap<(ClientId, IbcHeight), Timestamp>, + pub(crate) client_processed_times: HashMap<(ClientId, IbcHeight), Timestamp>, /// Tracks the processed height for client updates - client_processed_heights: HashMap<(ClientId, IbcHeight), IbcHeight>, + pub(crate) client_processed_heights: HashMap<(ClientId, IbcHeight), IbcHeight>, /// Map of host consensus states consensus_states: Arc>>, /// A typed-store for AnyClientState @@ -384,7 +384,7 @@ impl ValidationContext for IbcContext where S: Store + Debug, { - type ClientValidationContext = Self; + type V = Self; type E = Self; type AnyConsensusState = AnyConsensusState; type AnyClientState = TmClientState; @@ -577,40 +577,6 @@ where Ok(ack) } - /// Returns the time when the client state for the given [`ClientId`] was updated with a header for the given [`IbcHeight`] - fn client_update_time( - &self, - client_id: &ClientId, - height: &IbcHeight, - ) -> Result { - let processed_timestamp = self - .client_processed_times - .get(&(client_id.clone(), *height)) - .cloned() - .ok_or(ChannelError::ProcessedTimeNotFound { - client_id: client_id.clone(), - height: *height, - })?; - Ok(processed_timestamp) - } - - /// Returns the height when the client state for the given [`ClientId`] was updated with a header for the given [`IbcHeight`] - fn client_update_height( - &self, - client_id: &ClientId, - height: &IbcHeight, - ) -> Result { - let processed_height = self - .client_processed_heights - .get(&(client_id.clone(), *height)) - .cloned() - .ok_or(ChannelError::ProcessedHeightNotFound { - client_id: client_id.clone(), - height: *height, - })?; - Ok(processed_height) - } - /// Returns a counter on the number of channel ids have been created thus far. /// The value of this counter should increase only via method /// `ChannelKeeper::increase_channel_counter`. @@ -627,7 +593,7 @@ where Ok(()) } - fn get_client_validation_context(&self) -> &Self::ClientValidationContext { + fn get_client_validation_context(&self) -> &Self::V { self } } @@ -1005,34 +971,6 @@ where Ok(()) } - /// Called upon successful client update. - /// Implementations are expected to use this to record the specified time as the time at which - /// this update (or header) was processed. - fn store_update_time( - &mut self, - client_id: ClientId, - height: IbcHeight, - timestamp: Timestamp, - ) -> Result<(), ContextError> { - self.client_processed_times - .insert((client_id, height), timestamp); - Ok(()) - } - - /// Called upon successful client update. - /// Implementations are expected to use this to record the specified height as the height at - /// at which this update (or header) was processed. - fn store_update_height( - &mut self, - client_id: ClientId, - height: IbcHeight, - host_height: IbcHeight, - ) -> Result<(), ContextError> { - self.client_processed_heights - .insert((client_id, height), host_height); - Ok(()) - } - /// Stores the given connection_end at path fn store_connection( &mut self, diff --git a/crates/app/src/modules/upgrade/impls.rs b/crates/app/src/modules/upgrade/impls.rs index aaf89482..978ead22 100644 --- a/crates/app/src/modules/upgrade/impls.rs +++ b/crates/app/src/modules/upgrade/impls.rs @@ -216,7 +216,7 @@ impl UpgradeValidationContext for Upgrade where S: Store + Debug, { - type ClientValidationContext = IbcContext; + type V = IbcContext; type E = IbcContext; type AnyConsensusState = AnyConsensusState; type AnyClientState = TmClientState;