Skip to content

Commit

Permalink
Upgrade proto to ibc-go v1.2 and sdk v0.44 (informalsystems#1438)
Browse files Browse the repository at this point in the history
* Regenerated proto files with ibc-go v1.2 and sdk v0.44

* Make the code compile

* Restructure packet queries

* Added support to fetch chain version in bootstrap()

* Updated validation for port identifier (informalsystems#1523)

* Fix for compat. packet_commitment_sequences with ibc-go pre v1.2

* Fixed tests, better comments

* Re-generated using most recent commits.

* Fix bootstrap() unwraps in CLIs.

* Changelog

* Add log traces for version parsing

* FMT

* More test fixes

* Add commitment sequences to query ack request

* Remove version compatibility check in query_packet_acknowledgements

Co-authored-by: Anca Zamfir <zamfiranca@gmail.com>
Co-authored-by: Valery Litvin <litvintech@gmail.com>
Co-authored-by: Romain Ruetschi <romain@informal.systems>
  • Loading branch information
4 people committed Nov 8, 2021
1 parent 06c79f9 commit 2549c2e
Show file tree
Hide file tree
Showing 19 changed files with 475 additions and 320 deletions.
3 changes: 3 additions & 0 deletions .changelog/unreleased/features/1409-vega-protos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Support for compatibility with gaia Vega upgrade (protos matching ibc-go
v1.2.2 and SDK v0.44.3) ([#1409](https://github.com/informalsystems/ibc-
rs/issues/1409))
6 changes: 4 additions & 2 deletions relayer-cli/src/commands/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tokio::runtime::Runtime as TokioRuntime;

use ibc_relayer::chain::{ChainEndpoint, CosmosSdkChain, HealthCheck::*};

use crate::conclude::Output;
use crate::conclude::{exit_with_unrecoverable_error, Output};
use crate::prelude::*;

#[derive(Clone, Command, Debug, Options)]
Expand All @@ -31,7 +31,9 @@ impl Runnable for HealthCheckCmd {

info!("[{}] performing health check...", ch.id);

let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt).unwrap();
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt)
.unwrap_or_else(exit_with_unrecoverable_error);

match chain.health_check() {
Ok(Healthy) => info!("[{}] chain is healthy", ch.id),
Ok(Unhealthy(_)) => {
Expand Down
5 changes: 3 additions & 2 deletions relayer-cli/src/commands/query/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ibc::core::ics24_host::identifier::ChainId;
use ibc::core::ics24_host::identifier::{ChannelId, PortId};
use ibc_relayer::chain::{ChainEndpoint, CosmosSdkChain};

use crate::conclude::Output;
use crate::conclude::{exit_with_unrecoverable_error, Output};
use crate::prelude::*;
use ibc::core::ics04_channel::channel::State;

Expand Down Expand Up @@ -44,7 +44,8 @@ impl Runnable for QueryChannelEndCmd {
debug!("Options: {:?}", self);

let rt = Arc::new(TokioRuntime::new().unwrap());
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt).unwrap();
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt)
.unwrap_or_else(exit_with_unrecoverable_error);

let height = ibc::Height::new(chain.id().version(), self.height.unwrap_or(0_u64));
let res = chain.query_channel(&self.port_id, &self.channel_id, height);
Expand Down
14 changes: 9 additions & 5 deletions relayer-cli/src/commands/query/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use ibc_relayer::chain::ChainEndpoint;
use ibc_relayer::chain::CosmosSdkChain;

use crate::application::app_config;
use crate::conclude::Output;
use crate::conclude::{exit_with_unrecoverable_error, Output};

/// Query client state command
#[derive(Clone, Command, Debug, Options)]
Expand Down Expand Up @@ -50,7 +50,8 @@ impl Runnable for QueryClientStateCmd {
};

let rt = Arc::new(TokioRuntime::new().unwrap());
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt).unwrap();
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt)
.unwrap_or_else(exit_with_unrecoverable_error);
let height = ibc::Height::new(chain.id().version(), self.height.unwrap_or(0_u64));

match chain.query_client_state(&self.client_id, height) {
Expand Down Expand Up @@ -102,7 +103,8 @@ impl Runnable for QueryClientConsensusCmd {
debug!("Options: {:?}", self);

let rt = Arc::new(TokioRuntime::new().unwrap());
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt).unwrap();
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt)
.unwrap_or_else(exit_with_unrecoverable_error);

