Skip to content

Commit 10b47c0

Browse files
authored
ValidationContext::{next,prev}_consensus_state() don't take a Path (#460)
* revert * doc
1 parent 317770c commit 10b47c0

File tree

5 files changed

+19
-28
lines changed

5 files changed

+19
-28
lines changed

crates/ibc/src/clients/ics07_tendermint/client_state.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,11 @@ impl Ics2ClientState for ClientState {
578578
}
579579
}
580580

581-
let client_cons_state_path = ClientConsensusStatePath::new(&client_id, &header.height());
582581
// Monotonicity checks for timestamps for in-the-middle updates
583582
// (cs-new, cs-next, cs-latest)
584583
if header.height() < client_state.latest_height() {
585584
let maybe_next_cs = ctx
586-
.next_consensus_state(&client_cons_state_path)
585+
.next_consensus_state(&client_id, &header.height())
587586
.map_err(|e| match e {
588587
ContextError::ClientError(e) => e,
589588
_ => ClientError::Other {
@@ -612,7 +611,7 @@ impl Ics2ClientState for ClientState {
612611
// (cs-trusted, cs-prev, cs-new)
613612
if header.trusted_height < header.height() {
614613
let maybe_prev_cs = ctx
615-
.prev_consensus_state(&client_cons_state_path)
614+
.prev_consensus_state(&client_id, &header.height())
616615
.map_err(|e| match e {
617616
ContextError::ClientError(e) => e,
618617
_ => ClientError::Other {

crates/ibc/src/core/context.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,15 @@ pub trait ValidationContext: Router {
256256
/// Search for the lowest consensus state higher than `height`.
257257
fn next_consensus_state(
258258
&self,
259-
next_client_cons_state_path: &ClientConsensusStatePath,
259+
client_id: &ClientId,
260+
height: &Height,
260261
) -> Result<Option<Box<dyn ConsensusState>>, ContextError>;
261262

262263
/// Search for the highest consensus state lower than `height`.
263264
fn prev_consensus_state(
264265
&self,
265-
prev_client_cons_state_path: &ClientConsensusStatePath,
266+
client_id: &ClientId,
267+
height: &Height,
266268
) -> Result<Option<Box<dyn ConsensusState>>, ContextError>;
267269

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

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

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

397400
/// Returns a counter on the number of channel ids have been created thus far.
398401
/// The value of this counter should increase only via method
399-
/// `ChannelKeeper::increase_channel_counter`.
402+
/// `ExecutionContext::increase_channel_counter`.
400403
fn channel_counter(&self) -> Result<u64, ContextError>;
401404

402405
/// Returns the maximum expected time per block

crates/ibc/src/core/handler.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ mod tests {
9898
#[test]
9999
/// These tests exercise two main paths: (1) the ability of the ICS26 routing module to dispatch
100100
/// messages to the correct module handler, and more importantly: (2) the ability of ICS handlers
101-
/// to work with the context and correctly store results (i.e., the `ClientKeeper`,
102-
/// `ConnectionKeeper`, and `ChannelKeeper` traits).
101+
/// to work with the context and correctly store results.
103102
fn routing_module_and_keepers() {
104103
#[derive(Clone, Debug)]
105104
enum TestMsg {

crates/ibc/src/core/ics04_channel/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//! ICS4 (channel) context. The two traits `ChannelReader ` and `ChannelKeeper` define
2-
//! the interface that any host chain must implement to be able to process any `ChannelMsg`.
1+
//! ICS4 (channel) context.
2+
33
use crate::core::ics02_client::client_state::ClientState;
44
use crate::core::ics24_host::path::{ChannelEndPath, ClientConsensusStatePath, SeqSendPath};
55
use crate::core::{ContextError, ValidationContext};

crates/ibc/src/mock/context.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -742,14 +742,9 @@ impl ValidationContext for MockContext {
742742

743743
fn next_consensus_state(
744744
&self,
745-
next_client_cons_state_path: &ClientConsensusStatePath,
745+
client_id: &ClientId,
746+
height: &Height,
746747
) -> Result<Option<Box<dyn ConsensusState>>, ContextError> {
747-
let client_id = &next_client_cons_state_path.client_id;
748-
let height = Height::new(
749-
next_client_cons_state_path.epoch,
750-
next_client_cons_state_path.height,
751-
)?;
752-
753748
let ibc_store = self.ibc_store.lock();
754749
let client_record =
755750
ibc_store
@@ -765,7 +760,7 @@ impl ValidationContext for MockContext {
765760

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

778773
fn prev_consensus_state(
779774
&self,
780-
prev_client_cons_state_path: &ClientConsensusStatePath,
775+
client_id: &ClientId,
776+
height: &Height,
781777
) -> Result<Option<Box<dyn ConsensusState>>, ContextError> {
782-
let client_id = &prev_client_cons_state_path.client_id;
783-
let height = Height::new(
784-
prev_client_cons_state_path.epoch,
785-
prev_client_cons_state_path.height,
786-
)?;
787-
788778
let ibc_store = self.ibc_store.lock();
789779
let client_record =
790780
ibc_store
@@ -800,7 +790,7 @@ impl ValidationContext for MockContext {
800790

801791
// Search for previous state.
802792
for h in heights {
803-
if h < height {
793+
if h < *height {
804794
// unwrap should never happen, as the consensus state for h must exist
805795
return Ok(Some(
806796
client_record.consensus_states.get(&h).unwrap().clone(),

0 commit comments

Comments
 (0)