Skip to content

Commit

Permalink
imp: tracks ibc-rs pr915
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhad-Shabani committed Oct 11, 2023
1 parent 9610b29 commit 96f3123
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 79 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/abci/v0_37/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
84 changes: 78 additions & 6 deletions crates/app/src/modules/ibc/client_contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S> ClientValidationContext for IbcContext<S>
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<Timestamp, ContextError> {
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<IbcHeight, ContextError> {
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<S> ClientExecutionContext for IbcContext<S>
where
S: Store + Debug,
{
type ClientValidationContext = Self;
type V = Self;

type AnyClientState = TmClientState;

Expand Down Expand Up @@ -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<S> CommonContext for IbcContext<S>
Expand All @@ -66,6 +134,14 @@ where
type ConversionError = &'static str;
type AnyConsensusState = AnyConsensusState;

fn host_timestamp(&self) -> Result<Timestamp, ContextError> {
ValidationContext::host_timestamp(self)
}

fn host_height(&self) -> Result<IbcHeight, ContextError> {
ValidationContext::host_height(self)
}

fn consensus_state(
&self,
client_cons_state_path: &ClientConsensusStatePath,
Expand All @@ -78,10 +154,6 @@ impl<S> TmValidationContext for IbcContext<S>
where
S: Store + Debug,
{
fn host_timestamp(&self) -> Result<Timestamp, ContextError> {
ValidationContext::host_timestamp(self)
}

fn next_consensus_state(
&self,
client_id: &ClientId,
Expand Down
70 changes: 4 additions & 66 deletions crates/app/src/modules/ibc/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RwLock<HashMap<u64, TmConsensusState>>>,
/// A typed-store for AnyClientState
Expand Down Expand Up @@ -384,7 +384,7 @@ impl<S> ValidationContext for IbcContext<S>
where
S: Store + Debug,
{
type ClientValidationContext = Self;
type V = Self;
type E = Self;
type AnyConsensusState = AnyConsensusState;
type AnyClientState = TmClientState;
Expand Down Expand Up @@ -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<Timestamp, ContextError> {
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<IbcHeight, ContextError> {
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`.
Expand All @@ -627,7 +593,7 @@ where
Ok(())
}

fn get_client_validation_context(&self) -> &Self::ClientValidationContext {
fn get_client_validation_context(&self) -> &Self::V {
self
}
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/modules/upgrade/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<S> UpgradeValidationContext for Upgrade<S>
where
S: Store + Debug,
{
type ClientValidationContext = IbcContext<S>;
type V = IbcContext<S>;
type E = IbcContext<S>;
type AnyConsensusState = AnyConsensusState;
type AnyClientState = TmClientState;
Expand Down

0 comments on commit 96f3123

Please sign in to comment.