let counterparty_chain = match chain.query_client_state(&self.client_id, Height::zero()) {
Ok(cs) => cs.chain_id(),
Expand Down Expand Up @@ -185,7 +187,8 @@ impl Runnable for QueryClientHeaderCmd {
debug!("Options: {:?}", self);

let rt = Arc::new(TokioRuntime::new().unwrap());
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt).unwrap();
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt)
.unwrap_or_else(exit_with_unrecoverable_error);

let counterparty_chain = match chain.query_client_state(&self.client_id, Height::zero()) {
Ok(cs) => cs.chain_id(),
Expand Down Expand Up @@ -248,7 +251,8 @@ impl Runnable for QueryClientConnectionsCmd {
debug!("Options: {:?}", self);

let rt = Arc::new(TokioRuntime::new().unwrap());
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt).unwrap();
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt)
.unwrap_or_else(exit_with_unrecoverable_error);

let req = QueryClientConnectionsRequest {
client_id: self.client_id.to_string(),
Expand Down
5 changes: 3 additions & 2 deletions relayer-cli/src/commands/query/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ibc::core::ics24_host::identifier::{ChainId, ClientId};
use ibc_proto::ibc::core::client::v1::QueryClientStatesRequest;
use ibc_relayer::chain::{ChainEndpoint, CosmosSdkChain};

use crate::conclude::Output;
use crate::conclude::{exit_with_unrecoverable_error, Output};
use crate::error::Error;
use crate::prelude::*;

Expand Down Expand Up @@ -58,7 +58,8 @@ impl Runnable for QueryAllClientsCmd {
debug!("Options: {:?}", self);

let rt = Arc::new(TokioRuntime::new().unwrap());
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt).unwrap();
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt)
.unwrap_or_else(exit_with_unrecoverable_error);

let req = QueryClientStatesRequest {
pagination: ibc_proto::cosmos::base::query::pagination::all(),
Expand Down
8 changes: 5 additions & 3 deletions relayer-cli/src/commands/query/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ibc::core::{
use ibc_proto::ibc::core::channel::v1::QueryConnectionChannelsRequest;
use ibc_relayer::chain::{ChainEndpoint, CosmosSdkChain};

use crate::conclude::Output;
use crate::conclude::{exit_with_unrecoverable_error, Output};
use crate::error::Error;
use crate::prelude::*;

Expand Down Expand Up @@ -46,7 +46,8 @@ impl Runnable for QueryConnectionEndCmd {
debug!("Options: {:?}", self);

let rt = Arc::new(TokioRuntime::new().unwrap());
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt).unwrap();
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt)
.unwrap_or_else(exit_with_unrecoverable_error);

let height = ibc::Height::new(chain.id().version(), self.height.unwrap_or(0_u64));
let res = chain.query_connection(&self.connection_id, height);
Expand Down Expand Up @@ -97,7 +98,8 @@ impl Runnable for QueryConnectionChannelsCmd {
debug!("Options: {:?}", self);

let rt = Arc::new(TokioRuntime::new().unwrap());
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt).unwrap();
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt)
.unwrap_or_else(exit_with_unrecoverable_error);

let req = QueryConnectionChannelsRequest {
connection: self.connection_id.to_string(),
Expand Down
5 changes: 3 additions & 2 deletions relayer-cli/src/commands/query/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ibc::core::ics24_host::identifier::{ChainId, ConnectionId};
use ibc_proto::ibc::core::connection::v1::QueryConnectionsRequest;
use ibc_relayer::chain::{ChainEndpoint, CosmosSdkChain};

use crate::conclude::Output;
use crate::conclude::{exit_with_unrecoverable_error, Output};
use crate::prelude::*;

#[derive(Clone, Command, Debug, Options)]
Expand Down Expand Up @@ -35,7 +35,8 @@ impl Runnable for QueryConnectionsCmd {
debug!("Options: {:?}", self);

let rt = Arc::new(TokioRuntime::new().unwrap());
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt).unwrap();
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt)
.unwrap_or_else(exit_with_unrecoverable_error);

