diff --git a/.changelog/unreleased/improvements/relayer/2192-adr009-impl.md b/.changelog/unreleased/improvements/relayer/2192-adr009-impl.md new file mode 100644 index 0000000000..ab1172cbcf --- /dev/null +++ b/.changelog/unreleased/improvements/relayer/2192-adr009-impl.md @@ -0,0 +1,2 @@ +- Implement ADR 9: add domain type for request messages that are passed to query + functions ([#2192](https://github.com/informalsystems/ibc-rs/issues/2192)) \ No newline at end of file diff --git a/relayer-cli/src/commands/create/channel.rs b/relayer-cli/src/commands/create/channel.rs index 5118ae1a79..f26fa1fe2e 100644 --- a/relayer-cli/src/commands/create/channel.rs +++ b/relayer-cli/src/commands/create/channel.rs @@ -11,6 +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::channel::Channel; use ibc_relayer::connection::Connection; use ibc_relayer::foreign_client::ForeignClient; @@ -187,12 +188,18 @@ impl CreateChannelCommand { // Query the connection end. let height = Height::new(chain_a.id().version(), 0); let conn_end = chain_a - .query_connection(connection_a, height) + .query_connection(QueryConnectionRequest { + connection_id: connection_a.clone(), + height, + }) .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(conn_end.client_id(), height) + .query_client_state(QueryClientStateRequest { + client_id: conn_end.client_id().clone(), + height, + }) .map(|cs| cs.chain_id()) .unwrap_or_else(exit_with_unrecoverable_error); diff --git a/relayer-cli/src/commands/create/connection.rs b/relayer-cli/src/commands/create/connection.rs index 82a566e9c3..d8377287ea 100644 --- a/relayer-cli/src/commands/create/connection.rs +++ b/relayer-cli/src/commands/create/connection.rs @@ -7,6 +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::connection::Connection; use ibc_relayer::foreign_client::ForeignClient; @@ -114,7 +115,10 @@ 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(client_a_id, height) { + let chain_b_id = match chain_a.query_client_state(QueryClientStateRequest { + client_id: client_a_id.clone(), + height, + }) { Ok(cs) => cs.chain_id(), Err(e) => Output::error(format!( "failed while querying client '{}' on chain '{}' with error: {}", diff --git a/relayer-cli/src/commands/misbehaviour.rs b/relayer-cli/src/commands/misbehaviour.rs index e1b07c276b..2b33c5171d 100644 --- a/relayer-cli/src/commands/misbehaviour.rs +++ b/relayer-cli/src/commands/misbehaviour.rs @@ -5,6 +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::config::Config; use ibc_relayer::foreign_client::{ForeignClient, MisbehaviourResults}; use std::ops::Deref; @@ -99,7 +100,10 @@ fn misbehaviour_handling( update: Option, ) -> Result<(), Box> { let client_state = chain - .query_client_state(&client_id, Height::zero()) + .query_client_state(QueryClientStateRequest { + client_id: client_id.clone(), + height: Height::zero(), + }) .map_err(|e| format!("could not query client state for {}: {}", client_id, e))?; if client_state.is_frozen() { diff --git a/relayer-cli/src/commands/query/channel.rs b/relayer-cli/src/commands/query/channel.rs index b8165b5e79..24cef1d005 100644 --- a/relayer-cli/src/commands/query/channel.rs +++ b/relayer-cli/src/commands/query/channel.rs @@ -6,6 +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::{ChainEndpoint, CosmosSdkChain}; use crate::conclude::{exit_with_unrecoverable_error, Output}; @@ -46,8 +47,11 @@ impl Runnable for QueryChannelEndCmd { let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt) .unwrap_or_else(exit_with_unrecoverable_error); - let height = ibc::Height::new(chain.id().version(), self.height.unwrap_or(0_u64)); - let res = chain.query_channel(&self.port_id, &self.channel_id, height); + 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)), + }); match res { Ok(channel_end) => { if channel_end.state_matches(&State::Uninitialized) { diff --git a/relayer-cli/src/commands/query/channel_ends.rs b/relayer-cli/src/commands/query/channel_ends.rs index 669cd02c6c..774ae64f6c 100644 --- a/relayer-cli/src/commands/query/channel_ends.rs +++ b/relayer-cli/src/commands/query/channel_ends.rs @@ -9,6 +9,9 @@ use ibc::core::ics24_host::identifier::ChainId; use ibc::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; use ibc::Height; use ibc_relayer::chain::handle::{BaseChainHandle, ChainHandle}; +use ibc_relayer::chain::requests::{ + QueryChannelRequest, QueryClientStateRequest, QueryConnectionRequest, +}; use ibc_relayer::registry::Registry; use crate::conclude::Output; @@ -78,7 +81,11 @@ fn do_run(cmd: &QueryChannelEndsCmd) -> Result<(), Box chain.query_latest_height()?, }; - let channel_end = chain.query_channel(&port_id, &channel_id, chain_height)?; + let channel_end = chain.query_channel(QueryChannelRequest { + port_id: port_id.clone(), + channel_id, + height: chain_height, + })?; if channel_end.state_matches(&State::Uninitialized) { return Err(format!( "{}/{} on chain {} @ {:?} is uninitialized", @@ -98,11 +105,17 @@ fn do_run(cmd: &QueryChannelEndsCmd) -> Result<(), Box(cmd: &QueryChannelEndsCmd) -> Result<(), Box( let chain = registry.get_or_spawn(&cmd.chain_id)?; let chain_height = chain.query_latest_height()?; - let req = QueryChannelsRequest { - pagination: ibc_proto::cosmos::base::query::pagination::all(), - }; - - let identified_channels = chain.query_channels(req)?; + let identified_channels = chain.query_channels(QueryChannelsRequest { + pagination: Some(PageRequest::all()), + })?; for identified_channel in identified_channels { let port_id = identified_channel.port_id; @@ -125,9 +126,15 @@ fn query_channel_ends( channel_id: ChannelId, chain_height: Height, ) -> Result> { - let connection_end = chain.query_connection(&connection_id, chain_height)?; + let connection_end = chain.query_connection(QueryConnectionRequest { + connection_id: connection_id.clone(), + height: chain_height, + })?; let client_id = connection_end.client_id().clone(); - let client_state = chain.query_client_state(&client_id, chain_height)?; + let client_state = chain.query_client_state(QueryClientStateRequest { + client_id, + height: chain_height, + })?; let counterparty_chain_id = client_state.chain_id(); if let Some(dst_chain_id) = destination_chain { @@ -166,17 +173,23 @@ fn query_channel_ends( 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(&counterparty_connection_id, counterparty_chain_height)?; - - let counterparty_client_state = counterparty_chain - .query_client_state(&counterparty_client_id, counterparty_chain_height)?; - - let counterparty_channel_end = counterparty_chain.query_channel( - &counterparty_port_id, - &counterparty_channel_id, - counterparty_chain_height, - )?; + let counterparty_connection_end = + counterparty_chain.query_connection(QueryConnectionRequest { + connection_id: counterparty_connection_id, + height: counterparty_chain_height, + })?; + + 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, + })?; Ok(ChannelEnds { channel_end, diff --git a/relayer-cli/src/commands/query/client.rs b/relayer-cli/src/commands/query/client.rs index ce1fb8637a..f23c0fc40b 100644 --- a/relayer-cli/src/commands/query/client.rs +++ b/relayer-cli/src/commands/query/client.rs @@ -2,6 +2,10 @@ use alloc::sync::Arc; use abscissa_core::clap::Parser; use abscissa_core::{Command, Runnable}; +use ibc_relayer::chain::requests::{ + PageRequest, QueryClientConnectionsRequest, QueryClientStateRequest, + QueryConsensusStateRequest, QueryConsensusStatesRequest, +}; use tokio::runtime::Runtime as TokioRuntime; use tracing::debug; @@ -12,8 +16,6 @@ use ibc::core::ics24_host::identifier::ClientId; use ibc::events::WithBlockDataType; use ibc::query::QueryTxRequest; use ibc::Height; -use ibc_proto::ibc::core::client::v1::QueryConsensusStatesRequest; -use ibc_proto::ibc::core::connection::v1::QueryClientConnectionsRequest; use ibc_relayer::chain::ChainEndpoint; use ibc_relayer::chain::CosmosSdkChain; @@ -53,7 +55,10 @@ impl Runnable for QueryClientStateCmd { .unwrap_or_else(exit_with_unrecoverable_error); let height = ibc::Height::new(chain.id().version(), self.height.unwrap_or(0_u64)); - match chain.query_client_state(&self.client_id, height) { + match chain.query_client_state(QueryClientStateRequest { + client_id: self.client_id.clone(), + height, + }) { Ok(cs) => Output::success(cs).exit(), Err(e) => Output::error(format!("{}", e)).exit(), } @@ -108,7 +113,10 @@ impl Runnable for QueryClientConsensusCmd { let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt) .unwrap_or_else(exit_with_unrecoverable_error); - let counterparty_chain = match chain.query_client_state(&self.client_id, Height::zero()) { + let counterparty_chain = match chain.query_client_state(QueryClientStateRequest { + client_id: self.client_id.clone(), + height: Height::zero(), + }) { Ok(cs) => cs.chain_id(), Err(e) => Output::error(format!( "failed while querying client '{}' on chain '{}' with error: {}", @@ -122,8 +130,11 @@ impl Runnable for QueryClientConsensusCmd { let height = ibc::Height::new(chain.id().version(), self.height.unwrap_or(0_u64)); let consensus_height = ibc::Height::new(counterparty_chain.version(), cs_height); - let res = - chain.query_consensus_state(self.client_id.clone(), consensus_height, height); + let res = chain.query_consensus_state(QueryConsensusStateRequest { + client_id: self.client_id.clone(), + consensus_height, + query_height: height, + }); match res { Ok(cs) => Output::success(cs).exit(), @@ -132,8 +143,8 @@ impl Runnable for QueryClientConsensusCmd { } None => { let res = chain.query_consensus_states(QueryConsensusStatesRequest { - client_id: self.client_id.to_string(), - pagination: ibc_proto::cosmos::base::query::pagination::all(), + client_id: self.client_id.clone(), + pagination: Some(PageRequest::all()), }); match res { @@ -188,7 +199,10 @@ impl Runnable for QueryClientHeaderCmd { let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt) .unwrap_or_else(exit_with_unrecoverable_error); - let counterparty_chain = match chain.query_client_state(&self.client_id, Height::zero()) { + let counterparty_chain = match chain.query_client_state(QueryClientStateRequest { + client_id: self.client_id.clone(), + height: Height::zero(), + }) { Ok(cs) => cs.chain_id(), Err(e) => Output::error(format!( "failed while querying client '{}' on chain '{}' with error: {}", @@ -252,11 +266,9 @@ impl Runnable for QueryClientConnectionsCmd { let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt) .unwrap_or_else(exit_with_unrecoverable_error); - let req = QueryClientConnectionsRequest { - client_id: self.client_id.to_string(), - }; - - let res = chain.query_client_connections(req); + let res = chain.query_client_connections(QueryClientConnectionsRequest { + client_id: self.client_id.clone(), + }); match res { Ok(ce) => Output::success(ce).exit(), diff --git a/relayer-cli/src/commands/query/clients.rs b/relayer-cli/src/commands/query/clients.rs index 15c72b84d8..e6ca161980 100644 --- a/relayer-cli/src/commands/query/clients.rs +++ b/relayer-cli/src/commands/query/clients.rs @@ -7,7 +7,7 @@ use tokio::runtime::Runtime as TokioRuntime; use ibc::core::ics02_client::client_state::ClientState; use ibc::core::ics24_host::identifier::{ChainId, ClientId}; -use ibc_proto::ibc::core::client::v1::QueryClientStatesRequest; +use ibc_relayer::chain::requests::{PageRequest, QueryClientStatesRequest}; use ibc_relayer::chain::{ChainEndpoint, CosmosSdkChain}; use crate::conclude::{exit_with_unrecoverable_error, Output}; @@ -60,7 +60,7 @@ impl Runnable for QueryAllClientsCmd { .unwrap_or_else(exit_with_unrecoverable_error); let req = QueryClientStatesRequest { - pagination: ibc_proto::cosmos::base::query::pagination::all(), + pagination: Some(PageRequest::all()), }; let res: Result<_, Error> = chain.query_clients(req).map_err(Error::relayer); diff --git a/relayer-cli/src/commands/query/connection.rs b/relayer-cli/src/commands/query/connection.rs index 62dcc99d2a..ea1288dddb 100644 --- a/relayer-cli/src/commands/query/connection.rs +++ b/relayer-cli/src/commands/query/connection.rs @@ -2,6 +2,9 @@ use alloc::sync::Arc; use abscissa_core::clap::Parser; use abscissa_core::{Command, Runnable}; +use ibc_relayer::chain::requests::{ + PageRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, +}; use tokio::runtime::Runtime as TokioRuntime; use ibc::core::{ @@ -9,7 +12,6 @@ use ibc::core::{ ics24_host::identifier::ConnectionId, ics24_host::identifier::{ChainId, PortChannelId}, }; -use ibc_proto::ibc::core::channel::v1::QueryConnectionChannelsRequest; use ibc_relayer::chain::{ChainEndpoint, CosmosSdkChain}; use crate::conclude::{exit_with_unrecoverable_error, Output}; @@ -49,7 +51,10 @@ impl Runnable for QueryConnectionEndCmd { .unwrap_or_else(exit_with_unrecoverable_error); let height = ibc::Height::new(chain.id().version(), self.height.unwrap_or(0_u64)); - let res = chain.query_connection(&self.connection_id, height); + let res = chain.query_connection(QueryConnectionRequest { + connection_id: self.connection_id.clone(), + height, + }); match res { Ok(connection_end) => { if connection_end.state_matches(&State::Uninitialized) { @@ -98,12 +103,12 @@ impl Runnable for QueryConnectionChannelsCmd { let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt) .unwrap_or_else(exit_with_unrecoverable_error); - let req = QueryConnectionChannelsRequest { - connection: self.connection_id.to_string(), - pagination: ibc_proto::cosmos::base::query::pagination::all(), - }; - - let res: Result<_, Error> = chain.query_connection_channels(req).map_err(Error::relayer); + let res: Result<_, Error> = chain + .query_connection_channels(QueryConnectionChannelsRequest { + connection_id: self.connection_id.clone(), + pagination: Some(PageRequest::all()), + }) + .map_err(Error::relayer); match res { Ok(channels) => { diff --git a/relayer-cli/src/commands/query/connections.rs b/relayer-cli/src/commands/query/connections.rs index bbcbf4cd5c..60aa94139e 100644 --- a/relayer-cli/src/commands/query/connections.rs +++ b/relayer-cli/src/commands/query/connections.rs @@ -2,10 +2,10 @@ use alloc::sync::Arc; use abscissa_core::clap::Parser; use abscissa_core::Runnable; +use ibc_relayer::chain::requests::{PageRequest, QueryConnectionsRequest}; use tokio::runtime::Runtime as TokioRuntime; use ibc::core::ics24_host::identifier::{ChainId, ConnectionId}; -use ibc_proto::ibc::core::connection::v1::QueryConnectionsRequest; use ibc_relayer::chain::{ChainEndpoint, CosmosSdkChain}; use crate::conclude::{exit_with_unrecoverable_error, Output}; @@ -37,11 +37,9 @@ impl Runnable for QueryConnectionsCmd { let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt) .unwrap_or_else(exit_with_unrecoverable_error); - let req = QueryConnectionsRequest { - pagination: ibc_proto::cosmos::base::query::pagination::all(), - }; - - let res = chain.query_connections(req); + let res = chain.query_connections(QueryConnectionsRequest { + pagination: Some(PageRequest::all()), + }); match res { Ok(connections) => { diff --git a/relayer-cli/src/commands/query/packet/acks.rs b/relayer-cli/src/commands/query/packet/acks.rs index 12f2a07e40..d7179dc79d 100644 --- a/relayer-cli/src/commands/query/packet/acks.rs +++ b/relayer-cli/src/commands/query/packet/acks.rs @@ -1,5 +1,6 @@ use abscissa_core::clap::Parser; use abscissa_core::{Command, Runnable}; +use ibc::core::ics04_channel::packet::Sequence; use serde::Serialize; use ibc::core::ics24_host::identifier::{ChainId, ChannelId, PortId}; @@ -15,7 +16,7 @@ use ibc_relayer::chain::counterparty::acknowledgements_on_chain; #[derive(Serialize, Debug)] struct PacketSeqs { height: Height, - seqs: Vec, + seqs: Vec, } #[derive(Clone, Command, Debug, Parser)] diff --git a/relayer-cli/src/commands/query/packet/commitments.rs b/relayer-cli/src/commands/query/packet/commitments.rs index eef2476b24..15dfcac521 100644 --- a/relayer-cli/src/commands/query/packet/commitments.rs +++ b/relayer-cli/src/commands/query/packet/commitments.rs @@ -1,5 +1,6 @@ use abscissa_core::clap::Parser; use abscissa_core::{Command, Runnable}; +use ibc::core::ics04_channel::packet::Sequence; use serde::Serialize; use ibc::core::ics24_host::identifier::{ChainId, ChannelId, PortId}; @@ -14,7 +15,7 @@ use crate::prelude::*; #[derive(Serialize, Debug)] struct PacketSeqs { height: Height, - seqs: Vec, + seqs: Vec, } #[derive(Clone, Command, Debug, Parser)] diff --git a/relayer-cli/src/commands/query/packet/unreceived_acks.rs b/relayer-cli/src/commands/query/packet/unreceived_acks.rs index 225116bf72..a27ee607b3 100644 --- a/relayer-cli/src/commands/query/packet/unreceived_acks.rs +++ b/relayer-cli/src/commands/query/packet/unreceived_acks.rs @@ -1,6 +1,7 @@ use abscissa_core::clap::Parser; use abscissa_core::{Command, Runnable}; +use ibc::core::ics04_channel::packet::Sequence; use ibc::core::ics24_host::identifier::{ChainId, ChannelId, PortId}; use ibc_relayer::chain::counterparty::unreceived_acknowledgements; use ibc_relayer::chain::handle::BaseChainHandle; @@ -30,7 +31,7 @@ pub struct QueryUnreceivedAcknowledgementCmd { } impl QueryUnreceivedAcknowledgementCmd { - fn execute(&self) -> Result, Error> { + fn execute(&self) -> Result, Error> { let config = app_config(); debug!("Options: {:?}", self); diff --git a/relayer-cli/src/commands/query/packet/unreceived_packets.rs b/relayer-cli/src/commands/query/packet/unreceived_packets.rs index 0fa14056bf..fe027c50d7 100644 --- a/relayer-cli/src/commands/query/packet/unreceived_packets.rs +++ b/relayer-cli/src/commands/query/packet/unreceived_packets.rs @@ -1,6 +1,7 @@ use abscissa_core::clap::Parser; use abscissa_core::{Command, Runnable}; +use ibc::core::ics04_channel::packet::Sequence; use ibc::core::ics24_host::identifier::{ChainId, ChannelId, PortId}; use ibc_relayer::chain::counterparty::unreceived_packets; use ibc_relayer::chain::handle::BaseChainHandle; @@ -30,7 +31,7 @@ pub struct QueryUnreceivedPacketsCmd { } impl QueryUnreceivedPacketsCmd { - fn execute(&self) -> Result, Error> { + fn execute(&self) -> Result, Error> { let config = app_config(); debug!("Options: {:?}", self); diff --git a/relayer-cli/src/commands/tx/channel.rs b/relayer-cli/src/commands/tx/channel.rs index a206221b59..3aa61c2fe7 100644 --- a/relayer-cli/src/commands/tx/channel.rs +++ b/relayer-cli/src/commands/tx/channel.rs @@ -7,6 +7,7 @@ use ibc::core::ics24_host::identifier::{ChainId, ChannelId, ClientId, Connection use ibc::events::IbcEvent; use ibc::Height; use ibc_relayer::chain::handle::ChainHandle; +use ibc_relayer::chain::requests::QueryConnectionRequest; use ibc_relayer::channel::{Channel, ChannelSide}; use crate::cli_utils::ChainHandlePair; @@ -25,10 +26,10 @@ macro_rules! tx_chan_cmd { }; // Retrieve the connection - let dst_connection = match chains - .dst - .query_connection(&$self.dst_conn_id, Height::default()) - { + let dst_connection = match chains.dst.query_connection(QueryConnectionRequest { + connection_id: $self.dst_conn_id.clone(), + height: Height::default(), + }) { Ok(connection) => connection, Err(e) => Output::error(format!("{}", e)).exit(), }; @@ -82,10 +83,10 @@ impl Runnable for TxRawChanOpenInitCmd { }; // Retrieve the connection - let dst_connection = match chains - .dst - .query_connection(&self.dst_conn_id, Height::default()) - { + let dst_connection = match chains.dst.query_connection(QueryConnectionRequest { + connection_id: self.dst_conn_id.clone(), + height: Height::default(), + }) { Ok(connection) => connection, Err(e) => Output::error(format!("{}", e)).exit(), }; diff --git a/relayer-cli/src/commands/tx/client.rs b/relayer-cli/src/commands/tx/client.rs index 3d9753c395..67b3030afe 100644 --- a/relayer-cli/src/commands/tx/client.rs +++ b/relayer-cli/src/commands/tx/client.rs @@ -6,8 +6,10 @@ use abscissa_core::{Command, Runnable}; use ibc::core::ics02_client::client_state::ClientState; use ibc::core::ics24_host::identifier::{ChainId, ClientId}; use ibc::events::IbcEvent; -use ibc_proto::ibc::core::client::v1::QueryClientStatesRequest; use ibc_relayer::chain::handle::ChainHandle; +use ibc_relayer::chain::requests::{ + PageRequest, QueryClientStateRequest, QueryClientStatesRequest, +}; use ibc_relayer::config::Config; use ibc_relayer::foreign_client::{CreateOptions, ForeignClient}; use tendermint_light_client_verifier::types::TrustThreshold; @@ -114,17 +116,19 @@ impl Runnable for TxUpdateClientCmd { Err(e) => Output::error(format!("{}", e)).exit(), }; - let src_chain_id = - match dst_chain.query_client_state(&self.dst_client_id, ibc::Height::zero()) { - Ok(cs) => cs.chain_id(), - Err(e) => { - Output::error(format!( - "Query of client '{}' on chain '{}' failed with error: {}", - self.dst_client_id, self.dst_chain_id, e - )) - .exit(); - } - }; + let src_chain_id = match dst_chain.query_client_state(QueryClientStateRequest { + client_id: self.dst_client_id.clone(), + height: ibc::Height::zero(), + }) { + Ok(cs) => cs.chain_id(), + Err(e) => { + Output::error(format!( + "Query of client '{}' on chain '{}' failed with error: {}", + self.dst_client_id, self.dst_chain_id, e + )) + .exit(); + } + }; let src_chain = match spawn_chain_runtime(&config, &src_chain_id) { Ok(handle) => handle, @@ -176,8 +180,10 @@ impl Runnable for TxUpgradeClientCmd { Err(e) => Output::error(format!("{}", e)).exit(), }; - let src_chain_id = match dst_chain.query_client_state(&self.client_id, ibc::Height::zero()) - { + let src_chain_id = match dst_chain.query_client_state(QueryClientStateRequest { + client_id: self.client_id.clone(), + height: ibc::Height::zero(), + }) { Ok(cs) => cs.chain_id(), Err(e) => { Output::error(format!( @@ -249,7 +255,7 @@ impl TxUpgradeClientsCmd { let dst_chain = spawn_chain_runtime_generic::(config, dst_chain_id)?; let req = QueryClientStatesRequest { - pagination: ibc_proto::cosmos::base::query::pagination::all(), + pagination: Some(PageRequest::all()), }; let outputs = dst_chain .query_clients(req) diff --git a/relayer-cli/src/commands/tx/transfer.rs b/relayer-cli/src/commands/tx/transfer.rs index 973a87b800..8875e19172 100644 --- a/relayer-cli/src/commands/tx/transfer.rs +++ b/relayer-cli/src/commands/tx/transfer.rs @@ -11,6 +11,9 @@ use ibc::{ events::IbcEvent, }; use ibc_relayer::chain::handle::ChainHandle; +use ibc_relayer::chain::requests::{ + QueryChannelRequest, QueryClientStateRequest, QueryConnectionRequest, +}; use ibc_relayer::transfer::Amount; use ibc_relayer::{ config::Config, @@ -170,11 +173,11 @@ impl Runnable for TxIcs20MsgTransferCmd { // headers for the destination chain. let channel_end_src = chains .src - .query_channel( - &opts.packet_src_port_id, - &opts.packet_src_channel_id, - Height::zero(), - ) + .query_channel(QueryChannelRequest { + port_id: opts.packet_src_port_id.clone(), + channel_id: opts.packet_src_channel_id, + height: Height::zero(), + }) .unwrap_or_else(exit_with_unrecoverable_error); if !channel_end_src.is_open() { Output::error(format!( @@ -200,14 +203,20 @@ impl Runnable for TxIcs20MsgTransferCmd { let conn_end = chains .src - .query_connection(conn_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: conn_id.clone(), + height: Height::zero(), + }) .unwrap_or_else(exit_with_unrecoverable_error); debug!("connection hop underlying the channel: {:?}", conn_end); let src_chain_client_state = chains .src - .query_client_state(conn_end.client_id(), Height::zero()) + .query_client_state(QueryClientStateRequest { + client_id: conn_end.client_id().clone(), + height: Height::zero(), + }) .unwrap_or_else(exit_with_unrecoverable_error); debug!( diff --git a/relayer/src/chain.rs b/relayer/src/chain.rs index 6e36dde74f..271cc224fc 100644 --- a/relayer/src/chain.rs +++ b/relayer/src/chain.rs @@ -1,5 +1,6 @@ use alloc::sync::Arc; use core::convert::TryFrom; +use ibc::core::ics23_commitment::merkle::MerkleProof; use tokio::runtime::Runtime as TokioRuntime; @@ -24,17 +25,6 @@ use ibc::query::{QueryBlockRequest, QueryTxRequest}; use ibc::signer::Signer; use ibc::timestamp::Timestamp; use ibc::Height as ICSHeight; -use ibc_proto::ibc::core::channel::v1::{ - PacketState, QueryChannelClientStateRequest, QueryChannelsRequest, - QueryConnectionChannelsRequest, QueryNextSequenceReceiveRequest, - QueryPacketAcknowledgementsRequest, QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, - QueryUnreceivedPacketsRequest, -}; -use ibc_proto::ibc::core::client::v1::{QueryClientStatesRequest, QueryConsensusStatesRequest}; -use ibc_proto::ibc::core::commitment::v1::MerkleProof; -use ibc_proto::ibc::core::connection::v1::{ - QueryClientConnectionsRequest, QueryConnectionsRequest, -}; use tendermint::block::Height; use tendermint_rpc::endpoint::broadcast::tx_sync::Response as TxResponse; @@ -47,12 +37,22 @@ use crate::keyring::{KeyEntry, KeyRing}; use crate::light_client::LightClient; use self::client::ClientSettings; +use self::requests::{ + QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, + QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, + QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, + QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, + QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, +}; use self::tracking::TrackedMsgs; pub mod client; pub mod cosmos; pub mod counterparty; pub mod handle; +pub mod requests; pub mod runtime; pub mod tracking; @@ -172,11 +172,8 @@ pub trait ChainEndpoint: Sized { request: QueryClientStatesRequest, ) -> Result, Error>; - fn query_client_state( - &self, - client_id: &ClientId, - height: ICSHeight, - ) -> Result; + fn query_client_state(&self, request: QueryClientStateRequest) + -> Result; fn query_consensus_states( &self, @@ -187,19 +184,17 @@ pub trait ChainEndpoint: Sized { /// that an on-chain client stores. fn query_consensus_state( &self, - client_id: ClientId, - consensus_height: ICSHeight, - query_height: ICSHeight, + request: QueryConsensusStateRequest, ) -> Result; fn query_upgraded_client_state( &self, - height: ICSHeight, + request: QueryUpgradedClientStateRequest, ) -> Result<(AnyClientState, MerkleProof), Error>; fn query_upgraded_consensus_state( &self, - height: ICSHeight, + request: QueryUpgradedConsensusStateRequest, ) -> Result<(AnyConsensusState, MerkleProof), Error>; /// Performs a query to retrieve the identifiers of all connections. @@ -214,11 +209,7 @@ pub trait ChainEndpoint: Sized { request: QueryClientConnectionsRequest, ) -> Result, Error>; - fn query_connection( - &self, - connection_id: &ConnectionId, - height: ICSHeight, - ) -> Result; + fn query_connection(&self, request: QueryConnectionRequest) -> Result; /// Performs a query to retrieve the identifiers of all channels associated with a connection. fn query_connection_channels( @@ -232,37 +223,40 @@ pub trait ChainEndpoint: Sized { request: QueryChannelsRequest, ) -> Result, Error>; - fn query_channel( - &self, - port_id: &PortId, - channel_id: &ChannelId, - height: ICSHeight, - ) -> Result; + fn query_channel(&self, request: QueryChannelRequest) -> Result; fn query_channel_client_state( &self, request: QueryChannelClientStateRequest, ) -> Result, Error>; + /// Queries all the packet commitments hashes associated with a channel. + /// Returns the corresponding packet sequence numbers. fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, - ) -> Result<(Vec, ICSHeight), Error>; + ) -> Result<(Vec, ICSHeight), Error>; + /// Queries all the unreceived IBC packets associated with a channel and packet commit sequences. + /// Returns the corresponding packet sequence numbers. fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, - ) -> Result, Error>; + ) -> Result, Error>; + /// Queries all the packet acknowledgements associated with a channel. + /// Returns the corresponding packet sequence numbers. fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, - ) -> Result<(Vec, ICSHeight), Error>; + ) -> Result<(Vec, ICSHeight), Error>; + /// Queries all the unreceived packet acknowledgements associated with a + /// Returns the corresponding packet sequence numbers. fn query_unreceived_acknowledgements( &self, request: QueryUnreceivedAcksRequest, - ) -> Result, Error>; + ) -> Result, Error>; fn query_next_sequence_receive( &self, @@ -276,7 +270,10 @@ pub trait ChainEndpoint: Sized { request: QueryBlockRequest, ) -> Result<(Vec, Vec), Error>; - fn query_host_consensus_state(&self, height: ICSHeight) -> Result; + fn query_host_consensus_state( + &self, + request: QueryHostConsensusStateRequest, + ) -> Result; // Provable queries fn proven_client_state( diff --git a/relayer/src/chain/cosmos.rs b/relayer/src/chain/cosmos.rs index 6caff94455..05812c5607 100644 --- a/relayer/src/chain/cosmos.rs +++ b/relayer/src/chain/cosmos.rs @@ -23,7 +23,6 @@ use tokio::runtime::Runtime as TokioRuntime; use tonic::codegen::http::Uri; use tracing::{error, span, warn, Level}; -use ibc::clients::ics07_tendermint::client_state::{AllowUpdate, ClientState}; use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TMConsensusState; use ibc::clients::ics07_tendermint::header::Header as TmHeader; use ibc::core::ics02_client::client_consensus::{AnyConsensusState, AnyConsensusStateWithHeight}; @@ -48,18 +47,11 @@ use ibc::query::QueryBlockRequest; use ibc::query::QueryTxRequest; use ibc::signer::Signer; use ibc::Height as ICSHeight; -use ibc_proto::cosmos::staking::v1beta1::Params as StakingParams; -use ibc_proto::ibc::core::channel::v1::{ - PacketState, QueryChannelClientStateRequest, QueryChannelsRequest, - QueryConnectionChannelsRequest, QueryNextSequenceReceiveRequest, - QueryPacketAcknowledgementsRequest, QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, - QueryUnreceivedPacketsRequest, -}; -use ibc_proto::ibc::core::client::v1::{QueryClientStatesRequest, QueryConsensusStatesRequest}; -use ibc_proto::ibc::core::commitment::v1::MerkleProof; -use ibc_proto::ibc::core::connection::v1::{ - QueryClientConnectionsRequest, QueryConnectionsRequest, +use ibc::{ + clients::ics07_tendermint::client_state::{AllowUpdate, ClientState}, + core::ics23_commitment::merkle::MerkleProof, }; +use ibc_proto::cosmos::staking::v1beta1::Params as StakingParams; use crate::account::Balance; use crate::chain::client::ClientSettings; @@ -86,6 +78,16 @@ use crate::keyring::{KeyEntry, KeyRing}; use crate::light_client::tendermint::LightClient as TmLightClient; use crate::light_client::{LightClient, Verified}; +use super::requests::{ + QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, + QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, + QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, + QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, + QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, +}; + pub mod batch; pub mod client; pub mod compatibility; @@ -711,7 +713,7 @@ impl ChainEndpoint for CosmosSdkChain { ) .map_err(Error::grpc_transport)?; - let request = tonic::Request::new(request); + let request = tonic::Request::new(request.into()); let response = self .block_on(client.client_states(request)) .map_err(Error::grpc_status)? @@ -732,14 +734,13 @@ impl ChainEndpoint for CosmosSdkChain { fn query_client_state( &self, - client_id: &ClientId, - height: ICSHeight, + request: QueryClientStateRequest, ) -> Result { crate::time!("query_client_state"); crate::telemetry!(query, self.id(), "query_client_state"); let client_state = self - .query(ClientStatePath(client_id.clone()), height, false) + .query(ClientStatePath(request.client_id), request.height, false) .and_then(|v| AnyClientState::decode_vec(&v.value).map_err(Error::decode))?; Ok(client_state) @@ -747,15 +748,16 @@ impl ChainEndpoint for CosmosSdkChain { fn query_upgraded_client_state( &self, - height: ICSHeight, + request: QueryUpgradedClientStateRequest, ) -> Result<(AnyClientState, MerkleProof), Error> { crate::time!("query_upgraded_client_state"); crate::telemetry!(query, self.id(), "query_upgraded_client_state"); // Query for the value and the proof. - let tm_height = Height::try_from(height.revision_height).map_err(Error::invalid_height)?; + let tm_height = + Height::try_from(request.height.revision_height).map_err(Error::invalid_height)?; let (upgraded_client_state_raw, proof) = self.query_client_upgrade_state( - ClientUpgradePath::UpgradedClientState(height.revision_height), + ClientUpgradePath::UpgradedClientState(request.height.revision_height), tm_height, )?; @@ -767,16 +769,17 @@ impl ChainEndpoint for CosmosSdkChain { fn query_upgraded_consensus_state( &self, - height: ICSHeight, + request: QueryUpgradedConsensusStateRequest, ) -> Result<(AnyConsensusState, MerkleProof), Error> { crate::time!("query_upgraded_consensus_state"); crate::telemetry!(query, self.id(), "query_upgraded_consensus_state"); - let tm_height = Height::try_from(height.revision_height).map_err(Error::invalid_height)?; + let tm_height = + Height::try_from(request.height.revision_height).map_err(Error::invalid_height)?; // Fetch the consensus state and its proof. let (upgraded_consensus_state_raw, proof) = self.query_client_upgrade_state( - ClientUpgradePath::UpgradedClientConsensusState(height.revision_height), + ClientUpgradePath::UpgradedClientConsensusState(request.height.revision_height), tm_height, )?; @@ -802,7 +805,7 @@ impl ChainEndpoint for CosmosSdkChain { ) .map_err(Error::grpc_transport)?; - let request = tonic::Request::new(request); + let request = tonic::Request::new(request.into()); let response = self .block_on(client.consensus_states(request)) .map_err(Error::grpc_status)? @@ -820,15 +823,16 @@ impl ChainEndpoint for CosmosSdkChain { fn query_consensus_state( &self, - client_id: ClientId, - consensus_height: ICSHeight, - query_height: ICSHeight, + request: QueryConsensusStateRequest, ) -> Result { crate::time!("query_consensus_state"); crate::telemetry!(query, self.id(), "query_consensus_state"); - let (consensus_state, _proof) = - self.proven_client_consensus(&client_id, consensus_height, query_height)?; + let (consensus_state, _proof) = self.proven_client_consensus( + &request.client_id, + request.consensus_height, + request.query_height, + )?; Ok(consensus_state) } @@ -848,7 +852,7 @@ impl ChainEndpoint for CosmosSdkChain { ) .map_err(Error::grpc_transport)?; - let request = tonic::Request::new(request); + let request = tonic::Request::new(request.into()); let response = match self.block_on(client.client_connections(request)) { Ok(res) => res.into_inner(), @@ -883,7 +887,7 @@ impl ChainEndpoint for CosmosSdkChain { ) .map_err(Error::grpc_transport)?; - let request = tonic::Request::new(request); + let request = tonic::Request::new(request.into()); let response = self .block_on(client.connections(request)) @@ -902,11 +906,7 @@ impl ChainEndpoint for CosmosSdkChain { Ok(connections) } - fn query_connection( - &self, - connection_id: &ConnectionId, - height: ICSHeight, - ) -> Result { + fn query_connection(&self, request: QueryConnectionRequest) -> Result { crate::time!("query_connection"); crate::telemetry!(query, self.id(), "query_connection"); @@ -959,7 +959,9 @@ impl ChainEndpoint for CosmosSdkChain { } } - self.block_on(async { do_query_connection(self, connection_id, height).await }) + self.block_on(async { + do_query_connection(self, &request.connection_id, request.height).await + }) } fn query_connection_channels( @@ -977,7 +979,7 @@ impl ChainEndpoint for CosmosSdkChain { ) .map_err(Error::grpc_transport)?; - let request = tonic::Request::new(request); + let request = tonic::Request::new(request.into()); let response = self .block_on(client.connection_channels(request)) @@ -1010,7 +1012,7 @@ impl ChainEndpoint for CosmosSdkChain { ) .map_err(Error::grpc_transport)?; - let request = tonic::Request::new(request); + let request = tonic::Request::new(request.into()); let response = self .block_on(client.channels(request)) @@ -1025,16 +1027,15 @@ impl ChainEndpoint for CosmosSdkChain { Ok(channels) } - fn query_channel( - &self, - port_id: &PortId, - channel_id: &ChannelId, - height: ICSHeight, - ) -> Result { + fn query_channel(&self, request: QueryChannelRequest) -> Result { crate::time!("query_channel"); crate::telemetry!(query, self.id(), "query_channel"); - let res = self.query(ChannelEndsPath(port_id.clone(), *channel_id), height, false)?; + let res = self.query( + ChannelEndsPath(request.port_id, request.channel_id), + request.height, + false, + )?; let channel_end = ChannelEnd::decode_vec(&res.value).map_err(Error::decode)?; Ok(channel_end) @@ -1055,7 +1056,7 @@ impl ChainEndpoint for CosmosSdkChain { ) .map_err(Error::grpc_transport)?; - let request = tonic::Request::new(request); + let request = tonic::Request::new(request.into()); let response = self .block_on(client.channel_client_state(request)) @@ -1073,7 +1074,7 @@ impl ChainEndpoint for CosmosSdkChain { fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, - ) -> Result<(Vec, ICSHeight), Error> { + ) -> Result<(Vec, ICSHeight), Error> { crate::time!("query_packet_commitments"); crate::telemetry!(query, self.id(), "query_packet_commitments"); @@ -1085,29 +1086,33 @@ impl ChainEndpoint for CosmosSdkChain { ) .map_err(Error::grpc_transport)?; - let request = tonic::Request::new(request); + let request = tonic::Request::new(request.into()); let response = self .block_on(client.packet_commitments(request)) .map_err(Error::grpc_status)? .into_inner(); - let mut pc = response.commitments; - pc.sort_by_key(|ps| ps.sequence); + let mut commitment_sequences: Vec = response + .commitments + .into_iter() + .map(|v| v.sequence.into()) + .collect(); + commitment_sequences.sort_unstable(); let height = response .height .ok_or_else(|| Error::grpc_response_param("height".to_string()))? .into(); - Ok((pc, height)) + Ok((commitment_sequences, height)) } /// Queries the unreceived packet sequences associated with a channel. fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, - ) -> Result, Error> { + ) -> Result, Error> { crate::time!("query_unreceived_packets"); crate::telemetry!(query, self.id(), "query_unreceived_packets"); @@ -1119,7 +1124,7 @@ impl ChainEndpoint for CosmosSdkChain { ) .map_err(Error::grpc_transport)?; - let request = tonic::Request::new(request); + let request = tonic::Request::new(request.into()); let mut response = self .block_on(client.unreceived_packets(request)) @@ -1127,14 +1132,18 @@ impl ChainEndpoint for CosmosSdkChain { .into_inner(); response.sequences.sort_unstable(); - Ok(response.sequences) + Ok(response + .sequences + .into_iter() + .map(|seq| seq.into()) + .collect()) } /// Queries the packet acknowledgment hashes associated with a channel. fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, - ) -> Result<(Vec, ICSHeight), Error> { + ) -> Result<(Vec, ICSHeight), Error> { crate::time!("query_packet_acknowledgements"); crate::telemetry!(query, self.id(), "query_packet_acknowledgements"); @@ -1146,28 +1155,32 @@ impl ChainEndpoint for CosmosSdkChain { ) .map_err(Error::grpc_transport)?; - let request = tonic::Request::new(request); + let request = tonic::Request::new(request.into()); let response = self .block_on(client.packet_acknowledgements(request)) .map_err(Error::grpc_status)? .into_inner(); - let pc = response.acknowledgements; + let acks_sequences = response + .acknowledgements + .into_iter() + .map(|v| v.sequence.into()) + .collect(); let height = response .height .ok_or_else(|| Error::grpc_response_param("height".to_string()))? .into(); - Ok((pc, height)) + Ok((acks_sequences, height)) } /// Queries the unreceived acknowledgements sequences associated with a channel. fn query_unreceived_acknowledgements( &self, request: QueryUnreceivedAcksRequest, - ) -> Result, Error> { + ) -> Result, Error> { crate::time!("query_unreceived_acknowledgements"); crate::telemetry!(query, self.id(), "query_unreceived_acknowledgements"); @@ -1179,7 +1192,7 @@ impl ChainEndpoint for CosmosSdkChain { ) .map_err(Error::grpc_transport)?; - let request = tonic::Request::new(request); + let request = tonic::Request::new(request.into()); let mut response = self .block_on(client.unreceived_acks(request)) @@ -1187,7 +1200,11 @@ impl ChainEndpoint for CosmosSdkChain { .into_inner(); response.sequences.sort_unstable(); - Ok(response.sequences) + Ok(response + .sequences + .into_iter() + .map(|seq| seq.into()) + .collect()) } fn query_next_sequence_receive( @@ -1205,7 +1222,7 @@ impl ChainEndpoint for CosmosSdkChain { ) .map_err(Error::grpc_transport)?; - let request = tonic::Request::new(request); + let request = tonic::Request::new(request.into()); let response = self .block_on(client.next_sequence_receive(request)) @@ -1303,8 +1320,12 @@ impl ChainEndpoint for CosmosSdkChain { } } - fn query_host_consensus_state(&self, height: ICSHeight) -> Result { - let height = Height::try_from(height.revision_height).map_err(Error::invalid_height)?; + fn query_host_consensus_state( + &self, + request: QueryHostConsensusStateRequest, + ) -> Result { + let height = + Height::try_from(request.height.revision_height).map_err(Error::invalid_height)?; // TODO(hu55a1n1): use the `/header` RPC endpoint instead when we move to tendermint v0.35.x let rpc_call = match height.value() { diff --git a/relayer/src/chain/counterparty.rs b/relayer/src/chain/counterparty.rs index 582ce64164..88a7307e79 100644 --- a/relayer/src/chain/counterparty.rs +++ b/relayer/src/chain/counterparty.rs @@ -1,8 +1,18 @@ use std::collections::HashSet; +use ibc::core::ics04_channel::packet::Sequence; use serde::{Deserialize, Serialize}; use tracing::{error, trace}; +use super::requests::{ + PageRequest, QueryChannelRequest, QueryClientConnectionsRequest, QueryClientStateRequest, + QueryConnectionRequest, QueryPacketAcknowledgementsRequest, QueryUnreceivedAcksRequest, + QueryUnreceivedPacketsRequest, +}; +use super::{ + handle::ChainHandle, + requests::{QueryConnectionChannelsRequest, QueryPacketCommitmentsRequest}, +}; use crate::channel::ChannelError; use crate::path::PathIdentifiers; use crate::supervisor::Error; @@ -19,25 +29,24 @@ use ibc::{ }, Height, }; -use ibc_proto::ibc::core::channel::v1::{ - QueryConnectionChannelsRequest, QueryPacketAcknowledgementsRequest, - QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, -}; -use ibc_proto::ibc::core::connection::v1::QueryClientConnectionsRequest; - -use super::handle::ChainHandle; pub fn counterparty_chain_from_connection( src_chain: &impl ChainHandle, src_connection_id: &ConnectionId, ) -> Result { let connection_end = src_chain - .query_connection(src_connection_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: src_connection_id.clone(), + height: Height::zero(), + }) .map_err(Error::relayer)?; let client_id = connection_end.client_id(); let client_state = src_chain - .query_client_state(client_id, Height::zero()) + .query_client_state(QueryClientStateRequest { + client_id: client_id.clone(), + height: Height::zero(), + }) .map_err(Error::relayer)?; trace!( @@ -52,17 +61,18 @@ fn connection_on_destination( counterparty_client_id: &ClientId, counterparty_chain: &impl ChainHandle, ) -> Result, Error> { - let req = QueryClientConnectionsRequest { - client_id: counterparty_client_id.to_string(), - }; - let counterparty_connections = counterparty_chain - .query_client_connections(req) + .query_client_connections(QueryClientConnectionsRequest { + client_id: counterparty_client_id.clone(), + }) .map_err(Error::relayer)?; for counterparty_connection in counterparty_connections.into_iter() { let counterparty_connection_end = counterparty_chain - .query_connection(&counterparty_connection, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: counterparty_connection.clone(), + height: Height::zero(), + }) .map_err(Error::relayer)?; let local_connection_end = &counterparty_connection_end.counterparty(); @@ -81,7 +91,10 @@ pub fn connection_state_on_destination( ) -> Result { if let Some(remote_connection_id) = connection.connection_end.counterparty().connection_id() { let connection_end = counterparty_chain - .query_connection(remote_connection_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: remote_connection_id.clone(), + height: Height::zero(), + }) .map_err(Error::relayer)?; Ok(connection_end.state) @@ -132,7 +145,11 @@ pub fn channel_connection_client( channel_id: &ChannelId, ) -> Result { let channel_end = chain - .query_channel(port_id, channel_id, Height::zero()) + .query_channel(QueryChannelRequest { + port_id: port_id.clone(), + channel_id: *channel_id, + height: Height::zero(), + }) .map_err(Error::relayer)?; if channel_end.state_matches(&State::Uninitialized) { @@ -149,7 +166,10 @@ pub fn channel_connection_client( .ok_or_else(|| Error::missing_connection_hops(*channel_id, chain.id()))?; let connection_end = chain - .query_connection(connection_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: connection_id.clone(), + height: Height::zero(), + }) .map_err(Error::relayer)?; if !connection_end.is_open() { @@ -162,7 +182,10 @@ pub fn channel_connection_client( let client_id = connection_end.client_id(); let client_state = chain - .query_client_state(client_id, Height::zero()) + .query_client_state(QueryClientStateRequest { + client_id: client_id.clone(), + height: Height::zero(), + }) .map_err(Error::relayer)?; let client = IdentifiedAnyClientState::new(client_id.clone(), client_state); @@ -187,13 +210,11 @@ fn fetch_channel_on_destination( counterparty_chain: &impl ChainHandle, remote_connection_id: &ConnectionId, ) -> Result, Error> { - let req = QueryConnectionChannelsRequest { - connection: remote_connection_id.to_string(), - pagination: ibc_proto::cosmos::base::query::pagination::all(), - }; - let counterparty_channels = counterparty_chain - .query_connection_channels(req) + .query_connection_channels(QueryConnectionChannelsRequest { + connection_id: remote_connection_id.clone(), + pagination: Some(PageRequest::all()), + }) .map_err(Error::relayer)?; for counterparty_channel in counterparty_channels.into_iter() { @@ -226,11 +247,11 @@ pub fn channel_on_destination( ) -> Result, Error> { if let Some(remote_channel_id) = channel.channel_end.counterparty().channel_id() { let counterparty = counterparty_chain - .query_channel( - channel.channel_end.counterparty().port_id(), - remote_channel_id, - Height::zero(), - ) + .query_channel(QueryChannelRequest { + port_id: channel.channel_end.counterparty().port_id().clone(), + channel_id: *remote_channel_id, + height: Height::zero(), + }) .map(|c| IdentifiedChannelEnd { port_id: channel.channel_end.counterparty().port_id().clone(), channel_id: *remote_channel_id, @@ -261,11 +282,11 @@ pub fn check_channel_counterparty( expected: &PortChannelId, ) -> Result<(), ChannelError> { let channel_end_dst = target_chain - .query_channel( - &target_pchan.port_id, - &target_pchan.channel_id, - Height::zero(), - ) + .query_channel(QueryChannelRequest { + port_id: target_pchan.port_id.clone(), + channel_id: target_pchan.channel_id, + height: Height::zero(), + }) .map_err(|e| ChannelError::query(target_chain.id(), e))?; let counterparty = channel_end_dst.remote; @@ -308,20 +329,18 @@ pub fn commitments_on_chain( chain: &impl ChainHandle, port_id: &PortId, channel_id: &ChannelId, -) -> Result<(Vec, Height), Error> { +) -> Result<(Vec, Height), Error> { // get the packet commitments on the counterparty/ source chain - let commitments_request = QueryPacketCommitmentsRequest { - port_id: port_id.to_string(), - channel_id: channel_id.to_string(), - pagination: ibc_proto::cosmos::base::query::pagination::all(), - }; - - let (commitments, response_height) = chain - .query_packet_commitments(commitments_request) + let (mut commit_sequences, response_height) = chain + .query_packet_commitments(QueryPacketCommitmentsRequest { + port_id: port_id.clone(), + channel_id: *channel_id, + pagination: Some(PageRequest::all()), + }) .map_err(Error::relayer)?; - let mut commit_sequences: Vec = commitments.into_iter().map(|v| v.sequence).collect(); commit_sequences.sort_unstable(); + Ok((commit_sequences, response_height)) } @@ -331,20 +350,18 @@ pub fn unreceived_packets_sequences( chain: &impl ChainHandle, port_id: &PortId, channel_id: &ChannelId, - commitments_on_counterparty: Vec, -) -> Result, Error> { + commitments_on_counterparty: Vec, +) -> Result, Error> { if commitments_on_counterparty.is_empty() { return Ok(vec![]); } - let request = QueryUnreceivedPacketsRequest { - port_id: port_id.to_string(), - channel_id: channel_id.to_string(), - packet_commitment_sequences: commitments_on_counterparty, - }; - chain - .query_unreceived_packets(request) + .query_unreceived_packets(QueryUnreceivedPacketsRequest { + port_id: port_id.clone(), + channel_id: *channel_id, + packet_commitment_sequences: commitments_on_counterparty, + }) .map_err(Error::relayer) } @@ -354,22 +371,20 @@ pub fn packet_acknowledgements( chain: &impl ChainHandle, port_id: &PortId, channel_id: &ChannelId, - commit_sequences: Vec, -) -> Result<(Vec, Height), Error> { + commit_sequences: Vec, +) -> Result<(Vec, Height), Error> { let commit_set = commit_sequences.iter().cloned().collect::>(); // Get the packet acknowledgments on counterparty/source chain - let acks_request = QueryPacketAcknowledgementsRequest { - port_id: port_id.to_string(), - channel_id: channel_id.to_string(), - pagination: ibc_proto::cosmos::base::query::pagination::all(), - packet_commitment_sequences: commit_sequences, - }; - let (acks, response_height) = chain - .query_packet_acknowledgements(acks_request) + let (mut acked_sequences, response_height) = chain + .query_packet_acknowledgements(QueryPacketAcknowledgementsRequest { + port_id: port_id.clone(), + channel_id: *channel_id, + pagination: Some(PageRequest::all()), + packet_commitment_sequences: commit_sequences, + }) .map_err(Error::relayer)?; - let mut acked_sequences: Vec = acks.into_iter().map(|v| v.sequence).collect(); acked_sequences.retain(|s| commit_set.contains(s)); acked_sequences.sort_unstable(); @@ -383,20 +398,18 @@ pub fn unreceived_acknowledgements_sequences( chain: &impl ChainHandle, port_id: &PortId, channel_id: &ChannelId, - acks_on_counterparty: Vec, -) -> Result, Error> { + acks_on_counterparty: Vec, +) -> Result, Error> { if acks_on_counterparty.is_empty() { return Ok(vec![]); } - let request = QueryUnreceivedAcksRequest { - port_id: port_id.to_string(), - channel_id: channel_id.to_string(), - packet_ack_sequences: acks_on_counterparty, - }; - chain - .query_unreceived_acknowledgement(request) + .query_unreceived_acknowledgement(QueryUnreceivedAcksRequest { + port_id: port_id.clone(), + channel_id: *channel_id, + packet_ack_sequences: acks_on_counterparty, + }) .map_err(Error::relayer) } @@ -428,7 +441,7 @@ pub fn unreceived_packets( chain: &impl ChainHandle, counterparty_chain: &impl ChainHandle, path: &PathIdentifiers, -) -> Result<(Vec, Height), Error> { +) -> Result<(Vec, Height), Error> { let (commit_sequences, h) = commitments_on_chain( counterparty_chain, &path.counterparty_port_id, @@ -445,7 +458,7 @@ pub fn acknowledgements_on_chain( chain: &impl ChainHandle, counterparty_chain: &impl ChainHandle, channel: &IdentifiedChannelEnd, -) -> Result<(Vec, Height), Error> { +) -> Result<(Vec, Height), Error> { let counterparty = channel.channel_end.counterparty(); let counterparty_channel_id = counterparty .channel_id @@ -501,7 +514,7 @@ pub fn unreceived_acknowledgements( chain: &impl ChainHandle, counterparty_chain: &impl ChainHandle, path: &PathIdentifiers, -) -> Result<(Vec, Height), Error> { +) -> Result<(Vec, Height), Error> { let (commitments_on_src, _) = commitments_on_chain(chain, &path.port_id, &path.channel_id)?; let (acks_on_counterparty, src_response_height) = packet_acknowledgements( @@ -526,10 +539,10 @@ pub fn unreceived_acknowledgements( #[derive(Debug, Serialize)] pub struct PendingPackets { /// Not yet received on the counterparty chain. - pub unreceived_packets: Vec, + pub unreceived_packets: Vec, /// Received on the counterparty chain, /// but the acknowledgement is not yet received on the local chain. - pub unreceived_acks: Vec, + pub unreceived_acks: Vec, } pub fn pending_packet_summary( diff --git a/relayer/src/chain/handle.rs b/relayer/src/chain/handle.rs index 657dc96c85..01b2c86d5e 100644 --- a/relayer/src/chain/handle.rs +++ b/relayer/src/chain/handle.rs @@ -21,7 +21,7 @@ use ibc::{ channel::{ChannelEnd, IdentifiedChannelEnd}, packet::{PacketMsgType, Sequence}, }, - ics23_commitment::commitment::CommitmentPrefix, + ics23_commitment::{commitment::CommitmentPrefix, merkle::MerkleProof}, ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, PortId}, }, events::IbcEvent, @@ -31,18 +31,6 @@ use ibc::{ Height, }; -use ibc_proto::ibc::core::{ - channel::v1::{ - PacketState, QueryChannelClientStateRequest, QueryChannelsRequest, - QueryConnectionChannelsRequest, QueryNextSequenceReceiveRequest, - QueryPacketAcknowledgementsRequest, QueryPacketCommitmentsRequest, - QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, - }, - client::v1::{QueryClientStatesRequest, QueryConsensusStatesRequest}, - commitment::v1::MerkleProof, - connection::v1::{QueryClientConnectionsRequest, QueryConnectionsRequest}, -}; - use crate::{ account::Balance, config::ChainConfig, @@ -52,8 +40,19 @@ use crate::{ keyring::KeyEntry, }; -use super::client::ClientSettings; -use super::tracking::TrackedMsgs; +use super::{ + client::ClientSettings, + requests::{ + QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, + QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, + QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, + QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, + QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, + }, + tracking::TrackedMsgs, +}; use super::{ChainStatus, HealthCheck}; mod base; @@ -198,8 +197,7 @@ pub enum ChainRequest { }, QueryClientState { - client_id: ClientId, - height: Height, + request: QueryClientStateRequest, reply_to: ReplyTo, }, @@ -214,19 +212,17 @@ pub enum ChainRequest { }, QueryConsensusState { - client_id: ClientId, - consensus_height: Height, - query_height: Height, + request: QueryConsensusStateRequest, reply_to: ReplyTo, }, QueryUpgradedClientState { - height: Height, + request: QueryUpgradedClientStateRequest, reply_to: ReplyTo<(AnyClientState, MerkleProof)>, }, QueryUpgradedConsensusState { - height: Height, + request: QueryUpgradedConsensusStateRequest, reply_to: ReplyTo<(AnyConsensusState, MerkleProof)>, }, @@ -239,8 +235,7 @@ pub enum ChainRequest { }, QueryConnection { - connection_id: ConnectionId, - height: Height, + request: QueryConnectionRequest, reply_to: ReplyTo, }, @@ -260,9 +255,7 @@ pub enum ChainRequest { }, QueryChannel { - port_id: PortId, - channel_id: ChannelId, - height: Height, + request: QueryChannelRequest, reply_to: ReplyTo, }, @@ -313,22 +306,22 @@ pub enum ChainRequest { QueryPacketCommitments { request: QueryPacketCommitmentsRequest, - reply_to: ReplyTo<(Vec, Height)>, + reply_to: ReplyTo<(Vec, Height)>, }, QueryUnreceivedPackets { request: QueryUnreceivedPacketsRequest, - reply_to: ReplyTo>, + reply_to: ReplyTo>, }, QueryPacketAcknowledgement { request: QueryPacketAcknowledgementsRequest, - reply_to: ReplyTo<(Vec, Height)>, + reply_to: ReplyTo<(Vec, Height)>, }, QueryUnreceivedAcknowledgement { request: QueryUnreceivedAcksRequest, - reply_to: ReplyTo>, + reply_to: ReplyTo>, }, QueryPacketEventDataFromTxs { @@ -342,7 +335,7 @@ pub enum ChainRequest { }, QueryHostConsensusState { - height: Height, + request: QueryHostConsensusStateRequest, reply_to: ReplyTo, }, } @@ -403,11 +396,8 @@ pub trait ChainHandle: Clone + Send + Sync + Serialize + Debug + 'static { request: QueryClientStatesRequest, ) -> Result, Error>; - fn query_client_state( - &self, - client_id: &ClientId, - height: Height, - ) -> Result; + fn query_client_state(&self, request: QueryClientStateRequest) + -> Result; fn query_client_connections( &self, @@ -421,30 +411,24 @@ pub trait ChainHandle: Clone + Send + Sync + Serialize + Debug + 'static { fn query_consensus_state( &self, - client_id: ClientId, - consensus_height: Height, - query_height: Height, + request: QueryConsensusStateRequest, ) -> Result; fn query_upgraded_client_state( &self, - height: Height, + request: QueryUpgradedClientStateRequest, ) -> Result<(AnyClientState, MerkleProof), Error>; fn query_upgraded_consensus_state( &self, - height: Height, + request: QueryUpgradedConsensusStateRequest, ) -> Result<(AnyConsensusState, MerkleProof), Error>; fn query_commitment_prefix(&self) -> Result; fn query_compatible_versions(&self) -> Result, Error>; - fn query_connection( - &self, - connection_id: &ConnectionId, - height: Height, - ) -> Result; + fn query_connection(&self, request: QueryConnectionRequest) -> Result; fn query_connections( &self, @@ -466,12 +450,7 @@ pub trait ChainHandle: Clone + Send + Sync + Serialize + Debug + 'static { request: QueryChannelsRequest, ) -> Result, Error>; - fn query_channel( - &self, - port_id: &PortId, - channel_id: &ChannelId, - height: Height, - ) -> Result; + fn query_channel(&self, request: QueryChannelRequest) -> Result; fn query_channel_client_state( &self, @@ -552,22 +531,22 @@ pub trait ChainHandle: Clone + Send + Sync + Serialize + Debug + 'static { fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, - ) -> Result<(Vec, Height), Error>; + ) -> Result<(Vec, Height), Error>; fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, - ) -> Result, Error>; + ) -> Result, Error>; fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, - ) -> Result<(Vec, Height), Error>; + ) -> Result<(Vec, Height), Error>; fn query_unreceived_acknowledgement( &self, request: QueryUnreceivedAcksRequest, - ) -> Result, Error>; + ) -> Result, Error>; fn query_txs(&self, request: QueryTxRequest) -> Result, Error>; @@ -576,5 +555,8 @@ pub trait ChainHandle: Clone + Send + Sync + Serialize + Debug + 'static { request: QueryBlockRequest, ) -> Result<(Vec, Vec), Error>; - fn query_host_consensus_state(&self, height: Height) -> Result; + fn query_host_consensus_state( + &self, + request: QueryHostConsensusStateRequest, + ) -> Result; } diff --git a/relayer/src/chain/handle/base.rs b/relayer/src/chain/handle/base.rs index d2745cfefd..a9e3a77f67 100644 --- a/relayer/src/chain/handle/base.rs +++ b/relayer/src/chain/handle/base.rs @@ -14,7 +14,7 @@ use ibc::{ ics03_connection::version::Version, ics04_channel::channel::{ChannelEnd, IdentifiedChannelEnd}, ics04_channel::packet::{PacketMsgType, Sequence}, - ics23_commitment::commitment::CommitmentPrefix, + ics23_commitment::{commitment::CommitmentPrefix, merkle::MerkleProof}, ics24_host::identifier::ChainId, ics24_host::identifier::ChannelId, ics24_host::identifier::{ClientId, ConnectionId, PortId}, @@ -25,20 +25,24 @@ use ibc::{ signer::Signer, Height, }; -use ibc_proto::ibc::core::channel::v1::{ - PacketState, QueryChannelClientStateRequest, QueryChannelsRequest, - QueryConnectionChannelsRequest, QueryNextSequenceReceiveRequest, - QueryPacketAcknowledgementsRequest, QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, - QueryUnreceivedPacketsRequest, -}; -use ibc_proto::ibc::core::client::v1::{QueryClientStatesRequest, QueryConsensusStatesRequest}; -use ibc_proto::ibc::core::commitment::v1::MerkleProof; -use ibc_proto::ibc::core::connection::v1::QueryClientConnectionsRequest; -use ibc_proto::ibc::core::connection::v1::QueryConnectionsRequest; use crate::{ account::Balance, - chain::{client::ClientSettings, tracking::TrackedMsgs, ChainStatus}, + chain::{ + client::ClientSettings, + requests::{ + QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, + QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, + QueryConsensusStateRequest, QueryConsensusStatesRequest, + QueryHostConsensusStateRequest, QueryNextSequenceReceiveRequest, + QueryPacketAcknowledgementsRequest, QueryPacketCommitmentsRequest, + QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, + QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, + }, + tracking::TrackedMsgs, + ChainStatus, + }, config::ChainConfig, connection::ConnectionMsgType, error::Error, @@ -162,14 +166,9 @@ impl ChainHandle for BaseChainHandle { fn query_client_state( &self, - client_id: &ClientId, - height: Height, + request: QueryClientStateRequest, ) -> Result { - self.send(|reply_to| ChainRequest::QueryClientState { - client_id: client_id.clone(), - height, - reply_to, - }) + self.send(|reply_to| ChainRequest::QueryClientState { request, reply_to }) } fn query_client_connections( @@ -188,30 +187,23 @@ impl ChainHandle for BaseChainHandle { fn query_consensus_state( &self, - client_id: ClientId, - consensus_height: Height, - query_height: Height, + request: QueryConsensusStateRequest, ) -> Result { - self.send(|reply_to| ChainRequest::QueryConsensusState { - client_id, - consensus_height, - query_height, - reply_to, - }) + self.send(|reply_to| ChainRequest::QueryConsensusState { request, reply_to }) } fn query_upgraded_client_state( &self, - height: Height, + request: QueryUpgradedClientStateRequest, ) -> Result<(AnyClientState, MerkleProof), Error> { - self.send(|reply_to| ChainRequest::QueryUpgradedClientState { height, reply_to }) + self.send(|reply_to| ChainRequest::QueryUpgradedClientState { request, reply_to }) } fn query_upgraded_consensus_state( &self, - height: Height, + request: QueryUpgradedConsensusStateRequest, ) -> Result<(AnyConsensusState, MerkleProof), Error> { - self.send(|reply_to| ChainRequest::QueryUpgradedConsensusState { height, reply_to }) + self.send(|reply_to| ChainRequest::QueryUpgradedConsensusState { request, reply_to }) } fn query_commitment_prefix(&self) -> Result { @@ -222,16 +214,8 @@ impl ChainHandle for BaseChainHandle { self.send(|reply_to| ChainRequest::QueryCompatibleVersions { reply_to }) } - fn query_connection( - &self, - connection_id: &ConnectionId, - height: Height, - ) -> Result { - self.send(|reply_to| ChainRequest::QueryConnection { - connection_id: connection_id.clone(), - height, - reply_to, - }) + fn query_connection(&self, request: QueryConnectionRequest) -> Result { + self.send(|reply_to| ChainRequest::QueryConnection { request, reply_to }) } fn query_connections( @@ -262,18 +246,8 @@ impl ChainHandle for BaseChainHandle { self.send(|reply_to| ChainRequest::QueryChannels { request, reply_to }) } - fn query_channel( - &self, - port_id: &PortId, - channel_id: &ChannelId, - height: Height, - ) -> Result { - self.send(|reply_to| ChainRequest::QueryChannel { - port_id: port_id.clone(), - channel_id: *channel_id, - height, - reply_to, - }) + fn query_channel(&self, request: QueryChannelRequest) -> Result { + self.send(|reply_to| ChainRequest::QueryChannel { request, reply_to }) } fn query_channel_client_state( @@ -426,28 +400,28 @@ impl ChainHandle for BaseChainHandle { fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, - ) -> Result<(Vec, Height), Error> { + ) -> Result<(Vec, Height), Error> { self.send(|reply_to| ChainRequest::QueryPacketCommitments { request, reply_to }) } fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, - ) -> Result, Error> { + ) -> Result, Error> { self.send(|reply_to| ChainRequest::QueryUnreceivedPackets { request, reply_to }) } fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, - ) -> Result<(Vec, Height), Error> { + ) -> Result<(Vec, Height), Error> { self.send(|reply_to| ChainRequest::QueryPacketAcknowledgement { request, reply_to }) } fn query_unreceived_acknowledgement( &self, request: QueryUnreceivedAcksRequest, - ) -> Result, Error> { + ) -> Result, Error> { self.send(|reply_to| ChainRequest::QueryUnreceivedAcknowledgement { request, reply_to }) } @@ -462,8 +436,11 @@ impl ChainHandle for BaseChainHandle { self.send(|reply_to| ChainRequest::QueryPacketEventDataFromBlocks { request, reply_to }) } - fn query_host_consensus_state(&self, height: Height) -> Result { - self.send(|reply_to| ChainRequest::QueryHostConsensusState { height, reply_to }) + fn query_host_consensus_state( + &self, + request: QueryHostConsensusStateRequest, + ) -> Result { + self.send(|reply_to| ChainRequest::QueryHostConsensusState { request, reply_to }) } } diff --git a/relayer/src/chain/handle/cache.rs b/relayer/src/chain/handle/cache.rs index fe0f85fd64..34199ea717 100644 --- a/relayer/src/chain/handle/cache.rs +++ b/relayer/src/chain/handle/cache.rs @@ -6,6 +6,7 @@ use ibc::core::ics02_client::misbehaviour::MisbehaviourEvidence; use ibc::core::ics03_connection::connection::IdentifiedConnectionEnd; use ibc::core::ics04_channel::channel::IdentifiedChannelEnd; use ibc::core::ics04_channel::packet::{PacketMsgType, Sequence}; +use ibc::core::ics23_commitment::merkle::MerkleProof; use ibc::query::QueryTxRequest; use ibc::{ core::ics02_client::header::AnyHeader, @@ -22,22 +23,21 @@ use ibc::{ signer::Signer, Height, }; -use ibc_proto::ibc::core::channel::v1::{ - PacketState, QueryChannelClientStateRequest, QueryChannelsRequest, - QueryConnectionChannelsRequest, QueryNextSequenceReceiveRequest, - QueryPacketAcknowledgementsRequest, QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, - QueryUnreceivedPacketsRequest, -}; -use ibc_proto::ibc::core::client::v1::{QueryClientStatesRequest, QueryConsensusStatesRequest}; -use ibc_proto::ibc::core::commitment::v1::MerkleProof; -use ibc_proto::ibc::core::connection::v1::QueryClientConnectionsRequest; -use ibc_proto::ibc::core::connection::v1::QueryConnectionsRequest; use serde::{Serialize, Serializer}; use crate::account::Balance; use crate::cache::{Cache, CacheStatus}; use crate::chain::client::ClientSettings; use crate::chain::handle::{ChainHandle, ChainRequest, Subscription}; +use crate::chain::requests::{ + QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, + QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, + QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, + QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, + QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, +}; use crate::chain::tracking::TrackedMsgs; use crate::chain::{ChainStatus, HealthCheck}; use crate::config::ChainConfig; @@ -161,16 +161,18 @@ impl ChainHandle for CachingChainHandle { // TODO: Introduce new query_client_state_latest to separate from this one. fn query_client_state( &self, - client_id: &ClientId, - height: Height, + request: QueryClientStateRequest, ) -> Result { let handle = self.inner(); - if height.is_zero() { - let (result, in_cache) = self - .cache - .get_or_try_insert_client_state_with(client_id, || { - handle.query_client_state(client_id, height) - })?; + if request.height.is_zero() { + let (result, in_cache) = + self.cache + .get_or_try_insert_client_state_with(&request.client_id, || { + handle.query_client_state(QueryClientStateRequest { + client_id: request.client_id.clone(), + height: request.height, + }) + })?; if in_cache == CacheStatus::Hit { telemetry!(query_cache_hit, &self.id(), "query_client_state"); @@ -178,7 +180,7 @@ impl ChainHandle for CachingChainHandle { Ok(result) } else { - handle.query_client_state(client_id, height) + handle.query_client_state(request) } } @@ -198,26 +200,23 @@ impl ChainHandle for CachingChainHandle { fn query_consensus_state( &self, - client_id: ClientId, - consensus_height: Height, - query_height: Height, + request: QueryConsensusStateRequest, ) -> Result { - self.inner() - .query_consensus_state(client_id, consensus_height, query_height) + self.inner().query_consensus_state(request) } fn query_upgraded_client_state( &self, - height: Height, + request: QueryUpgradedClientStateRequest, ) -> Result<(AnyClientState, MerkleProof), Error> { - self.inner().query_upgraded_client_state(height) + self.inner().query_upgraded_client_state(request) } fn query_upgraded_consensus_state( &self, - height: Height, + request: QueryUpgradedConsensusStateRequest, ) -> Result<(AnyConsensusState, MerkleProof), Error> { - self.inner().query_upgraded_consensus_state(height) + self.inner().query_upgraded_consensus_state(request) } fn query_commitment_prefix(&self) -> Result { @@ -228,17 +227,13 @@ impl ChainHandle for CachingChainHandle { self.inner().query_compatible_versions() } - fn query_connection( - &self, - connection_id: &ConnectionId, - height: Height, - ) -> Result { + fn query_connection(&self, request: QueryConnectionRequest) -> Result { let handle = self.inner(); - if height.is_zero() { + if request.height.is_zero() { let (result, in_cache) = self .cache - .get_or_try_insert_connection_with(connection_id, || { - handle.query_connection(connection_id, height) + .get_or_try_insert_connection_with(&request.connection_id, || { + handle.query_connection(request.clone()) })?; if in_cache == CacheStatus::Hit { @@ -247,7 +242,7 @@ impl ChainHandle for CachingChainHandle { Ok(result) } else { - handle.query_connection(connection_id, height) + handle.query_connection(request) } } @@ -279,17 +274,12 @@ impl ChainHandle for CachingChainHandle { self.inner().query_channels(request) } - fn query_channel( - &self, - port_id: &PortId, - channel_id: &ChannelId, - height: Height, - ) -> Result { + fn query_channel(&self, request: QueryChannelRequest) -> Result { let handle = self.inner(); - if height.is_zero() { + if request.height.is_zero() { let (result, in_cache) = self.cache.get_or_try_insert_channel_with( - &PortChannelId::new(*channel_id, port_id.clone()), - || handle.query_channel(port_id, channel_id, height), + &PortChannelId::new(request.channel_id, request.port_id.clone()), + || handle.query_channel(request), )?; if in_cache == CacheStatus::Hit { @@ -298,7 +288,7 @@ impl ChainHandle for CachingChainHandle { Ok(result) } else { - handle.query_channel(port_id, channel_id, height) + handle.query_channel(request) } } @@ -413,28 +403,28 @@ impl ChainHandle for CachingChainHandle { fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, - ) -> Result<(Vec, Height), Error> { + ) -> Result<(Vec, Height), Error> { self.inner().query_packet_commitments(request) } fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, - ) -> Result, Error> { + ) -> Result, Error> { self.inner().query_unreceived_packets(request) } fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, - ) -> Result<(Vec, Height), Error> { + ) -> Result<(Vec, Height), Error> { self.inner().query_packet_acknowledgements(request) } fn query_unreceived_acknowledgement( &self, request: QueryUnreceivedAcksRequest, - ) -> Result, Error> { + ) -> Result, Error> { self.inner().query_unreceived_acknowledgement(request) } @@ -449,7 +439,10 @@ impl ChainHandle for CachingChainHandle { self.inner().query_blocks(request) } - fn query_host_consensus_state(&self, height: Height) -> Result { - self.inner.query_host_consensus_state(height) + fn query_host_consensus_state( + &self, + request: QueryHostConsensusStateRequest, + ) -> Result { + self.inner.query_host_consensus_state(request) } } diff --git a/relayer/src/chain/handle/counting.rs b/relayer/src/chain/handle/counting.rs index 286892c5aa..df10b5790a 100644 --- a/relayer/src/chain/handle/counting.rs +++ b/relayer/src/chain/handle/counting.rs @@ -6,6 +6,7 @@ use ibc::core::ics02_client::misbehaviour::MisbehaviourEvidence; use ibc::core::ics03_connection::connection::IdentifiedConnectionEnd; use ibc::core::ics04_channel::channel::IdentifiedChannelEnd; use ibc::core::ics04_channel::packet::{PacketMsgType, Sequence}; +use ibc::core::ics23_commitment::merkle::MerkleProof; use ibc::query::QueryTxRequest; use ibc::{ core::ics02_client::header::AnyHeader, @@ -20,16 +21,6 @@ use ibc::{ signer::Signer, Height, }; -use ibc_proto::ibc::core::channel::v1::{ - PacketState, QueryChannelClientStateRequest, QueryChannelsRequest, - QueryConnectionChannelsRequest, QueryNextSequenceReceiveRequest, - QueryPacketAcknowledgementsRequest, QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, - QueryUnreceivedPacketsRequest, -}; -use ibc_proto::ibc::core::client::v1::{QueryClientStatesRequest, QueryConsensusStatesRequest}; -use ibc_proto::ibc::core::commitment::v1::MerkleProof; -use ibc_proto::ibc::core::connection::v1::QueryClientConnectionsRequest; -use ibc_proto::ibc::core::connection::v1::QueryConnectionsRequest; use serde::{Serialize, Serializer}; use std::collections::HashMap; use std::sync::{Arc, RwLock, RwLockReadGuard}; @@ -38,6 +29,15 @@ use tracing::debug; use crate::account::Balance; use crate::chain::client::ClientSettings; use crate::chain::handle::{ChainHandle, ChainRequest, Subscription}; +use crate::chain::requests::{ + QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, + QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, + QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, + QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, + QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, +}; use crate::chain::tracking::TrackedMsgs; use crate::chain::{ChainStatus, HealthCheck}; use crate::config::ChainConfig; @@ -181,11 +181,13 @@ impl ChainHandle for CountingChainHandle { fn query_client_state( &self, - client_id: &ClientId, - height: Height, + request: QueryClientStateRequest, ) -> Result { - self.inc_metric(&format!("query_client_state({}, {})", client_id, height)); - self.inner().query_client_state(client_id, height) + self.inc_metric(&format!( + "query_client_state({}, {})", + request.client_id, request.height + )); + self.inner().query_client_state(request) } fn query_client_connections( @@ -206,29 +208,26 @@ impl ChainHandle for CountingChainHandle { fn query_consensus_state( &self, - client_id: ClientId, - consensus_height: Height, - query_height: Height, + request: QueryConsensusStateRequest, ) -> Result { self.inc_metric("query_consensus_state"); - self.inner() - .query_consensus_state(client_id, consensus_height, query_height) + self.inner().query_consensus_state(request) } fn query_upgraded_client_state( &self, - height: Height, + request: QueryUpgradedClientStateRequest, ) -> Result<(AnyClientState, MerkleProof), Error> { self.inc_metric("query_upgraded_client_state"); - self.inner().query_upgraded_client_state(height) + self.inner().query_upgraded_client_state(request) } fn query_upgraded_consensus_state( &self, - height: Height, + request: QueryUpgradedConsensusStateRequest, ) -> Result<(AnyConsensusState, MerkleProof), Error> { self.inc_metric("query_upgraded_consensus_state"); - self.inner().query_upgraded_consensus_state(height) + self.inner().query_upgraded_consensus_state(request) } fn query_commitment_prefix(&self) -> Result { @@ -241,13 +240,9 @@ impl ChainHandle for CountingChainHandle { self.inner().query_compatible_versions() } - fn query_connection( - &self, - connection_id: &ConnectionId, - height: Height, - ) -> Result { + fn query_connection(&self, request: QueryConnectionRequest) -> Result { self.inc_metric("query_connection"); - self.inner().query_connection(connection_id, height) + self.inner().query_connection(request) } fn query_connections( @@ -282,14 +277,9 @@ impl ChainHandle for CountingChainHandle { self.inner().query_channels(request) } - fn query_channel( - &self, - port_id: &PortId, - channel_id: &ChannelId, - height: Height, - ) -> Result { + fn query_channel(&self, request: QueryChannelRequest) -> Result { self.inc_metric("query_channel"); - self.inner().query_channel(port_id, channel_id, height) + self.inner().query_channel(request) } fn query_channel_client_state( @@ -414,7 +404,7 @@ impl ChainHandle for CountingChainHandle { fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, - ) -> Result<(Vec, Height), Error> { + ) -> Result<(Vec, Height), Error> { self.inc_metric("query_packet_commitments"); self.inner().query_packet_commitments(request) } @@ -422,7 +412,7 @@ impl ChainHandle for CountingChainHandle { fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, - ) -> Result, Error> { + ) -> Result, Error> { self.inc_metric("query_unreceived_packets"); self.inner().query_unreceived_packets(request) } @@ -430,7 +420,7 @@ impl ChainHandle for CountingChainHandle { fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, - ) -> Result<(Vec, Height), Error> { + ) -> Result<(Vec, Height), Error> { self.inc_metric("query_packet_acknowledgements"); self.inner().query_packet_acknowledgements(request) } @@ -438,7 +428,7 @@ impl ChainHandle for CountingChainHandle { fn query_unreceived_acknowledgement( &self, request: QueryUnreceivedAcksRequest, - ) -> Result, Error> { + ) -> Result, Error> { self.inc_metric("query_unreceived_acknowledgement"); self.inner().query_unreceived_acknowledgement(request) } @@ -456,7 +446,10 @@ impl ChainHandle for CountingChainHandle { self.inner().query_blocks(request) } - fn query_host_consensus_state(&self, height: Height) -> Result { - self.inner.query_host_consensus_state(height) + fn query_host_consensus_state( + &self, + request: QueryHostConsensusStateRequest, + ) -> Result { + self.inner.query_host_consensus_state(request) } } diff --git a/relayer/src/chain/mock.rs b/relayer/src/chain/mock.rs index 6e0946ffcf..79ee256e8c 100644 --- a/relayer/src/chain/mock.rs +++ b/relayer/src/chain/mock.rs @@ -1,6 +1,7 @@ use alloc::sync::Arc; use core::ops::Add; use core::time::Duration; +use ibc::core::ics23_commitment::merkle::MerkleProof; use crossbeam_channel as channel; use tendermint_testgen::light_block::TmLightBlock; @@ -27,20 +28,12 @@ use ibc::relayer::ics18_relayer::context::Ics18Context; use ibc::signer::Signer; use ibc::test_utils::get_dummy_account_id; use ibc::Height; -use ibc_proto::ibc::core::channel::v1::{ - PacketState, QueryChannelClientStateRequest, QueryChannelsRequest, - QueryConnectionChannelsRequest, QueryNextSequenceReceiveRequest, - QueryPacketAcknowledgementsRequest, QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, - QueryUnreceivedPacketsRequest, -}; -use ibc_proto::ibc::core::client::v1::{QueryClientStatesRequest, QueryConsensusStatesRequest}; -use ibc_proto::ibc::core::commitment::v1::MerkleProof; -use ibc_proto::ibc::core::connection::v1::{ - QueryClientConnectionsRequest, QueryConnectionsRequest, -}; use crate::account::Balance; use crate::chain::client::ClientSettings; +use crate::chain::requests::{ + QueryChannelClientStateRequest, QueryChannelRequest, QueryClientStatesRequest, +}; use crate::chain::{ChainEndpoint, ChainStatus}; use crate::config::ChainConfig; use crate::error::Error; @@ -49,6 +42,14 @@ use crate::keyring::{KeyEntry, KeyRing}; use crate::light_client::Verified; use crate::light_client::{mock::LightClient as MockLightClient, LightClient}; +use super::requests::{ + QueryChannelsRequest, QueryClientConnectionsRequest, QueryClientStateRequest, + QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, + QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, + QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, + QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, +}; use super::tracking::TrackedMsgs; use super::HealthCheck; @@ -188,13 +189,12 @@ impl ChainEndpoint for MockChain { fn query_client_state( &self, - client_id: &ClientId, - _height: Height, + request: QueryClientStateRequest, ) -> Result { // TODO: unclear what are the scenarios where we need to take height into account. let client_state = self .context - .query_client_full_state(client_id) + .query_client_full_state(&request.client_id) .ok_or_else(Error::empty_response_value)?; Ok(client_state) @@ -202,16 +202,12 @@ impl ChainEndpoint for MockChain { fn query_upgraded_client_state( &self, - _height: Height, + _request: QueryUpgradedClientStateRequest, ) -> Result<(AnyClientState, MerkleProof), Error> { unimplemented!() } - fn query_connection( - &self, - _connection_id: &ConnectionId, - _height: Height, - ) -> Result { + fn query_connection(&self, _request: QueryConnectionRequest) -> Result { unimplemented!() } @@ -243,12 +239,7 @@ impl ChainEndpoint for MockChain { unimplemented!() } - fn query_channel( - &self, - _port_id: &PortId, - _channel_id: &ChannelId, - _height: Height, - ) -> Result { + fn query_channel(&self, _request: QueryChannelRequest) -> Result { unimplemented!() } @@ -262,28 +253,28 @@ impl ChainEndpoint for MockChain { fn query_packet_commitments( &self, _request: QueryPacketCommitmentsRequest, - ) -> Result<(Vec, Height), Error> { + ) -> Result<(Vec, Height), Error> { unimplemented!() } fn query_unreceived_packets( &self, _request: QueryUnreceivedPacketsRequest, - ) -> Result, Error> { + ) -> Result, Error> { unimplemented!() } fn query_packet_acknowledgements( &self, _request: QueryPacketAcknowledgementsRequest, - ) -> Result<(Vec, Height), Error> { + ) -> Result<(Vec, Height), Error> { unimplemented!() } fn query_unreceived_acknowledgements( &self, _request: QueryUnreceivedAcksRequest, - ) -> Result, Error> { + ) -> Result, Error> { unimplemented!() } @@ -305,7 +296,10 @@ impl ChainEndpoint for MockChain { unimplemented!() } - fn query_host_consensus_state(&self, _height: Height) -> Result { + fn query_host_consensus_state( + &self, + _request: QueryHostConsensusStateRequest, + ) -> Result { unimplemented!() } @@ -426,28 +420,24 @@ impl ChainEndpoint for MockChain { &self, request: QueryConsensusStatesRequest, ) -> Result, Error> { - Ok(self - .context - .consensus_states(&request.client_id.parse().unwrap())) + Ok(self.context.consensus_states(&request.client_id)) } fn query_consensus_state( &self, - client_id: ClientId, - consensus_height: Height, - _query_height: Height, + request: QueryConsensusStateRequest, ) -> Result { - let consensus_states = self.context.consensus_states(&client_id); + let consensus_states = self.context.consensus_states(&request.client_id); Ok(consensus_states .into_iter() - .find(|s| s.height == consensus_height) + .find(|s| s.height == request.consensus_height) .unwrap() .consensus_state) } fn query_upgraded_consensus_state( &self, - _height: Height, + _request: QueryUpgradedConsensusStateRequest, ) -> Result<(AnyConsensusState, MerkleProof), Error> { unimplemented!() } diff --git a/relayer/src/chain/requests.rs b/relayer/src/chain/requests.rs new file mode 100644 index 0000000000..24a8405d9d --- /dev/null +++ b/relayer/src/chain/requests.rs @@ -0,0 +1,302 @@ +use ibc::core::ics04_channel::packet::Sequence; +use ibc::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; +use ibc::Height; +use ibc_proto::cosmos::base::query::v1beta1::PageRequest as RawPageRequest; +use ibc_proto::ibc::core::channel::v1::{ + QueryChannelClientStateRequest as RawQueryChannelClientStateRequest, + QueryChannelsRequest as RawQueryChannelsRequest, + QueryConnectionChannelsRequest as RawQueryConnectionChannelsRequest, + QueryNextSequenceReceiveRequest as RawQueryNextSequenceReceiveRequest, + QueryPacketAcknowledgementsRequest as RawQueryPacketAcknowledgementsRequest, + QueryPacketCommitmentsRequest as RawQueryPacketCommitmentsRequest, + QueryUnreceivedAcksRequest as RawQueryUnreceivedAcksRequest, + QueryUnreceivedPacketsRequest as RawQueryUnreceivedPacketsRequest, +}; +use ibc_proto::ibc::core::client::v1::{ + QueryClientStatesRequest as RawQueryClientStatesRequest, + QueryConsensusStatesRequest as RawQueryConsensusStatesRequest, +}; +use ibc_proto::ibc::core::connection::v1::{ + QueryClientConnectionsRequest as RawQueryClientConnectionsRequest, + QueryConnectionsRequest as RawQueryConnectionsRequest, +}; + +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +pub struct PageRequest { + /// key is a value returned in PageResponse.next_key to begin + /// querying the next page most efficiently. Only one of offset or key + /// should be set. + pub key: ::prost::alloc::vec::Vec, + /// offset is a numeric offset that can be used when key is unavailable. + /// It is less efficient than using key. Only one of offset or key should + /// be set. + pub offset: u64, + /// limit is the total number of results to be returned in the result page. + /// If left empty it will default to a value to be set by each app. + pub limit: u64, + /// count_total is set to true to indicate that the result set should include + /// a count of the total number of items available for pagination in UIs. + /// count_total is only respected when offset is used. It is ignored when key + /// is set. + pub count_total: bool, + /// reverse is set to true if results are to be returned in the descending order. + pub reverse: bool, +} + +impl PageRequest { + pub fn all() -> PageRequest { + PageRequest { + limit: u64::MAX, + ..Default::default() + } + } +} + +impl From for RawPageRequest { + fn from(request: PageRequest) -> Self { + RawPageRequest { + key: request.key, + offset: request.offset, + limit: request.limit, + count_total: request.count_total, + reverse: request.reverse, + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryClientStateRequest { + pub client_id: ClientId, + pub height: Height, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryClientStatesRequest { + pub pagination: Option, +} + +impl From for RawQueryClientStatesRequest { + fn from(request: QueryClientStatesRequest) -> Self { + RawQueryClientStatesRequest { + pagination: request.pagination.map(|pagination| pagination.into()), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryConsensusStateRequest { + pub client_id: ClientId, + pub consensus_height: Height, + pub query_height: Height, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryUpgradedClientStateRequest { + pub height: Height, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryUpgradedConsensusStateRequest { + pub height: Height, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryConsensusStatesRequest { + pub client_id: ClientId, + pub pagination: Option, +} + +impl From for RawQueryConsensusStatesRequest { + fn from(request: QueryConsensusStatesRequest) -> Self { + RawQueryConsensusStatesRequest { + client_id: request.client_id.to_string(), + pagination: request.pagination.map(|pagination| pagination.into()), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryConnectionsRequest { + pub pagination: Option, +} + +impl From for RawQueryConnectionsRequest { + fn from(request: QueryConnectionsRequest) -> Self { + RawQueryConnectionsRequest { + pagination: request.pagination.map(|pagination| pagination.into()), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryClientConnectionsRequest { + pub client_id: ClientId, +} + +impl From for RawQueryClientConnectionsRequest { + fn from(request: QueryClientConnectionsRequest) -> Self { + RawQueryClientConnectionsRequest { + client_id: request.client_id.to_string(), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryConnectionRequest { + pub connection_id: ConnectionId, + pub height: Height, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryConnectionChannelsRequest { + pub connection_id: ConnectionId, + pub pagination: Option, +} + +impl From for RawQueryConnectionChannelsRequest { + fn from(request: QueryConnectionChannelsRequest) -> Self { + RawQueryConnectionChannelsRequest { + connection: request.connection_id.to_string(), + pagination: request.pagination.map(|pagination| pagination.into()), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryChannelsRequest { + pub pagination: Option, +} + +impl From for RawQueryChannelsRequest { + fn from(request: QueryChannelsRequest) -> Self { + RawQueryChannelsRequest { + pagination: request.pagination.map(|pagination| pagination.into()), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryChannelRequest { + pub port_id: PortId, + pub channel_id: ChannelId, + pub height: Height, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryChannelClientStateRequest { + pub port_id: PortId, + pub channel_id: ChannelId, +} + +impl From for RawQueryChannelClientStateRequest { + fn from(request: QueryChannelClientStateRequest) -> Self { + RawQueryChannelClientStateRequest { + port_id: request.port_id.to_string(), + channel_id: request.channel_id.to_string(), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryPacketCommitmentsRequest { + pub port_id: PortId, + pub channel_id: ChannelId, + pub pagination: Option, +} + +impl From for RawQueryPacketCommitmentsRequest { + fn from(request: QueryPacketCommitmentsRequest) -> Self { + RawQueryPacketCommitmentsRequest { + port_id: request.port_id.to_string(), + channel_id: request.channel_id.to_string(), + pagination: request.pagination.map(|pagination| pagination.into()), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryUnreceivedPacketsRequest { + pub port_id: PortId, + pub channel_id: ChannelId, + pub packet_commitment_sequences: Vec, +} + +impl From for RawQueryUnreceivedPacketsRequest { + fn from(request: QueryUnreceivedPacketsRequest) -> Self { + RawQueryUnreceivedPacketsRequest { + port_id: request.port_id.to_string(), + channel_id: request.channel_id.to_string(), + packet_commitment_sequences: request + .packet_commitment_sequences + .into_iter() + .map(|seq| seq.into()) + .collect(), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryPacketAcknowledgementsRequest { + pub port_id: PortId, + pub channel_id: ChannelId, + pub pagination: Option, + pub packet_commitment_sequences: Vec, +} + +impl From for RawQueryPacketAcknowledgementsRequest { + fn from(request: QueryPacketAcknowledgementsRequest) -> Self { + RawQueryPacketAcknowledgementsRequest { + port_id: request.port_id.to_string(), + channel_id: request.channel_id.to_string(), + pagination: request.pagination.map(|pagination| pagination.into()), + packet_commitment_sequences: request + .packet_commitment_sequences + .into_iter() + .map(|seq| seq.into()) + .collect(), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryUnreceivedAcksRequest { + pub port_id: PortId, + pub channel_id: ChannelId, + pub packet_ack_sequences: Vec, +} + +impl From for RawQueryUnreceivedAcksRequest { + fn from(request: QueryUnreceivedAcksRequest) -> Self { + RawQueryUnreceivedAcksRequest { + port_id: request.port_id.to_string(), + channel_id: request.channel_id.to_string(), + packet_ack_sequences: request + .packet_ack_sequences + .into_iter() + .map(|seq| seq.into()) + .collect(), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryNextSequenceReceiveRequest { + pub port_id: PortId, + pub channel_id: ChannelId, +} + +impl From for RawQueryNextSequenceReceiveRequest { + fn from(request: QueryNextSequenceReceiveRequest) -> Self { + RawQueryNextSequenceReceiveRequest { + port_id: request.port_id.to_string(), + channel_id: request.channel_id.to_string(), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryHostConsensusStateRequest { + pub height: Height, +} diff --git a/relayer/src/chain/runtime.rs b/relayer/src/chain/runtime.rs index 4cf6eb4a8d..d142a0e256 100644 --- a/relayer/src/chain/runtime.rs +++ b/relayer/src/chain/runtime.rs @@ -22,7 +22,7 @@ use ibc::{ channel::{ChannelEnd, IdentifiedChannelEnd}, packet::{PacketMsgType, Sequence}, }, - ics23_commitment::commitment::CommitmentPrefix, + ics23_commitment::{commitment::CommitmentPrefix, merkle::MerkleProof}, ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}, }, events::IbcEvent, @@ -31,21 +31,9 @@ use ibc::{ signer::Signer, Height, }; -use ibc_proto::ibc::core::{ - channel::v1::{ - PacketState, QueryChannelClientStateRequest, QueryChannelsRequest, - QueryConnectionChannelsRequest, QueryNextSequenceReceiveRequest, - QueryPacketAcknowledgementsRequest, QueryPacketCommitmentsRequest, - QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, - }, - client::v1::{QueryClientStatesRequest, QueryConsensusStatesRequest}, - commitment::v1::MerkleProof, - connection::v1::{QueryClientConnectionsRequest, QueryConnectionsRequest}, -}; use crate::{ account::Balance, - chain::{client::ClientSettings, ChainStatus}, config::ChainConfig, connection::ConnectionMsgType, error::Error, @@ -58,9 +46,19 @@ use crate::{ }; use super::{ + client::ClientSettings, handle::{ChainHandle, ChainRequest, ReplyTo, Subscription}, + requests::{ + QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, + QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, + QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, + QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, + QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, + }, tracking::TrackedMsgs, - ChainEndpoint, HealthCheck, + ChainEndpoint, ChainStatus, HealthCheck, }; pub struct Threads { @@ -319,24 +317,24 @@ where self.query_client_connections(request, reply_to)? }, - Ok(ChainRequest::QueryClientState { client_id, height, reply_to }) => { - self.query_client_state(client_id, height, reply_to)? + Ok(ChainRequest::QueryClientState { request, reply_to }) => { + self.query_client_state(request, reply_to)? }, Ok(ChainRequest::QueryConsensusStates { request, reply_to }) => { self.query_consensus_states(request, reply_to)? }, - Ok(ChainRequest::QueryConsensusState { client_id, consensus_height, query_height, reply_to }) => { - self.query_consensus_state(client_id, consensus_height, query_height, reply_to)? + Ok(ChainRequest::QueryConsensusState { request, reply_to }) => { + self.query_consensus_state(request, reply_to)? }, - Ok(ChainRequest::QueryUpgradedClientState { height, reply_to }) => { - self.query_upgraded_client_state(height, reply_to)? + Ok(ChainRequest::QueryUpgradedClientState { request, reply_to }) => { + self.query_upgraded_client_state(request, reply_to)? } - Ok(ChainRequest::QueryUpgradedConsensusState { height, reply_to }) => { - self.query_upgraded_consensus_state(height, reply_to)? + Ok(ChainRequest::QueryUpgradedConsensusState { request, reply_to }) => { + self.query_upgraded_consensus_state(request, reply_to)? } Ok(ChainRequest::QueryCommitmentPrefix { reply_to }) => { @@ -347,8 +345,8 @@ where self.query_compatible_versions(reply_to)? }, - Ok(ChainRequest::QueryConnection { connection_id, height, reply_to }) => { - self.query_connection(connection_id, height, reply_to)? + Ok(ChainRequest::QueryConnection { request, reply_to }) => { + self.query_connection(request, reply_to)? }, Ok(ChainRequest::QueryConnections { request, reply_to }) => { @@ -363,8 +361,8 @@ where self.query_channels(request, reply_to)? }, - Ok(ChainRequest::QueryChannel { port_id, channel_id, height, reply_to }) => { - self.query_channel(port_id, channel_id, height, reply_to)? + Ok(ChainRequest::QueryChannel { request, reply_to }) => { + self.query_channel(request, reply_to)? }, Ok(ChainRequest::QueryChannelClientState { request, reply_to }) => { @@ -415,8 +413,8 @@ where self.query_blocks(request, reply_to)? }, - Ok(ChainRequest::QueryHostConsensusState { height, reply_to }) => { - self.query_host_consensus_state(height, reply_to)? + Ok(ChainRequest::QueryHostConsensusState { request, reply_to }) => { + self.query_host_consensus_state(request, reply_to)? }, Err(e) => error!("received error via chain request channel: {}", e), @@ -621,13 +619,12 @@ where fn query_client_state( &self, - client_id: ClientId, - height: Height, + request: QueryClientStateRequest, reply_to: ReplyTo, ) -> Result<(), Error> { let client_state = self .chain - .query_client_state(&client_id, height) + .query_client_state(request) .map(|cs| cs.wrap_any()); reply_to.send(client_state).map_err(Error::send) @@ -635,12 +632,12 @@ where fn query_upgraded_client_state( &self, - height: Height, + request: QueryUpgradedClientStateRequest, reply_to: ReplyTo<(AnyClientState, MerkleProof)>, ) -> Result<(), Error> { let result = self .chain - .query_upgraded_client_state(height) + .query_upgraded_client_state(request) .map(|(cl, proof)| (cl.wrap_any(), proof)); reply_to.send(result).map_err(Error::send) @@ -657,26 +654,22 @@ where fn query_consensus_state( &self, - client_id: ClientId, - consensus_height: Height, - query_height: Height, + request: QueryConsensusStateRequest, reply_to: ReplyTo, ) -> Result<(), Error> { - let consensus_state = - self.chain - .query_consensus_state(client_id, consensus_height, query_height); + let consensus_state = self.chain.query_consensus_state(request); reply_to.send(consensus_state).map_err(Error::send) } fn query_upgraded_consensus_state( &self, - height: Height, + request: QueryUpgradedConsensusStateRequest, reply_to: ReplyTo<(AnyConsensusState, MerkleProof)>, ) -> Result<(), Error> { let result = self .chain - .query_upgraded_consensus_state(height) + .query_upgraded_consensus_state(request) .map(|(cs, proof)| (cs.wrap_any(), proof)); reply_to.send(result).map_err(Error::send) @@ -694,11 +687,10 @@ where fn query_connection( &self, - connection_id: ConnectionId, - height: Height, + request: QueryConnectionRequest, reply_to: ReplyTo, ) -> Result<(), Error> { - let connection_end = self.chain.query_connection(&connection_id, height); + let connection_end = self.chain.query_connection(request); reply_to.send(connection_end).map_err(Error::send) } @@ -731,12 +723,10 @@ where fn query_channel( &self, - port_id: PortId, - channel_id: ChannelId, - height: Height, + request: QueryChannelRequest, reply_to: ReplyTo, ) -> Result<(), Error> { - let result = self.chain.query_channel(&port_id, &channel_id, height); + let result = self.chain.query_channel(request); reply_to.send(result).map_err(Error::send) } @@ -821,7 +811,7 @@ where fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, - reply_to: ReplyTo<(Vec, Height)>, + reply_to: ReplyTo<(Vec, Height)>, ) -> Result<(), Error> { let result = self.chain.query_packet_commitments(request); reply_to.send(result).map_err(Error::send) @@ -830,7 +820,7 @@ where fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, - reply_to: ReplyTo>, + reply_to: ReplyTo>, ) -> Result<(), Error> { let result = self.chain.query_unreceived_packets(request); reply_to.send(result).map_err(Error::send) @@ -839,7 +829,7 @@ where fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, - reply_to: ReplyTo<(Vec, Height)>, + reply_to: ReplyTo<(Vec, Height)>, ) -> Result<(), Error> { let result = self.chain.query_packet_acknowledgements(request); reply_to.send(result).map_err(Error::send) @@ -848,7 +838,7 @@ where fn query_unreceived_acknowledgement( &self, request: QueryUnreceivedAcksRequest, - reply_to: ReplyTo>, + reply_to: ReplyTo>, ) -> Result<(), Error> { let result = self.chain.query_unreceived_acknowledgements(request); reply_to.send(result).map_err(Error::send) @@ -886,12 +876,12 @@ where fn query_host_consensus_state( &self, - height: Height, + request: QueryHostConsensusStateRequest, reply_to: ReplyTo, ) -> Result<(), Error> { let result = self .chain - .query_host_consensus_state(height) + .query_host_consensus_state(request) .map(|h| h.wrap_any()); reply_to.send(result).map_err(Error::send)?; diff --git a/relayer/src/channel.rs b/relayer/src/channel.rs index 4f5babd8a7..506e57ed89 100644 --- a/relayer/src/channel.rs +++ b/relayer/src/channel.rs @@ -19,10 +19,12 @@ use ibc::core::ics24_host::identifier::{ChainId, ChannelId, ClientId, Connection use ibc::events::IbcEvent; use ibc::tx_msg::Msg; use ibc::Height; -use ibc_proto::ibc::core::channel::v1::QueryConnectionChannelsRequest; use crate::chain::counterparty::{channel_connection_client, channel_state_on_destination}; use crate::chain::handle::ChainHandle; +use crate::chain::requests::{ + PageRequest, QueryChannelRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, +}; use crate::chain::tracking::TrackedMsgs; use crate::connection::Connection; use crate::foreign_client::{ForeignClient, HasExpiredOrFrozenError}; @@ -205,7 +207,10 @@ impl Channel { let connection_id = channel_event_attributes.connection_id.clone(); let connection = chain - .query_connection(&connection_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: connection_id.clone(), + height: Height::zero(), + }) .map_err(ChannelError::relayer)?; let connection_counterparty = connection.counterparty(); @@ -250,7 +255,11 @@ impl Channel { height: Height, ) -> Result<(Channel, State), ChannelError> { let a_channel = chain - .query_channel(&channel.src_port_id, &channel.src_channel_id, height) + .query_channel(QueryChannelRequest { + port_id: channel.src_port_id.clone(), + channel_id: channel.src_channel_id, + height, + }) .map_err(ChannelError::relayer)?; let a_connection_id = a_channel.connection_hops().first().ok_or_else(|| { @@ -261,7 +270,10 @@ impl Channel { })?; let a_connection = chain - .query_connection(a_connection_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: a_connection_id.clone(), + height: Height::zero(), + }) .map_err(ChannelError::relayer)?; let b_connection_id = a_connection @@ -298,13 +310,11 @@ impl Channel { }; if a_channel.state_matches(&State::Init) && a_channel.remote.channel_id.is_none() { - let req = QueryConnectionChannelsRequest { - connection: b_connection_id.to_string(), - pagination: ibc_proto::cosmos::base::query::pagination::all(), - }; - let channels: Vec = counterparty_chain - .query_connection_channels(req) + .query_connection_channels(QueryConnectionChannelsRequest { + connection_id: b_connection_id, + pagination: Some(PageRequest::all()), + }) .map_err(ChannelError::relayer)?; for chan in channels { @@ -477,7 +487,11 @@ impl Channel { // Continue loop if query error let a_channel = channel .src_chain() - .query_channel(channel.src_port_id(), src_channel_id, Height::zero()) + .query_channel(QueryChannelRequest { + port_id: channel.src_port_id().clone(), + channel_id: *src_channel_id, + height: Height::zero(), + }) .map_err(|e| { ChannelError::handshake_finalize( channel.src_port_id().clone(), @@ -489,7 +503,11 @@ impl Channel { let b_channel = channel .dst_chain() - .query_channel(channel.dst_port_id(), dst_channel_id, Height::zero()) + .query_channel(QueryChannelRequest { + port_id: channel.dst_port_id().clone(), + channel_id: *dst_channel_id, + height: Height::zero(), + }) .map_err(|e| { ChannelError::handshake_finalize( channel.dst_port_id().clone(), @@ -823,7 +841,11 @@ impl Channel { // Retrieve existing channel let dst_channel = self .dst_chain() - .query_channel(self.dst_port_id(), dst_channel_id, Height::zero()) + .query_channel(QueryChannelRequest { + port_id: self.dst_port_id().clone(), + channel_id: *dst_channel_id, + height: Height::zero(), + }) .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; // Check if a channel is expected to exist on destination chain @@ -850,7 +872,11 @@ impl Channel { // Channel must exist on source let src_channel = self .src_chain() - .query_channel(self.src_port_id(), src_channel_id, Height::zero()) + .query_channel(QueryChannelRequest { + port_id: self.src_port_id().clone(), + channel_id: *src_channel_id, + height: Height::zero(), + }) .map_err(|e| ChannelError::query(self.src_chain().id(), e))?; if src_channel.counterparty().port_id() != self.dst_port_id() { @@ -865,7 +891,10 @@ impl Channel { // Connection must exist on destination self.dst_chain() - .query_connection(self.dst_connection_id(), Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: self.dst_connection_id().clone(), + height: Height::zero(), + }) .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; let query_height = self @@ -964,12 +993,19 @@ impl Channel { // Channel must exist on source let src_channel = self .src_chain() - .query_channel(self.src_port_id(), src_channel_id, Height::zero()) + .query_channel(QueryChannelRequest { + port_id: self.src_port_id().clone(), + channel_id: *src_channel_id, + height: Height::zero(), + }) .map_err(|e| ChannelError::query(self.src_chain().id(), e))?; // Connection must exist on destination self.dst_chain() - .query_connection(self.dst_connection_id(), Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: self.dst_connection_id().clone(), + height: Height::zero(), + }) .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; let query_height = self @@ -1064,12 +1100,19 @@ impl Channel { // Channel must exist on source self.src_chain() - .query_channel(self.src_port_id(), src_channel_id, Height::zero()) + .query_channel(QueryChannelRequest { + port_id: self.src_port_id().clone(), + channel_id: *src_channel_id, + height: Height::zero(), + }) .map_err(|e| ChannelError::query(self.src_chain().id(), e))?; // Connection must exist on destination self.dst_chain() - .query_connection(self.dst_connection_id(), Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: self.dst_connection_id().clone(), + height: Height::zero(), + }) .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; let query_height = self @@ -1152,7 +1195,11 @@ impl Channel { // Channel must exist on destination self.dst_chain() - .query_channel(self.dst_port_id(), dst_channel_id, Height::zero()) + .query_channel(QueryChannelRequest { + port_id: self.dst_port_id().clone(), + channel_id: *dst_channel_id, + height: Height::zero(), + }) .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; let signer = self @@ -1212,12 +1259,19 @@ impl Channel { // Channel must exist on source self.src_chain() - .query_channel(self.src_port_id(), src_channel_id, Height::zero()) + .query_channel(QueryChannelRequest { + port_id: self.src_port_id().clone(), + channel_id: *src_channel_id, + height: Height::zero(), + }) .map_err(|e| ChannelError::query(self.src_chain().id(), e))?; // Connection must exist on destination self.dst_chain() - .query_connection(self.dst_connection_id(), Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: self.dst_connection_id().clone(), + height: Height::zero(), + }) .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; let query_height = self diff --git a/relayer/src/connection.rs b/relayer/src/connection.rs index c5b4824598..d76cc840f3 100644 --- a/relayer/src/connection.rs +++ b/relayer/src/connection.rs @@ -1,11 +1,11 @@ use core::time::Duration; use crate::chain::counterparty::connection_state_on_destination; +use crate::chain::requests::{PageRequest, QueryConnectionRequest, QueryConnectionsRequest}; use crate::chain::tracking::TrackedMsgs; use crate::util::retry::RetryResult; use flex_error::define_error; use ibc_proto::google::protobuf::Any; -use ibc_proto::ibc::core::connection::v1::QueryConnectionsRequest; use serde::Serialize; use tracing::{error, info, warn}; @@ -338,7 +338,10 @@ impl Connection { height: Height, ) -> Result<(Connection, State), ConnectionError> { let a_connection = chain - .query_connection(&connection.src_connection_id, height) + .query_connection(QueryConnectionRequest { + connection_id: connection.src_connection_id.clone(), + height, + }) .map_err(ConnectionError::relayer)?; let client_id = a_connection.client_id(); @@ -363,11 +366,10 @@ impl Connection { }; if a_connection.state_matches(&State::Init) && counterparty_connection_id.is_none() { - let req = QueryConnectionsRequest { - pagination: ibc_proto::cosmos::base::query::pagination::all(), - }; let connections: Vec = counterparty_chain - .query_connections(req) + .query_connections(QueryConnectionsRequest { + pagination: Some(PageRequest::all()), + }) .map_err(ConnectionError::relayer)?; for conn in connections { @@ -551,11 +553,17 @@ impl Connection { .ok_or_else(ConnectionError::missing_counterparty_connection_id)?; // Continue loop if query error - let a_connection = a_chain.query_connection(src_connection_id, Height::zero()); + let a_connection = a_chain.query_connection(QueryConnectionRequest { + connection_id: src_connection_id.clone(), + height: Height::zero(), + }); if a_connection.is_err() { continue; } - let b_connection = b_chain.query_connection(dst_connection_id, Height::zero()); + let b_connection = b_chain.query_connection(QueryConnectionRequest { + connection_id: dst_connection_id.clone(), + height: Height::zero(), + }); if b_connection.is_err() { continue; } @@ -610,7 +618,10 @@ impl Connection { let connection_end = self .src_chain() - .query_connection(connection_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: connection_id.clone(), + height: Height::zero(), + }) .map_err(|e| ConnectionError::connection_query(connection_id.clone(), e))?; let connection = IdentifiedConnectionEnd { @@ -727,7 +738,10 @@ impl Connection { // Retrieve existing connection if any let dst_connection = self .dst_chain() - .query_connection(dst_connection_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: dst_connection_id.clone(), + height: Height::zero(), + }) .map_err(|e| ConnectionError::chain_query(self.dst_chain().id(), e))?; // Check if a connection is expected to exist on destination chain @@ -836,7 +850,10 @@ impl Connection { let src_connection = self .src_chain() - .query_connection(src_connection_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: src_connection_id.clone(), + height: Height::zero(), + }) .map_err(|e| ConnectionError::chain_query(self.src_chain().id(), e))?; // TODO - check that the src connection is consistent with the try options @@ -973,7 +990,10 @@ impl Connection { let src_connection = self .src_chain() - .query_connection(src_connection_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: src_connection_id.clone(), + height: Height::zero(), + }) .map_err(|e| ConnectionError::chain_query(self.src_chain().id(), e))?; // TODO - check that the src connection is consistent with the ack options @@ -1075,7 +1095,10 @@ impl Connection { let _src_connection = self .src_chain() - .query_connection(src_connection_id, query_height) + .query_connection(QueryConnectionRequest { + connection_id: src_connection_id.clone(), + height: query_height, + }) .map_err(|e| ConnectionError::connection_query(src_connection_id.clone(), e))?; // TODO - check that the src connection is consistent with the confirm options diff --git a/relayer/src/foreign_client.rs b/relayer/src/foreign_client.rs index a651efa6b4..b87ef6f9d7 100644 --- a/relayer/src/foreign_client.rs +++ b/relayer/src/foreign_client.rs @@ -34,10 +34,13 @@ use ibc::query::QueryTxRequest; use ibc::timestamp::{Timestamp, TimestampOverflowError}; use ibc::tx_msg::Msg; use ibc::Height; -use ibc_proto::ibc::core::client::v1::QueryConsensusStatesRequest; use crate::chain::client::ClientSettings; use crate::chain::handle::ChainHandle; +use crate::chain::requests::{ + PageRequest, QueryClientStateRequest, QueryConsensusStateRequest, QueryConsensusStatesRequest, + QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, +}; use crate::chain::tracking::TrackedMsgs; use crate::error::Error as RelayerError; @@ -395,7 +398,10 @@ impl ForeignClient Result, ForeignClientError> { let height = Height::new(expected_target_chain.id().version(), 0); - match host_chain.query_client_state(client_id, height) { + match host_chain.query_client_state(QueryClientStateRequest { + client_id: client_id.clone(), + height, + }) { Ok(cs) => { if cs.chain_id() != expected_target_chain.id() { Err(ForeignClientError::mismatch_chain_id( @@ -438,7 +444,7 @@ impl ForeignClient ForeignClient ForeignClient ForeignClient Result<(AnyClientState, Option), ForeignClientError> { - let client_state = self - .dst_chain - .query_client_state(self.id(), Height::zero()) - .map_err(|e| { - ForeignClientError::client_refresh( - self.id().clone(), - "failed querying client state on dst chain".to_string(), - e, - ) - })?; + let client_state = { + self.dst_chain + .query_client_state(QueryClientStateRequest { + client_id: self.id().clone(), + height: Height::zero(), + }) + .map_err(|e| { + ForeignClientError::client_refresh( + self.id().clone(), + "failed querying client state on dst chain".to_string(), + e, + ) + })? + }; if client_state.is_frozen() { return Err(ForeignClientError::expired_or_frozen( @@ -1107,19 +1119,17 @@ impl ForeignClient Result, ForeignClientError> { - let request = QueryClientEventRequest { - height: Height::zero(), - event_id: WithBlockDataType::UpdateClient, - client_id: self.id.clone(), - consensus_height, - }; - let mut events = vec![]; for i in 0..MAX_RETRIES { thread::sleep(Duration::from_millis(100)); let result = self .dst_chain - .query_txs(QueryTxRequest::Client(request.clone())) + .query_txs(QueryTxRequest::Client(QueryClientEventRequest { + height: Height::zero(), + event_id: WithBlockDataType::UpdateClient, + client_id: self.id.clone(), + consensus_height, + })) .map_err(|e| { ForeignClientError::client_event_query( self.id().clone(), @@ -1173,8 +1183,8 @@ impl ForeignClient ForeignClient Result { let res = self .dst_chain - .query_consensus_state(self.id.clone(), height, Height::zero()) + .query_consensus_state(QueryConsensusStateRequest { + client_id: self.id.clone(), + consensus_height: height, + query_height: Height::zero(), + }) .map_err(|e| { ForeignClientError::client_consensus_query( self.id.clone(), @@ -1262,15 +1276,19 @@ impl ForeignClient Link { let a_channel_id = &opts.src_channel_id; let a_port_id = &opts.src_port_id; let a_channel = a_chain - .query_channel(a_port_id, a_channel_id, Height::default()) + .query_channel(QueryChannelRequest { + port_id: opts.src_port_id.clone(), + channel_id: opts.src_channel_id, + height: Height::default(), + }) .map_err(|e| { LinkError::channel_not_found(a_port_id.clone(), *a_channel_id, a_chain.id(), e) })?; @@ -100,7 +105,10 @@ impl Link { // Check the underlying connection let a_connection_id = a_channel.connection_hops()[0].clone(); let a_connection = a_chain - .query_connection(&a_connection_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: a_connection_id.clone(), + height: Height::zero(), + }) .map_err(LinkError::relayer)?; if !a_connection.state_matches(&ConnectionState::Open) { diff --git a/relayer/src/link/cli.rs b/relayer/src/link/cli.rs index 7b97e99c89..f41e5a1b1e 100644 --- a/relayer/src/link/cli.rs +++ b/relayer/src/link/cli.rs @@ -133,7 +133,7 @@ impl Link { fn relay_packet_messages( &self, - sequences: Vec, + sequences: Vec, src_response_height: Height, query_fn: impl Fn( &ChainA, diff --git a/relayer/src/link/operational_data.rs b/relayer/src/link/operational_data.rs index c1d81801d5..34bd663e52 100644 --- a/relayer/src/link/operational_data.rs +++ b/relayer/src/link/operational_data.rs @@ -11,6 +11,7 @@ use ibc::events::IbcEvent; use ibc::Height; use crate::chain::handle::ChainHandle; +use crate::chain::requests::QueryClientStateRequest; use crate::chain::tracking::TrackedMsgs; use crate::chain::tracking::TrackingId; use crate::link::error::LinkError; @@ -169,11 +170,18 @@ impl OperationalData { let client_state = match self.target { OperationalDataTarget::Source => relay_path .src_chain() - .query_client_state(relay_path.src_client_id(), Height::zero()) + .query_client_state(QueryClientStateRequest { + client_id: relay_path.src_client_id().clone(), + height: Height::zero(), + }) .map_err(|e| LinkError::query(relay_path.src_chain().id(), e))?, + OperationalDataTarget::Destination => relay_path .dst_chain() - .query_client_state(relay_path.dst_client_id(), Height::zero()) + .query_client_state(QueryClientStateRequest { + client_id: relay_path.dst_client_id().clone(), + height: Height::zero(), + }) .map_err(|e| LinkError::query(relay_path.dst_chain().id(), e))?, }; diff --git a/relayer/src/link/packet_events.rs b/relayer/src/link/packet_events.rs index 1b40694cbe..ba8ed36833 100644 --- a/relayer/src/link/packet_events.rs +++ b/relayer/src/link/packet_events.rs @@ -17,7 +17,7 @@ pub const QUERY_RESULT_LIMIT: usize = 50; /// Returns an iterator on batches of packet events. pub fn query_packet_events_with<'a, ChainA>( - sequence_nrs: &'a [u64], + sequence_nrs: &'a [Sequence], query_height: Height, src_chain: &'a ChainA, path: &'a PathIdentifiers, @@ -33,7 +33,7 @@ where sequence_nrs .chunks(QUERY_RESULT_LIMIT) .map_while(move |c| { - let sequences_nrs_chunk = c.iter().map(|&i| Sequence::from(i)).collect(); + let sequences_nrs_chunk = c.to_vec(); match query_fn(src_chain, path, sequences_nrs_chunk, query_height) { Ok(mut events) => { events_left_count -= c.len(); diff --git a/relayer/src/link/relay_path.rs b/relayer/src/link/relay_path.rs index 4b5a7bc3f3..96fce59f1f 100644 --- a/relayer/src/link/relay_path.rs +++ b/relayer/src/link/relay_path.rs @@ -7,6 +7,35 @@ use ibc_proto::google::protobuf::Any; use itertools::Itertools; use tracing::{debug, error, info, span, trace, warn, Level}; +use crate::chain::counterparty::unreceived_acknowledgements; +use crate::chain::counterparty::unreceived_packets; +use crate::chain::handle::ChainHandle; +use crate::chain::requests::QueryChannelRequest; +use crate::chain::requests::QueryHostConsensusStateRequest; +use crate::chain::requests::QueryNextSequenceReceiveRequest; +use crate::chain::requests::QueryUnreceivedAcksRequest; +use crate::chain::requests::QueryUnreceivedPacketsRequest; +use crate::chain::tracking::TrackedMsgs; +use crate::chain::tracking::TrackingId; +use crate::chain::ChainStatus; +use crate::channel::error::ChannelError; +use crate::channel::Channel; +use crate::event::monitor::EventBatch; +use crate::foreign_client::{ForeignClient, ForeignClientError}; +use crate::link::error::{self, LinkError}; +use crate::link::operational_data::{ + OperationalData, OperationalDataTarget, TrackedEvents, TransitMessage, +}; +use crate::link::packet_events::query_packet_events_with; +use crate::link::packet_events::query_send_packet_events; +use crate::link::packet_events::query_write_ack_events; +use crate::link::pending::PendingTxs; +use crate::link::relay_sender::{AsyncReply, SubmitReply}; +use crate::link::relay_summary::RelaySummary; +use crate::link::{pending, relay_sender}; +use crate::path::PathIdentifiers; +use crate::telemetry; +use crate::util::queue::Queue; use ibc::{ core::{ ics02_client::{ @@ -33,33 +62,6 @@ use ibc::{ tx_msg::Msg, Height, }; -use ibc_proto::ibc::core::channel::v1::{ - QueryNextSequenceReceiveRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, -}; - -use crate::chain::counterparty::{unreceived_acknowledgements, unreceived_packets}; -use crate::chain::handle::ChainHandle; -use crate::chain::tracking::TrackedMsgs; -use crate::chain::tracking::TrackingId; -use crate::chain::ChainStatus; -use crate::channel::error::ChannelError; -use crate::channel::Channel; -use crate::event::monitor::EventBatch; -use crate::foreign_client::{ForeignClient, ForeignClientError}; -use crate::link::error::{self, LinkError}; -use crate::link::operational_data::{ - OperationalData, OperationalDataTarget, TrackedEvents, TransitMessage, -}; -use crate::link::packet_events::{ - query_packet_events_with, query_send_packet_events, query_write_ack_events, -}; -use crate::link::pending::PendingTxs; -use crate::link::relay_sender::{AsyncReply, SubmitReply}; -use crate::link::relay_summary::RelaySummary; -use crate::link::{pending, relay_sender}; -use crate::path::PathIdentifiers; -use crate::telemetry; -use crate::util::queue::Queue; const MAX_RETRIES: usize = 5; @@ -198,13 +200,21 @@ impl RelayPath { fn src_channel(&self, height: Height) -> Result { self.src_chain() - .query_channel(self.src_port_id(), self.src_channel_id(), height) + .query_channel(QueryChannelRequest { + port_id: self.src_port_id().clone(), + channel_id: *self.src_channel_id(), + height, + }) .map_err(|e| LinkError::channel(ChannelError::query(self.src_chain().id(), e))) } fn dst_channel(&self, height: Height) -> Result { self.dst_chain() - .query_channel(self.dst_port_id(), self.dst_channel_id(), height) + .query_channel(QueryChannelRequest { + port_id: self.dst_port_id().clone(), + channel_id: *self.dst_channel_id(), + height, + }) .map_err(|e| LinkError::channel(ChannelError::query(self.dst_chain().id(), e))) } @@ -749,9 +759,9 @@ impl RelayPath { let unreceived_packet = self .dst_chain() .query_unreceived_packets(QueryUnreceivedPacketsRequest { - port_id: self.dst_port_id().to_string(), - channel_id: self.dst_channel_id().to_string(), - packet_commitment_sequences: vec![packet.sequence.into()], + port_id: self.dst_port_id().clone(), + channel_id: *self.dst_channel_id(), + packet_commitment_sequences: vec![packet.sequence], }) .map_err(LinkError::relayer)?; @@ -788,9 +798,9 @@ impl RelayPath { let unreceived_ack = self .dst_chain() .query_unreceived_acknowledgement(QueryUnreceivedAcksRequest { - port_id: self.dst_port_id().to_string(), - channel_id: self.dst_channel_id().to_string(), - packet_ack_sequences: vec![packet.sequence.into()], + port_id: self.dst_port_id().clone(), + channel_id: *self.dst_channel_id(), + packet_ack_sequences: vec![packet.sequence], }) .map_err(LinkError::relayer)?; @@ -864,7 +874,7 @@ impl RelayPath { height: Height, ) -> Result { let chain_time = chain - .query_host_consensus_state(height) + .query_host_consensus_state(QueryHostConsensusStateRequest { height }) .map_err(LinkError::relayer)? .timestamp(); let duration = Timestamp::now() @@ -1169,8 +1179,8 @@ impl RelayPath { let next_seq = self .dst_chain() .query_next_sequence_receive(QueryNextSequenceReceiveRequest { - port_id: self.dst_port_id().to_string(), - channel_id: dst_channel_id.to_string(), + port_id: self.dst_port_id().clone(), + channel_id: *dst_channel_id, }) .map_err(|e| LinkError::query(self.dst_chain().id(), e))?; (PacketMsgType::TimeoutOrdered, next_seq) diff --git a/relayer/src/object.rs b/relayer/src/object.rs index a3fa9f5fde..1ddff6f077 100644 --- a/relayer/src/object.rs +++ b/relayer/src/object.rs @@ -19,6 +19,7 @@ use crate::chain::{ counterparty_chain_from_connection, }, handle::ChainHandle, + requests::QueryClientStateRequest, }; use crate::error::Error as RelayerError; use crate::supervisor::Error as SupervisorError; @@ -303,7 +304,10 @@ impl Object { dst_chain: &impl ChainHandle, ) -> Result { let client_state = dst_chain - .query_client_state(e.client_id(), Height::zero()) + .query_client_state(QueryClientStateRequest { + client_id: e.client_id().clone(), + height: Height::zero(), + }) .map_err(ObjectError::relayer)?; if client_state.refresh_period().is_none() { @@ -312,7 +316,6 @@ impl Object { dst_chain.id(), )); } - let src_chain_id = client_state.chain_id(); Ok(Client { diff --git a/relayer/src/supervisor/client_state_filter.rs b/relayer/src/supervisor/client_state_filter.rs index 46525ea75e..9658c5ad93 100644 --- a/relayer/src/supervisor/client_state_filter.rs +++ b/relayer/src/supervisor/client_state_filter.rs @@ -11,6 +11,9 @@ use ibc::core::ics24_host::identifier::{ChainId, ChannelId, ClientId, Connection use ibc::Height; use crate::chain::handle::ChainHandle; +use crate::chain::requests::{ + QueryChannelRequest, QueryClientStateRequest, QueryConnectionRequest, +}; use crate::error::Error as RelayerError; use crate::object; use crate::registry::{Registry, SpawnError}; @@ -107,9 +110,14 @@ impl FilterPolicy { .get_or_spawn(&counterparty_chain_id) .map_err(FilterError::spawn)?; let counterparty_client_id = connection.counterparty().client_id(); - let counterparty_client_state = counterparty_chain - .query_client_state(counterparty_client_id, Height::zero()) - .map_err(FilterError::relayer)?; + let counterparty_client_state = { + counterparty_chain + .query_client_state(QueryClientStateRequest { + client_id: counterparty_client_id.clone(), + height: Height::zero(), + }) + .map_err(FilterError::relayer)? + }; // Control both clients, cache their results. let client_permission = self.control_client(chain_id, connection.client_id(), client_state); @@ -218,7 +226,10 @@ impl FilterPolicy { ); let client_state = chain - .query_client_state(&obj.dst_client_id, Height::zero()) + .query_client_state(QueryClientStateRequest { + client_id: obj.dst_client_id.clone(), + height: Height::zero(), + }) .map_err(FilterError::relayer)?; Ok(self.control_client(&obj.dst_chain_id, &obj.dst_client_id, &client_state)) @@ -254,11 +265,17 @@ impl FilterPolicy { ); let connection_end = src_chain - .query_connection(&obj.src_connection_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: obj.src_connection_id.clone(), + height: Height::zero(), + }) .map_err(FilterError::relayer)?; let client_state = src_chain - .query_client_state(connection_end.client_id(), Height::zero()) + .query_client_state(QueryClientStateRequest { + client_id: connection_end.client_id().clone(), + height: Height::zero(), + }) .map_err(FilterError::relayer)?; self.control_connection_end_and_client( @@ -295,7 +312,11 @@ impl FilterPolicy { .map_err(FilterError::spawn)?; let channel_end = src_chain - .query_channel(port_id, channel_id, Height::zero()) + .query_channel(QueryChannelRequest { + port_id: port_id.clone(), + channel_id: *channel_id, + height: Height::zero(), + }) .map_err(FilterError::relayer)?; let conn_id = channel_end.connection_hops.first().ok_or_else(|| { @@ -306,11 +327,17 @@ impl FilterPolicy { })?; let connection_end = src_chain - .query_connection(conn_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: conn_id.clone(), + height: Height::zero(), + }) .map_err(FilterError::relayer)?; let client_state = src_chain - .query_client_state(connection_end.client_id(), Height::zero()) + .query_client_state(QueryClientStateRequest { + client_id: connection_end.client_id().clone(), + height: Height::zero(), + }) .map_err(FilterError::relayer)?; let permission = self.control_connection_end_and_client( diff --git a/relayer/src/supervisor/scan.rs b/relayer/src/supervisor/scan.rs index 1925668926..b745c8dc10 100644 --- a/relayer/src/supervisor/scan.rs +++ b/relayer/src/supervisor/scan.rs @@ -8,21 +8,24 @@ use ibc::{ core::{ ics02_client::client_state::{ClientState, IdentifiedAnyClientState}, ics03_connection::connection::{IdentifiedConnectionEnd, State as ConnectionState}, - ics04_channel::channel::{IdentifiedChannelEnd, State as ChannelState}, + ics04_channel::{ + channel::{IdentifiedChannelEnd, State as ChannelState}, + packet::Sequence, + }, ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, PortId}, }, Height, }; -use ibc_proto::ibc::core::{ - channel::v1::QueryConnectionChannelsRequest, client::v1::QueryClientStatesRequest, - connection::v1::QueryClientConnectionsRequest, -}; - use crate::{ chain::{ counterparty::{channel_on_destination, connection_state_on_destination}, handle::ChainHandle, + requests::{ + PageRequest, QueryChannelRequest, QueryClientConnectionsRequest, + QueryClientStateRequest, QueryClientStatesRequest, QueryConnectionChannelsRequest, + QueryConnectionRequest, + }, }, config::{filter::ChannelFilters, ChainConfig, Config, PacketFilter}, registry::Registry, @@ -221,7 +224,7 @@ impl ChannelScan { &self, chain: &impl ChainHandle, counterparty_chain: &impl ChainHandle, - ) -> Option> { + ) -> Option> { self.counterparty.as_ref().map(|counterparty| { unreceived_packets(counterparty_chain, chain, &counterparty.into()) .map(|(seq, _)| seq) @@ -233,7 +236,7 @@ impl ChannelScan { &self, chain: &impl ChainHandle, counterparty_chain: &impl ChainHandle, - ) -> Option> { + ) -> Option> { self.counterparty.as_ref().map(|counterparty| { unreceived_acknowledgements(counterparty_chain, chain, &counterparty.into()) .map(|(sns, _)| sns) @@ -695,7 +698,10 @@ fn query_client( client_id: &ClientId, ) -> Result { let client = chain - .query_client_state(client_id, Height::zero()) + .query_client_state(QueryClientStateRequest { + client_id: client_id.clone(), + height: Height::zero(), + }) .map_err(Error::query)?; Ok(IdentifiedAnyClientState::new(client_id.clone(), client)) @@ -707,7 +713,11 @@ fn query_channel( channel_id: &ChannelId, ) -> Result { let channel_end = chain - .query_channel(port_id, channel_id, Height::zero()) + .query_channel(QueryChannelRequest { + port_id: port_id.clone(), + channel_id: *channel_id, + height: Height::zero(), + }) .map_err(Error::query)?; Ok(IdentifiedChannelEnd::new( @@ -737,7 +747,7 @@ fn query_all_clients( chain: &Chain, ) -> Result, Error> { let clients_req = QueryClientStatesRequest { - pagination: ibc_proto::cosmos::base::query::pagination::all(), + pagination: Some(PageRequest::all()), }; chain.query_clients(clients_req).map_err(Error::query) @@ -747,12 +757,10 @@ fn query_client_connections( chain: &Chain, client_id: &ClientId, ) -> Result, Error> { - let conns_req = QueryClientConnectionsRequest { - client_id: client_id.to_string(), - }; - let ids = chain - .query_client_connections(conns_req) + .query_client_connections(QueryClientConnectionsRequest { + client_id: client_id.clone(), + }) .map_err(Error::query)?; let connections = ids @@ -774,7 +782,10 @@ fn query_connection( connection_id: &ConnectionId, ) -> Result { let connection_end = chain - .query_connection(connection_id, Height::zero()) + .query_connection(QueryConnectionRequest { + connection_id: connection_id.clone(), + height: Height::zero(), + }) .map_err(Error::query)?; Ok(IdentifiedConnectionEnd { @@ -787,12 +798,10 @@ fn query_connection_channels( chain: &Chain, connection_id: &ConnectionId, ) -> Result, Error> { - let chans_req = QueryConnectionChannelsRequest { - connection: connection_id.to_string(), - pagination: ibc_proto::cosmos::base::query::pagination::all(), - }; - chain - .query_connection_channels(chans_req) + .query_connection_channels(QueryConnectionChannelsRequest { + connection_id: connection_id.clone(), + pagination: Some(PageRequest::all()), + }) .map_err(Error::query) } diff --git a/relayer/src/upgrade_chain.rs b/relayer/src/upgrade_chain.rs index 2bb0b956a4..fcaff1d5d0 100644 --- a/relayer/src/upgrade_chain.rs +++ b/relayer/src/upgrade_chain.rs @@ -18,6 +18,7 @@ use ibc_proto::cosmos::upgrade::v1beta1::Plan; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::client::v1::UpgradeProposal; +use crate::chain::requests::QueryClientStateRequest; use crate::chain::tracking::TrackedMsgs; use crate::chain::{ChainEndpoint, CosmosSdkChain}; use crate::config::ChainConfig; @@ -75,7 +76,10 @@ pub fn build_and_send_ibc_upgrade_proposal( .add(opts.height_offset); let client_state = src_chain - .query_client_state(&opts.src_client_id, Height::zero()) + .query_client_state(QueryClientStateRequest { + client_id: opts.src_client_id.clone(), + height: Height::zero(), + }) .map_err(UpgradeChainError::query)?; let client_state = downcast!(client_state => AnyClientState::Tendermint) diff --git a/tools/integration-test/src/tests/client_settings.rs b/tools/integration-test/src/tests/client_settings.rs index 0080230075..cc438b49d4 100644 --- a/tools/integration-test/src/tests/client_settings.rs +++ b/tools/integration-test/src/tests/client_settings.rs @@ -5,6 +5,7 @@ use ibc::core::ics02_client::trust_threshold::TrustThreshold; use ibc::clients::ics07_tendermint::client_state::ClientState as TendermintClientState; use ibc::core::ics02_client::client_state::AnyClientState; use ibc::Height; +use ibc_relayer::chain::requests::QueryClientStateRequest; use ibc_relayer::foreign_client::CreateOptions; use ibc_test_framework::prelude::*; @@ -105,7 +106,10 @@ fn query_client_state( handle: Chain, id: &ClientId, ) -> Result { - let state = handle.query_client_state(id, Height::zero())?; + let state = handle.query_client_state(QueryClientStateRequest { + client_id: id.clone(), + height: Height::zero(), + })?; #[allow(unreachable_patterns)] match state { AnyClientState::Tendermint(state) => Ok(state), diff --git a/tools/integration-test/src/tests/query_packet.rs b/tools/integration-test/src/tests/query_packet.rs index 7a7fc57b49..86480cfdce 100644 --- a/tools/integration-test/src/tests/query_packet.rs +++ b/tools/integration-test/src/tests/query_packet.rs @@ -77,7 +77,7 @@ impl BinaryChannelTest for QueryPacketPendingTest { let summary = pending_packet_summary(chains.handle_a(), chains.handle_b(), channel_end.value())?; - assert_eq!(summary.unreceived_packets, [1]); + assert_eq!(summary.unreceived_packets, [1.into()]); assert!(summary.unreceived_acks.is_empty()); // Receive the packet on the destination chain @@ -87,7 +87,7 @@ impl BinaryChannelTest for QueryPacketPendingTest { pending_packet_summary(chains.handle_a(), chains.handle_b(), channel_end.value())?; assert!(summary.unreceived_packets.is_empty()); - assert_eq!(summary.unreceived_acks, [1]); + assert_eq!(summary.unreceived_acks, [1.into()]); // Acknowledge the packet on the source chain let link = link.reverse(false)?; @@ -136,7 +136,7 @@ impl BinaryChannelTest for QueryPacketPendingTest { &counterparty_channel_end, )?; - assert_eq!(summary.unreceived_packets, [1]); + assert_eq!(summary.unreceived_packets, [1.into()]); assert!(summary.unreceived_acks.is_empty()); Ok(()) diff --git a/tools/test-framework/src/relayer/chain.rs b/tools/test-framework/src/relayer/chain.rs index 13ad853134..ad69229cbd 100644 --- a/tools/test-framework/src/relayer/chain.rs +++ b/tools/test-framework/src/relayer/chain.rs @@ -28,6 +28,7 @@ use ibc::core::ics02_client::misbehaviour::MisbehaviourEvidence; use ibc::core::ics03_connection::connection::IdentifiedConnectionEnd; use ibc::core::ics04_channel::channel::IdentifiedChannelEnd; use ibc::core::ics04_channel::packet::{PacketMsgType, Sequence}; +use ibc::core::ics23_commitment::merkle::MerkleProof; use ibc::query::QueryTxRequest; use ibc::{ core::ics02_client::header::AnyHeader, @@ -44,19 +45,18 @@ use ibc::{ signer::Signer, Height, }; -use ibc_proto::ibc::core::channel::v1::{ - PacketState, QueryChannelClientStateRequest, QueryChannelsRequest, - QueryConnectionChannelsRequest, QueryNextSequenceReceiveRequest, - QueryPacketAcknowledgementsRequest, QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, - QueryUnreceivedPacketsRequest, -}; -use ibc_proto::ibc::core::client::v1::{QueryClientStatesRequest, QueryConsensusStatesRequest}; -use ibc_proto::ibc::core::commitment::v1::MerkleProof; -use ibc_proto::ibc::core::connection::v1::QueryClientConnectionsRequest; -use ibc_proto::ibc::core::connection::v1::QueryConnectionsRequest; use ibc_relayer::account::Balance; use ibc_relayer::chain::client::ClientSettings; use ibc_relayer::chain::handle::{ChainHandle, ChainRequest, Subscription}; +use ibc_relayer::chain::requests::{ + QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, + QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, + QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, + QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, + QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, +}; use ibc_relayer::chain::tracking::TrackedMsgs; use ibc_relayer::chain::{ChainStatus, HealthCheck}; use ibc_relayer::config::ChainConfig; @@ -146,10 +146,9 @@ where fn query_client_state( &self, - client_id: &ClientId, - height: Height, + request: QueryClientStateRequest, ) -> Result { - self.value().query_client_state(client_id, height) + self.value().query_client_state(request) } fn query_client_connections( @@ -168,26 +167,23 @@ where fn query_consensus_state( &self, - client_id: ClientId, - consensus_height: Height, - query_height: Height, + request: QueryConsensusStateRequest, ) -> Result { - self.value() - .query_consensus_state(client_id, consensus_height, query_height) + self.value().query_consensus_state(request) } fn query_upgraded_client_state( &self, - height: Height, + request: QueryUpgradedClientStateRequest, ) -> Result<(AnyClientState, MerkleProof), Error> { - self.value().query_upgraded_client_state(height) + self.value().query_upgraded_client_state(request) } fn query_upgraded_consensus_state( &self, - height: Height, + request: QueryUpgradedConsensusStateRequest, ) -> Result<(AnyConsensusState, MerkleProof), Error> { - self.value().query_upgraded_consensus_state(height) + self.value().query_upgraded_consensus_state(request) } fn query_commitment_prefix(&self) -> Result { @@ -198,12 +194,8 @@ where self.value().query_compatible_versions() } - fn query_connection( - &self, - connection_id: &ConnectionId, - height: Height, - ) -> Result { - self.value().query_connection(connection_id, height) + fn query_connection(&self, request: QueryConnectionRequest) -> Result { + self.value().query_connection(request) } fn query_connections( @@ -234,13 +226,8 @@ where self.value().query_channels(request) } - fn query_channel( - &self, - port_id: &PortId, - channel_id: &ChannelId, - height: Height, - ) -> Result { - self.value().query_channel(port_id, channel_id, height) + fn query_channel(&self, request: QueryChannelRequest) -> Result { + self.value().query_channel(request) } fn query_channel_client_state( @@ -354,28 +341,28 @@ where fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, - ) -> Result<(Vec, Height), Error> { + ) -> Result<(Vec, Height), Error> { self.value().query_packet_commitments(request) } fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, - ) -> Result, Error> { + ) -> Result, Error> { self.value().query_unreceived_packets(request) } fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, - ) -> Result<(Vec, Height), Error> { + ) -> Result<(Vec, Height), Error> { self.value().query_packet_acknowledgements(request) } fn query_unreceived_acknowledgement( &self, request: QueryUnreceivedAcksRequest, - ) -> Result, Error> { + ) -> Result, Error> { self.value().query_unreceived_acknowledgement(request) } @@ -390,8 +377,11 @@ where self.value().query_blocks(request) } - fn query_host_consensus_state(&self, height: Height) -> Result { - self.value().query_host_consensus_state(height) + fn query_host_consensus_state( + &self, + request: QueryHostConsensusStateRequest, + ) -> Result { + self.value().query_host_consensus_state(request) } fn query_balance(&self) -> Result { diff --git a/tools/test-framework/src/relayer/channel.rs b/tools/test-framework/src/relayer/channel.rs index 4c0223c77d..b7830422c3 100644 --- a/tools/test-framework/src/relayer/channel.rs +++ b/tools/test-framework/src/relayer/channel.rs @@ -4,6 +4,7 @@ use ibc::core::ics04_channel::channel::State as ChannelState; use ibc::core::ics04_channel::channel::{ChannelEnd, IdentifiedChannelEnd, Order}; use ibc::Height; use ibc_relayer::chain::handle::ChainHandle; +use ibc_relayer::chain::requests::QueryChannelRequest; use ibc_relayer::channel::{extract_channel_id, Channel, ChannelSide}; use crate::error::Error; @@ -76,7 +77,11 @@ pub fn query_channel_end( channel_id: &TaggedChannelIdRef, port_id: &TaggedPortIdRef, ) -> Result, Error> { - let channel_end = handle.query_channel(port_id.value(), channel_id.value(), Height::zero())?; + let channel_end = handle.query_channel(QueryChannelRequest { + port_id: port_id.into_value().clone(), + channel_id: *channel_id.into_value(), + height: Height::zero(), + })?; Ok(DualTagged::new(channel_end)) } @@ -86,7 +91,11 @@ pub fn query_identified_channel_end( channel_id: TaggedChannelIdRef, port_id: TaggedPortIdRef, ) -> Result, Error> { - let channel_end = handle.query_channel(port_id.value(), channel_id.value(), Height::zero())?; + let channel_end = handle.query_channel(QueryChannelRequest { + port_id: port_id.into_value().clone(), + channel_id: *channel_id.into_value(), + height: Height::zero(), + })?; Ok(DualTagged::new(IdentifiedChannelEnd::new( port_id.into_value().clone(), *channel_id.into_value(), diff --git a/tools/test-framework/src/relayer/connection.rs b/tools/test-framework/src/relayer/connection.rs index 8e2dfcc93c..cdacfa7e6d 100644 --- a/tools/test-framework/src/relayer/connection.rs +++ b/tools/test-framework/src/relayer/connection.rs @@ -9,6 +9,7 @@ use ibc::core::ics03_connection::connection::{ConnectionEnd, IdentifiedConnectio use ibc::timestamp::ZERO_DURATION; use ibc::Height; use ibc_relayer::chain::handle::ChainHandle; +use ibc_relayer::chain::requests::QueryConnectionRequest; use ibc_relayer::connection::{extract_connection_id, Connection, ConnectionSide}; use crate::error::Error; @@ -88,7 +89,10 @@ pub fn query_connection_end( handle: &ChainA, connection_id: &TaggedConnectionIdRef, ) -> Result, Error> { - let connection_end = handle.query_connection(connection_id.value(), Height::zero())?; + let connection_end = handle.query_connection(QueryConnectionRequest { + connection_id: connection_id.into_value().clone(), + height: Height::zero(), + })?; Ok(DualTagged::new(connection_end)) } @@ -97,7 +101,10 @@ pub fn query_identified_connection_end( handle: &ChainA, connection_id: TaggedConnectionIdRef, ) -> Result, Error> { - let connection_end = handle.query_connection(connection_id.value(), Height::zero())?; + let connection_end = handle.query_connection(QueryConnectionRequest { + connection_id: connection_id.into_value().clone(), + height: Height::zero(), + })?; Ok(DualTagged::new(IdentifiedConnectionEnd::new( connection_id.into_value().clone(), connection_end,