Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate ChainEndpoint/Handle proven queries #2226

Merged
merged 26 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
67fc521
Remove TODO
plafer May 19, 2022
1e188f9
query_client_state consolidation
plafer May 19, 2022
cbf58a6
query_connection consolidation
plafer May 19, 2022
2c0292c
query_channel consolidation
plafer May 19, 2022
da744fe
Merge remote-tracking branch 'origin/master' into plafer/2223-consoli…
plafer May 20, 2022
8ee1343
Merge remote-tracking branch 'origin/master' into plafer/2223-consoli…
plafer May 26, 2022
69891bb
query_packet_commitment function
plafer May 26, 2022
76002e3
query_packet_acknowledgement
plafer May 26, 2022
3f8f927
query_packet_receipt
plafer May 26, 2022
5d296ea
query_next_sequence_receive
plafer May 27, 2022
a7ec4bb
use request instead of build_packet_proofs
plafer May 27, 2022
5ecb37a
build_packet_proofs now only returns proofs
plafer May 27, 2022
e205d00
build_packet_proofs no longer uses proven_packet
plafer May 27, 2022
d1b5d88
proven_packet removed
plafer May 27, 2022
c2f9689
query_consensus_state
plafer May 31, 2022
8f0eba9
remove proven_client_consensus
plafer May 31, 2022
150c43d
cleanup
plafer May 31, 2022
7bb9aeb
docstrings
plafer May 31, 2022
9245023
changelog
plafer May 31, 2022
e2d81ab
Merge remote-tracking branch 'origin/master' into plafer/2223-consoli…
plafer May 31, 2022
399e5f2
fix compilation errors
plafer Jun 1, 2022
65f3857
Merge remote-tracking branch 'origin/master' into plafer/2223-consoli…
plafer Jun 1, 2022
d857019
Merge branch 'master' into plafer/2223-consolidate-chain-query-proven
romac Jun 3, 2022
b03568b
Merge remote-tracking branch 'origin/master' into plafer/2223-consoli…
plafer Jun 6, 2022
5386516
Merge branch 'plafer/2223-consolidate-chain-query-proven' of github.c…
plafer Jun 6, 2022
54c8127
mock consensus_state query
plafer Jun 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Consolidate ChainEndpoint::proven_* methods with their corresponding query_*()
form ([#2223](https://github.com/informalsystems/ibc-rs/issues/2223))
20 changes: 0 additions & 20 deletions proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,6 @@ pub mod cosmos {
pub mod v1beta1 {
include_proto!("cosmos.base.query.v1beta1.rs");
}

// TODO (BEFORE MERGING PR): Remove
pub mod pagination {
use super::v1beta1::PageRequest;

pub fn all() -> Option<PageRequest> {
Some(PageRequest {
limit: u64::MAX,
..Default::default()
})
}

pub fn latest_limited(limit: u64) -> Option<PageRequest> {
Some(PageRequest {
limit,
reverse: true,
..Default::default()
})
}
}
}
pub mod reflection {
pub mod v1beta1 {
Expand Down
28 changes: 17 additions & 11 deletions relayer-cli/src/commands/create/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ibc::core::ics04_channel::Version;
use ibc::core::ics24_host::identifier::{ChainId, ConnectionId, PortId};
use ibc::Height;
use ibc_relayer::chain::handle::ChainHandle;
use ibc_relayer::chain::requests::{QueryClientStateRequest, QueryConnectionRequest};
use ibc_relayer::chain::requests::{IncludeProof, QueryClientStateRequest, QueryConnectionRequest};
use ibc_relayer::channel::Channel;
use ibc_relayer::connection::Connection;
use ibc_relayer::foreign_client::ForeignClient;
Expand Down Expand Up @@ -187,20 +187,26 @@ impl CreateChannelCommand {

// Query the connection end.
let height = Height::new(chain_a.id().version(), 0);
let conn_end = chain_a
.query_connection(QueryConnectionRequest {
connection_id: connection_a.clone(),
height,
})
let (conn_end, _) = chain_a
.query_connection(
QueryConnectionRequest {
connection_id: connection_a.clone(),
height,
},
IncludeProof::No,
)
.unwrap_or_else(exit_with_unrecoverable_error);

// Query the client state, obtain the identifier of chain b.
let chain_b = chain_a
.query_client_state(QueryClientStateRequest {
client_id: conn_end.client_id().clone(),
height,
})
.map(|cs| cs.chain_id())
.query_client_state(
QueryClientStateRequest {
client_id: conn_end.client_id().clone(),
height,
},
IncludeProof::No,
)
.map(|(cs, _)| cs.chain_id())
.unwrap_or_else(exit_with_unrecoverable_error);

// Spawn the runtime for side b.
Expand Down
15 changes: 9 additions & 6 deletions relayer-cli/src/commands/create/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ibc::core::ics02_client::client_state::ClientState;
use ibc::core::ics24_host::identifier::{ChainId, ClientId};
use ibc::Height;
use ibc_relayer::chain::handle::ChainHandle;
use ibc_relayer::chain::requests::QueryClientStateRequest;
use ibc_relayer::chain::requests::{IncludeProof, QueryClientStateRequest};
use ibc_relayer::connection::Connection;
use ibc_relayer::foreign_client::ForeignClient;

Expand Down Expand Up @@ -115,11 +115,14 @@ impl CreateConnectionCommand {

// Query client state. Extract the target chain (chain_id which this client is verifying).
let height = Height::new(chain_a.id().version(), 0);
let chain_b_id = match chain_a.query_client_state(QueryClientStateRequest {
client_id: client_a_id.clone(),
height,
}) {
Ok(cs) => cs.chain_id(),
let chain_b_id = match chain_a.query_client_state(
QueryClientStateRequest {
client_id: client_a_id.clone(),
height,
},
IncludeProof::No,
) {
Ok((cs, _)) => cs.chain_id(),
Err(e) => Output::error(format!(
"failed while querying client '{}' on chain '{}' with error: {}",
client_a_id, self.chain_a_id, e
Expand Down
15 changes: 9 additions & 6 deletions relayer-cli/src/commands/misbehaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ibc::core::ics02_client::height::Height;
use ibc::core::ics24_host::identifier::{ChainId, ClientId};
use ibc::events::IbcEvent;
use ibc_relayer::chain::handle::ChainHandle;
use ibc_relayer::chain::requests::QueryClientStateRequest;
use ibc_relayer::chain::requests::{IncludeProof, QueryClientStateRequest};
use ibc_relayer::config::Config;
use ibc_relayer::foreign_client::{ForeignClient, MisbehaviourResults};
use std::ops::Deref;
Expand Down Expand Up @@ -99,11 +99,14 @@ fn misbehaviour_handling<Chain: ChainHandle>(
client_id: ClientId,
update: Option<UpdateClient>,
) -> Result<(), Box<dyn std::error::Error>> {
let client_state = chain
.query_client_state(QueryClientStateRequest {
client_id: client_id.clone(),
height: Height::zero(),
})
let (client_state, _) = chain
.query_client_state(
QueryClientStateRequest {
client_id: client_id.clone(),
height: Height::zero(),
},
IncludeProof::No,
)
.map_err(|e| format!("could not query client state for {}: {}", client_id, e))?;

if client_state.is_frozen() {
Expand Down
17 changes: 10 additions & 7 deletions relayer-cli/src/commands/query/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tokio::runtime::Runtime as TokioRuntime;

use ibc::core::ics24_host::identifier::ChainId;
use ibc::core::ics24_host::identifier::{ChannelId, PortId};
use ibc_relayer::chain::requests::QueryChannelRequest;
use ibc_relayer::chain::requests::{IncludeProof, QueryChannelRequest};
use ibc_relayer::chain::{ChainEndpoint, CosmosSdkChain};

use crate::conclude::{exit_with_unrecoverable_error, Output};
Expand Down Expand Up @@ -47,13 +47,16 @@ impl Runnable for QueryChannelEndCmd {
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt)
.unwrap_or_else(exit_with_unrecoverable_error);

let res = chain.query_channel(QueryChannelRequest {
port_id: self.port_id.clone(),
channel_id: self.channel_id,
height: ibc::Height::new(chain.id().version(), self.height.unwrap_or(0_u64)),
});
let res = chain.query_channel(
QueryChannelRequest {
port_id: self.port_id.clone(),
channel_id: self.channel_id,
height: ibc::Height::new(chain.id().version(), self.height.unwrap_or(0_u64)),
},
IncludeProof::No,
);
match res {
Ok(channel_end) => {
Ok((channel_end, _)) => {
if channel_end.state_matches(&State::Uninitialized) {
Output::error(format!(
"port '{}' & channel '{}' does not exist",
Expand Down
68 changes: 42 additions & 26 deletions relayer-cli/src/commands/query/channel_ends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ibc::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortI
use ibc::Height;
use ibc_relayer::chain::handle::{BaseChainHandle, ChainHandle};
use ibc_relayer::chain::requests::{
QueryChannelRequest, QueryClientStateRequest, QueryConnectionRequest,
IncludeProof, QueryChannelRequest, QueryClientStateRequest, QueryConnectionRequest,
};
use ibc_relayer::registry::Registry;

Expand Down Expand Up @@ -81,11 +81,14 @@ fn do_run<Chain: ChainHandle>(cmd: &QueryChannelEndsCmd) -> Result<(), Box<dyn s
None => chain.query_latest_height()?,
};

let channel_end = chain.query_channel(QueryChannelRequest {
port_id: port_id.clone(),
channel_id,
height: chain_height,
})?;
let (channel_end, _) = chain.query_channel(
QueryChannelRequest {
port_id: port_id.clone(),
channel_id,
height: chain_height,
},
IncludeProof::No,
)?;
if channel_end.state_matches(&State::Uninitialized) {
return Err(format!(
"{}/{} on chain {} @ {:?} is uninitialized",
Expand All @@ -105,17 +108,23 @@ fn do_run<Chain: ChainHandle>(cmd: &QueryChannelEndsCmd) -> Result<(), Box<dyn s
})?
.clone();

let connection_end = chain.query_connection(QueryConnectionRequest {
connection_id: connection_id.clone(),
height: chain_height,
})?;
let (connection_end, _) = chain.query_connection(
QueryConnectionRequest {
connection_id: connection_id.clone(),
height: chain_height,
},
IncludeProof::No,
)?;

let client_id = connection_end.client_id().clone();

let client_state = chain.query_client_state(QueryClientStateRequest {
client_id: client_id.clone(),
height: chain_height,
})?;
let (client_state, _) = chain.query_client_state(
QueryClientStateRequest {
client_id: client_id.clone(),
height: chain_height,
},
IncludeProof::No,
)?;

let channel_counterparty = channel_end.counterparty().clone();
let connection_counterparty = connection_end.counterparty().clone();
Expand Down Expand Up @@ -145,23 +154,30 @@ fn do_run<Chain: ChainHandle>(cmd: &QueryChannelEndsCmd) -> Result<(), Box<dyn s
let counterparty_chain = registry.get_or_spawn(&counterparty_chain_id)?;
let counterparty_chain_height = counterparty_chain.query_latest_height()?;

let counterparty_connection_end =
counterparty_chain.query_connection(QueryConnectionRequest {
let (counterparty_connection_end, _) = counterparty_chain.query_connection(
QueryConnectionRequest {
connection_id: counterparty_connection_id.clone(),
height: counterparty_chain_height,
})?;
},
IncludeProof::No,
)?;

let counterparty_client_state =
counterparty_chain.query_client_state(QueryClientStateRequest {
let (counterparty_client_state, _) = counterparty_chain.query_client_state(
QueryClientStateRequest {
client_id: counterparty_client_id.clone(),
height: counterparty_chain_height,
})?;

let counterparty_channel_end = counterparty_chain.query_channel(QueryChannelRequest {
port_id: counterparty_port_id.clone(),
channel_id: counterparty_channel_id,
height: counterparty_chain_height,
})?;
},
IncludeProof::No,
)?;

let (counterparty_channel_end, _) = counterparty_chain.query_channel(
QueryChannelRequest {
port_id: counterparty_port_id.clone(),
channel_id: counterparty_channel_id,
height: counterparty_chain_height,
},
IncludeProof::No,
)?;

if cmd.verbose {
let res = ChannelEnds {
Expand Down
55 changes: 34 additions & 21 deletions relayer-cli/src/commands/query/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ibc::core::ics24_host::identifier::{ChainId, ChannelId, ConnectionId, PortCh
use ibc::Height;
use ibc_relayer::chain::handle::{BaseChainHandle, ChainHandle};
use ibc_relayer::chain::requests::{
PageRequest, QueryChannelRequest, QueryChannelsRequest, QueryClientStateRequest,
IncludeProof, PageRequest, QueryChannelRequest, QueryChannelsRequest, QueryClientStateRequest,
QueryConnectionRequest,
};
use ibc_relayer::registry::Registry;
Expand Down Expand Up @@ -126,15 +126,21 @@ fn query_channel_ends<Chain: ChainHandle>(
channel_id: ChannelId,
chain_height: Height,
) -> Result<ChannelEnds, Box<dyn std::error::Error>> {
let connection_end = chain.query_connection(QueryConnectionRequest {
connection_id: connection_id.clone(),
height: chain_height,
})?;
let (connection_end, _) = chain.query_connection(
QueryConnectionRequest {
connection_id: connection_id.clone(),
height: chain_height,
},
IncludeProof::No,
)?;
let client_id = connection_end.client_id().clone();
let client_state = chain.query_client_state(QueryClientStateRequest {
client_id,
height: chain_height,
})?;
let (client_state, _) = chain.query_client_state(
QueryClientStateRequest {
client_id,
height: chain_height,
},
IncludeProof::No,
)?;
let counterparty_chain_id = client_state.chain_id();

if let Some(dst_chain_id) = destination_chain {
Expand Down Expand Up @@ -173,23 +179,30 @@ fn query_channel_ends<Chain: ChainHandle>(
let counterparty_chain = registry.get_or_spawn(&counterparty_chain_id)?;
let counterparty_chain_height = counterparty_chain.query_latest_height()?;

let counterparty_connection_end =
counterparty_chain.query_connection(QueryConnectionRequest {
let (counterparty_connection_end, _) = counterparty_chain.query_connection(
QueryConnectionRequest {
connection_id: counterparty_connection_id,
height: counterparty_chain_height,
})?;
},
IncludeProof::No,
)?;

let counterparty_client_state =
counterparty_chain.query_client_state(QueryClientStateRequest {
let (counterparty_client_state, _) = counterparty_chain.query_client_state(
QueryClientStateRequest {
client_id: counterparty_client_id,
height: counterparty_chain_height,
})?;

let counterparty_channel_end = counterparty_chain.query_channel(QueryChannelRequest {
port_id: counterparty_port_id,
channel_id: counterparty_channel_id,
height: counterparty_chain_height,
})?;
},
IncludeProof::No,
)?;

let (counterparty_channel_end, _) = counterparty_chain.query_channel(
QueryChannelRequest {
port_id: counterparty_port_id,
channel_id: counterparty_channel_id,
height: counterparty_chain_height,
},
IncludeProof::No,
)?;

Ok(ChannelEnds {
channel_end,
Expand Down
Loading