let req = QueryConnectionsRequest {
pagination: ibc_proto::cosmos::base::query::pagination::all(),
Expand Down
29 changes: 12 additions & 17 deletions relayer-cli/src/commands/query/packet/acks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use serde::Serialize;

use ibc::core::ics24_host::identifier::{ChainId, ChannelId, PortId};
use ibc::Height;
use ibc_proto::ibc::core::channel::v1::QueryPacketAcknowledgementsRequest;
use ibc_relayer::chain::handle::ChainHandle;
use ibc_relayer::chain::handle::ProdChainHandle;

use crate::cli_utils::spawn_chain_runtime;
use crate::cli_utils::spawn_chain_counterparty;
use crate::conclude::Output;
use crate::error::Error;
use crate::prelude::*;
use ibc_relayer::chain::counterparty::acknowledgements_on_chain;

#[derive(Serialize, Debug)]
struct PacketSeqs {
Expand All @@ -35,22 +35,17 @@ impl QueryPacketAcknowledgementsCmd {

debug!("Options: {:?}", self);

let chain = spawn_chain_runtime(&*config, &self.chain_id)?;
let (chains, channel) = spawn_chain_counterparty::<ProdChainHandle>(
&config,
&self.chain_id,
&self.port_id,
&self.channel_id,
)?;

let grpc_request = QueryPacketAcknowledgementsRequest {
port_id: self.port_id.to_string(),
channel_id: self.channel_id.to_string(),
pagination: ibc_proto::cosmos::base::query::pagination::all(),
};
let (seqs, height) = acknowledgements_on_chain(&chains.src, &chains.dst, &channel)
.map_err(Error::supervisor)?;

// Transform the list fo raw packet state into the list of sequence numbers
chain
.query_packet_acknowledgements(grpc_request)
.map_err(Error::relayer)
.map(|(packet, height)| PacketSeqs {
seqs: packet.iter().map(|p| p.sequence).collect(),
height,
})
Ok(PacketSeqs { seqs, height })
}
}

Expand Down
17 changes: 3 additions & 14 deletions relayer-cli/src/commands/query/packet/commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use serde::Serialize;

use ibc::core::ics24_host::identifier::{ChainId, ChannelId, PortId};
use ibc::Height;
use ibc_proto::ibc::core::channel::v1::QueryPacketCommitmentsRequest;
use ibc_relayer::chain::handle::ChainHandle;
use ibc_relayer::chain::counterparty::commitments_on_chain;

use crate::cli_utils::spawn_chain_runtime;
use crate::conclude::Output;
Expand Down Expand Up @@ -37,18 +36,8 @@ impl QueryPacketCommitmentsCmd {

let chain = spawn_chain_runtime(&config, &self.chain_id)?;

let grpc_request = QueryPacketCommitmentsRequest {
port_id: self.port_id.to_string(),
channel_id: self.channel_id.to_string(),
pagination: ibc_proto::cosmos::base::query::pagination::all(),
};

chain
.query_packet_commitments(grpc_request)
.map_err(Error::relayer)
// Transform the raw packet commitm. state into the list of sequence numbers
.map(|(ps_vec, height)| (ps_vec.iter().map(|ps| ps.sequence).collect(), height))
// Assemble into a coherent result
commitments_on_chain(&chain, &self.port_id, &self.channel_id)
.map_err(Error::supervisor)
.map(|(seqs_vec, height)| PacketSeqs {
height,
seqs: seqs_vec,
Expand Down
2 changes: 1 addition & 1 deletion relayer-cli/src/commands/query/packet/unreceived_acks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl QueryUnreceivedAcknowledgementCmd {
self.chain_id, channel
);

unreceived_acknowledgements(&chains.src, &chains.dst, channel).map_err(Error::supervisor)
unreceived_acknowledgements(&chains.src, &chains.dst, &channel).map_err(Error::supervisor)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl QueryUnreceivedPacketsCmd {
self.chain_id, channel
);

unreceived_packets(&chains.src, &chains.dst, channel).map_err(Error::supervisor)
unreceived_packets(&chains.src, &chains.dst, &channel).map_err(Error::supervisor)
}
}

Expand Down
4 changes: 2 additions & 2 deletions relayer-cli/src/commands/query/tx/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ibc_relayer::chain::handle::{ChainHandle, ProdChainHandle};
use ibc_relayer::chain::runtime::ChainRuntime;
use ibc_relayer::chain::CosmosSdkChain;

use crate::conclude::Output;
use crate::conclude::{exit_with_unrecoverable_error, Output};
use crate::error::Error;
use crate::prelude::app_config;

Expand Down Expand Up @@ -46,7 +46,7 @@ impl Runnable for QueryTxEventsCmd {
let rt = Arc::new(TokioRuntime::new().unwrap());
let chain =
ChainRuntime::<CosmosSdkChain>::spawn::<ProdChainHandle>(chain_config.clone(), rt)
.unwrap();
.unwrap_or_else(exit_with_unrecoverable_error);

let res = Hash::from_str(self.hash.as_str())
.map_err(|e| Error::invalid_hash(self.hash.clone(), e))
Expand Down
55 changes: 37 additions & 18 deletions relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ use crate::{
use super::{ChainEndpoint, HealthCheck};

mod compatibility;
pub mod version;

/// Default gas limit when submitting a transaction.
const DEFAULT_MAX_GAS: u64 = 300_000;
Expand All @@ -116,6 +117,7 @@ mod retry_strategy {

pub struct CosmosSdkChain {
config: ChainConfig,
version_specs: version::Specs,
rpc_client: HttpClient,
grpc_addr: Uri,
rt: Arc<TokioRuntime>,
Expand Down Expand Up @@ -768,8 +770,12 @@ impl ChainEndpoint for CosmosSdkChain {
let grpc_addr = Uri::from_str(&config.grpc_addr.to_string())
.map_err(|e| Error::invalid_uri(config.grpc_addr.to_string(), e))?;

// Retrieve the version specification of this chain
let version_specs = rt.block_on(fetch_version_specs(&config.id, &grpc_addr))?;

let chain = Self {
config,
version_specs,
rpc_client,
grpc_addr,
rt,
Expand Down Expand Up @@ -2223,13 +2229,32 @@ async fn do_health_check(chain: &CosmosSdkChain) -> Result<(), Error> {
)
})?;

// Construct a grpc client
let mut client = ServiceClient::connect(chain.grpc_addr.clone())
// Checkup on the underlying SDK & IBC-go versions
if let Err(diagnostic) = compatibility::run_diagnostic(&chain.version_specs) {
return Err(Error::sdk_module_version(
chain_id.clone(),
grpc_address.clone(),
diagnostic.to_string(),
));
}

Ok(())
}

/// Queries the chain to obtain the version information.
async fn fetch_version_specs(
chain_id: &ChainId,
grpc_address: &Uri,
) -> Result<version::Specs, Error> {
let grpc_addr_string = grpc_address.to_string();

// Construct a gRPC client
let mut client = ServiceClient::connect(grpc_address.clone())
.await
.map_err(|e| {
Error::health_check_grpc_transport(
Error::fetch_version_grpc_transport(
chain_id.clone(),
grpc_address.clone(),
grpc_addr_string.clone(),
"tendermint::ServiceClient".to_string(),
e,
)
Expand All @@ -2238,32 +2263,26 @@ async fn do_health_check(chain: &CosmosSdkChain) -> Result<(), Error> {
let request = tonic::Request::new(GetNodeInfoRequest {});

let response = client.get_node_info(request).await.map_err(|e| {
Error::health_check_grpc_status(
Error::fetch_version_grpc_status(
chain_id.clone(),
grpc_address.clone(),
grpc_addr_string.clone(),
"tendermint::ServiceClient".to_string(),
e,
)
})?;

let version = response.into_inner().application_version.ok_or_else(|| {
Error::health_check_invalid_version(
Error::fetch_version_invalid_version_response(
chain_id.clone(),
grpc_address.clone(),
grpc_addr_string.clone(),
"tendermint::GetNodeInfoRequest".to_string(),
)
})?;

// Checkup on the underlying SDK version
if let Err(diagnostic) = compatibility::run_diagnostic(version) {
return Err(Error::sdk_module_version(
chain_id.clone(),
grpc_address.clone(),
diagnostic.to_string(),
));
}

Ok(())
// Parse the raw version info into a domain-type `version::Specs`
version
.try_into()
.map_err(|e| Error::fetch_version_parsing(chain_id.clone(), grpc_addr_string.clone(), e))
}

struct PrettyFee<'a>(&'a Fee);
Expand Down
Loading

0 comments on commit 2549c2e

Please sign in to comment.