diff --git a/crates/relayer-cli/src/chain_registry.rs b/crates/relayer-cli/src/chain_registry.rs index 255105f0fe..fa5eb217ab 100644 --- a/crates/relayer-cli/src/chain_registry.rs +++ b/crates/relayer-cli/src/chain_registry.rs @@ -3,7 +3,6 @@ use std::collections::HashMap; use std::fmt::Display; use std::marker::Send; -use std::path::PathBuf; use futures::future::join_all; use http::Uri; @@ -20,7 +19,6 @@ use ibc_chain_registry::querier::*; use ibc_relayer::config::filter::{FilterPattern, PacketFilter}; use ibc_relayer::config::gas_multiplier::GasMultiplier; use ibc_relayer::config::types::{MaxMsgNum, MaxTxSize, Memo}; -use ibc_relayer::config::CanisterIdConfig; use ibc_relayer::config::{default, AddressType, ChainConfig, EventSourceMode, GasPrice}; use ibc_relayer::keyring::Store; @@ -124,9 +122,6 @@ where Ok(ChainConfig { id: chain_data.chain_id, - ic_endpoint: String::new(), - canister_id: CanisterIdConfig::default(), - canister_pem: PathBuf::new(), near_ibc_address: ibc_relayer::config::NearIbcContractAddress::default(), r#type: default::chain_type(), rpc_addr: rpc_data.rpc_address, diff --git a/crates/relayer-cli/src/commands/tx/client.rs b/crates/relayer-cli/src/commands/tx/client.rs index 99bd5bc095..16f2eff945 100644 --- a/crates/relayer-cli/src/commands/tx/client.rs +++ b/crates/relayer-cli/src/commands/tx/client.rs @@ -7,6 +7,7 @@ use ibc_relayer_types::core::ics02_client::msgs::create_client::MsgCreateClient; use ibc_relayer_types::tx_msg::Msg; use std::sync::Arc; use std::thread; +use std::{env, path::PathBuf}; use abscissa_core::clap::Parser; use abscissa_core::{Command, Runnable}; @@ -19,7 +20,6 @@ use ibc_relayer::chain::requests::{ }; use ibc_relayer::chain::tracking::TrackedMsgs; use ibc_relayer::client_state::AnyClientState; -use ibc_relayer::config::ChainConfig; use ibc_relayer::config::Config; use ibc_relayer::error::Error as RelayerError; use ibc_relayer::event::IbcEventWithHeight; @@ -168,15 +168,12 @@ fn run_create_client( fn run_only_init_vp( config: &Config, src_chain_id: &ChainId, - dst_chain_id: &ChainId, + _dst_chain_id: &ChainId, clock_drift: Option, trusting_period: Option, trust_threshold: Option, ) { // this config use dst chain config to init vp - let chain_config = config - .find_chain(dst_chain_id) - .expect("not found dst chain Config"); let src_chain = match spawn_chain_runtime(&config, src_chain_id) { Ok(handle) => handle, Err(e) => Output::error(e).exit(), @@ -190,7 +187,7 @@ fn run_only_init_vp( let rt = Arc::new(TokioRuntime::new().unwrap()); - let vp_client = match VpChain::new(src_chain_id.clone(), chain_config.clone(), rt) { + let vp_client = match VpChain::new(src_chain_id.clone(), rt) { Ok(client) => client, Err(e) => Output::error(e).exit(), }; @@ -309,24 +306,28 @@ fn build_and_create_client_and_send( #[derive(Debug, Clone)] pub struct VpChain { chain_id: ChainId, - config: ChainConfig, rt: Arc, vp_client: VpClient, signer: String, + canister_id: String, } impl VpChain { - pub fn new( - chain_id: ChainId, - chain_config: ChainConfig, - rt: Arc, - ) -> Result { - let canister_pem_path = if chain_config.canister_pem.is_absolute() { - chain_config.canister_pem.clone() + pub fn new(chain_id: ChainId, rt: Arc) -> Result { + let canister_pem_path: PathBuf = env::var("CANISTER_PEM_PATH") + .map_err(|_| RelayerError::report_error("cann't read cansiter pem path env".into()))? + .into(); + let ic_endpoint = env::var("IC_ENDPOINT") + .map_err(|_| RelayerError::report_error("cann't read ic endpoint env".into()))?; + let canister_id = env::var("CANISTER_ID") + .map_err(|_| RelayerError::report_error("cann't read cansiter id env".into()))?; + + let canister_pem_path = if canister_pem_path.is_absolute() { + canister_pem_path.clone() } else { let current_dir = std::env::current_dir().map_err(|e| RelayerError::report_error(e.to_string()))?; - current_dir.join(chain_config.canister_pem.clone()) + current_dir.join(canister_pem_path.clone()) }; let signer = Secp256k1Identity::from_pem_file(canister_pem_path.clone()).map_err(|e| { @@ -349,7 +350,7 @@ impl VpChain { .to_text(); let vp_client = rt - .block_on(VpClient::new(&chain_config.ic_endpoint, &canister_pem_path)) + .block_on(VpClient::new(&ic_endpoint, &canister_pem_path)) .map_err(|e| { let position = std::panic::Location::caller(); RelayerError::report_error(format!( @@ -361,10 +362,10 @@ impl VpChain { Ok(Self { chain_id, - config: chain_config.clone(), vp_client, rt, signer: sender, + canister_id, }) } @@ -389,11 +390,13 @@ impl VpChain { ) -> Result, RelayerError> { // let mut tracked_msgs = tracked_msgs.clone(); // if tracked_msgs.tracking_id().to_string() != "ft-transfer" { - let canister_id = self.config.canister_id.id.as_str(); let mut msgs: Vec = Vec::new(); for msg in tracked_msgs.messages() { let res = self - .block_on(self.vp_client.deliver(canister_id, msg.encode_to_vec())) + .block_on( + self.vp_client + .deliver(&self.canister_id, msg.encode_to_vec()), + ) .map_err(|e| { let position = std::panic::Location::caller(); RelayerError::report_error(format!( diff --git a/crates/relayer/src/chain/cosmos.rs b/crates/relayer/src/chain/cosmos.rs index 541f137be7..1ef449692d 100644 --- a/crates/relayer/src/chain/cosmos.rs +++ b/crates/relayer/src/chain/cosmos.rs @@ -10,7 +10,8 @@ use core::{ use futures::future::join_all; use num_bigint::BigInt; use prost::Message; -use std::{cmp::Ordering, thread}; +use std::env; +use std::{cmp::Ordering, path::PathBuf, thread}; use tokio::runtime::Runtime as TokioRuntime; use tonic::codegen::http::Uri; @@ -154,6 +155,9 @@ pub struct CosmosSdkChain { account: Option, tx_monitor_cmd: Option, + + /// config for icp config + canister_id: String, } impl CosmosSdkChain { @@ -898,16 +902,24 @@ impl ChainEndpoint for CosmosSdkChain { let tx_config = TxConfig::try_from(&config)?; - let canister_pem_path = if config.canister_pem.is_absolute() { - config.canister_pem.clone() + let canister_pem_path: PathBuf = env::var("CANISTER_PEM_PATH") + .map_err(|_| Error::report_error("cann't read cansiter pem path env".into()))? + .into(); + let ic_endpoint = env::var("IC_ENDPOINT") + .map_err(|_| Error::report_error("cann't read ic endpoint env".into()))?; + let canister_id = env::var("CANISTER_ID") + .map_err(|_| Error::report_error("cann't read cansiter id env".into()))?; + + let canister_pem_path = if canister_pem_path.is_absolute() { + canister_pem_path.clone() } else { let current_dir = std::env::current_dir().map_err(|e| Error::report_error(e.to_string()))?; - current_dir.join(config.canister_pem.clone()) + current_dir.join(canister_pem_path.clone()) }; let vp_client = rt - .block_on(VpClient::new(&config.ic_endpoint, &canister_pem_path)) + .block_on(VpClient::new(&ic_endpoint, &canister_pem_path)) .map_err(|e| { let position = std::panic::Location::caller(); Error::report_error(format!( @@ -929,6 +941,7 @@ impl ChainEndpoint for CosmosSdkChain { tx_config, account: None, tx_monitor_cmd: None, + canister_id, }; Ok(chain) @@ -1063,7 +1076,6 @@ impl ChainEndpoint for CosmosSdkChain { ); use ibc_proto::google::protobuf::Any; - let canister_id = self.config.canister_id.id.clone(); let mut result = vec![]; if tracked_msgs.tracking_id().to_string() != "ft-transfer" { @@ -1078,7 +1090,10 @@ impl ChainEndpoint for CosmosSdkChain { info!("near msg envelope: {near_msg_envelope:?}"); let res = self - .block_on(self.vp_client.deliver(&canister_id, msg.encode_to_vec())) + .block_on( + self.vp_client + .deliver(&self.canister_id, msg.encode_to_vec()), + ) .map_err(|e| { let position = std::panic::Location::caller(); Error::report_error(format!( @@ -1133,7 +1148,6 @@ impl ChainEndpoint for CosmosSdkChain { ); use ibc_proto::google::protobuf::Any; - let canister_id = self.config.canister_id.id.clone(); let mut result = vec![]; if tracked_msgs.tracking_id().to_string() != "ft-transfer" { @@ -1148,7 +1162,10 @@ impl ChainEndpoint for CosmosSdkChain { info!("near msg envelope: {near_msg_envelope:?}"); let res = self - .block_on(self.vp_client.deliver(&canister_id, msg.encode_to_vec())) + .block_on( + self.vp_client + .deliver(&self.canister_id, msg.encode_to_vec()), + ) .map_err(|e| { let position = std::panic::Location::caller(); Error::report_error(format!( @@ -1352,8 +1369,6 @@ impl ChainEndpoint for CosmosSdkChain { crate::telemetry!(query, self.id(), "query_client_state"); if matches!(include_proof, IncludeProof::No) { - let canister_id = self.config.canister_id.id.as_str(); - let serialized_request = serde_json::to_vec(&request).map_err(|e| { let position = std::panic::Location::caller(); Error::report_error(format!( @@ -1364,7 +1379,7 @@ impl ChainEndpoint for CosmosSdkChain { let res = self .block_on( self.vp_client - .query_client_state(canister_id, serialized_request), + .query_client_state(&self.canister_id, serialized_request), ) .map_err(|e| { let position = std::panic::Location::caller(); @@ -1463,11 +1478,10 @@ impl ChainEndpoint for CosmosSdkChain { ); crate::telemetry!(query, self.id(), "query_consensus_state_heights"); - let canister_id = self.config.canister_id.id.as_str(); inner_query_consensus_state_heights( self.rt.clone(), self.vp_client.clone(), - canister_id, + &self.canister_id, request, ) } @@ -1488,8 +1502,6 @@ impl ChainEndpoint for CosmosSdkChain { assert!(matches!(include_proof, IncludeProof::No)); assert!(request.client_id.to_string().starts_with("06-solomachine")); - let canister_id = self.config.canister_id.id.as_str(); - let serialized_request = serde_json::to_vec(&request).map_err(|e| { let position = std::panic::Location::caller(); Error::report_error(format!( @@ -1501,7 +1513,7 @@ impl ChainEndpoint for CosmosSdkChain { let res = self .block_on( self.vp_client - .query_consensus_state(canister_id, serialized_request), + .query_consensus_state(&self.canister_id, serialized_request), ) .map_err(|e| { let position = std::panic::Location::caller(); diff --git a/crates/relayer/src/chain/near/mod.rs b/crates/relayer/src/chain/near/mod.rs index 21c330bd7b..178f942e23 100644 --- a/crates/relayer/src/chain/near/mod.rs +++ b/crates/relayer/src/chain/near/mod.rs @@ -146,9 +146,9 @@ impl NearIbcContract for NearChain { } impl NearChain { - fn init_event_monitor(&self) -> Result { + fn init_event_source(&self) -> Result { info!("initializing event monitor"); - crate::time!("init_event_monitor"); + crate::time!("init_event_source"); let (event_monitor, monitor_tx) = NearEventMonitor::new( self.config.id.clone(), @@ -167,10 +167,6 @@ impl NearChain { &self.config } - pub fn canister_id(&self) -> &str { - &self.config.canister_id.id - } - /// Subscribe Events /// todo near don't have events subscription pub fn subscribe_ibc_events(&self) -> Result, Error> { @@ -1653,7 +1649,7 @@ impl ChainEndpoint for NearChain { let tx_monitor_cmd = match &self.tx_monitor_cmd { Some(tx_monitor_cmd) => tx_monitor_cmd, None => { - let tx_monitor_cmd = self.init_event_monitor()?; + let tx_monitor_cmd = self.init_event_source()?; self.tx_monitor_cmd = Some(tx_monitor_cmd); self.tx_monitor_cmd.as_ref().ok_or(Error::report_error( "subscribe tx_monitor_cmd is None".to_string(), diff --git a/crates/relayer/src/config.rs b/crates/relayer/src/config.rs index 8ac31fb350..5f6cd2c947 100644 --- a/crates/relayer/src/config.rs +++ b/crates/relayer/src/config.rs @@ -654,15 +654,6 @@ pub struct ChainConfig { /// The chain's network identifier pub id: ChainId, - #[serde(default = "default::default_canister_id")] - pub canister_id: CanisterIdConfig, - - #[serde(default = "default::default_canister_pem_path")] - pub canister_pem: PathBuf, - - #[serde(default = "default::default_ic_endpoint")] - pub ic_endpoint: String, - /// The chain type #[serde(default = "default::near_ibc_contract_address")] pub near_ibc_address: NearIbcContractAddress, diff --git a/tools/test-framework/src/types/single/node.rs b/tools/test-framework/src/types/single/node.rs index 55197217cc..43f8ee82a2 100644 --- a/tools/test-framework/src/types/single/node.rs +++ b/tools/test-framework/src/types/single/node.rs @@ -10,7 +10,6 @@ use ibc_relayer::chain::ChainType; use ibc_relayer::config; use ibc_relayer::config::compat_mode::CompatMode; use ibc_relayer::config::gas_multiplier::GasMultiplier; -use ibc_relayer::config::CanisterIdConfig; use ibc_relayer::config::NearIbcContractAddress; use ibc_relayer::keyring::Store; use ibc_relayer_types::core::ics24_host::identifier::ChainId; @@ -147,11 +146,9 @@ impl FullNode { Ok(config::ChainConfig { id: self.chain_driver.chain_id.clone(), r#type: ChainType::CosmosSdk, - ic_endpoint: test_config.ic_endpoint.clone(), - canister_pem: test_config.canister_pem.clone(), + near_ibc_address: NearIbcContractAddress::from_str(&test_config.near_ibc_address) .unwrap(), - canister_id: CanisterIdConfig::from_str(&test_config.canister_id).unwrap(), rpc_addr: Url::from_str(&self.chain_driver.rpc_address())?, grpc_addr: Url::from_str(&self.chain_driver.grpc_address())?, event_source: config::EventSourceMode::Push {