From e54b914fe7ccbbf7de9e43b706f0b3a9ad079b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Laferri=C3=A8re?= Date: Mon, 6 Jun 2022 17:08:05 +0000 Subject: [PATCH] Consolidate ChainEndpoint/Handle proven queries (#2226) * Remove TODO * query_client_state consolidation * query_connection consolidation * query_channel consolidation * query_packet_commitment function * query_packet_acknowledgement * query_packet_receipt * query_next_sequence_receive * use request instead of build_packet_proofs where appropriate * build_packet_proofs now only returns proofs * build_packet_proofs no longer uses proven_packet * proven_packet removed * query_consensus_state * remove proven_client_consensus * cleanup * docstrings * changelog * fix compilation errors * mock consensus_state query Co-authored-by: Romain Ruetschi --- .../2223-consolidate-chain-query-proven.md | 2 + relayer-cli/src/commands/create/channel.rs | 28 +- relayer-cli/src/commands/create/connection.rs | 15 +- relayer-cli/src/commands/misbehaviour.rs | 15 +- relayer-cli/src/commands/query/channel.rs | 17 +- .../src/commands/query/channel_ends.rs | 68 ++-- relayer-cli/src/commands/query/channels.rs | 55 ++- relayer-cli/src/commands/query/client.rs | 56 ++- relayer-cli/src/commands/query/connection.rs | 15 +- relayer-cli/src/commands/query/packet/ack.rs | 20 +- .../src/commands/query/packet/commitment.rs | 20 +- relayer-cli/src/commands/tx/channel.rs | 28 +- relayer-cli/src/commands/tx/client.rs | 28 +- relayer-cli/src/commands/tx/transfer.rs | 43 ++- relayer/src/chain/cosmos.rs | 360 ++++++++++-------- relayer/src/chain/counterparty.rs | 131 ++++--- relayer/src/chain/endpoint.rs | 300 +++++++++++---- relayer/src/chain/handle.rs | 196 ++++++---- relayer/src/chain/handle/base.rs | 142 ++++--- relayer/src/chain/handle/cache.rs | 197 ++++++---- relayer/src/chain/handle/counting.rs | 105 ++--- relayer/src/chain/mock.rs | 116 +++--- relayer/src/chain/requests.rs | 33 ++ relayer/src/chain/runtime.rs | 164 ++++---- relayer/src/channel.rs | 202 ++++++---- relayer/src/connection.rs | 113 ++++-- relayer/src/error.rs | 3 + relayer/src/foreign_client.rs | 93 +++-- relayer/src/link.rs | 30 +- relayer/src/link/operational_data.rs | 25 +- relayer/src/link/relay_path.rs | 69 ++-- relayer/src/object.rs | 15 +- relayer/src/supervisor/client_state_filter.rs | 95 +++-- relayer/src/supervisor/scan.rs | 43 ++- relayer/src/upgrade_chain.rs | 15 +- tools/integration-test/src/mbt/utils.rs | 2 +- .../src/tests/client_settings.rs | 13 +- tools/test-framework/src/relayer/chain.rs | 99 ++--- tools/test-framework/src/relayer/channel.rs | 28 +- .../test-framework/src/relayer/connection.rs | 24 +- 40 files changed, 1841 insertions(+), 1182 deletions(-) create mode 100644 .changelog/unreleased/improvements/relayer/2223-consolidate-chain-query-proven.md diff --git a/.changelog/unreleased/improvements/relayer/2223-consolidate-chain-query-proven.md b/.changelog/unreleased/improvements/relayer/2223-consolidate-chain-query-proven.md new file mode 100644 index 0000000000..df7817429a --- /dev/null +++ b/.changelog/unreleased/improvements/relayer/2223-consolidate-chain-query-proven.md @@ -0,0 +1,2 @@ +- Consolidate ChainEndpoint::proven_* methods with their corresponding query_*() + form ([#2223](https://github.com/informalsystems/ibc-rs/issues/2223)) \ 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 f26fa1fe2e..837724b457 100644 --- a/relayer-cli/src/commands/create/channel.rs +++ b/relayer-cli/src/commands/create/channel.rs @@ -11,7 +11,7 @@ use ibc::core::ics04_channel::Version; use ibc::core::ics24_host::identifier::{ChainId, ConnectionId, PortId}; use ibc::Height; use ibc_relayer::chain::handle::ChainHandle; -use ibc_relayer::chain::requests::{QueryClientStateRequest, QueryConnectionRequest}; +use ibc_relayer::chain::requests::{IncludeProof, QueryClientStateRequest, QueryConnectionRequest}; use ibc_relayer::channel::Channel; use ibc_relayer::connection::Connection; use ibc_relayer::foreign_client::ForeignClient; @@ -187,20 +187,26 @@ impl CreateChannelCommand { // Query the connection end. let height = Height::new(chain_a.id().version(), 0); - let conn_end = chain_a - .query_connection(QueryConnectionRequest { - connection_id: connection_a.clone(), - height, - }) + let (conn_end, _) = chain_a + .query_connection( + QueryConnectionRequest { + connection_id: connection_a.clone(), + height, + }, + IncludeProof::No, + ) .unwrap_or_else(exit_with_unrecoverable_error); // Query the client state, obtain the identifier of chain b. let chain_b = chain_a - .query_client_state(QueryClientStateRequest { - client_id: conn_end.client_id().clone(), - height, - }) - .map(|cs| cs.chain_id()) + .query_client_state( + QueryClientStateRequest { + client_id: conn_end.client_id().clone(), + height, + }, + IncludeProof::No, + ) + .map(|(cs, _)| cs.chain_id()) .unwrap_or_else(exit_with_unrecoverable_error); // Spawn the runtime for side b. diff --git a/relayer-cli/src/commands/create/connection.rs b/relayer-cli/src/commands/create/connection.rs index d8377287ea..f694a5538d 100644 --- a/relayer-cli/src/commands/create/connection.rs +++ b/relayer-cli/src/commands/create/connection.rs @@ -7,7 +7,7 @@ use ibc::core::ics02_client::client_state::ClientState; use ibc::core::ics24_host::identifier::{ChainId, ClientId}; use ibc::Height; use ibc_relayer::chain::handle::ChainHandle; -use ibc_relayer::chain::requests::QueryClientStateRequest; +use ibc_relayer::chain::requests::{IncludeProof, QueryClientStateRequest}; use ibc_relayer::connection::Connection; use ibc_relayer::foreign_client::ForeignClient; @@ -115,11 +115,14 @@ impl CreateConnectionCommand { // Query client state. Extract the target chain (chain_id which this client is verifying). let height = Height::new(chain_a.id().version(), 0); - let chain_b_id = match chain_a.query_client_state(QueryClientStateRequest { - client_id: client_a_id.clone(), - height, - }) { - Ok(cs) => cs.chain_id(), + let chain_b_id = match chain_a.query_client_state( + QueryClientStateRequest { + client_id: client_a_id.clone(), + height, + }, + IncludeProof::No, + ) { + Ok((cs, _)) => cs.chain_id(), Err(e) => Output::error(format!( "failed while querying client '{}' on chain '{}' with error: {}", client_a_id, self.chain_a_id, e diff --git a/relayer-cli/src/commands/misbehaviour.rs b/relayer-cli/src/commands/misbehaviour.rs index 2b33c5171d..db33522873 100644 --- a/relayer-cli/src/commands/misbehaviour.rs +++ b/relayer-cli/src/commands/misbehaviour.rs @@ -5,7 +5,7 @@ use ibc::core::ics02_client::height::Height; use ibc::core::ics24_host::identifier::{ChainId, ClientId}; use ibc::events::IbcEvent; use ibc_relayer::chain::handle::ChainHandle; -use ibc_relayer::chain::requests::QueryClientStateRequest; +use ibc_relayer::chain::requests::{IncludeProof, QueryClientStateRequest}; use ibc_relayer::config::Config; use ibc_relayer::foreign_client::{ForeignClient, MisbehaviourResults}; use std::ops::Deref; @@ -99,11 +99,14 @@ fn misbehaviour_handling( client_id: ClientId, update: Option, ) -> Result<(), Box> { - let client_state = chain - .query_client_state(QueryClientStateRequest { - client_id: client_id.clone(), - height: Height::zero(), - }) + let (client_state, _) = chain + .query_client_state( + QueryClientStateRequest { + client_id: client_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| format!("could not query client state for {}: {}", client_id, e))?; if client_state.is_frozen() { diff --git a/relayer-cli/src/commands/query/channel.rs b/relayer-cli/src/commands/query/channel.rs index 922c232be4..c62a732c14 100644 --- a/relayer-cli/src/commands/query/channel.rs +++ b/relayer-cli/src/commands/query/channel.rs @@ -4,7 +4,7 @@ use ibc_relayer::chain::handle::ChainHandle; use ibc::core::ics24_host::identifier::ChainId; use ibc::core::ics24_host::identifier::{ChannelId, PortId}; -use ibc_relayer::chain::requests::QueryChannelRequest; +use ibc_relayer::chain::requests::{IncludeProof, QueryChannelRequest}; use crate::cli_utils::spawn_chain_runtime; use crate::conclude::{exit_with_unrecoverable_error, Output}; @@ -35,13 +35,16 @@ impl Runnable for QueryChannelEndCmd { let chain = spawn_chain_runtime(&config, &self.chain_id) .unwrap_or_else(exit_with_unrecoverable_error); - let res = chain.query_channel(QueryChannelRequest { - port_id: self.port_id.clone(), - channel_id: self.channel_id, - height: ibc::Height::new(chain.id().version(), self.height.unwrap_or(0_u64)), - }); + let res = chain.query_channel( + QueryChannelRequest { + port_id: self.port_id.clone(), + channel_id: self.channel_id, + height: ibc::Height::new(chain.id().version(), self.height.unwrap_or(0_u64)), + }, + IncludeProof::No, + ); match res { - Ok(channel_end) => { + Ok((channel_end, _)) => { if channel_end.state_matches(&State::Uninitialized) { Output::error(format!( "port '{}' & channel '{}' does not exist", diff --git a/relayer-cli/src/commands/query/channel_ends.rs b/relayer-cli/src/commands/query/channel_ends.rs index 774ae64f6c..c38e21b9e0 100644 --- a/relayer-cli/src/commands/query/channel_ends.rs +++ b/relayer-cli/src/commands/query/channel_ends.rs @@ -10,7 +10,7 @@ use ibc::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortI use ibc::Height; use ibc_relayer::chain::handle::{BaseChainHandle, ChainHandle}; use ibc_relayer::chain::requests::{ - QueryChannelRequest, QueryClientStateRequest, QueryConnectionRequest, + IncludeProof, QueryChannelRequest, QueryClientStateRequest, QueryConnectionRequest, }; use ibc_relayer::registry::Registry; @@ -81,11 +81,14 @@ fn do_run(cmd: &QueryChannelEndsCmd) -> Result<(), Box chain.query_latest_height()?, }; - let channel_end = chain.query_channel(QueryChannelRequest { - port_id: port_id.clone(), - channel_id, - height: chain_height, - })?; + let (channel_end, _) = chain.query_channel( + QueryChannelRequest { + port_id: port_id.clone(), + channel_id, + height: chain_height, + }, + IncludeProof::No, + )?; if channel_end.state_matches(&State::Uninitialized) { return Err(format!( "{}/{} on chain {} @ {:?} is uninitialized", @@ -105,17 +108,23 @@ fn do_run(cmd: &QueryChannelEndsCmd) -> Result<(), Box(cmd: &QueryChannelEndsCmd) -> Result<(), Box( channel_id: ChannelId, chain_height: Height, ) -> Result> { - let connection_end = chain.query_connection(QueryConnectionRequest { - connection_id: connection_id.clone(), - height: chain_height, - })?; + let (connection_end, _) = chain.query_connection( + QueryConnectionRequest { + connection_id: connection_id.clone(), + height: chain_height, + }, + IncludeProof::No, + )?; let client_id = connection_end.client_id().clone(); - let client_state = chain.query_client_state(QueryClientStateRequest { - client_id, - height: chain_height, - })?; + let (client_state, _) = chain.query_client_state( + QueryClientStateRequest { + client_id, + height: chain_height, + }, + IncludeProof::No, + )?; let counterparty_chain_id = client_state.chain_id(); if let Some(dst_chain_id) = destination_chain { @@ -173,23 +179,30 @@ 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(QueryConnectionRequest { + let (counterparty_connection_end, _) = counterparty_chain.query_connection( + QueryConnectionRequest { connection_id: counterparty_connection_id, height: counterparty_chain_height, - })?; + }, + IncludeProof::No, + )?; - let counterparty_client_state = - counterparty_chain.query_client_state(QueryClientStateRequest { + let (counterparty_client_state, _) = counterparty_chain.query_client_state( + QueryClientStateRequest { client_id: counterparty_client_id, height: counterparty_chain_height, - })?; - - let counterparty_channel_end = counterparty_chain.query_channel(QueryChannelRequest { - port_id: counterparty_port_id, - channel_id: counterparty_channel_id, - height: counterparty_chain_height, - })?; + }, + IncludeProof::No, + )?; + + let (counterparty_channel_end, _) = counterparty_chain.query_channel( + QueryChannelRequest { + port_id: counterparty_port_id, + channel_id: counterparty_channel_id, + height: counterparty_chain_height, + }, + IncludeProof::No, + )?; Ok(ChannelEnds { channel_end, diff --git a/relayer-cli/src/commands/query/client.rs b/relayer-cli/src/commands/query/client.rs index 2c1172ed2f..823cb95cf7 100644 --- a/relayer-cli/src/commands/query/client.rs +++ b/relayer-cli/src/commands/query/client.rs @@ -4,7 +4,7 @@ use tracing::debug; use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer::chain::requests::{ - PageRequest, QueryClientConnectionsRequest, QueryClientStateRequest, + IncludeProof, PageRequest, QueryClientConnectionsRequest, QueryClientStateRequest, QueryConsensusStateRequest, QueryConsensusStatesRequest, }; @@ -44,11 +44,14 @@ impl Runnable for QueryClientStateCmd { let height = ibc::Height::new(chain.id().version(), self.height.unwrap_or(0_u64)); - match chain.query_client_state(QueryClientStateRequest { - client_id: self.client_id.clone(), - height, - }) { - Ok(cs) => Output::success(cs).exit(), + match chain.query_client_state( + QueryClientStateRequest { + client_id: self.client_id.clone(), + height, + }, + IncludeProof::No, + ) { + Ok((cs, _)) => Output::success(cs).exit(), Err(e) => Output::error(format!("{}", e)).exit(), } } @@ -92,11 +95,14 @@ impl Runnable for QueryClientConsensusCmd { let chain = spawn_chain_runtime(&config, &self.chain_id) .unwrap_or_else(exit_with_unrecoverable_error); - let counterparty_chain = match chain.query_client_state(QueryClientStateRequest { - client_id: self.client_id.clone(), - height: Height::zero(), - }) { - Ok(cs) => cs.chain_id(), + let counterparty_chain = match chain.query_client_state( + QueryClientStateRequest { + client_id: self.client_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) { + Ok((cs, _)) => cs.chain_id(), Err(e) => Output::error(format!( "failed while querying client '{}' on chain '{}' with error: {}", self.client_id, self.chain_id, e @@ -109,11 +115,16 @@ 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(QueryConsensusStateRequest { - client_id: self.client_id.clone(), - consensus_height, - query_height: height, - }); + let res = chain + .query_consensus_state( + QueryConsensusStateRequest { + client_id: self.client_id.clone(), + consensus_height, + query_height: height, + }, + IncludeProof::No, + ) + .map(|(consensus_state, _)| consensus_state); match res { Ok(cs) => Output::success(cs).exit(), @@ -168,11 +179,14 @@ impl Runnable for QueryClientHeaderCmd { let chain = spawn_chain_runtime(&config, &self.chain_id) .unwrap_or_else(exit_with_unrecoverable_error); - let counterparty_chain = match chain.query_client_state(QueryClientStateRequest { - client_id: self.client_id.clone(), - height: Height::zero(), - }) { - Ok(cs) => cs.chain_id(), + let counterparty_chain = match chain.query_client_state( + QueryClientStateRequest { + client_id: self.client_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) { + Ok((cs, _)) => cs.chain_id(), Err(e) => Output::error(format!( "failed while querying client '{}' on chain '{}' with error: {}", self.client_id, self.chain_id, e diff --git a/relayer-cli/src/commands/query/connection.rs b/relayer-cli/src/commands/query/connection.rs index 6605d41ed3..7925c4800b 100644 --- a/relayer-cli/src/commands/query/connection.rs +++ b/relayer-cli/src/commands/query/connection.rs @@ -2,7 +2,7 @@ use abscissa_core::clap::Parser; use abscissa_core::{Command, Runnable}; use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer::chain::requests::{ - PageRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, + IncludeProof, PageRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, }; use ibc::core::{ @@ -39,12 +39,15 @@ 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(QueryConnectionRequest { - connection_id: self.connection_id.clone(), - height, - }); + let res = chain.query_connection( + QueryConnectionRequest { + connection_id: self.connection_id.clone(), + height, + }, + IncludeProof::No, + ); match res { - Ok(connection_end) => { + Ok((connection_end, _)) => { if connection_end.state_matches(&State::Uninitialized) { Output::error(format!( "connection '{}' does not exist", diff --git a/relayer-cli/src/commands/query/packet/ack.rs b/relayer-cli/src/commands/query/packet/ack.rs index afbbd07c99..cfd45e3b3f 100644 --- a/relayer-cli/src/commands/query/packet/ack.rs +++ b/relayer-cli/src/commands/query/packet/ack.rs @@ -1,8 +1,9 @@ use abscissa_core::clap::Parser; use abscissa_core::{Command, Runnable}; +use ibc_relayer::chain::requests::{IncludeProof, QueryPacketAcknowledgementRequest}; use subtle_encoding::{Encoding, Hex}; -use ibc::core::ics04_channel::packet::{PacketMsgType, Sequence}; +use ibc::core::ics04_channel::packet::Sequence; use ibc::core::ics24_host::identifier::{ChainId, ChannelId, PortId}; use ibc::Height; use ibc_relayer::chain::handle::ChainHandle; @@ -39,16 +40,17 @@ impl QueryPacketAcknowledgmentCmd { let chain = spawn_chain_runtime(&config, &self.chain_id)?; chain - .build_packet_proofs( - PacketMsgType::Ack, - &self.port_id, - &self.channel_id, - self.sequence, - Height::new(chain.id().version(), self.height.unwrap_or(0_u64)), + .query_packet_acknowledgement( + QueryPacketAcknowledgementRequest { + port_id: self.port_id.clone(), + channel_id: self.channel_id, + sequence: self.sequence, + height: Height::new(chain.id().version(), self.height.unwrap_or(0_u64)), + }, + IncludeProof::No, ) .map_err(Error::relayer) - .map(|(b, _)| b) - .map(|bytes| { + .map(|(bytes, _)| { Hex::upper_case() .encode_to_string(bytes.clone()) .unwrap_or_else(|_| format!("{:?}", bytes)) diff --git a/relayer-cli/src/commands/query/packet/commitment.rs b/relayer-cli/src/commands/query/packet/commitment.rs index 7910c53030..47c941df79 100644 --- a/relayer-cli/src/commands/query/packet/commitment.rs +++ b/relayer-cli/src/commands/query/packet/commitment.rs @@ -1,9 +1,10 @@ use abscissa_core::clap::Parser; use abscissa_core::{Command, Runnable}; +use ibc_relayer::chain::requests::{IncludeProof, QueryPacketCommitmentRequest}; use serde::Serialize; use subtle_encoding::{Encoding, Hex}; -use ibc::core::ics04_channel::packet::{PacketMsgType, Sequence}; +use ibc::core::ics04_channel::packet::Sequence; use ibc::core::ics24_host::identifier::{ChainId, ChannelId, PortId}; use ibc::Height; use ibc_relayer::chain::handle::ChainHandle; @@ -45,15 +46,16 @@ impl QueryPacketCommitmentCmd { let chain = spawn_chain_runtime(&config, &self.chain_id)?; - let bytes = chain - .build_packet_proofs( - PacketMsgType::Recv, - &self.port_id, - &self.channel_id, - self.sequence, - Height::new(chain.id().version(), self.height.unwrap_or(0_u64)), + let (bytes, _) = chain + .query_packet_commitment( + QueryPacketCommitmentRequest { + port_id: self.port_id.clone(), + channel_id: self.channel_id, + sequence: self.sequence, + height: Height::new(chain.id().version(), self.height.unwrap_or(0_u64)), + }, + IncludeProof::No, ) - .map(|(bytes, _)| bytes) .map_err(Error::relayer)?; if bytes.is_empty() { diff --git a/relayer-cli/src/commands/tx/channel.rs b/relayer-cli/src/commands/tx/channel.rs index 3aa61c2fe7..d0c2187b34 100644 --- a/relayer-cli/src/commands/tx/channel.rs +++ b/relayer-cli/src/commands/tx/channel.rs @@ -7,7 +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::chain::requests::{IncludeProof, QueryConnectionRequest}; use ibc_relayer::channel::{Channel, ChannelSide}; use crate::cli_utils::ChainHandlePair; @@ -26,11 +26,14 @@ macro_rules! tx_chan_cmd { }; // Retrieve the connection - let dst_connection = match chains.dst.query_connection(QueryConnectionRequest { - connection_id: $self.dst_conn_id.clone(), - height: Height::default(), - }) { - Ok(connection) => connection, + let dst_connection = match chains.dst.query_connection( + QueryConnectionRequest { + connection_id: $self.dst_conn_id.clone(), + height: Height::default(), + }, + IncludeProof::No, + ) { + Ok((connection, _)) => connection, Err(e) => Output::error(format!("{}", e)).exit(), }; @@ -83,11 +86,14 @@ impl Runnable for TxRawChanOpenInitCmd { }; // Retrieve the connection - let dst_connection = match chains.dst.query_connection(QueryConnectionRequest { - connection_id: self.dst_conn_id.clone(), - height: Height::default(), - }) { - Ok(connection) => connection, + let dst_connection = match chains.dst.query_connection( + QueryConnectionRequest { + connection_id: self.dst_conn_id.clone(), + height: Height::default(), + }, + IncludeProof::No, + ) { + 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 67b3030afe..e791ec21c7 100644 --- a/relayer-cli/src/commands/tx/client.rs +++ b/relayer-cli/src/commands/tx/client.rs @@ -8,7 +8,7 @@ use ibc::core::ics24_host::identifier::{ChainId, ClientId}; use ibc::events::IbcEvent; use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer::chain::requests::{ - PageRequest, QueryClientStateRequest, QueryClientStatesRequest, + IncludeProof, PageRequest, QueryClientStateRequest, QueryClientStatesRequest, }; use ibc_relayer::config::Config; use ibc_relayer::foreign_client::{CreateOptions, ForeignClient}; @@ -116,11 +116,14 @@ impl Runnable for TxUpdateClientCmd { Err(e) => Output::error(format!("{}", 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(), + let src_chain_id = match dst_chain.query_client_state( + QueryClientStateRequest { + client_id: self.dst_client_id.clone(), + height: ibc::Height::zero(), + }, + IncludeProof::No, + ) { + Ok((cs, _)) => cs.chain_id(), Err(e) => { Output::error(format!( "Query of client '{}' on chain '{}' failed with error: {}", @@ -180,11 +183,14 @@ impl Runnable for TxUpgradeClientCmd { Err(e) => Output::error(format!("{}", e)).exit(), }; - 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(), + let src_chain_id = match dst_chain.query_client_state( + QueryClientStateRequest { + client_id: self.client_id.clone(), + height: ibc::Height::zero(), + }, + IncludeProof::No, + ) { + Ok((cs, _)) => cs.chain_id(), Err(e) => { Output::error(format!( "Query of client '{}' on chain '{}' failed with error: {}", diff --git a/relayer-cli/src/commands/tx/transfer.rs b/relayer-cli/src/commands/tx/transfer.rs index 860a7c51e2..77c92a9ace 100644 --- a/relayer-cli/src/commands/tx/transfer.rs +++ b/relayer-cli/src/commands/tx/transfer.rs @@ -13,7 +13,7 @@ use ibc::{ }; use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer::chain::requests::{ - QueryChannelRequest, QueryClientStateRequest, QueryConnectionRequest, + IncludeProof, QueryChannelRequest, QueryClientStateRequest, QueryConnectionRequest, }; use ibc_relayer::{ config::Config, @@ -171,13 +171,16 @@ impl Runnable for TxIcs20MsgTransferCmd { // To do this, fetch from the source chain the channel end, then the associated connection // end, and then the underlying client state; finally, check that this client is verifying // headers for the destination chain. - let channel_end_src = chains + let (channel_end_src, _) = chains .src - .query_channel(QueryChannelRequest { - port_id: opts.packet_src_port_id.clone(), - channel_id: opts.packet_src_channel_id, - height: Height::zero(), - }) + .query_channel( + QueryChannelRequest { + port_id: opts.packet_src_port_id.clone(), + channel_id: opts.packet_src_channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) .unwrap_or_else(exit_with_unrecoverable_error); if !channel_end_src.is_open() { Output::error(format!( @@ -201,22 +204,28 @@ impl Runnable for TxIcs20MsgTransferCmd { Some(cid) => cid, }; - let conn_end = chains + let (conn_end, _) = chains .src - .query_connection(QueryConnectionRequest { - connection_id: conn_id.clone(), - height: Height::zero(), - }) + .query_connection( + QueryConnectionRequest { + connection_id: conn_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .unwrap_or_else(exit_with_unrecoverable_error); debug!("connection hop underlying the channel: {:?}", conn_end); - let src_chain_client_state = chains + let (src_chain_client_state, _) = chains .src - .query_client_state(QueryClientStateRequest { - client_id: conn_end.client_id().clone(), - height: Height::zero(), - }) + .query_client_state( + QueryClientStateRequest { + client_id: conn_end.client_id().clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .unwrap_or_else(exit_with_unrecoverable_error); debug!( diff --git a/relayer/src/chain/cosmos.rs b/relayer/src/chain/cosmos.rs index b064f07d05..93b500a871 100644 --- a/relayer/src/chain/cosmos.rs +++ b/relayer/src/chain/cosmos.rs @@ -1,4 +1,5 @@ use alloc::sync::Arc; +use bytes::{Buf, Bytes}; use core::{ convert::{TryFrom, TryInto}, future::Future, @@ -34,9 +35,9 @@ use ibc::core::ics04_channel::channel::{ ChannelEnd, IdentifiedChannelEnd, QueryPacketEventDataRequest, }; use ibc::core::ics04_channel::events as ChannelEvents; -use ibc::core::ics04_channel::packet::{Packet, PacketMsgType, Sequence}; +use ibc::core::ics04_channel::packet::{Packet, Sequence}; use ibc::core::ics23_commitment::commitment::CommitmentPrefix; -use ibc::core::ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, PortId}; +use ibc::core::ics24_host::identifier::{ChainId, ClientId, ConnectionId}; use ibc::core::ics24_host::path::{ AcksPath, ChannelEndsPath, ClientConsensusStatePath, ClientStatePath, CommitmentsPath, ConnectionsPath, ReceiptsPath, SeqRecvsPath, @@ -78,13 +79,15 @@ use crate::light_client::tendermint::LightClient as TmLightClient; use crate::light_client::{LightClient, Verified}; use super::requests::{ - QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + IncludeProof, QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, - QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, - QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, - QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementRequest, + QueryPacketAcknowledgementsRequest, QueryPacketCommitmentRequest, + QueryPacketCommitmentsRequest, QueryPacketReceiptRequest, QueryUnreceivedAcksRequest, + QueryUnreceivedPacketsRequest, QueryUpgradedClientStateRequest, + QueryUpgradedConsensusStateRequest, }; pub mod batch; @@ -747,15 +750,25 @@ impl ChainEndpoint for CosmosSdkChain { fn query_client_state( &self, request: QueryClientStateRequest, - ) -> Result { + include_proof: IncludeProof, + ) -> Result<(AnyClientState, Option), Error> { crate::time!("query_client_state"); crate::telemetry!(query, self.id(), "query_client_state"); - let client_state = self - .query(ClientStatePath(request.client_id), request.height, false) - .and_then(|v| AnyClientState::decode_vec(&v.value).map_err(Error::decode))?; + let res = self.query( + ClientStatePath(request.client_id.clone()), + request.height, + matches!(include_proof, IncludeProof::Yes), + )?; + let client_state = AnyClientState::decode_vec(&res.value).map_err(Error::decode)?; - Ok(client_state) + match include_proof { + IncludeProof::Yes => { + let proof = res.proof.ok_or_else(Error::empty_response_proof)?; + Ok((client_state, Some(proof))) + } + IncludeProof::No => Ok((client_state, None)), + } } fn query_upgraded_client_state( @@ -836,17 +849,37 @@ impl ChainEndpoint for CosmosSdkChain { fn query_consensus_state( &self, request: QueryConsensusStateRequest, - ) -> Result { + include_proof: IncludeProof, + ) -> Result<(AnyConsensusState, Option), Error> { crate::time!("query_consensus_state"); crate::telemetry!(query, self.id(), "query_consensus_state"); - let (consensus_state, _proof) = self.proven_client_consensus( - &request.client_id, - request.consensus_height, + let res = self.query( + ClientConsensusStatePath { + client_id: request.client_id.clone(), + epoch: request.consensus_height.revision_number, + height: request.consensus_height.revision_height, + }, request.query_height, + matches!(include_proof, IncludeProof::Yes), )?; - Ok(consensus_state) + let consensus_state = AnyConsensusState::decode_vec(&res.value).map_err(Error::decode)?; + + if !matches!(consensus_state, AnyConsensusState::Tendermint(_)) { + return Err(Error::consensus_state_type_mismatch( + ClientType::Tendermint, + consensus_state.client_type(), + )); + } + + match include_proof { + IncludeProof::Yes => { + let proof = res.proof.ok_or_else(Error::empty_response_proof)?; + Ok((consensus_state, Some(proof))) + } + IncludeProof::No => Ok((consensus_state, None)), + } } fn query_client_connections( @@ -918,7 +951,11 @@ impl ChainEndpoint for CosmosSdkChain { Ok(connections) } - fn query_connection(&self, request: QueryConnectionRequest) -> Result { + fn query_connection( + &self, + request: QueryConnectionRequest, + include_proof: IncludeProof, + ) -> Result<(ConnectionEnd, Option), Error> { crate::time!("query_connection"); crate::telemetry!(query, self.id(), "query_connection"); @@ -971,9 +1008,27 @@ impl ChainEndpoint for CosmosSdkChain { } } - self.block_on(async { - do_query_connection(self, &request.connection_id, request.height).await - }) + match include_proof { + IncludeProof::Yes => { + let res = self.query( + ConnectionsPath(request.connection_id.clone()), + request.height, + true, + )?; + let connection_end = + ConnectionEnd::decode_vec(&res.value).map_err(Error::decode)?; + + Ok(( + connection_end, + Some(res.proof.ok_or_else(Error::empty_response_proof)?), + )) + } + IncludeProof::No => self + .block_on(async { + do_query_connection(self, &request.connection_id, request.height).await + }) + .map(|conn_end| (conn_end, None)), + } } fn query_connection_channels( @@ -1039,18 +1094,29 @@ impl ChainEndpoint for CosmosSdkChain { Ok(channels) } - fn query_channel(&self, request: QueryChannelRequest) -> Result { + fn query_channel( + &self, + request: QueryChannelRequest, + include_proof: IncludeProof, + ) -> Result<(ChannelEnd, Option), Error> { crate::time!("query_channel"); crate::telemetry!(query, self.id(), "query_channel"); let res = self.query( ChannelEndsPath(request.port_id, request.channel_id), request.height, - false, + matches!(include_proof, IncludeProof::Yes), )?; + let channel_end = ChannelEnd::decode_vec(&res.value).map_err(Error::decode)?; - Ok(channel_end) + match include_proof { + IncludeProof::Yes => { + let proof = res.proof.ok_or_else(Error::empty_response_proof)?; + Ok((channel_end, Some(proof))) + } + IncludeProof::No => Ok((channel_end, None)), + } } fn query_channel_client_state( @@ -1082,6 +1148,31 @@ impl ChainEndpoint for CosmosSdkChain { Ok(client_state) } + fn query_packet_commitment( + &self, + request: QueryPacketCommitmentRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + let res = self.query( + CommitmentsPath { + port_id: request.port_id, + channel_id: request.channel_id, + sequence: request.sequence, + }, + request.height, + matches!(include_proof, IncludeProof::Yes), + )?; + + match include_proof { + IncludeProof::Yes => { + let proof = res.proof.ok_or_else(Error::empty_response_proof)?; + + Ok((res.value, Some(proof))) + } + IncludeProof::No => Ok((res.value, None)), + } + } + /// Queries the packet commitment hashes associated with a channel. fn query_packet_commitments( &self, @@ -1120,6 +1211,31 @@ impl ChainEndpoint for CosmosSdkChain { Ok((commitment_sequences, height)) } + fn query_packet_receipt( + &self, + request: QueryPacketReceiptRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + let res = self.query( + ReceiptsPath { + port_id: request.port_id, + channel_id: request.channel_id, + sequence: request.sequence, + }, + request.height, + matches!(include_proof, IncludeProof::Yes), + )?; + + match include_proof { + IncludeProof::Yes => { + let proof = res.proof.ok_or_else(Error::empty_response_proof)?; + + Ok((res.value, Some(proof))) + } + IncludeProof::No => Ok((res.value, None)), + } + } + /// Queries the unreceived packet sequences associated with a channel. fn query_unreceived_packets( &self, @@ -1151,6 +1267,31 @@ impl ChainEndpoint for CosmosSdkChain { .collect()) } + fn query_packet_acknowledgement( + &self, + request: QueryPacketAcknowledgementRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + let res = self.query( + AcksPath { + port_id: request.port_id, + channel_id: request.channel_id, + sequence: request.sequence, + }, + request.height, + matches!(include_proof, IncludeProof::Yes), + )?; + + match include_proof { + IncludeProof::Yes => { + let proof = res.proof.ok_or_else(Error::empty_response_proof)?; + + Ok((res.value, Some(proof))) + } + IncludeProof::No => Ok((res.value, None)), + } + } + /// Queries the packet acknowledgment hashes associated with a channel. fn query_packet_acknowledgements( &self, @@ -1222,26 +1363,49 @@ impl ChainEndpoint for CosmosSdkChain { fn query_next_sequence_receive( &self, request: QueryNextSequenceReceiveRequest, - ) -> Result { + include_proof: IncludeProof, + ) -> Result<(Sequence, Option), Error> { crate::time!("query_next_sequence_receive"); crate::telemetry!(query, self.id(), "query_next_sequence_receive"); - let mut client = self - .block_on( - ibc_proto::ibc::core::channel::v1::query_client::QueryClient::connect( - self.grpc_addr.clone(), - ), - ) - .map_err(Error::grpc_transport)?; + match include_proof { + IncludeProof::Yes => { + let res = self.query( + SeqRecvsPath(request.port_id, request.channel_id), + request.height, + true, + )?; + + // Note: We expect the return to be a u64 encoded in big-endian. Refer to ibc-go: + // https://github.com/cosmos/ibc-go/blob/25767f6bdb5bab2c2a116b41d92d753c93e18121/modules/core/04-channel/client/utils/utils.go#L191 + if res.value.len() != 8 { + return Err(Error::query("next_sequence_receive".into())); + } + let seq: Sequence = Bytes::from(res.value).get_u64().into(); - let request = tonic::Request::new(request.into()); + let proof = res.proof.ok_or_else(Error::empty_response_proof)?; - let response = self - .block_on(client.next_sequence_receive(request)) - .map_err(Error::grpc_status)? - .into_inner(); + Ok((seq, Some(proof))) + } + IncludeProof::No => { + let mut client = self + .block_on( + ibc_proto::ibc::core::channel::v1::query_client::QueryClient::connect( + self.grpc_addr.clone(), + ), + ) + .map_err(Error::grpc_transport)?; - Ok(Sequence::from(response.next_sequence_receive)) + let request = tonic::Request::new(request.into()); + + let response = self + .block_on(client.next_sequence_receive(request)) + .map_err(Error::grpc_status)? + .into_inner(); + + Ok((Sequence::from(response.next_sequence_receive), None)) + } + } } /// This function queries transactions for events matching certain criteria. @@ -1350,128 +1514,6 @@ impl ChainEndpoint for CosmosSdkChain { Ok(response.block.header.into()) } - fn proven_client_state( - &self, - client_id: &ClientId, - height: ICSHeight, - ) -> Result<(AnyClientState, MerkleProof), Error> { - crate::time!("proven_client_state"); - - let res = self.query(ClientStatePath(client_id.clone()), height, true)?; - - let client_state = AnyClientState::decode_vec(&res.value).map_err(Error::decode)?; - - Ok(( - client_state, - res.proof.ok_or_else(Error::empty_response_proof)?, - )) - } - - fn proven_client_consensus( - &self, - client_id: &ClientId, - consensus_height: ICSHeight, - height: ICSHeight, - ) -> Result<(AnyConsensusState, MerkleProof), Error> { - crate::time!("proven_client_consensus"); - - let res = self.query( - ClientConsensusStatePath { - client_id: client_id.clone(), - epoch: consensus_height.revision_number, - height: consensus_height.revision_height, - }, - height, - true, - )?; - - let consensus_state = AnyConsensusState::decode_vec(&res.value).map_err(Error::decode)?; - - if !matches!(consensus_state, AnyConsensusState::Tendermint(_)) { - return Err(Error::consensus_state_type_mismatch( - ClientType::Tendermint, - consensus_state.client_type(), - )); - } - - let proof = res.proof.ok_or_else(Error::empty_response_proof)?; - - Ok((consensus_state, proof)) - } - - fn proven_connection( - &self, - connection_id: &ConnectionId, - height: ICSHeight, - ) -> Result<(ConnectionEnd, MerkleProof), Error> { - let res = self.query(ConnectionsPath(connection_id.clone()), height, true)?; - let connection_end = ConnectionEnd::decode_vec(&res.value).map_err(Error::decode)?; - - Ok(( - connection_end, - res.proof.ok_or_else(Error::empty_response_proof)?, - )) - } - - fn proven_channel( - &self, - port_id: &PortId, - channel_id: &ChannelId, - height: ICSHeight, - ) -> Result<(ChannelEnd, MerkleProof), Error> { - let res = self.query(ChannelEndsPath(port_id.clone(), *channel_id), height, true)?; - - let channel_end = ChannelEnd::decode_vec(&res.value).map_err(Error::decode)?; - - Ok(( - channel_end, - res.proof.ok_or_else(Error::empty_response_proof)?, - )) - } - - fn proven_packet( - &self, - packet_type: PacketMsgType, - port_id: PortId, - channel_id: ChannelId, - sequence: Sequence, - height: ICSHeight, - ) -> Result<(Vec, MerkleProof), Error> { - let data: Path = match packet_type { - PacketMsgType::Recv => CommitmentsPath { - port_id, - channel_id, - sequence, - } - .into(), - PacketMsgType::Ack => AcksPath { - port_id, - channel_id, - sequence, - } - .into(), - PacketMsgType::TimeoutUnordered => ReceiptsPath { - port_id, - channel_id, - sequence, - } - .into(), - PacketMsgType::TimeoutOrdered => SeqRecvsPath(port_id, channel_id).into(), - PacketMsgType::TimeoutOnClose => ReceiptsPath { - port_id, - channel_id, - sequence, - } - .into(), - }; - - let res = self.query(data, height, true)?; - - let commitment_proof_bytes = res.proof.ok_or_else(Error::empty_response_proof)?; - - Ok((res.value, commitment_proof_bytes)) - } - fn build_client_state( &self, height: ICSHeight, diff --git a/relayer/src/chain/counterparty.rs b/relayer/src/chain/counterparty.rs index 88a7307e79..acc75b26fd 100644 --- a/relayer/src/chain/counterparty.rs +++ b/relayer/src/chain/counterparty.rs @@ -5,9 +5,9 @@ use serde::{Deserialize, Serialize}; use tracing::{error, trace}; use super::requests::{ - PageRequest, QueryChannelRequest, QueryClientConnectionsRequest, QueryClientStateRequest, - QueryConnectionRequest, QueryPacketAcknowledgementsRequest, QueryUnreceivedAcksRequest, - QueryUnreceivedPacketsRequest, + IncludeProof, PageRequest, QueryChannelRequest, QueryClientConnectionsRequest, + QueryClientStateRequest, QueryConnectionRequest, QueryPacketAcknowledgementsRequest, + QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, }; use super::{ handle::ChainHandle, @@ -34,19 +34,25 @@ pub fn counterparty_chain_from_connection( src_chain: &impl ChainHandle, src_connection_id: &ConnectionId, ) -> Result { - let connection_end = src_chain - .query_connection(QueryConnectionRequest { - connection_id: src_connection_id.clone(), - height: Height::zero(), - }) + let (connection_end, _) = src_chain + .query_connection( + QueryConnectionRequest { + connection_id: src_connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(Error::relayer)?; let client_id = connection_end.client_id(); - let client_state = src_chain - .query_client_state(QueryClientStateRequest { - client_id: client_id.clone(), - height: Height::zero(), - }) + let (client_state, _) = src_chain + .query_client_state( + QueryClientStateRequest { + client_id: client_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(Error::relayer)?; trace!( @@ -68,11 +74,14 @@ fn connection_on_destination( .map_err(Error::relayer)?; for counterparty_connection in counterparty_connections.into_iter() { - let counterparty_connection_end = counterparty_chain - .query_connection(QueryConnectionRequest { - connection_id: counterparty_connection.clone(), - height: Height::zero(), - }) + let (counterparty_connection_end, _) = counterparty_chain + .query_connection( + QueryConnectionRequest { + connection_id: counterparty_connection.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(Error::relayer)?; let local_connection_end = &counterparty_connection_end.counterparty(); @@ -90,11 +99,14 @@ pub fn connection_state_on_destination( counterparty_chain: &impl ChainHandle, ) -> Result { if let Some(remote_connection_id) = connection.connection_end.counterparty().connection_id() { - let connection_end = counterparty_chain - .query_connection(QueryConnectionRequest { - connection_id: remote_connection_id.clone(), - height: Height::zero(), - }) + let (connection_end, _) = counterparty_chain + .query_connection( + QueryConnectionRequest { + connection_id: remote_connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(Error::relayer)?; Ok(connection_end.state) @@ -144,12 +156,15 @@ pub fn channel_connection_client( port_id: &PortId, channel_id: &ChannelId, ) -> Result { - let channel_end = chain - .query_channel(QueryChannelRequest { - port_id: port_id.clone(), - channel_id: *channel_id, - height: Height::zero(), - }) + let (channel_end, _) = chain + .query_channel( + QueryChannelRequest { + port_id: port_id.clone(), + channel_id: *channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(Error::relayer)?; if channel_end.state_matches(&State::Uninitialized) { @@ -165,11 +180,14 @@ pub fn channel_connection_client( .first() .ok_or_else(|| Error::missing_connection_hops(*channel_id, chain.id()))?; - let connection_end = chain - .query_connection(QueryConnectionRequest { - connection_id: connection_id.clone(), - height: Height::zero(), - }) + let (connection_end, _) = chain + .query_connection( + QueryConnectionRequest { + connection_id: connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(Error::relayer)?; if !connection_end.is_open() { @@ -181,11 +199,14 @@ pub fn channel_connection_client( } let client_id = connection_end.client_id(); - let client_state = chain - .query_client_state(QueryClientStateRequest { - client_id: client_id.clone(), - height: Height::zero(), - }) + let (client_state, _) = chain + .query_client_state( + QueryClientStateRequest { + client_id: client_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(Error::relayer)?; let client = IdentifiedAnyClientState::new(client_id.clone(), client_state); @@ -247,12 +268,15 @@ 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(QueryChannelRequest { - port_id: channel.channel_end.counterparty().port_id().clone(), - channel_id: *remote_channel_id, - height: Height::zero(), - }) - .map(|c| IdentifiedChannelEnd { + .query_channel( + QueryChannelRequest { + port_id: channel.channel_end.counterparty().port_id().clone(), + channel_id: *remote_channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) + .map(|(c, _)| IdentifiedChannelEnd { port_id: channel.channel_end.counterparty().port_id().clone(), channel_id: *remote_channel_id, channel_end: c, @@ -281,12 +305,15 @@ pub fn check_channel_counterparty( target_pchan: &PortChannelId, expected: &PortChannelId, ) -> Result<(), ChannelError> { - let channel_end_dst = target_chain - .query_channel(QueryChannelRequest { - port_id: target_pchan.port_id.clone(), - channel_id: target_pchan.channel_id, - height: Height::zero(), - }) + let (channel_end_dst, _) = target_chain + .query_channel( + QueryChannelRequest { + port_id: target_pchan.port_id.clone(), + channel_id: target_pchan.channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ChannelError::query(target_chain.id(), e))?; let counterparty = channel_end_dst.remote; @@ -405,7 +432,7 @@ pub fn unreceived_acknowledgements_sequences( } chain - .query_unreceived_acknowledgement(QueryUnreceivedAcksRequest { + .query_unreceived_acknowledgements(QueryUnreceivedAcksRequest { port_id: port_id.clone(), channel_id: *channel_id, packet_ack_sequences: acks_on_counterparty, diff --git a/relayer/src/chain/endpoint.rs b/relayer/src/chain/endpoint.rs index 6b75fddc9c..b63d627f06 100644 --- a/relayer/src/chain/endpoint.rs +++ b/relayer/src/chain/endpoint.rs @@ -39,11 +39,16 @@ use crate::chain::requests::{ use crate::chain::tracking::TrackedMsgs; use crate::config::ChainConfig; use crate::connection::ConnectionMsgType; -use crate::error::Error; +use crate::error::{Error, QUERY_PROOF_EXPECT_MSG}; use crate::event::monitor::{EventReceiver, TxMonitorCmd}; use crate::keyring::{KeyEntry, KeyRing}; use crate::light_client::LightClient; +use super::requests::{ + IncludeProof, QueryPacketAcknowledgementRequest, QueryPacketCommitmentRequest, + QueryPacketReceiptRequest, +}; + /// The result of a health check. #[derive(Debug)] pub enum HealthCheck { @@ -149,20 +154,28 @@ pub trait ChainEndpoint: Sized { request: QueryClientStatesRequest, ) -> Result, Error>; - fn query_client_state(&self, request: QueryClientStateRequest) - -> Result; - - fn query_consensus_states( + /// Performs a query to retrieve the state of the specified light client. A + /// proof can optionally be returned along with the result. + fn query_client_state( &self, - request: QueryConsensusStatesRequest, - ) -> Result, Error>; + request: QueryClientStateRequest, + include_proof: IncludeProof, + ) -> Result<(AnyClientState, Option), Error>; - /// Performs a query to retrieve the consensus state (for a specific height `consensus_height`) - /// that an on-chain client stores. + /// Performs a query to retrieve the consensus state for a specified height + /// `consensus_height` that the specified light client stores. fn query_consensus_state( &self, request: QueryConsensusStateRequest, - ) -> Result; + include_proof: IncludeProof, + ) -> Result<(AnyConsensusState, Option), Error>; + + /// Performs a query to retrieve all the consensus states that the specified + /// light client stores. + fn query_consensus_states( + &self, + request: QueryConsensusStatesRequest, + ) -> Result, Error>; fn query_upgraded_client_state( &self, @@ -186,59 +199,116 @@ pub trait ChainEndpoint: Sized { request: QueryClientConnectionsRequest, ) -> Result, Error>; - fn query_connection(&self, request: QueryConnectionRequest) -> Result; + /// Performs a query to retrieve the connection associated with a given + /// connection identifier. A proof can optionally be returned along with the + /// result. + fn query_connection( + &self, + request: QueryConnectionRequest, + include_proof: IncludeProof, + ) -> Result<(ConnectionEnd, Option), Error>; - /// Performs a query to retrieve the identifiers of all channels associated with a connection. + /// Performs a query to retrieve all channels associated with a connection. fn query_connection_channels( &self, request: QueryConnectionChannelsRequest, ) -> Result, Error>; - /// Performs a query to retrieve the identifiers of all channels. + /// Performs a query to retrieve all the channels of a chain. fn query_channels( &self, request: QueryChannelsRequest, ) -> Result, Error>; - fn query_channel(&self, request: QueryChannelRequest) -> Result; + /// Performs a query to retrieve the channel associated with a given channel + /// identifier. A proof can optionally be returned along with the result. + fn query_channel( + &self, + request: QueryChannelRequest, + include_proof: IncludeProof, + ) -> Result<(ChannelEnd, Option), Error>; + /// Performs a query to retrieve the client state for the channel associated + /// with a given channel identifier. 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. + /// Performs a query to retrieve a stored packet commitment hash, stored on + /// the chain at path `path::CommitmentsPath`. A proof can optionally be + /// returned along with the result. + fn query_packet_commitment( + &self, + request: QueryPacketCommitmentRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error>; + + /// Performs a query to retrieve all the packet commitments hashes + /// associated with a channel. Returns the corresponding packet sequence + /// numbers and the height at which they were retrieved. fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, ) -> Result<(Vec, ICSHeight), Error>; - /// Queries all the unreceived IBC packets associated with a channel and packet commit sequences. - /// Returns the corresponding packet sequence numbers. + /// Performs a query to retrieve a given packet receipt, stored on the chain at path + /// `path::CommitmentsPath`. A proof can optionally be returned along with the result. + fn query_packet_receipt( + &self, + request: QueryPacketReceiptRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error>; + + /// Performs a query about which IBC packets in the specified list has not + /// been received. Returns the sequence numbers of the packets that were not + /// received. + /// + /// For example, given a request with the sequence numbers `[5,6,7,8]`, a + /// response of `[7,8]` would indicate that packets 5 & 6 were received, + /// while packets 7, 8 were not. fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, ) -> Result, Error>; - /// Queries all the packet acknowledgements associated with a channel. - /// Returns the corresponding packet sequence numbers. + /// Performs a query to retrieve a stored packet acknowledgement hash, + /// stored on the chain at path `path::AcksPath`. A proof can optionally be + /// returned along with the result. + fn query_packet_acknowledgement( + &self, + request: QueryPacketAcknowledgementRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error>; + + /// Performs a query to retrieve all the packet acknowledgements associated + /// with a channel. Returns the corresponding packet sequence numbers and + /// the height at which they were retrieved. fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, ) -> Result<(Vec, ICSHeight), Error>; - /// Queries all the unreceived packet acknowledgements associated with a - /// Returns the corresponding packet sequence numbers. + /// Performs a query about which IBC packets in the specified list has not + /// been acknowledged. Returns the sequence numbers of the packets that were not + /// acknowledged. + /// + /// For example, given a request with the sequence numbers `[5,6,7,8]`, a + /// response of `[7,8]` would indicate that packets 5 & 6 were acknowledged, + /// while packets 7, 8 were not. fn query_unreceived_acknowledgements( &self, request: QueryUnreceivedAcksRequest, ) -> Result, Error>; + /// Performs a query to retrieve `nextSequenceRecv` stored at path + /// `path::SeqRecvsPath` as defined in ICS-4. A proof can optionally be + /// returned along with the result. fn query_next_sequence_receive( &self, request: QueryNextSequenceReceiveRequest, - ) -> Result; + include_proof: IncludeProof, + ) -> Result<(Sequence, Option), Error>; fn query_txs(&self, request: QueryTxRequest) -> Result, Error>; @@ -252,42 +322,6 @@ pub trait ChainEndpoint: Sized { request: QueryHostConsensusStateRequest, ) -> Result; - // Provable queries - fn proven_client_state( - &self, - client_id: &ClientId, - height: ICSHeight, - ) -> Result<(AnyClientState, MerkleProof), Error>; - - fn proven_connection( - &self, - connection_id: &ConnectionId, - height: ICSHeight, - ) -> Result<(ConnectionEnd, MerkleProof), Error>; - - fn proven_client_consensus( - &self, - client_id: &ClientId, - consensus_height: ICSHeight, - height: ICSHeight, - ) -> Result<(AnyConsensusState, MerkleProof), Error>; - - fn proven_channel( - &self, - port_id: &PortId, - channel_id: &ChannelId, - height: ICSHeight, - ) -> Result<(ChannelEnd, MerkleProof), Error>; - - fn proven_packet( - &self, - packet_type: PacketMsgType, - port_id: PortId, - channel_id: ChannelId, - sequence: Sequence, - height: ICSHeight, - ) -> Result<(Vec, MerkleProof), Error>; - fn build_client_state( &self, height: ICSHeight, @@ -321,7 +355,14 @@ pub trait ChainEndpoint: Sized { client_id: &ClientId, height: ICSHeight, ) -> Result<(Option, Proofs), Error> { - let (connection_end, connection_proof) = self.proven_connection(connection_id, height)?; + let (connection_end, maybe_connection_proof) = self.query_connection( + QueryConnectionRequest { + connection_id: connection_id.clone(), + height, + }, + IncludeProof::Yes, + )?; + let connection_proof = maybe_connection_proof.expect(QUERY_PROOF_EXPECT_MSG); // Check that the connection state is compatible with the message match message_type { @@ -352,17 +393,32 @@ pub trait ChainEndpoint: Sized { match message_type { ConnectionMsgType::OpenTry | ConnectionMsgType::OpenAck => { - let (client_state_value, client_state_proof) = - self.proven_client_state(client_id, height)?; + let (client_state_value, maybe_client_state_proof) = self.query_client_state( + QueryClientStateRequest { + client_id: client_id.clone(), + height, + }, + IncludeProof::Yes, + )?; + let client_state_proof = maybe_client_state_proof.expect(QUERY_PROOF_EXPECT_MSG); client_proof = Some( CommitmentProofBytes::try_from(client_state_proof) .map_err(Error::malformed_proof)?, ); - let consensus_state_proof = self - .proven_client_consensus(client_id, client_state_value.latest_height(), height)? - .1; + let consensus_state_proof = { + let (_, maybe_consensus_state_proof) = self.query_consensus_state( + QueryConsensusStateRequest { + client_id: client_id.clone(), + consensus_height: client_state_value.latest_height(), + query_height: height, + }, + IncludeProof::Yes, + )?; + + maybe_consensus_state_proof.expect(QUERY_PROOF_EXPECT_MSG) + }; consensus_proof = Option::from( ConsensusProof::new( @@ -399,11 +455,19 @@ pub trait ChainEndpoint: Sized { height: ICSHeight, ) -> Result { // Collect all proofs as required - let channel_proof = - CommitmentProofBytes::try_from(self.proven_channel(port_id, channel_id, height)?.1) - .map_err(Error::malformed_proof)?; - - Proofs::new(channel_proof, None, None, None, height.increment()) + let (_, maybe_channel_proof) = self.query_channel( + QueryChannelRequest { + port_id: port_id.clone(), + channel_id: *channel_id, + height, + }, + IncludeProof::Yes, + )?; + let channel_proof = maybe_channel_proof.expect(QUERY_PROOF_EXPECT_MSG); + let channel_proof_bytes = + CommitmentProofBytes::try_from(channel_proof).map_err(Error::malformed_proof)?; + + Proofs::new(channel_proof_bytes, None, None, None, height.increment()) .map_err(Error::malformed_proof) } @@ -415,20 +479,90 @@ pub trait ChainEndpoint: Sized { channel_id: ChannelId, sequence: Sequence, height: ICSHeight, - ) -> Result<(Vec, Proofs), Error> { - let channel_proof = if packet_type == PacketMsgType::TimeoutOnClose { - Some( - CommitmentProofBytes::try_from( - self.proven_channel(&port_id, &channel_id, height)?.1, - ) - .map_err(Error::malformed_proof)?, - ) - } else { - None + ) -> Result { + let (maybe_packet_proof, channel_proof) = match packet_type { + PacketMsgType::Recv => { + let (_, maybe_packet_proof) = self.query_packet_commitment( + QueryPacketCommitmentRequest { + port_id, + channel_id, + sequence, + height, + }, + IncludeProof::Yes, + )?; + + (maybe_packet_proof, None) + } + PacketMsgType::Ack => { + let (_, maybe_packet_proof) = self.query_packet_acknowledgement( + QueryPacketAcknowledgementRequest { + port_id, + channel_id, + sequence, + height, + }, + IncludeProof::Yes, + )?; + + (maybe_packet_proof, None) + } + PacketMsgType::TimeoutUnordered => { + let (_, maybe_packet_proof) = self.query_packet_receipt( + QueryPacketReceiptRequest { + port_id, + channel_id, + sequence, + height, + }, + IncludeProof::Yes, + )?; + + (maybe_packet_proof, None) + } + PacketMsgType::TimeoutOrdered => { + let (_, maybe_packet_proof) = self.query_next_sequence_receive( + QueryNextSequenceReceiveRequest { + port_id, + channel_id, + height, + }, + IncludeProof::Yes, + )?; + + (maybe_packet_proof, None) + } + PacketMsgType::TimeoutOnClose => { + let channel_proof = { + let (_, maybe_channel_proof) = self.query_channel( + QueryChannelRequest { + port_id: port_id.clone(), + channel_id, + height, + }, + IncludeProof::Yes, + )?; + let channel_merkle_proof = maybe_channel_proof.expect(QUERY_PROOF_EXPECT_MSG); + Some( + CommitmentProofBytes::try_from(channel_merkle_proof) + .map_err(Error::malformed_proof)?, + ) + }; + let (_, maybe_packet_proof) = self.query_packet_receipt( + QueryPacketReceiptRequest { + port_id, + channel_id, + sequence, + height, + }, + IncludeProof::Yes, + )?; + + (maybe_packet_proof, channel_proof) + } }; - let (bytes, packet_proof) = - self.proven_packet(packet_type, port_id, channel_id, sequence, height)?; + let packet_proof = maybe_packet_proof.expect(QUERY_PROOF_EXPECT_MSG); let proofs = Proofs::new( CommitmentProofBytes::try_from(packet_proof).map_err(Error::malformed_proof)?, @@ -439,6 +573,6 @@ pub trait ChainEndpoint: Sized { ) .map_err(Error::malformed_proof)?; - Ok((bytes, proofs)) + Ok(proofs) } } diff --git a/relayer/src/chain/handle.rs b/relayer/src/chain/handle.rs index dfffb2c187..6766590a3c 100644 --- a/relayer/src/chain/handle.rs +++ b/relayer/src/chain/handle.rs @@ -44,13 +44,15 @@ use super::{ client::ClientSettings, endpoint::{ChainStatus, HealthCheck}, requests::{ - QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + IncludeProof, QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, - QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, - QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, - QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementRequest, + QueryPacketAcknowledgementsRequest, QueryPacketCommitmentRequest, + QueryPacketCommitmentsRequest, QueryPacketReceiptRequest, QueryUnreceivedAcksRequest, + QueryUnreceivedPacketsRequest, QueryUpgradedClientStateRequest, + QueryUpgradedConsensusStateRequest, }, tracking::TrackedMsgs, }; @@ -199,7 +201,8 @@ pub enum ChainRequest { QueryClientState { request: QueryClientStateRequest, - reply_to: ReplyTo, + include_proof: IncludeProof, + reply_to: ReplyTo<(AnyClientState, Option)>, }, QueryClientConnections { @@ -207,16 +210,17 @@ pub enum ChainRequest { reply_to: ReplyTo>, }, + QueryConsensusState { + request: QueryConsensusStateRequest, + include_proof: IncludeProof, + reply_to: ReplyTo<(AnyConsensusState, Option)>, + }, + QueryConsensusStates { request: QueryConsensusStatesRequest, reply_to: ReplyTo>, }, - QueryConsensusState { - request: QueryConsensusStateRequest, - reply_to: ReplyTo, - }, - QueryUpgradedClientState { request: QueryUpgradedClientStateRequest, reply_to: ReplyTo<(AnyClientState, MerkleProof)>, @@ -237,7 +241,8 @@ pub enum ChainRequest { QueryConnection { request: QueryConnectionRequest, - reply_to: ReplyTo, + include_proof: IncludeProof, + reply_to: ReplyTo<(ConnectionEnd, Option)>, }, QueryConnections { @@ -257,7 +262,8 @@ pub enum ChainRequest { QueryChannel { request: QueryChannelRequest, - reply_to: ReplyTo, + include_proof: IncludeProof, + reply_to: ReplyTo<(ChannelEnd, Option)>, }, QueryChannelClientState { @@ -267,26 +273,8 @@ pub enum ChainRequest { QueryNextSequenceReceive { request: QueryNextSequenceReceiveRequest, - reply_to: ReplyTo, - }, - - ProvenClientState { - client_id: ClientId, - height: Height, - reply_to: ReplyTo<(AnyClientState, MerkleProof)>, - }, - - ProvenConnection { - connection_id: ConnectionId, - height: Height, - reply_to: ReplyTo<(ConnectionEnd, MerkleProof)>, - }, - - ProvenClientConsensus { - client_id: ClientId, - consensus_height: Height, - height: Height, - reply_to: ReplyTo<(AnyConsensusState, MerkleProof)>, + include_proof: IncludeProof, + reply_to: ReplyTo<(Sequence, Option)>, }, BuildChannelProofs { @@ -302,7 +290,13 @@ pub enum ChainRequest { channel_id: ChannelId, sequence: Sequence, height: Height, - reply_to: ReplyTo<(Vec, Proofs)>, + reply_to: ReplyTo, + }, + + QueryPacketCommitment { + request: QueryPacketCommitmentRequest, + include_proof: IncludeProof, + reply_to: ReplyTo<(Vec, Option)>, }, QueryPacketCommitments { @@ -310,12 +304,24 @@ pub enum ChainRequest { reply_to: ReplyTo<(Vec, Height)>, }, + QueryPacketReceipt { + request: QueryPacketReceiptRequest, + include_proof: IncludeProof, + reply_to: ReplyTo<(Vec, Option)>, + }, + QueryUnreceivedPackets { request: QueryUnreceivedPacketsRequest, reply_to: ReplyTo>, }, QueryPacketAcknowledgement { + request: QueryPacketAcknowledgementRequest, + include_proof: IncludeProof, + reply_to: ReplyTo<(Vec, Option)>, + }, + + QueryPacketAcknowledgements { request: QueryPacketAcknowledgementsRequest, reply_to: ReplyTo<(Vec, Height)>, }, @@ -387,35 +393,48 @@ pub trait ChainHandle: Clone + Send + Sync + Serialize + Debug + 'static { /// If no account is given, behavior must be specified, e.g. retrieve it from configuration file. fn query_balance(&self, key_name: Option) -> Result; + /// Query the latest height and timestamp the application is at fn query_application_status(&self) -> Result; fn query_latest_height(&self) -> Result { Ok(self.query_application_status()?.height) } + /// Performs a query to retrieve the state of all clients that a chain hosts. fn query_clients( &self, request: QueryClientStatesRequest, ) -> Result, Error>; - fn query_client_state(&self, request: QueryClientStateRequest) - -> Result; + /// Performs a query to retrieve the state of the specified light client. A + /// proof can optionally be returned along with the result. + fn query_client_state( + &self, + request: QueryClientStateRequest, + include_proof: IncludeProof, + ) -> Result<(AnyClientState, Option), Error>; + /// Performs a query to retrieve the identifiers of all connections. fn query_client_connections( &self, request: QueryClientConnectionsRequest, ) -> Result, Error>; + /// Performs a query to retrieve the consensus state for a specified height + /// `consensus_height` that the specified light client stores. + fn query_consensus_state( + &self, + request: QueryConsensusStateRequest, + include_proof: IncludeProof, + ) -> Result<(AnyConsensusState, Option), Error>; + + /// Performs a query to retrieve all the consensus states that the specified + /// light client stores. fn query_consensus_states( &self, request: QueryConsensusStatesRequest, ) -> Result, Error>; - fn query_consensus_state( - &self, - request: QueryConsensusStateRequest, - ) -> Result; - fn query_upgraded_client_state( &self, request: QueryUpgradedClientStateRequest, @@ -430,54 +449,57 @@ pub trait ChainHandle: Clone + Send + Sync + Serialize + Debug + 'static { fn query_compatible_versions(&self) -> Result, Error>; - fn query_connection(&self, request: QueryConnectionRequest) -> Result; + /// Performs a query to retrieve the connection associated with a given + /// connection identifier. A proof can optionally be returned along with the + /// result. + fn query_connection( + &self, + request: QueryConnectionRequest, + include_proof: IncludeProof, + ) -> Result<(ConnectionEnd, Option), Error>; + /// Performs a query to retrieve the identifiers of all connections. fn query_connections( &self, request: QueryConnectionsRequest, ) -> Result, Error>; + /// Performs a query to retrieve all channels associated with a connection. fn query_connection_channels( &self, request: QueryConnectionChannelsRequest, ) -> Result, Error>; + /// Performs a query to retrieve `nextSequenceRecv` stored at path + /// `path::SeqRecvsPath` as defined in ICS-4. A proof can optionally be + /// returned along with the result. fn query_next_sequence_receive( &self, request: QueryNextSequenceReceiveRequest, - ) -> Result; + include_proof: IncludeProof, + ) -> Result<(Sequence, Option), Error>; + /// Performs a query to retrieve all the channels of a chain. fn query_channels( &self, request: QueryChannelsRequest, ) -> Result, Error>; - fn query_channel(&self, request: QueryChannelRequest) -> Result; + /// Performs a query to retrieve the channel associated with a given channel + /// identifier. A proof can optionally be returned along with the result. + fn query_channel( + &self, + request: QueryChannelRequest, + include_proof: IncludeProof, + ) -> Result<(ChannelEnd, Option), Error>; + /// Performs a query to retrieve the client state for the channel associated + /// with a given channel identifier. fn query_channel_client_state( &self, request: QueryChannelClientStateRequest, ) -> Result, Error>; - fn proven_client_state( - &self, - client_id: &ClientId, - height: Height, - ) -> Result<(AnyClientState, MerkleProof), Error>; - - fn proven_connection( - &self, - connection_id: &ConnectionId, - height: Height, - ) -> Result<(ConnectionEnd, MerkleProof), Error>; - - fn proven_client_consensus( - &self, - client_id: &ClientId, - consensus_height: Height, - height: Height, - ) -> Result<(AnyConsensusState, MerkleProof), Error>; - fn build_header( &self, trusted_height: Height, @@ -528,24 +550,70 @@ pub trait ChainHandle: Clone + Send + Sync + Serialize + Debug + 'static { channel_id: &ChannelId, sequence: Sequence, height: Height, - ) -> Result<(Vec, Proofs), Error>; + ) -> Result; + + /// Performs a query to retrieve a stored packet commitment hash, stored on + /// the chain at path `path::CommitmentsPath`. A proof can optionally be + /// returned along with the result. + fn query_packet_commitment( + &self, + request: QueryPacketCommitmentRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error>; + /// Performs a query to retrieve all the packet commitments hashes + /// associated with a channel. Returns the corresponding packet sequence + /// numbers and the height at which they were retrieved. fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, ) -> Result<(Vec, Height), Error>; + /// Performs a query to retrieve a given packet receipt, stored on the chain at path + /// `path::CommitmentsPath`. A proof can optionally be returned along with the result. + fn query_packet_receipt( + &self, + request: QueryPacketReceiptRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error>; + + /// Performs a query about which IBC packets in the specified list has not + /// been received. Returns the sequence numbers of the packets that were not + /// received. + /// + /// For example, given a request with the sequence numbers `[5,6,7,8]`, a + /// response of `[7,8]` would indicate that packets 5 & 6 were received, + /// while packets 7, 8 were not. fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, ) -> Result, Error>; + /// Performs a query to retrieve a stored packet acknowledgement hash, + /// stored on the chain at path `path::AcksPath`. A proof can optionally be + /// returned along with the result. + fn query_packet_acknowledgement( + &self, + request: QueryPacketAcknowledgementRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error>; + + /// Performs a query to retrieve all the packet acknowledgements associated + /// with a channel. Returns the corresponding packet sequence numbers and + /// the height at which they were retrieved. fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, ) -> Result<(Vec, Height), Error>; - fn query_unreceived_acknowledgement( + /// Performs a query about which IBC packets in the specified list has not + /// been acknowledged. Returns the sequence numbers of the packets that were not + /// acknowledged. + /// + /// For example, given a request with the sequence numbers `[5,6,7,8]`, a + /// response of `[7,8]` would indicate that packets 5 & 6 were acknowledged, + /// while packets 7, 8 were not. + fn query_unreceived_acknowledgements( &self, request: QueryUnreceivedAcksRequest, ) -> Result, Error>; diff --git a/relayer/src/chain/handle/base.rs b/relayer/src/chain/handle/base.rs index b086242eb6..738118aaf7 100644 --- a/relayer/src/chain/handle/base.rs +++ b/relayer/src/chain/handle/base.rs @@ -32,12 +32,13 @@ use crate::{ client::ClientSettings, endpoint::ChainStatus, requests::{ - QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, - QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, - QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, - QueryConsensusStateRequest, QueryConsensusStatesRequest, + IncludeProof, QueryChannelClientStateRequest, QueryChannelRequest, + QueryChannelsRequest, QueryClientConnectionsRequest, QueryClientStateRequest, + QueryClientStatesRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, + QueryConnectionsRequest, QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, QueryNextSequenceReceiveRequest, - QueryPacketAcknowledgementsRequest, QueryPacketCommitmentsRequest, + QueryPacketAcknowledgementRequest, QueryPacketAcknowledgementsRequest, + QueryPacketCommitmentRequest, QueryPacketCommitmentsRequest, QueryPacketReceiptRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, }, @@ -167,8 +168,13 @@ impl ChainHandle for BaseChainHandle { fn query_client_state( &self, request: QueryClientStateRequest, - ) -> Result { - self.send(|reply_to| ChainRequest::QueryClientState { request, reply_to }) + include_proof: IncludeProof, + ) -> Result<(AnyClientState, Option), Error> { + self.send(|reply_to| ChainRequest::QueryClientState { + request, + include_proof, + reply_to, + }) } fn query_client_connections( @@ -188,8 +194,13 @@ impl ChainHandle for BaseChainHandle { fn query_consensus_state( &self, request: QueryConsensusStateRequest, - ) -> Result { - self.send(|reply_to| ChainRequest::QueryConsensusState { request, reply_to }) + include_proof: IncludeProof, + ) -> Result<(AnyConsensusState, Option), Error> { + self.send(|reply_to| ChainRequest::QueryConsensusState { + request, + include_proof, + reply_to, + }) } fn query_upgraded_client_state( @@ -214,8 +225,16 @@ impl ChainHandle for BaseChainHandle { self.send(|reply_to| ChainRequest::QueryCompatibleVersions { reply_to }) } - fn query_connection(&self, request: QueryConnectionRequest) -> Result { - self.send(|reply_to| ChainRequest::QueryConnection { request, reply_to }) + fn query_connection( + &self, + request: QueryConnectionRequest, + include_proof: IncludeProof, + ) -> Result<(ConnectionEnd, Option), Error> { + self.send(|reply_to| ChainRequest::QueryConnection { + request, + include_proof, + reply_to, + }) } fn query_connections( @@ -235,8 +254,13 @@ impl ChainHandle for BaseChainHandle { fn query_next_sequence_receive( &self, request: QueryNextSequenceReceiveRequest, - ) -> Result { - self.send(|reply_to| ChainRequest::QueryNextSequenceReceive { request, reply_to }) + include_proof: IncludeProof, + ) -> Result<(Sequence, Option), Error> { + self.send(|reply_to| ChainRequest::QueryNextSequenceReceive { + request, + include_proof, + reply_to, + }) } fn query_channels( @@ -246,8 +270,16 @@ impl ChainHandle for BaseChainHandle { self.send(|reply_to| ChainRequest::QueryChannels { request, reply_to }) } - fn query_channel(&self, request: QueryChannelRequest) -> Result { - self.send(|reply_to| ChainRequest::QueryChannel { request, reply_to }) + fn query_channel( + &self, + request: QueryChannelRequest, + include_proof: IncludeProof, + ) -> Result<(ChannelEnd, Option), Error> { + self.send(|reply_to| ChainRequest::QueryChannel { + request, + include_proof, + reply_to, + }) } fn query_channel_client_state( @@ -257,44 +289,6 @@ impl ChainHandle for BaseChainHandle { self.send(|reply_to| ChainRequest::QueryChannelClientState { request, reply_to }) } - fn proven_client_state( - &self, - client_id: &ClientId, - height: Height, - ) -> Result<(AnyClientState, MerkleProof), Error> { - self.send(|reply_to| ChainRequest::ProvenClientState { - client_id: client_id.clone(), - height, - reply_to, - }) - } - - fn proven_connection( - &self, - connection_id: &ConnectionId, - height: Height, - ) -> Result<(ConnectionEnd, MerkleProof), Error> { - self.send(|reply_to| ChainRequest::ProvenConnection { - connection_id: connection_id.clone(), - height, - reply_to, - }) - } - - fn proven_client_consensus( - &self, - client_id: &ClientId, - consensus_height: Height, - height: Height, - ) -> Result<(AnyConsensusState, MerkleProof), Error> { - self.send(|reply_to| ChainRequest::ProvenClientConsensus { - client_id: client_id.clone(), - consensus_height, - height, - reply_to, - }) - } - fn build_header( &self, trusted_height: Height, @@ -386,7 +380,7 @@ impl ChainHandle for BaseChainHandle { channel_id: &ChannelId, sequence: Sequence, height: Height, - ) -> Result<(Vec, Proofs), Error> { + ) -> Result { self.send(|reply_to| ChainRequest::BuildPacketProofs { packet_type, port_id: port_id.clone(), @@ -397,6 +391,18 @@ impl ChainHandle for BaseChainHandle { }) } + fn query_packet_commitment( + &self, + request: QueryPacketCommitmentRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + self.send(|reply_to| ChainRequest::QueryPacketCommitment { + request, + include_proof, + reply_to, + }) + } + fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, @@ -404,6 +410,18 @@ impl ChainHandle for BaseChainHandle { self.send(|reply_to| ChainRequest::QueryPacketCommitments { request, reply_to }) } + fn query_packet_receipt( + &self, + request: QueryPacketReceiptRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + self.send(|reply_to| ChainRequest::QueryPacketReceipt { + request, + include_proof, + reply_to, + }) + } + fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, @@ -411,14 +429,26 @@ impl ChainHandle for BaseChainHandle { self.send(|reply_to| ChainRequest::QueryUnreceivedPackets { request, reply_to }) } + fn query_packet_acknowledgement( + &self, + request: QueryPacketAcknowledgementRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + self.send(|reply_to| ChainRequest::QueryPacketAcknowledgement { + request, + include_proof, + reply_to, + }) + } + fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, ) -> Result<(Vec, Height), Error> { - self.send(|reply_to| ChainRequest::QueryPacketAcknowledgement { request, reply_to }) + self.send(|reply_to| ChainRequest::QueryPacketAcknowledgements { request, reply_to }) } - fn query_unreceived_acknowledgement( + fn query_unreceived_acknowledgements( &self, request: QueryUnreceivedAcksRequest, ) -> Result, Error> { diff --git a/relayer/src/chain/handle/cache.rs b/relayer/src/chain/handle/cache.rs index 31f7adfbdb..17b7562fa1 100644 --- a/relayer/src/chain/handle/cache.rs +++ b/relayer/src/chain/handle/cache.rs @@ -31,13 +31,15 @@ use crate::chain::client::ClientSettings; use crate::chain::endpoint::{ChainStatus, HealthCheck}; use crate::chain::handle::{ChainHandle, ChainRequest, Subscription}; use crate::chain::requests::{ - QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + IncludeProof, QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, - QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, - QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, - QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementRequest, + QueryPacketAcknowledgementsRequest, QueryPacketCommitmentRequest, + QueryPacketCommitmentsRequest, QueryPacketReceiptRequest, QueryUnreceivedAcksRequest, + QueryUnreceivedPacketsRequest, QueryUpgradedClientStateRequest, + QueryUpgradedConsensusStateRequest, }; use crate::chain::tracking::TrackedMsgs; use crate::config::ChainConfig; @@ -163,25 +165,31 @@ impl ChainHandle for CachingChainHandle { fn query_client_state( &self, request: QueryClientStateRequest, - ) -> Result { + include_proof: IncludeProof, + ) -> Result<(AnyClientState, Option), Error> { let handle = self.inner(); - 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"); + match include_proof { + IncludeProof::Yes => handle.query_client_state(request, IncludeProof::Yes), + IncludeProof::No => { + 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(request.clone(), IncludeProof::No) + .map(|(client_state, _)| client_state) + }, + )?; + + if in_cache == CacheStatus::Hit { + telemetry!(query_cache_hit, &self.id(), "query_client_state"); + } + + Ok((result, None)) + } else { + handle.query_client_state(request, IncludeProof::No) + } } - - Ok(result) - } else { - handle.query_client_state(request) } } @@ -202,8 +210,9 @@ impl ChainHandle for CachingChainHandle { fn query_consensus_state( &self, request: QueryConsensusStateRequest, - ) -> Result { - self.inner().query_consensus_state(request) + include_proof: IncludeProof, + ) -> Result<(AnyConsensusState, Option), Error> { + self.inner().query_consensus_state(request, include_proof) } fn query_upgraded_client_state( @@ -228,22 +237,34 @@ impl ChainHandle for CachingChainHandle { self.inner().query_compatible_versions() } - fn query_connection(&self, request: QueryConnectionRequest) -> Result { + fn query_connection( + &self, + request: QueryConnectionRequest, + include_proof: IncludeProof, + ) -> Result<(ConnectionEnd, Option), Error> { let handle = self.inner(); - if request.height.is_zero() { - let (result, in_cache) = self - .cache - .get_or_try_insert_connection_with(&request.connection_id, || { - handle.query_connection(request.clone()) - })?; - - if in_cache == CacheStatus::Hit { - telemetry!(query_cache_hit, &self.id(), "query_connection"); + match include_proof { + IncludeProof::Yes => handle.query_connection(request, IncludeProof::Yes), + IncludeProof::No => { + if request.height.is_zero() { + let (result, in_cache) = self.cache.get_or_try_insert_connection_with( + &request.connection_id, + || { + handle + .query_connection(request.clone(), IncludeProof::No) + .map(|(conn_end, _)| conn_end) + }, + )?; + + if in_cache == CacheStatus::Hit { + telemetry!(query_cache_hit, &self.id(), "query_connection"); + } + + Ok((result, None)) + } else { + handle.query_connection(request, IncludeProof::No) + } } - - Ok(result) - } else { - handle.query_connection(request) } } @@ -264,8 +285,10 @@ impl ChainHandle for CachingChainHandle { fn query_next_sequence_receive( &self, request: QueryNextSequenceReceiveRequest, - ) -> Result { - self.inner().query_next_sequence_receive(request) + include_proof: IncludeProof, + ) -> Result<(Sequence, Option), Error> { + self.inner() + .query_next_sequence_receive(request, include_proof) } fn query_channels( @@ -275,21 +298,34 @@ impl ChainHandle for CachingChainHandle { self.inner().query_channels(request) } - fn query_channel(&self, request: QueryChannelRequest) -> Result { + fn query_channel( + &self, + request: QueryChannelRequest, + include_proof: IncludeProof, + ) -> Result<(ChannelEnd, Option), Error> { let handle = self.inner(); - if request.height.is_zero() { - let (result, in_cache) = self.cache.get_or_try_insert_channel_with( - &PortChannelId::new(request.channel_id, request.port_id.clone()), - || handle.query_channel(request), - )?; - - if in_cache == CacheStatus::Hit { - telemetry!(query_cache_hit, &self.id(), "query_channel"); + match include_proof { + IncludeProof::Yes => handle.query_channel(request, IncludeProof::Yes), + IncludeProof::No => { + if request.height.is_zero() { + let (result, in_cache) = self.cache.get_or_try_insert_channel_with( + &PortChannelId::new(request.channel_id, request.port_id.clone()), + || { + handle + .query_channel(request, IncludeProof::No) + .map(|(channel_end, _)| channel_end) + }, + )?; + + if in_cache == CacheStatus::Hit { + telemetry!(query_cache_hit, &self.id(), "query_channel"); + } + + Ok((result, None)) + } else { + handle.query_channel(request, IncludeProof::No) + } } - - Ok(result) - } else { - handle.query_channel(request) } } @@ -300,32 +336,6 @@ impl ChainHandle for CachingChainHandle { self.inner().query_channel_client_state(request) } - fn proven_client_state( - &self, - client_id: &ClientId, - height: Height, - ) -> Result<(AnyClientState, MerkleProof), Error> { - self.inner().proven_client_state(client_id, height) - } - - fn proven_connection( - &self, - connection_id: &ConnectionId, - height: Height, - ) -> Result<(ConnectionEnd, MerkleProof), Error> { - self.inner().proven_connection(connection_id, height) - } - - fn proven_client_consensus( - &self, - client_id: &ClientId, - consensus_height: Height, - height: Height, - ) -> Result<(AnyConsensusState, MerkleProof), Error> { - self.inner() - .proven_client_consensus(client_id, consensus_height, height) - } - fn build_header( &self, trusted_height: Height, @@ -396,11 +406,19 @@ impl ChainHandle for CachingChainHandle { channel_id: &ChannelId, sequence: Sequence, height: Height, - ) -> Result<(Vec, Proofs), Error> { + ) -> Result { self.inner() .build_packet_proofs(packet_type, port_id, channel_id, sequence, height) } + fn query_packet_commitment( + &self, + request: QueryPacketCommitmentRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + self.inner().query_packet_commitment(request, include_proof) + } + fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, @@ -408,6 +426,14 @@ impl ChainHandle for CachingChainHandle { self.inner().query_packet_commitments(request) } + fn query_packet_receipt( + &self, + request: QueryPacketReceiptRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + self.inner().query_packet_receipt(request, include_proof) + } + fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, @@ -415,6 +441,15 @@ impl ChainHandle for CachingChainHandle { self.inner().query_unreceived_packets(request) } + fn query_packet_acknowledgement( + &self, + request: QueryPacketAcknowledgementRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + self.inner() + .query_packet_acknowledgement(request, include_proof) + } + fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, @@ -422,11 +457,11 @@ impl ChainHandle for CachingChainHandle { self.inner().query_packet_acknowledgements(request) } - fn query_unreceived_acknowledgement( + fn query_unreceived_acknowledgements( &self, request: QueryUnreceivedAcksRequest, ) -> Result, Error> { - self.inner().query_unreceived_acknowledgement(request) + self.inner().query_unreceived_acknowledgements(request) } fn query_txs(&self, request: QueryTxRequest) -> Result, Error> { diff --git a/relayer/src/chain/handle/counting.rs b/relayer/src/chain/handle/counting.rs index b5dcac3b05..1d18f1114f 100644 --- a/relayer/src/chain/handle/counting.rs +++ b/relayer/src/chain/handle/counting.rs @@ -31,13 +31,15 @@ use crate::chain::client::ClientSettings; use crate::chain::endpoint::{ChainStatus, HealthCheck}; use crate::chain::handle::{ChainHandle, ChainRequest, Subscription}; use crate::chain::requests::{ - QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + IncludeProof, QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, - QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, - QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, - QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementRequest, + QueryPacketAcknowledgementsRequest, QueryPacketCommitmentRequest, + QueryPacketCommitmentsRequest, QueryPacketReceiptRequest, QueryUnreceivedAcksRequest, + QueryUnreceivedPacketsRequest, QueryUpgradedClientStateRequest, + QueryUpgradedConsensusStateRequest, }; use crate::chain::tracking::TrackedMsgs; use crate::config::ChainConfig; @@ -182,12 +184,13 @@ impl ChainHandle for CountingChainHandle { fn query_client_state( &self, request: QueryClientStateRequest, - ) -> Result { + include_proof: IncludeProof, + ) -> Result<(AnyClientState, Option), Error> { self.inc_metric(&format!( "query_client_state({}, {})", request.client_id, request.height )); - self.inner().query_client_state(request) + self.inner().query_client_state(request, include_proof) } fn query_client_connections( @@ -209,9 +212,10 @@ impl ChainHandle for CountingChainHandle { fn query_consensus_state( &self, request: QueryConsensusStateRequest, - ) -> Result { + include_proof: IncludeProof, + ) -> Result<(AnyConsensusState, Option), Error> { self.inc_metric("query_consensus_state"); - self.inner().query_consensus_state(request) + self.inner().query_consensus_state(request, include_proof) } fn query_upgraded_client_state( @@ -240,9 +244,13 @@ impl ChainHandle for CountingChainHandle { self.inner().query_compatible_versions() } - fn query_connection(&self, request: QueryConnectionRequest) -> Result { + fn query_connection( + &self, + request: QueryConnectionRequest, + include_proof: IncludeProof, + ) -> Result<(ConnectionEnd, Option), Error> { self.inc_metric("query_connection"); - self.inner().query_connection(request) + self.inner().query_connection(request, include_proof) } fn query_connections( @@ -264,9 +272,11 @@ impl ChainHandle for CountingChainHandle { fn query_next_sequence_receive( &self, request: QueryNextSequenceReceiveRequest, - ) -> Result { + include_proof: IncludeProof, + ) -> Result<(Sequence, Option), Error> { self.inc_metric("query_next_sequence_receive"); - self.inner().query_next_sequence_receive(request) + self.inner() + .query_next_sequence_receive(request, include_proof) } fn query_channels( @@ -277,9 +287,13 @@ impl ChainHandle for CountingChainHandle { self.inner().query_channels(request) } - fn query_channel(&self, request: QueryChannelRequest) -> Result { + fn query_channel( + &self, + request: QueryChannelRequest, + include_proof: IncludeProof, + ) -> Result<(ChannelEnd, Option), Error> { self.inc_metric("query_channel"); - self.inner().query_channel(request) + self.inner().query_channel(request, include_proof) } fn query_channel_client_state( @@ -290,35 +304,6 @@ impl ChainHandle for CountingChainHandle { self.inner().query_channel_client_state(request) } - fn proven_client_state( - &self, - client_id: &ClientId, - height: Height, - ) -> Result<(AnyClientState, MerkleProof), Error> { - self.inc_metric("proven_client_state"); - self.inner().proven_client_state(client_id, height) - } - - fn proven_connection( - &self, - connection_id: &ConnectionId, - height: Height, - ) -> Result<(ConnectionEnd, MerkleProof), Error> { - self.inc_metric("proven_connection"); - self.inner().proven_connection(connection_id, height) - } - - fn proven_client_consensus( - &self, - client_id: &ClientId, - consensus_height: Height, - height: Height, - ) -> Result<(AnyConsensusState, MerkleProof), Error> { - self.inc_metric("proven_client_consensus"); - self.inner() - .proven_client_consensus(client_id, consensus_height, height) - } - fn build_header( &self, trusted_height: Height, @@ -395,12 +380,21 @@ impl ChainHandle for CountingChainHandle { channel_id: &ChannelId, sequence: Sequence, height: Height, - ) -> Result<(Vec, Proofs), Error> { + ) -> Result { self.inc_metric("build_packet_proofs"); self.inner() .build_packet_proofs(packet_type, port_id, channel_id, sequence, height) } + fn query_packet_commitment( + &self, + request: QueryPacketCommitmentRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + self.inc_metric("query_packet_commitment"); + self.inner().query_packet_commitment(request, include_proof) + } + fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, @@ -409,6 +403,15 @@ impl ChainHandle for CountingChainHandle { self.inner().query_packet_commitments(request) } + fn query_packet_receipt( + &self, + request: QueryPacketReceiptRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + self.inc_metric("query_packet_receipt"); + self.inner().query_packet_receipt(request, include_proof) + } + fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, @@ -417,6 +420,16 @@ impl ChainHandle for CountingChainHandle { self.inner().query_unreceived_packets(request) } + fn query_packet_acknowledgement( + &self, + request: QueryPacketAcknowledgementRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + self.inc_metric("query_packet_acknowledgement"); + self.inner() + .query_packet_acknowledgement(request, include_proof) + } + fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, @@ -425,12 +438,12 @@ impl ChainHandle for CountingChainHandle { self.inner().query_packet_acknowledgements(request) } - fn query_unreceived_acknowledgement( + fn query_unreceived_acknowledgements( &self, request: QueryUnreceivedAcksRequest, ) -> Result, Error> { self.inc_metric("query_unreceived_acknowledgement"); - self.inner().query_unreceived_acknowledgement(request) + self.inner().query_unreceived_acknowledgements(request) } fn query_txs(&self, request: QueryTxRequest) -> Result, Error> { diff --git a/relayer/src/chain/mock.rs b/relayer/src/chain/mock.rs index f61b334980..a98461ef46 100644 --- a/relayer/src/chain/mock.rs +++ b/relayer/src/chain/mock.rs @@ -17,9 +17,9 @@ use ibc::core::ics02_client::client_state::{AnyClientState, IdentifiedAnyClientS use ibc::core::ics03_connection::connection::{ConnectionEnd, IdentifiedConnectionEnd}; use ibc::core::ics04_channel::channel::{ChannelEnd, IdentifiedChannelEnd}; use ibc::core::ics04_channel::context::ChannelReader; -use ibc::core::ics04_channel::packet::{PacketMsgType, Sequence}; +use ibc::core::ics04_channel::packet::Sequence; use ibc::core::ics23_commitment::{commitment::CommitmentPrefix, specs::ProofSpecs}; -use ibc::core::ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, PortId}; +use ibc::core::ics24_host::identifier::{ChainId, ConnectionId}; use ibc::events::IbcEvent; use ibc::mock::context::MockContext; use ibc::mock::host::HostType; @@ -43,12 +43,14 @@ use crate::light_client::Verified; use crate::light_client::{mock::LightClient as MockLightClient, LightClient}; use super::requests::{ - QueryChannelsRequest, QueryClientConnectionsRequest, QueryClientStateRequest, + IncludeProof, QueryChannelsRequest, QueryClientConnectionsRequest, QueryClientStateRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, - QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, - QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, - QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementRequest, + QueryPacketAcknowledgementsRequest, QueryPacketCommitmentRequest, + QueryPacketCommitmentsRequest, QueryPacketReceiptRequest, QueryUnreceivedAcksRequest, + QueryUnreceivedPacketsRequest, QueryUpgradedClientStateRequest, + QueryUpgradedConsensusStateRequest, }; use super::tracking::TrackedMsgs; @@ -189,14 +191,15 @@ impl ChainEndpoint for MockChain { fn query_client_state( &self, request: QueryClientStateRequest, - ) -> Result { + _include_proof: IncludeProof, + ) -> Result<(AnyClientState, Option), Error> { // TODO: unclear what are the scenarios where we need to take height into account. let client_state = self .context .query_client_full_state(&request.client_id) .ok_or_else(Error::empty_response_value)?; - Ok(client_state) + Ok((client_state, None)) } fn query_upgraded_client_state( @@ -206,7 +209,11 @@ impl ChainEndpoint for MockChain { unimplemented!() } - fn query_connection(&self, _request: QueryConnectionRequest) -> Result { + fn query_connection( + &self, + _request: QueryConnectionRequest, + _include_proof: IncludeProof, + ) -> Result<(ConnectionEnd, Option), Error> { unimplemented!() } @@ -238,7 +245,11 @@ impl ChainEndpoint for MockChain { unimplemented!() } - fn query_channel(&self, _request: QueryChannelRequest) -> Result { + fn query_channel( + &self, + _request: QueryChannelRequest, + _include_proof: IncludeProof, + ) -> Result<(ChannelEnd, Option), Error> { unimplemented!() } @@ -249,6 +260,14 @@ impl ChainEndpoint for MockChain { unimplemented!() } + fn query_packet_commitment( + &self, + _request: QueryPacketCommitmentRequest, + _include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + unimplemented!() + } + fn query_packet_commitments( &self, _request: QueryPacketCommitmentsRequest, @@ -256,6 +275,14 @@ impl ChainEndpoint for MockChain { unimplemented!() } + fn query_packet_receipt( + &self, + _request: QueryPacketReceiptRequest, + _include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + unimplemented!() + } + fn query_unreceived_packets( &self, _request: QueryUnreceivedPacketsRequest, @@ -263,6 +290,14 @@ impl ChainEndpoint for MockChain { unimplemented!() } + fn query_packet_acknowledgement( + &self, + _request: QueryPacketAcknowledgementRequest, + _include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + unimplemented!() + } + fn query_packet_acknowledgements( &self, _request: QueryPacketAcknowledgementsRequest, @@ -280,7 +315,8 @@ impl ChainEndpoint for MockChain { fn query_next_sequence_receive( &self, _request: QueryNextSequenceReceiveRequest, - ) -> Result { + _include_proof: IncludeProof, + ) -> Result<(Sequence, Option), Error> { unimplemented!() } @@ -302,51 +338,6 @@ impl ChainEndpoint for MockChain { unimplemented!() } - fn proven_client_state( - &self, - _client_id: &ClientId, - _height: Height, - ) -> Result<(AnyClientState, MerkleProof), Error> { - unimplemented!() - } - - fn proven_connection( - &self, - _connection_id: &ConnectionId, - _height: Height, - ) -> Result<(ConnectionEnd, MerkleProof), Error> { - unimplemented!() - } - - fn proven_client_consensus( - &self, - _client_id: &ClientId, - _consensus_height: Height, - _height: Height, - ) -> Result<(AnyConsensusState, MerkleProof), Error> { - unimplemented!() - } - - fn proven_channel( - &self, - _port_id: &PortId, - _channel_id: &ChannelId, - _height: Height, - ) -> Result<(ChannelEnd, MerkleProof), Error> { - unimplemented!() - } - - fn proven_packet( - &self, - _packet_type: PacketMsgType, - _port_id: PortId, - _channel_id: ChannelId, - _sequence: Sequence, - _height: Height, - ) -> Result<(Vec, MerkleProof), Error> { - unimplemented!() - } - fn build_client_state( &self, height: Height, @@ -425,13 +416,18 @@ impl ChainEndpoint for MockChain { fn query_consensus_state( &self, request: QueryConsensusStateRequest, - ) -> Result { + include_proof: IncludeProof, + ) -> Result<(AnyConsensusState, Option), Error> { + // IncludeProof::Yes not implemented + assert!(matches!(include_proof, IncludeProof::No)); + let consensus_states = self.context.consensus_states(&request.client_id); - Ok(consensus_states + let consensus_state = consensus_states .into_iter() .find(|s| s.height == request.consensus_height) - .unwrap() - .consensus_state) + .ok_or_else(|| Error::query("Invalid consensus height".into()))? + .consensus_state; + Ok((consensus_state, None)) } fn query_upgraded_consensus_state( diff --git a/relayer/src/chain/requests.rs b/relayer/src/chain/requests.rs index 24a8405d9d..027df4e3d4 100644 --- a/relayer/src/chain/requests.rs +++ b/relayer/src/chain/requests.rs @@ -23,6 +23,14 @@ use ibc_proto::ibc::core::connection::v1::{ use serde::{Deserialize, Serialize}; +/// Defines a type to be used in select requests to specify whether or not a proof should be +/// returned along with the response. +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +pub enum IncludeProof { + Yes, + No, +} + #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub struct PageRequest { /// key is a value returned in PageResponse.next_key to begin @@ -199,6 +207,14 @@ impl From for RawQueryChannelClientStateRequest } } +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryPacketCommitmentRequest { + pub port_id: PortId, + pub channel_id: ChannelId, + pub sequence: Sequence, + pub height: Height, +} + #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct QueryPacketCommitmentsRequest { pub port_id: PortId, @@ -216,6 +232,14 @@ impl From for RawQueryPacketCommitmentsRequest { } } +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryPacketReceiptRequest { + pub port_id: PortId, + pub channel_id: ChannelId, + pub sequence: Sequence, + pub height: Height, +} + #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct QueryUnreceivedPacketsRequest { pub port_id: PortId, @@ -237,6 +261,14 @@ impl From for RawQueryUnreceivedPacketsRequest { } } +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct QueryPacketAcknowledgementRequest { + pub port_id: PortId, + pub channel_id: ChannelId, + pub sequence: Sequence, + pub height: Height, +} + #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct QueryPacketAcknowledgementsRequest { pub port_id: PortId, @@ -285,6 +317,7 @@ impl From for RawQueryUnreceivedAcksRequest { pub struct QueryNextSequenceReceiveRequest { pub port_id: PortId, pub channel_id: ChannelId, + pub height: Height, } impl From for RawQueryNextSequenceReceiveRequest { diff --git a/relayer/src/chain/runtime.rs b/relayer/src/chain/runtime.rs index 1202ec8859..7a721ab03b 100644 --- a/relayer/src/chain/runtime.rs +++ b/relayer/src/chain/runtime.rs @@ -50,13 +50,15 @@ use super::{ endpoint::{ChainEndpoint, ChainStatus, HealthCheck}, handle::{ChainHandle, ChainRequest, ReplyTo, Subscription}, requests::{ - QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + IncludeProof, QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, - QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, - QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, - QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementRequest, + QueryPacketAcknowledgementsRequest, QueryPacketCommitmentRequest, + QueryPacketCommitmentsRequest, QueryPacketReceiptRequest, QueryUnreceivedAcksRequest, + QueryUnreceivedPacketsRequest, QueryUpgradedClientStateRequest, + QueryUpgradedConsensusStateRequest, }, tracking::TrackedMsgs, }; @@ -317,16 +319,16 @@ where self.query_client_connections(request, reply_to)? }, - Ok(ChainRequest::QueryClientState { request, reply_to }) => { - self.query_client_state(request, reply_to)? + Ok(ChainRequest::QueryClientState { request, include_proof, reply_to }) => { + self.query_client_state(request, include_proof, reply_to)? }, Ok(ChainRequest::QueryConsensusStates { request, reply_to }) => { self.query_consensus_states(request, reply_to)? }, - Ok(ChainRequest::QueryConsensusState { request, reply_to }) => { - self.query_consensus_state(request, reply_to)? + Ok(ChainRequest::QueryConsensusState { request, include_proof, reply_to }) => { + self.query_consensus_state(request, include_proof, reply_to)? }, Ok(ChainRequest::QueryUpgradedClientState { request, reply_to }) => { @@ -345,8 +347,8 @@ where self.query_compatible_versions(reply_to)? }, - Ok(ChainRequest::QueryConnection { request, reply_to }) => { - self.query_connection(request, reply_to)? + Ok(ChainRequest::QueryConnection { request, include_proof, reply_to }) => { + self.query_connection(request, include_proof, reply_to)? }, Ok(ChainRequest::QueryConnections { request, reply_to }) => { @@ -361,39 +363,39 @@ where self.query_channels(request, reply_to)? }, - Ok(ChainRequest::QueryChannel { request, reply_to }) => { - self.query_channel(request, reply_to)? + Ok(ChainRequest::QueryChannel { request, include_proof, reply_to }) => { + self.query_channel(request, include_proof, reply_to)? }, Ok(ChainRequest::QueryChannelClientState { request, reply_to }) => { self.query_channel_client_state(request, reply_to)? }, - Ok(ChainRequest::ProvenClientState { client_id, height, reply_to }) => { - self.proven_client_state(client_id, height, reply_to)? - }, - - Ok(ChainRequest::ProvenConnection { connection_id, height, reply_to }) => { - self.proven_connection(connection_id, height, reply_to)? - }, - - Ok(ChainRequest::ProvenClientConsensus { client_id, consensus_height, height, reply_to }) => { - self.proven_client_consensus(client_id, consensus_height, height, reply_to)? - }, - Ok(ChainRequest::BuildPacketProofs { packet_type, port_id, channel_id, sequence, height, reply_to }) => { self.build_packet_proofs(packet_type, port_id, channel_id, sequence, height, reply_to)? }, + Ok(ChainRequest::QueryPacketCommitment { request, include_proof, reply_to }) => { + self.query_packet_commitment(request, include_proof, reply_to)? + }, + Ok(ChainRequest::QueryPacketCommitments { request, reply_to }) => { self.query_packet_commitments(request, reply_to)? }, + Ok(ChainRequest::QueryPacketReceipt { request, include_proof, reply_to }) => { + self.query_packet_receipt(request, include_proof, reply_to)? + }, + Ok(ChainRequest::QueryUnreceivedPackets { request, reply_to }) => { self.query_unreceived_packets(request, reply_to)? }, - Ok(ChainRequest::QueryPacketAcknowledgement { request, reply_to }) => { + Ok(ChainRequest::QueryPacketAcknowledgement { request, include_proof, reply_to }) => { + self.query_packet_acknowledgement(request, include_proof, reply_to)? + }, + + Ok(ChainRequest::QueryPacketAcknowledgements { request, reply_to }) => { self.query_packet_acknowledgements(request, reply_to)? }, @@ -401,8 +403,8 @@ where self.query_unreceived_acknowledgement(request, reply_to)? }, - Ok(ChainRequest::QueryNextSequenceReceive { request, reply_to }) => { - self.query_next_sequence_receive(request, reply_to)? + Ok(ChainRequest::QueryNextSequenceReceive { request, include_proof, reply_to }) => { + self.query_next_sequence_receive(request, include_proof, reply_to)? }, Ok(ChainRequest::QueryPacketEventDataFromTxs { request, reply_to }) => { @@ -624,14 +626,15 @@ where fn query_client_state( &self, request: QueryClientStateRequest, - reply_to: ReplyTo, + include_proof: IncludeProof, + reply_to: ReplyTo<(AnyClientState, Option)>, ) -> Result<(), Error> { - let client_state = self + let res = self .chain - .query_client_state(request) - .map(|cs| cs.wrap_any()); + .query_client_state(request, include_proof) + .map(|(cs, proof)| (cs.wrap_any(), proof)); - reply_to.send(client_state).map_err(Error::send) + reply_to.send(res).map_err(Error::send) } fn query_upgraded_client_state( @@ -659,11 +662,12 @@ where fn query_consensus_state( &self, request: QueryConsensusStateRequest, - reply_to: ReplyTo, + include_proof: IncludeProof, + reply_to: ReplyTo<(AnyConsensusState, Option)>, ) -> Result<(), Error> { - let consensus_state = self.chain.query_consensus_state(request); + let res = self.chain.query_consensus_state(request, include_proof); - reply_to.send(consensus_state).map_err(Error::send) + reply_to.send(res).map_err(Error::send) } fn query_upgraded_consensus_state( @@ -692,9 +696,10 @@ where fn query_connection( &self, request: QueryConnectionRequest, - reply_to: ReplyTo, + include_proof: IncludeProof, + reply_to: ReplyTo<(ConnectionEnd, Option)>, ) -> Result<(), Error> { - let connection_end = self.chain.query_connection(request); + let connection_end = self.chain.query_connection(request, include_proof); reply_to.send(connection_end).map_err(Error::send) } @@ -728,9 +733,10 @@ where fn query_channel( &self, request: QueryChannelRequest, - reply_to: ReplyTo, + include_proof: IncludeProof, + reply_to: ReplyTo<(ChannelEnd, Option)>, ) -> Result<(), Error> { - let result = self.chain.query_channel(request); + let result = self.chain.query_channel(request, include_proof); reply_to.send(result).map_err(Error::send) } @@ -743,45 +749,6 @@ where reply_to.send(result).map_err(Error::send) } - fn proven_client_state( - &self, - client_id: ClientId, - height: Height, - reply_to: ReplyTo<(AnyClientState, MerkleProof)>, - ) -> Result<(), Error> { - let result = self - .chain - .proven_client_state(&client_id, height) - .map(|(cs, mp)| (cs.wrap_any(), mp)); - - reply_to.send(result).map_err(Error::send) - } - - fn proven_connection( - &self, - connection_id: ConnectionId, - height: Height, - reply_to: ReplyTo<(ConnectionEnd, MerkleProof)>, - ) -> Result<(), Error> { - let result = self.chain.proven_connection(&connection_id, height); - reply_to.send(result).map_err(Error::send) - } - - fn proven_client_consensus( - &self, - client_id: ClientId, - consensus_height: Height, - height: Height, - reply_to: ReplyTo<(AnyConsensusState, MerkleProof)>, - ) -> Result<(), Error> { - let result = self - .chain - .proven_client_consensus(&client_id, consensus_height, height) - .map(|(cs, mp)| (cs.wrap_any(), mp)); - - reply_to.send(result).map_err(Error::send) - } - fn build_channel_proofs( &self, port_id: PortId, @@ -803,7 +770,7 @@ where channel_id: ChannelId, sequence: Sequence, height: Height, - reply_to: ReplyTo<(Vec, Proofs)>, + reply_to: ReplyTo, ) -> Result<(), Error> { let result = self.chain @@ -812,6 +779,16 @@ where reply_to.send(result).map_err(Error::send) } + fn query_packet_commitment( + &self, + request: QueryPacketCommitmentRequest, + include_proof: IncludeProof, + reply_to: ReplyTo<(Vec, Option)>, + ) -> Result<(), Error> { + let result = self.chain.query_packet_commitment(request, include_proof); + reply_to.send(result).map_err(Error::send) + } + fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, @@ -821,6 +798,16 @@ where reply_to.send(result).map_err(Error::send) } + fn query_packet_receipt( + &self, + request: QueryPacketReceiptRequest, + include_proof: IncludeProof, + reply_to: ReplyTo<(Vec, Option)>, + ) -> Result<(), Error> { + let result = self.chain.query_packet_receipt(request, include_proof); + reply_to.send(result).map_err(Error::send) + } + fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, @@ -830,6 +817,18 @@ where reply_to.send(result).map_err(Error::send) } + fn query_packet_acknowledgement( + &self, + request: QueryPacketAcknowledgementRequest, + include_proof: IncludeProof, + reply_to: ReplyTo<(Vec, Option)>, + ) -> Result<(), Error> { + let result = self + .chain + .query_packet_acknowledgement(request, include_proof); + reply_to.send(result).map_err(Error::send) + } + fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, @@ -851,9 +850,12 @@ where fn query_next_sequence_receive( &self, request: QueryNextSequenceReceiveRequest, - reply_to: ReplyTo, + include_proof: IncludeProof, + reply_to: ReplyTo<(Sequence, Option)>, ) -> Result<(), Error> { - let result = self.chain.query_next_sequence_receive(request); + let result = self + .chain + .query_next_sequence_receive(request, include_proof); reply_to.send(result).map_err(Error::send) } diff --git a/relayer/src/channel.rs b/relayer/src/channel.rs index 506e57ed89..46b7e1b639 100644 --- a/relayer/src/channel.rs +++ b/relayer/src/channel.rs @@ -23,7 +23,8 @@ use ibc::Height; use crate::chain::counterparty::{channel_connection_client, channel_state_on_destination}; use crate::chain::handle::ChainHandle; use crate::chain::requests::{ - PageRequest, QueryChannelRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, + IncludeProof, PageRequest, QueryChannelRequest, QueryConnectionChannelsRequest, + QueryConnectionRequest, }; use crate::chain::tracking::TrackedMsgs; use crate::connection::Connection; @@ -206,11 +207,14 @@ impl Channel { let channel_id = channel_event_attributes.channel_id; let connection_id = channel_event_attributes.connection_id.clone(); - let connection = chain - .query_connection(QueryConnectionRequest { - connection_id: connection_id.clone(), - height: Height::zero(), - }) + let (connection, _) = chain + .query_connection( + QueryConnectionRequest { + connection_id: connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(ChannelError::relayer)?; let connection_counterparty = connection.counterparty(); @@ -254,12 +258,15 @@ impl Channel { channel: WorkerChannelObject, height: Height, ) -> Result<(Channel, State), ChannelError> { - let a_channel = chain - .query_channel(QueryChannelRequest { - port_id: channel.src_port_id.clone(), - channel_id: channel.src_channel_id, - height, - }) + let (a_channel, _) = chain + .query_channel( + QueryChannelRequest { + port_id: channel.src_port_id.clone(), + channel_id: channel.src_channel_id, + height, + }, + IncludeProof::No, + ) .map_err(ChannelError::relayer)?; let a_connection_id = a_channel.connection_hops().first().ok_or_else(|| { @@ -269,11 +276,14 @@ impl Channel { )) })?; - let a_connection = chain - .query_connection(QueryConnectionRequest { - connection_id: a_connection_id.clone(), - height: Height::zero(), - }) + let (a_connection, _) = chain + .query_connection( + QueryConnectionRequest { + connection_id: a_connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(ChannelError::relayer)?; let b_connection_id = a_connection @@ -485,13 +495,16 @@ impl Channel { ); // Continue loop if query error - let a_channel = channel + let (a_channel, _) = channel .src_chain() - .query_channel(QueryChannelRequest { - port_id: channel.src_port_id().clone(), - channel_id: *src_channel_id, - height: Height::zero(), - }) + .query_channel( + QueryChannelRequest { + port_id: channel.src_port_id().clone(), + channel_id: *src_channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| { ChannelError::handshake_finalize( channel.src_port_id().clone(), @@ -501,13 +514,16 @@ impl Channel { ) })?; - let b_channel = channel + let (b_channel, _) = channel .dst_chain() - .query_channel(QueryChannelRequest { - port_id: channel.dst_port_id().clone(), - channel_id: *dst_channel_id, - height: Height::zero(), - }) + .query_channel( + QueryChannelRequest { + port_id: channel.dst_port_id().clone(), + channel_id: *dst_channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| { ChannelError::handshake_finalize( channel.dst_port_id().clone(), @@ -839,13 +855,16 @@ impl Channel { ); // Retrieve existing channel - let dst_channel = self + let (dst_channel, _) = self .dst_chain() - .query_channel(QueryChannelRequest { - port_id: self.dst_port_id().clone(), - channel_id: *dst_channel_id, - height: Height::zero(), - }) + .query_channel( + QueryChannelRequest { + port_id: self.dst_port_id().clone(), + channel_id: *dst_channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; // Check if a channel is expected to exist on destination chain @@ -870,13 +889,16 @@ impl Channel { .ok_or_else(ChannelError::missing_local_channel_id)?; // Channel must exist on source - let src_channel = self + let (src_channel, _) = self .src_chain() - .query_channel(QueryChannelRequest { - port_id: self.src_port_id().clone(), - channel_id: *src_channel_id, - height: Height::zero(), - }) + .query_channel( + QueryChannelRequest { + port_id: self.src_port_id().clone(), + channel_id: *src_channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ChannelError::query(self.src_chain().id(), e))?; if src_channel.counterparty().port_id() != self.dst_port_id() { @@ -891,10 +913,13 @@ impl Channel { // Connection must exist on destination self.dst_chain() - .query_connection(QueryConnectionRequest { - connection_id: self.dst_connection_id().clone(), - height: Height::zero(), - }) + .query_connection( + QueryConnectionRequest { + connection_id: self.dst_connection_id().clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; let query_height = self @@ -991,21 +1016,27 @@ impl Channel { self.validated_expected_channel(ChannelMsgType::OpenAck)?; // Channel must exist on source - let src_channel = self + let (src_channel, _) = self .src_chain() - .query_channel(QueryChannelRequest { - port_id: self.src_port_id().clone(), - channel_id: *src_channel_id, - height: Height::zero(), - }) + .query_channel( + QueryChannelRequest { + port_id: self.src_port_id().clone(), + channel_id: *src_channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ChannelError::query(self.src_chain().id(), e))?; // Connection must exist on destination self.dst_chain() - .query_connection(QueryConnectionRequest { - connection_id: self.dst_connection_id().clone(), - height: Height::zero(), - }) + .query_connection( + QueryConnectionRequest { + connection_id: self.dst_connection_id().clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; let query_height = self @@ -1100,19 +1131,25 @@ impl Channel { // Channel must exist on source self.src_chain() - .query_channel(QueryChannelRequest { - port_id: self.src_port_id().clone(), - channel_id: *src_channel_id, - height: Height::zero(), - }) + .query_channel( + QueryChannelRequest { + port_id: self.src_port_id().clone(), + channel_id: *src_channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ChannelError::query(self.src_chain().id(), e))?; // Connection must exist on destination self.dst_chain() - .query_connection(QueryConnectionRequest { - connection_id: self.dst_connection_id().clone(), - height: Height::zero(), - }) + .query_connection( + QueryConnectionRequest { + connection_id: self.dst_connection_id().clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; let query_height = self @@ -1195,11 +1232,14 @@ impl Channel { // Channel must exist on destination self.dst_chain() - .query_channel(QueryChannelRequest { - port_id: self.dst_port_id().clone(), - channel_id: *dst_channel_id, - height: Height::zero(), - }) + .query_channel( + QueryChannelRequest { + port_id: self.dst_port_id().clone(), + channel_id: *dst_channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; let signer = self @@ -1259,19 +1299,25 @@ impl Channel { // Channel must exist on source self.src_chain() - .query_channel(QueryChannelRequest { - port_id: self.src_port_id().clone(), - channel_id: *src_channel_id, - height: Height::zero(), - }) + .query_channel( + QueryChannelRequest { + port_id: self.src_port_id().clone(), + channel_id: *src_channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ChannelError::query(self.src_chain().id(), e))?; // Connection must exist on destination self.dst_chain() - .query_connection(QueryConnectionRequest { - connection_id: self.dst_connection_id().clone(), - height: Height::zero(), - }) + .query_connection( + QueryConnectionRequest { + connection_id: self.dst_connection_id().clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .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 d76cc840f3..52566c6b59 100644 --- a/relayer/src/connection.rs +++ b/relayer/src/connection.rs @@ -1,7 +1,9 @@ use core::time::Duration; use crate::chain::counterparty::connection_state_on_destination; -use crate::chain::requests::{PageRequest, QueryConnectionRequest, QueryConnectionsRequest}; +use crate::chain::requests::{ + IncludeProof, PageRequest, QueryConnectionRequest, QueryConnectionsRequest, +}; use crate::chain::tracking::TrackedMsgs; use crate::util::retry::RetryResult; use flex_error::define_error; @@ -337,11 +339,14 @@ impl Connection { connection: WorkerConnectionObject, height: Height, ) -> Result<(Connection, State), ConnectionError> { - let a_connection = chain - .query_connection(QueryConnectionRequest { - connection_id: connection.src_connection_id.clone(), - height, - }) + let (a_connection, _) = chain + .query_connection( + QueryConnectionRequest { + connection_id: connection.src_connection_id.clone(), + height, + }, + IncludeProof::No, + ) .map_err(ConnectionError::relayer)?; let client_id = a_connection.client_id(); @@ -553,22 +558,31 @@ impl Connection { .ok_or_else(ConnectionError::missing_counterparty_connection_id)?; // Continue loop if query error - let a_connection = a_chain.query_connection(QueryConnectionRequest { - connection_id: src_connection_id.clone(), - height: Height::zero(), - }); - if a_connection.is_err() { + let a_connection_res = a_chain.query_connection( + QueryConnectionRequest { + connection_id: src_connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ); + if a_connection_res.is_err() { continue; } - let b_connection = b_chain.query_connection(QueryConnectionRequest { - connection_id: dst_connection_id.clone(), - height: Height::zero(), - }); - if b_connection.is_err() { + let b_connection_res = b_chain.query_connection( + QueryConnectionRequest { + connection_id: dst_connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ); + if b_connection_res.is_err() { continue; } - match (a_connection.unwrap().state(), b_connection.unwrap().state()) { + match ( + a_connection_res.unwrap().0.state(), + b_connection_res.unwrap().0.state(), + ) { (State::Init, State::TryOpen) | (State::TryOpen, State::TryOpen) => { // Ack to a_chain match self.flipped().build_conn_ack_and_send() { @@ -616,12 +630,15 @@ impl Connection { .src_connection_id() .ok_or_else(ConnectionError::missing_local_connection_id)?; - let connection_end = self + let (connection_end, _) = self .src_chain() - .query_connection(QueryConnectionRequest { - connection_id: connection_id.clone(), - height: Height::zero(), - }) + .query_connection( + QueryConnectionRequest { + connection_id: connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ConnectionError::connection_query(connection_id.clone(), e))?; let connection = IdentifiedConnectionEnd { @@ -736,12 +753,15 @@ impl Connection { ); // Retrieve existing connection if any - let dst_connection = self + let (dst_connection, _) = self .dst_chain() - .query_connection(QueryConnectionRequest { - connection_id: dst_connection_id.clone(), - height: Height::zero(), - }) + .query_connection( + QueryConnectionRequest { + connection_id: dst_connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ConnectionError::chain_query(self.dst_chain().id(), e))?; // Check if a connection is expected to exist on destination chain @@ -848,12 +868,15 @@ impl Connection { .src_connection_id() .ok_or_else(ConnectionError::missing_local_connection_id)?; - let src_connection = self + let (src_connection, _) = self .src_chain() - .query_connection(QueryConnectionRequest { - connection_id: src_connection_id.clone(), - height: Height::zero(), - }) + .query_connection( + QueryConnectionRequest { + connection_id: src_connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ConnectionError::chain_query(self.src_chain().id(), e))?; // TODO - check that the src connection is consistent with the try options @@ -988,12 +1011,15 @@ impl Connection { let _expected_dst_connection = self.validated_expected_connection(ConnectionMsgType::OpenAck)?; - let src_connection = self + let (src_connection, _) = self .src_chain() - .query_connection(QueryConnectionRequest { - connection_id: src_connection_id.clone(), - height: Height::zero(), - }) + .query_connection( + QueryConnectionRequest { + connection_id: src_connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| ConnectionError::chain_query(self.src_chain().id(), e))?; // TODO - check that the src connection is consistent with the ack options @@ -1093,12 +1119,15 @@ impl Connection { .query_latest_height() .map_err(|e| ConnectionError::chain_query(self.src_chain().id(), e))?; - let _src_connection = self + let (_src_connection, _) = self .src_chain() - .query_connection(QueryConnectionRequest { - connection_id: src_connection_id.clone(), - height: query_height, - }) + .query_connection( + QueryConnectionRequest { + connection_id: src_connection_id.clone(), + height: query_height, + }, + IncludeProof::No, + ) .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/error.rs b/relayer/src/error.rs index 61e1e53b0a..704da24d5f 100644 --- a/relayer/src/error.rs +++ b/relayer/src/error.rs @@ -555,3 +555,6 @@ impl GrpcStatusSubdetail { .starts_with("account sequence mismatch") } } + +pub const QUERY_PROOF_EXPECT_MSG: &str = + "Internal error. Requested proof with query but no proof was returned."; diff --git a/relayer/src/foreign_client.rs b/relayer/src/foreign_client.rs index b87ef6f9d7..ecb39ad700 100644 --- a/relayer/src/foreign_client.rs +++ b/relayer/src/foreign_client.rs @@ -38,8 +38,9 @@ use ibc::Height; use crate::chain::client::ClientSettings; use crate::chain::handle::ChainHandle; use crate::chain::requests::{ - PageRequest, QueryClientStateRequest, QueryConsensusStateRequest, QueryConsensusStatesRequest, - QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, + IncludeProof, PageRequest, QueryClientStateRequest, QueryConsensusStateRequest, + QueryConsensusStatesRequest, QueryUpgradedClientStateRequest, + QueryUpgradedConsensusStateRequest, }; use crate::chain::tracking::TrackedMsgs; use crate::error::Error as RelayerError; @@ -398,11 +399,14 @@ impl ForeignClient Result, ForeignClientError> { let height = Height::new(expected_target_chain.id().version(), 0); - match host_chain.query_client_state(QueryClientStateRequest { - client_id: client_id.clone(), - height, - }) { - Ok(cs) => { + match host_chain.query_client_state( + QueryClientStateRequest { + client_id: client_id.clone(), + height, + }, + IncludeProof::No, + ) { + Ok((cs, _)) => { if cs.chain_id() != expected_target_chain.id() { Err(ForeignClientError::mismatch_chain_id( client_id.clone(), @@ -651,12 +655,15 @@ impl ForeignClient Result<(AnyClientState, Option), ForeignClientError> { - let client_state = { + let (client_state, _) = { self.dst_chain - .query_client_state(QueryClientStateRequest { - client_id: self.id().clone(), - height: Height::zero(), - }) + .query_client_state( + QueryClientStateRequest { + client_id: self.id().clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| { ForeignClientError::client_refresh( self.id().clone(), @@ -1195,13 +1202,16 @@ impl ForeignClient Result { - let res = self + let (consensus_state, _) = self .dst_chain - .query_consensus_state(QueryConsensusStateRequest { - client_id: self.id.clone(), - consensus_height: height, - query_height: Height::zero(), - }) + .query_consensus_state( + QueryConsensusStateRequest { + client_id: self.id.clone(), + consensus_height: height, + query_height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| { ForeignClientError::client_consensus_query( self.id.clone(), @@ -1211,7 +1221,7 @@ impl ForeignClient ForeignClient Link { // Check that the packet's channel on source chain is Open let a_channel_id = &opts.src_channel_id; let a_port_id = &opts.src_port_id; - let a_channel = a_chain - .query_channel(QueryChannelRequest { - port_id: opts.src_port_id.clone(), - channel_id: opts.src_channel_id, - height: Height::default(), - }) + let (a_channel, _) = a_chain + .query_channel( + QueryChannelRequest { + port_id: opts.src_port_id.clone(), + channel_id: opts.src_channel_id, + height: Height::default(), + }, + IncludeProof::No, + ) .map_err(|e| { LinkError::channel_not_found(a_port_id.clone(), *a_channel_id, a_chain.id(), e) })?; @@ -104,11 +107,14 @@ impl Link { // Check the underlying connection let a_connection_id = a_channel.connection_hops()[0].clone(); - let a_connection = a_chain - .query_connection(QueryConnectionRequest { - connection_id: a_connection_id.clone(), - height: Height::zero(), - }) + let (a_connection, _) = a_chain + .query_connection( + QueryConnectionRequest { + connection_id: a_connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(LinkError::relayer)?; if !a_connection.state_matches(&ConnectionState::Open) { diff --git a/relayer/src/link/operational_data.rs b/relayer/src/link/operational_data.rs index c78fa61379..c1797a6fd5 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::IncludeProof; use crate::chain::requests::QueryClientStateRequest; use crate::chain::tracking::TrackedMsgs; use crate::chain::tracking::TrackingId; @@ -174,21 +175,27 @@ impl OperationalData { client_update_opt.pop() } else { - let client_state = match self.target { + let (client_state, _) = match self.target { OperationalDataTarget::Source => relay_path .src_chain() - .query_client_state(QueryClientStateRequest { - client_id: relay_path.src_client_id().clone(), - height: Height::zero(), - }) + .query_client_state( + QueryClientStateRequest { + client_id: relay_path.src_client_id().clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| LinkError::query(relay_path.src_chain().id(), e))?, OperationalDataTarget::Destination => relay_path .dst_chain() - .query_client_state(QueryClientStateRequest { - client_id: relay_path.dst_client_id().clone(), - height: Height::zero(), - }) + .query_client_state( + QueryClientStateRequest { + client_id: relay_path.dst_client_id().clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(|e| LinkError::query(relay_path.dst_chain().id(), e))?, }; diff --git a/relayer/src/link/relay_path.rs b/relayer/src/link/relay_path.rs index b1e708c980..5a2ea75b89 100644 --- a/relayer/src/link/relay_path.rs +++ b/relayer/src/link/relay_path.rs @@ -11,9 +11,11 @@ use crate::chain::counterparty::unreceived_acknowledgements; use crate::chain::counterparty::unreceived_packets; use crate::chain::endpoint::ChainStatus; use crate::chain::handle::ChainHandle; +use crate::chain::requests::IncludeProof; use crate::chain::requests::QueryChannelRequest; use crate::chain::requests::QueryHostConsensusStateRequest; use crate::chain::requests::QueryNextSequenceReceiveRequest; +use crate::chain::requests::QueryPacketCommitmentRequest; use crate::chain::requests::QueryUnreceivedAcksRequest; use crate::chain::requests::QueryUnreceivedPacketsRequest; use crate::chain::tracking::TrackedMsgs; @@ -200,21 +202,29 @@ impl RelayPath { fn src_channel(&self, height: Height) -> Result { self.src_chain() - .query_channel(QueryChannelRequest { - port_id: self.src_port_id().clone(), - channel_id: *self.src_channel_id(), - height, - }) + .query_channel( + QueryChannelRequest { + port_id: self.src_port_id().clone(), + channel_id: *self.src_channel_id(), + height, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) .map_err(|e| LinkError::channel(ChannelError::query(self.src_chain().id(), e))) } fn dst_channel(&self, height: Height) -> Result { self.dst_chain() - .query_channel(QueryChannelRequest { - port_id: self.dst_port_id().clone(), - channel_id: *self.dst_channel_id(), - height, - }) + .query_channel( + QueryChannelRequest { + port_id: self.dst_port_id().clone(), + channel_id: *self.dst_channel_id(), + height, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) .map_err(|e| LinkError::channel(ChannelError::query(self.dst_chain().id(), e))) } @@ -774,12 +784,14 @@ impl RelayPath { fn send_packet_commitment_cleared_on_src(&self, packet: &Packet) -> Result { let (bytes, _) = self .src_chain() - .build_packet_proofs( - PacketMsgType::Recv, - self.src_port_id(), - self.src_channel_id(), - packet.sequence, - Height::zero(), + .query_packet_commitment( + QueryPacketCommitmentRequest { + port_id: self.src_port_id().clone(), + channel_id: *self.src_channel_id(), + sequence: packet.sequence, + height: Height::zero(), + }, + IncludeProof::No, ) .map_err(LinkError::relayer)?; @@ -798,7 +810,7 @@ impl RelayPath { fn recv_packet_acknowledged_on_src(&self, packet: &Packet) -> Result { let unreceived_ack = self .dst_chain() - .query_unreceived_acknowledgement(QueryUnreceivedAcksRequest { + .query_unreceived_acknowledgements(QueryUnreceivedAcksRequest { port_id: self.dst_port_id().clone(), channel_id: *self.dst_channel_id(), packet_ack_sequences: vec![packet.sequence], @@ -1113,7 +1125,7 @@ impl RelayPath { } fn build_recv_packet(&self, packet: &Packet, height: Height) -> Result, LinkError> { - let (_, proofs) = self + let proofs = self .src_chain() .build_packet_proofs( PacketMsgType::Recv, @@ -1141,7 +1153,7 @@ impl RelayPath { ) -> Result, LinkError> { let packet = event.packet.clone(); - let (_, proofs) = self + let proofs = self .src_chain() .build_packet_proofs( PacketMsgType::Ack, @@ -1177,19 +1189,24 @@ impl RelayPath { debug!("build timeout for channel"); let (packet_type, next_sequence_received) = if self.ordered_channel() { - let next_seq = self + let (next_seq, _) = self .dst_chain() - .query_next_sequence_receive(QueryNextSequenceReceiveRequest { - port_id: self.dst_port_id().clone(), - channel_id: *dst_channel_id, - }) + .query_next_sequence_receive( + QueryNextSequenceReceiveRequest { + port_id: self.dst_port_id().clone(), + channel_id: *dst_channel_id, + height, + }, + IncludeProof::No, + ) .map_err(|e| LinkError::query(self.dst_chain().id(), e))?; + (PacketMsgType::TimeoutOrdered, next_seq) } else { (PacketMsgType::TimeoutUnordered, packet.sequence) }; - let (_, proofs) = self + let proofs = self .dst_chain() .build_packet_proofs( packet_type, @@ -1221,7 +1238,7 @@ impl RelayPath { packet: &Packet, height: Height, ) -> Result, LinkError> { - let (_, proofs) = self + let proofs = self .dst_chain() .build_packet_proofs( PacketMsgType::TimeoutOnClose, diff --git a/relayer/src/object.rs b/relayer/src/object.rs index 1ddff6f077..ff74819a24 100644 --- a/relayer/src/object.rs +++ b/relayer/src/object.rs @@ -19,7 +19,7 @@ use crate::chain::{ counterparty_chain_from_connection, }, handle::ChainHandle, - requests::QueryClientStateRequest, + requests::{IncludeProof, QueryClientStateRequest}, }; use crate::error::Error as RelayerError; use crate::supervisor::Error as SupervisorError; @@ -303,11 +303,14 @@ impl Object { e: &UpdateClient, dst_chain: &impl ChainHandle, ) -> Result { - let client_state = dst_chain - .query_client_state(QueryClientStateRequest { - client_id: e.client_id().clone(), - height: Height::zero(), - }) + let (client_state, _) = dst_chain + .query_client_state( + QueryClientStateRequest { + client_id: e.client_id().clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(ObjectError::relayer)?; if client_state.refresh_period().is_none() { diff --git a/relayer/src/supervisor/client_state_filter.rs b/relayer/src/supervisor/client_state_filter.rs index dbb0d51ae4..dfaa6419e8 100644 --- a/relayer/src/supervisor/client_state_filter.rs +++ b/relayer/src/supervisor/client_state_filter.rs @@ -12,7 +12,7 @@ use ibc::Height; use crate::chain::handle::ChainHandle; use crate::chain::requests::{ - QueryChannelRequest, QueryClientStateRequest, QueryConnectionRequest, + IncludeProof, QueryChannelRequest, QueryClientStateRequest, QueryConnectionRequest, }; use crate::error::Error as RelayerError; use crate::object; @@ -111,12 +111,15 @@ impl FilterPolicy { .get_or_spawn(&counterparty_chain_id) .map_err(FilterError::spawn)?; let counterparty_client_id = connection.counterparty().client_id(); - let counterparty_client_state = { + let (counterparty_client_state, _) = { counterparty_chain - .query_client_state(QueryClientStateRequest { - client_id: counterparty_client_id.clone(), - height: Height::zero(), - }) + .query_client_state( + QueryClientStateRequest { + client_id: counterparty_client_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(FilterError::relayer)? }; @@ -226,11 +229,14 @@ impl FilterPolicy { obj.dst_chain_id ); - let client_state = chain - .query_client_state(QueryClientStateRequest { - client_id: obj.dst_client_id.clone(), - height: Height::zero(), - }) + let (client_state, _) = chain + .query_client_state( + QueryClientStateRequest { + client_id: obj.dst_client_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(FilterError::relayer)?; Ok(self.control_client(&obj.dst_chain_id, &obj.dst_client_id, &client_state)) @@ -265,18 +271,24 @@ impl FilterPolicy { obj.src_chain_id ); - let connection_end = src_chain - .query_connection(QueryConnectionRequest { - connection_id: obj.src_connection_id.clone(), - height: Height::zero(), - }) + let (connection_end, _) = src_chain + .query_connection( + QueryConnectionRequest { + connection_id: obj.src_connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(FilterError::relayer)?; - let client_state = src_chain - .query_client_state(QueryClientStateRequest { - client_id: connection_end.client_id().clone(), - height: Height::zero(), - }) + let (client_state, _) = src_chain + .query_client_state( + QueryClientStateRequest { + client_id: connection_end.client_id().clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(FilterError::relayer)?; self.control_connection_end_and_client( @@ -312,12 +324,15 @@ impl FilterPolicy { .get_or_spawn(chain_id) .map_err(FilterError::spawn)?; - let channel_end = src_chain - .query_channel(QueryChannelRequest { - port_id: port_id.clone(), - channel_id: *channel_id, - height: Height::zero(), - }) + let (channel_end, _) = src_chain + .query_channel( + QueryChannelRequest { + port_id: port_id.clone(), + channel_id: *channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(FilterError::relayer)?; let conn_id = channel_end.connection_hops.first().ok_or_else(|| { @@ -327,18 +342,24 @@ impl FilterPolicy { )) })?; - let connection_end = src_chain - .query_connection(QueryConnectionRequest { - connection_id: conn_id.clone(), - height: Height::zero(), - }) + let (connection_end, _) = src_chain + .query_connection( + QueryConnectionRequest { + connection_id: conn_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(FilterError::relayer)?; - let client_state = src_chain - .query_client_state(QueryClientStateRequest { - client_id: connection_end.client_id().clone(), - height: Height::zero(), - }) + let (client_state, _) = src_chain + .query_client_state( + QueryClientStateRequest { + client_id: connection_end.client_id().clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .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 e27be69896..4e5301f0c6 100644 --- a/relayer/src/supervisor/scan.rs +++ b/relayer/src/supervisor/scan.rs @@ -22,7 +22,7 @@ use crate::{ counterparty::{channel_on_destination, connection_state_on_destination}, handle::ChainHandle, requests::{ - PageRequest, QueryChannelRequest, QueryClientConnectionsRequest, + IncludeProof, PageRequest, QueryChannelRequest, QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, }, @@ -697,11 +697,14 @@ fn query_client( chain: &Chain, client_id: &ClientId, ) -> Result { - let client = chain - .query_client_state(QueryClientStateRequest { - client_id: client_id.clone(), - height: Height::zero(), - }) + let (client, _) = chain + .query_client_state( + QueryClientStateRequest { + client_id: client_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(Error::query)?; Ok(IdentifiedAnyClientState::new(client_id.clone(), client)) @@ -712,12 +715,15 @@ fn query_channel( port_id: &PortId, channel_id: &ChannelId, ) -> Result { - let channel_end = chain - .query_channel(QueryChannelRequest { - port_id: port_id.clone(), - channel_id: *channel_id, - height: Height::zero(), - }) + let (channel_end, _) = chain + .query_channel( + QueryChannelRequest { + port_id: port_id.clone(), + channel_id: *channel_id, + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(Error::query)?; Ok(IdentifiedChannelEnd::new( @@ -781,11 +787,14 @@ fn query_connection( chain: &Chain, connection_id: &ConnectionId, ) -> Result { - let connection_end = chain - .query_connection(QueryConnectionRequest { - connection_id: connection_id.clone(), - height: Height::zero(), - }) + let (connection_end, _) = chain + .query_connection( + QueryConnectionRequest { + connection_id: connection_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(Error::query)?; Ok(IdentifiedConnectionEnd { diff --git a/relayer/src/upgrade_chain.rs b/relayer/src/upgrade_chain.rs index 786d5496cf..3ba4f191db 100644 --- a/relayer/src/upgrade_chain.rs +++ b/relayer/src/upgrade_chain.rs @@ -19,7 +19,7 @@ use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::client::v1::UpgradeProposal; use crate::chain::handle::ChainHandle; -use crate::chain::requests::QueryClientStateRequest; +use crate::chain::requests::{IncludeProof, QueryClientStateRequest}; use crate::chain::tracking::TrackedMsgs; use crate::config::ChainConfig; use crate::error::Error; @@ -75,11 +75,14 @@ pub fn build_and_send_ibc_upgrade_proposal( .map_err(UpgradeChainError::query)? .add(opts.height_offset); - let client_state = src_chain - .query_client_state(QueryClientStateRequest { - client_id: opts.src_client_id.clone(), - height: Height::zero(), - }) + let (client_state, _) = src_chain + .query_client_state( + QueryClientStateRequest { + client_id: opts.src_client_id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + ) .map_err(UpgradeChainError::query)?; let client_state = downcast!(client_state => AnyClientState::Tendermint) diff --git a/tools/integration-test/src/mbt/utils.rs b/tools/integration-test/src/mbt/utils.rs index 97af0c01cc..1245f3d6b2 100644 --- a/tools/integration-test/src/mbt/utils.rs +++ b/tools/integration-test/src/mbt/utils.rs @@ -115,7 +115,7 @@ pub fn get_unacknowledged_packets_at_src( diff --git a/tools/integration-test/src/tests/client_settings.rs b/tools/integration-test/src/tests/client_settings.rs index cc438b49d4..6aa2074552 100644 --- a/tools/integration-test/src/tests/client_settings.rs +++ b/tools/integration-test/src/tests/client_settings.rs @@ -5,7 +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::chain::requests::{IncludeProof, QueryClientStateRequest}; use ibc_relayer::foreign_client::CreateOptions; use ibc_test_framework::prelude::*; @@ -106,10 +106,13 @@ fn query_client_state( handle: Chain, id: &ClientId, ) -> Result { - let state = handle.query_client_state(QueryClientStateRequest { - client_id: id.clone(), - height: Height::zero(), - })?; + let (state, _) = handle.query_client_state( + QueryClientStateRequest { + client_id: id.clone(), + height: Height::zero(), + }, + IncludeProof::No, + )?; #[allow(unreachable_patterns)] match state { AnyClientState::Tendermint(state) => Ok(state), diff --git a/tools/test-framework/src/relayer/chain.rs b/tools/test-framework/src/relayer/chain.rs index 86cc962723..cf80f7f4cb 100644 --- a/tools/test-framework/src/relayer/chain.rs +++ b/tools/test-framework/src/relayer/chain.rs @@ -50,13 +50,15 @@ use ibc_relayer::chain::client::ClientSettings; use ibc_relayer::chain::endpoint::{ChainStatus, HealthCheck}; use ibc_relayer::chain::handle::{ChainHandle, ChainRequest, Subscription}; use ibc_relayer::chain::requests::{ - QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, + IncludeProof, QueryChannelClientStateRequest, QueryChannelRequest, QueryChannelsRequest, QueryClientConnectionsRequest, QueryClientStateRequest, QueryClientStatesRequest, QueryConnectionChannelsRequest, QueryConnectionRequest, QueryConnectionsRequest, QueryConsensusStateRequest, QueryConsensusStatesRequest, QueryHostConsensusStateRequest, - QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementsRequest, - QueryPacketCommitmentsRequest, QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, - QueryUpgradedClientStateRequest, QueryUpgradedConsensusStateRequest, + QueryNextSequenceReceiveRequest, QueryPacketAcknowledgementRequest, + QueryPacketAcknowledgementsRequest, QueryPacketCommitmentRequest, + QueryPacketCommitmentsRequest, QueryPacketReceiptRequest, QueryUnreceivedAcksRequest, + QueryUnreceivedPacketsRequest, QueryUpgradedClientStateRequest, + QueryUpgradedConsensusStateRequest, }; use ibc_relayer::chain::tracking::TrackedMsgs; use ibc_relayer::config::ChainConfig; @@ -148,8 +150,9 @@ where fn query_client_state( &self, request: QueryClientStateRequest, - ) -> Result { - self.value().query_client_state(request) + include_proof: IncludeProof, + ) -> Result<(AnyClientState, Option), Error> { + self.value().query_client_state(request, include_proof) } fn query_client_connections( @@ -169,8 +172,9 @@ where fn query_consensus_state( &self, request: QueryConsensusStateRequest, - ) -> Result { - self.value().query_consensus_state(request) + include_proof: IncludeProof, + ) -> Result<(AnyConsensusState, Option), Error> { + self.value().query_consensus_state(request, include_proof) } fn query_upgraded_client_state( @@ -195,8 +199,12 @@ where self.value().query_compatible_versions() } - fn query_connection(&self, request: QueryConnectionRequest) -> Result { - self.value().query_connection(request) + fn query_connection( + &self, + request: QueryConnectionRequest, + include_proof: IncludeProof, + ) -> Result<(ConnectionEnd, Option), Error> { + self.value().query_connection(request, include_proof) } fn query_connections( @@ -216,8 +224,10 @@ where fn query_next_sequence_receive( &self, request: QueryNextSequenceReceiveRequest, - ) -> Result { - self.value().query_next_sequence_receive(request) + include_proof: IncludeProof, + ) -> Result<(Sequence, Option), Error> { + self.value() + .query_next_sequence_receive(request, include_proof) } fn query_channels( @@ -227,8 +237,12 @@ where self.value().query_channels(request) } - fn query_channel(&self, request: QueryChannelRequest) -> Result { - self.value().query_channel(request) + fn query_channel( + &self, + request: QueryChannelRequest, + include_proof: IncludeProof, + ) -> Result<(ChannelEnd, Option), Error> { + self.value().query_channel(request, include_proof) } fn query_channel_client_state( @@ -238,32 +252,6 @@ where self.value().query_channel_client_state(request) } - fn proven_client_state( - &self, - client_id: &ClientId, - height: Height, - ) -> Result<(AnyClientState, MerkleProof), Error> { - self.value().proven_client_state(client_id, height) - } - - fn proven_connection( - &self, - connection_id: &ConnectionId, - height: Height, - ) -> Result<(ConnectionEnd, MerkleProof), Error> { - self.value().proven_connection(connection_id, height) - } - - fn proven_client_consensus( - &self, - client_id: &ClientId, - consensus_height: Height, - height: Height, - ) -> Result<(AnyConsensusState, MerkleProof), Error> { - self.value() - .proven_client_consensus(client_id, consensus_height, height) - } - fn build_header( &self, trusted_height: Height, @@ -334,11 +322,19 @@ where channel_id: &ChannelId, sequence: Sequence, height: Height, - ) -> Result<(Vec, Proofs), Error> { + ) -> Result { self.value() .build_packet_proofs(packet_type, port_id, channel_id, sequence, height) } + fn query_packet_commitment( + &self, + request: QueryPacketCommitmentRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + self.value().query_packet_commitment(request, include_proof) + } + fn query_packet_commitments( &self, request: QueryPacketCommitmentsRequest, @@ -346,6 +342,14 @@ where self.value().query_packet_commitments(request) } + fn query_packet_receipt( + &self, + request: QueryPacketReceiptRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + self.value().query_packet_receipt(request, include_proof) + } + fn query_unreceived_packets( &self, request: QueryUnreceivedPacketsRequest, @@ -353,6 +357,15 @@ where self.value().query_unreceived_packets(request) } + fn query_packet_acknowledgement( + &self, + request: QueryPacketAcknowledgementRequest, + include_proof: IncludeProof, + ) -> Result<(Vec, Option), Error> { + self.value() + .query_packet_acknowledgement(request, include_proof) + } + fn query_packet_acknowledgements( &self, request: QueryPacketAcknowledgementsRequest, @@ -360,11 +373,11 @@ where self.value().query_packet_acknowledgements(request) } - fn query_unreceived_acknowledgement( + fn query_unreceived_acknowledgements( &self, request: QueryUnreceivedAcksRequest, ) -> Result, Error> { - self.value().query_unreceived_acknowledgement(request) + self.value().query_unreceived_acknowledgements(request) } fn query_txs(&self, request: QueryTxRequest) -> Result, Error> { diff --git a/tools/test-framework/src/relayer/channel.rs b/tools/test-framework/src/relayer/channel.rs index b7830422c3..560c6d369b 100644 --- a/tools/test-framework/src/relayer/channel.rs +++ b/tools/test-framework/src/relayer/channel.rs @@ -4,7 +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::chain::requests::{IncludeProof, QueryChannelRequest}; use ibc_relayer::channel::{extract_channel_id, Channel, ChannelSide}; use crate::error::Error; @@ -77,11 +77,14 @@ pub fn query_channel_end( channel_id: &TaggedChannelIdRef, port_id: &TaggedPortIdRef, ) -> Result, Error> { - let channel_end = handle.query_channel(QueryChannelRequest { - port_id: port_id.into_value().clone(), - channel_id: *channel_id.into_value(), - height: 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(), + }, + IncludeProof::No, + )?; Ok(DualTagged::new(channel_end)) } @@ -91,11 +94,14 @@ pub fn query_identified_channel_end( channel_id: TaggedChannelIdRef, port_id: TaggedPortIdRef, ) -> Result, Error> { - let channel_end = handle.query_channel(QueryChannelRequest { - port_id: port_id.into_value().clone(), - channel_id: *channel_id.into_value(), - height: 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(), + }, + IncludeProof::No, + )?; 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 cdacfa7e6d..757e1d8091 100644 --- a/tools/test-framework/src/relayer/connection.rs +++ b/tools/test-framework/src/relayer/connection.rs @@ -9,7 +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::chain::requests::{IncludeProof, QueryConnectionRequest}; use ibc_relayer::connection::{extract_connection_id, Connection, ConnectionSide}; use crate::error::Error; @@ -89,10 +89,13 @@ pub fn query_connection_end( handle: &ChainA, connection_id: &TaggedConnectionIdRef, ) -> Result, Error> { - let connection_end = handle.query_connection(QueryConnectionRequest { - connection_id: connection_id.into_value().clone(), - height: Height::zero(), - })?; + let (connection_end, _) = handle.query_connection( + QueryConnectionRequest { + connection_id: connection_id.into_value().clone(), + height: Height::zero(), + }, + IncludeProof::No, + )?; Ok(DualTagged::new(connection_end)) } @@ -101,10 +104,13 @@ pub fn query_identified_connection_end( handle: &ChainA, connection_id: TaggedConnectionIdRef, ) -> Result, Error> { - let connection_end = handle.query_connection(QueryConnectionRequest { - connection_id: connection_id.into_value().clone(), - height: Height::zero(), - })?; + let (connection_end, _) = handle.query_connection( + QueryConnectionRequest { + connection_id: connection_id.into_value().clone(), + height: Height::zero(), + }, + IncludeProof::No, + )?; Ok(DualTagged::new(IdentifiedConnectionEnd::new( connection_id.into_value().clone(), connection_end,