Skip to content

Commit

Permalink
ValidationContext::{next,prev}_consensus_state() don't take a Path (#…
Browse files Browse the repository at this point in the history
…460)

* revert

* doc
  • Loading branch information
plafer authored Feb 21, 2023
1 parent 317770c commit 10b47c0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 28 deletions.
5 changes: 2 additions & 3 deletions crates/ibc/src/clients/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,11 @@ impl Ics2ClientState for ClientState {
}
}

let client_cons_state_path = ClientConsensusStatePath::new(&client_id, &header.height());
// Monotonicity checks for timestamps for in-the-middle updates
// (cs-new, cs-next, cs-latest)
if header.height() < client_state.latest_height() {
let maybe_next_cs = ctx
.next_consensus_state(&client_cons_state_path)
.next_consensus_state(&client_id, &header.height())
.map_err(|e| match e {
ContextError::ClientError(e) => e,
_ => ClientError::Other {
Expand Down Expand Up @@ -612,7 +611,7 @@ impl Ics2ClientState for ClientState {
// (cs-trusted, cs-prev, cs-new)
if header.trusted_height < header.height() {
let maybe_prev_cs = ctx
.prev_consensus_state(&client_cons_state_path)
.prev_consensus_state(&client_id, &header.height())
.map_err(|e| match e {
ContextError::ClientError(e) => e,
_ => ClientError::Other {
Expand Down
13 changes: 8 additions & 5 deletions crates/ibc/src/core/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,15 @@ pub trait ValidationContext: Router {
/// Search for the lowest consensus state higher than `height`.
fn next_consensus_state(
&self,
next_client_cons_state_path: &ClientConsensusStatePath,
client_id: &ClientId,
height: &Height,
) -> Result<Option<Box<dyn ConsensusState>>, ContextError>;

/// Search for the highest consensus state lower than `height`.
fn prev_consensus_state(
&self,
prev_client_cons_state_path: &ClientConsensusStatePath,
client_id: &ClientId,
height: &Height,
) -> Result<Option<Box<dyn ConsensusState>>, ContextError>;

/// Returns the current height of the local chain.
Expand All @@ -277,8 +279,9 @@ pub trait ValidationContext: Router {
height: &Height,
) -> Result<Box<dyn ConsensusState>, ContextError>;

/// Returns a natural number, counting how many clients have been created thus far.
/// The value of this counter should increase only via method `ClientKeeper::increase_client_counter`.
/// Returns a natural number, counting how many clients have been created
/// thus far. The value of this counter should increase only via method
/// `ExecutionContext::increase_client_counter`.
fn client_counter(&self) -> Result<u64, ContextError>;

/// Returns the ConnectionEnd for the given identifier `conn_id`.
Expand Down Expand Up @@ -396,7 +399,7 @@ pub trait ValidationContext: Router {

/// 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`.
/// `ExecutionContext::increase_channel_counter`.
fn channel_counter(&self) -> Result<u64, ContextError>;

/// Returns the maximum expected time per block
Expand Down
3 changes: 1 addition & 2 deletions crates/ibc/src/core/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ mod tests {
#[test]
/// These tests exercise two main paths: (1) the ability of the ICS26 routing module to dispatch
/// messages to the correct module handler, and more importantly: (2) the ability of ICS handlers
/// to work with the context and correctly store results (i.e., the `ClientKeeper`,
/// `ConnectionKeeper`, and `ChannelKeeper` traits).
/// to work with the context and correctly store results.
fn routing_module_and_keepers() {
#[derive(Clone, Debug)]
enum TestMsg {
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/core/ics04_channel/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! ICS4 (channel) context. The two traits `ChannelReader ` and `ChannelKeeper` define
//! the interface that any host chain must implement to be able to process any `ChannelMsg`.
//! ICS4 (channel) context.
use crate::core::ics02_client::client_state::ClientState;
use crate::core::ics24_host::path::{ChannelEndPath, ClientConsensusStatePath, SeqSendPath};
use crate::core::{ContextError, ValidationContext};
Expand Down
22 changes: 6 additions & 16 deletions crates/ibc/src/mock/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,14 +742,9 @@ impl ValidationContext for MockContext {

fn next_consensus_state(
&self,
next_client_cons_state_path: &ClientConsensusStatePath,
client_id: &ClientId,
height: &Height,
) -> Result<Option<Box<dyn ConsensusState>>, ContextError> {
let client_id = &next_client_cons_state_path.client_id;
let height = Height::new(
next_client_cons_state_path.epoch,
next_client_cons_state_path.height,
)?;

let ibc_store = self.ibc_store.lock();
let client_record =
ibc_store
Expand All @@ -765,7 +760,7 @@ impl ValidationContext for MockContext {

// Search for next state.
for h in heights {
if h > height {
if h > *height {
// unwrap should never happen, as the consensus state for h must exist
return Ok(Some(
client_record.consensus_states.get(&h).unwrap().clone(),
Expand All @@ -777,14 +772,9 @@ impl ValidationContext for MockContext {

fn prev_consensus_state(
&self,
prev_client_cons_state_path: &ClientConsensusStatePath,
client_id: &ClientId,
height: &Height,
) -> Result<Option<Box<dyn ConsensusState>>, ContextError> {
let client_id = &prev_client_cons_state_path.client_id;
let height = Height::new(
prev_client_cons_state_path.epoch,
prev_client_cons_state_path.height,
)?;

let ibc_store = self.ibc_store.lock();
let client_record =
ibc_store
Expand All @@ -800,7 +790,7 @@ impl ValidationContext for MockContext {

// Search for previous state.
for h in heights {
if h < height {
if h < *height {
// unwrap should never happen, as the consensus state for h must exist
return Ok(Some(
client_record.consensus_states.get(&h).unwrap().clone(),
Expand Down

0 comments on commit 10b47c0

Please sign in to comment.