Skip to content

Commit

Permalink
Return a 'Specs' struct in 'version_specs()' method
Browse files Browse the repository at this point in the history
  • Loading branch information
ljoss17 committed Nov 16, 2023
1 parent 10225c6 commit f135f41
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 18 deletions.
5 changes: 3 additions & 2 deletions crates/relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ use crate::util::pretty::{
use crate::{chain::client::ClientSettings, config::Error as ConfigError};

use self::types::app_state::GenesisAppState;
use self::version::Specs;

pub mod batch;
pub mod client;
Expand Down Expand Up @@ -1078,9 +1079,9 @@ impl ChainEndpoint for CosmosSdkChain {
ChainConfig::CosmosSdk(self.config.clone())
}

fn version_specs(&self) -> Result<(Option<semver::Version>, semver::Version), Error> {
fn version_specs(&self) -> Result<Specs, Error> {
let version_specs = self.block_on(fetch_version_specs(self.id(), &self.grpc_addr))?;
Ok((version_specs.ibc_go, version_specs.cosmos_sdk))
Ok(version_specs)
}

fn query_balance(&self, key_name: Option<&str>, denom: Option<&str>) -> Result<Balance, Error> {
Expand Down
3 changes: 2 additions & 1 deletion crates/relayer/src/chain/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use tendermint_rpc::endpoint::broadcast::tx_sync::Response as TxResponse;

use crate::account::Balance;
use crate::chain::client::ClientSettings;
use crate::chain::cosmos::version::Specs;
use crate::chain::handle::Subscription;
use crate::chain::requests::*;
use crate::chain::tracking::TrackedMsgs;
Expand Down Expand Up @@ -124,7 +125,7 @@ pub trait ChainEndpoint: Sized {
// Versioning

/// Return the version of the IBC protocol that this chain is running, if known.
fn version_specs(&self) -> Result<(Option<semver::Version>, semver::Version), Error>;
fn version_specs(&self) -> Result<Specs, Error>;

// Send transactions

Expand Down
5 changes: 3 additions & 2 deletions crates/relayer/src/chain/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use crate::{

use super::{
client::ClientSettings,
cosmos::version::Specs,
endpoint::{ChainStatus, HealthCheck},
requests::*,
tracking::TrackedMsgs,
Expand Down Expand Up @@ -141,7 +142,7 @@ pub enum ChainRequest {
},

VersionSpecs {
reply_to: ReplyTo<(Option<semver::Version>, semver::Version)>,
reply_to: ReplyTo<Specs>,
},

QueryBalance {
Expand Down Expand Up @@ -412,7 +413,7 @@ pub trait ChainHandle: Clone + Display + Send + Sync + Debug + 'static {
fn add_key(&self, key_name: String, key: AnySigningKeyPair) -> Result<(), Error>;

/// Return the version of the IBC protocol that this chain is running, if known.
fn version_specs(&self) -> Result<(Option<semver::Version>, semver::Version), Error>;
fn version_specs(&self) -> Result<Specs, Error>;

/// Query the balance of the given account for the given denom.
/// If no account is given, behavior must be specified, e.g. retrieve it from configuration file.
Expand Down
7 changes: 5 additions & 2 deletions crates/relayer/src/chain/handle/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ use ibc_relayer_types::{

use crate::{
account::Balance,
chain::{client::ClientSettings, endpoint::ChainStatus, requests::*, tracking::TrackedMsgs},
chain::{
client::ClientSettings, cosmos::version::Specs, endpoint::ChainStatus, requests::*,
tracking::TrackedMsgs,
},
client_state::{AnyClientState, IdentifiedAnyClientState},
config::ChainConfig,
connection::ConnectionMsgType,
Expand Down Expand Up @@ -144,7 +147,7 @@ impl ChainHandle for BaseChainHandle {
})
}

fn version_specs(&self) -> Result<(Option<semver::Version>, semver::Version), Error> {
fn version_specs(&self) -> Result<Specs, Error> {
self.send(|reply_to| ChainRequest::VersionSpecs { reply_to })
}

Expand Down
3 changes: 2 additions & 1 deletion crates/relayer/src/chain/handle/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use ibc_relayer_types::Height;
use crate::account::Balance;
use crate::cache::{Cache, CacheStatus};
use crate::chain::client::ClientSettings;
use crate::chain::cosmos::version::Specs;
use crate::chain::endpoint::{ChainStatus, HealthCheck};
use crate::chain::handle::{ChainHandle, ChainRequest, Subscription};
use crate::chain::requests::*;
Expand Down Expand Up @@ -122,7 +123,7 @@ impl<Handle: ChainHandle> ChainHandle for CachingChainHandle<Handle> {
self.inner().add_key(key_name, key)
}

fn version_specs(&self) -> Result<(Option<semver::Version>, semver::Version), Error> {
fn version_specs(&self) -> Result<Specs, Error> {
self.inner().version_specs()
}

Expand Down
3 changes: 2 additions & 1 deletion crates/relayer/src/chain/handle/counting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use ibc_relayer_types::Height;

use crate::account::Balance;
use crate::chain::client::ClientSettings;
use crate::chain::cosmos::version::Specs;
use crate::chain::endpoint::{ChainStatus, HealthCheck};
use crate::chain::handle::{ChainHandle, ChainRequest, Subscription};
use crate::chain::requests::*;
Expand Down Expand Up @@ -150,7 +151,7 @@ impl<Handle: ChainHandle> ChainHandle for CountingChainHandle<Handle> {
self.inner().add_key(key_name, key)
}

fn version_specs(&self) -> Result<(Option<semver::Version>, semver::Version), Error> {
fn version_specs(&self) -> Result<Specs, Error> {
self.inc_metric("ibc_version");
self.inner().version_specs()
}
Expand Down
6 changes: 2 additions & 4 deletions crates/relayer/src/chain/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use crate::{

use super::{
client::ClientSettings,
cosmos::version::Specs,
endpoint::{ChainEndpoint, ChainStatus, HealthCheck},
handle::{ChainHandle, ChainRequest, ReplyTo, Subscription},
requests::*,
Expand Down Expand Up @@ -449,10 +450,7 @@ where
reply_to.send(result).map_err(Error::send)
}

fn version_specs(
&mut self,
reply_to: ReplyTo<(Option<semver::Version>, semver::Version)>,
) -> Result<(), Error> {
fn version_specs(&mut self, reply_to: ReplyTo<Specs>) -> Result<(), Error> {
let result = self.chain.version_specs();
reply_to.send(result).map_err(Error::send)
}
Expand Down
8 changes: 4 additions & 4 deletions crates/relayer/src/upgrade_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ pub fn build_and_send_ibc_upgrade_proposal(
/// If the ibc-go version returned isn't reliable, a deprecated version, then the version
/// of Cosmos SDK is used.
pub fn requires_legacy_upgrade_proposal(dst_chain: impl ChainHandle) -> bool {
let (maybe_ibc_version, sdk_version) = dst_chain.version_specs().unwrap();
match maybe_ibc_version {
let version_specs = dst_chain.version_specs().unwrap();
match version_specs.ibc_go {
Some(ibc_version) => {
// Some ibc-go simapps return unreliable ibc-go versions, such as simapp v8.0.0
// returns version v1.0.0. So if the ibc-go version matches which is not maintained
// anymore, use the Cosmos SDK version to determine if the legacy upgrade proposal
// has to be used
if ibc_version.major < 4 {
sdk_version.minor < 50
version_specs.cosmos_sdk.minor < 50
} else {
ibc_version.major < 8
}
}
None => sdk_version.minor < 50,
None => version_specs.cosmos_sdk.minor < 50,
}
}

Expand Down
3 changes: 2 additions & 1 deletion tools/test-framework/src/relayer/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

use crossbeam_channel as channel;
use ibc_relayer::chain::cosmos::version::Specs;
use tracing::Span;

use ibc_proto::ibc::apps::fee::v1::{
Expand Down Expand Up @@ -121,7 +122,7 @@ where
self.value().add_key(key_name, key)
}

fn version_specs(&self) -> Result<(Option<semver::Version>, semver::Version), Error> {
fn version_specs(&self) -> Result<Specs, Error> {
self.value().version_specs()
}

Expand Down

0 comments on commit f135f41

Please sign in to comment.