diff --git a/crates/relayer/src/chain/axon.rs b/crates/relayer/src/chain/axon.rs index 6bc0c87fd..a86fe3512 100644 --- a/crates/relayer/src/chain/axon.rs +++ b/crates/relayer/src/chain/axon.rs @@ -24,7 +24,7 @@ use ethers::{ prelude::{k256::ecdsa::SigningKey, EthLogDecode, SignerMiddleware}, providers::{Middleware, Provider, Ws}, signers::{Signer as _, Wallet}, - types::{TransactionRequest, TxHash, U64}, + types::{BlockNumber, TransactionRequest, TxHash, U64}, utils::rlp, }; use ibc_proto::google::protobuf::Any; @@ -277,7 +277,8 @@ impl ChainEndpoint for AxonChain { _key_name: Option<&str>, _denom: Option<&str>, ) -> Result { - // use mock coin to eliminate warns in wallet worker + // TODO: implement the real `query_balance` function later + warn!("axon query_balance() cannot implement"); Ok(Balance { amount: "100".to_owned(), denom: "AT".to_owned(), @@ -285,11 +286,13 @@ impl ChainEndpoint for AxonChain { } fn query_all_balances(&self, _key_name: Option<&str>) -> Result, Error> { + // TODO: implement the real `query_all_balances` function later warn!("axon query_all_balances() cannot implement"); Ok(vec![]) } fn query_denom_trace(&self, _hash: String) -> Result { + // TODO: implement the real `query_denom_trace` function later warn!("axon query_denom_trace() cannot implement"); Ok(DenomTrace { path: "".to_owned(), @@ -303,23 +306,23 @@ impl ChainEndpoint for AxonChain { } fn query_application_status(&self) -> Result { - let tip_block_number = self - .rt - .block_on(self.client.get_block_number()) - .map_err(|e| Error::rpc_response(e.to_string()))? - .as_u64(); let tip_block = self .rt - .block_on(self.client.get_block(tip_block_number)) + .block_on(self.client.get_block(BlockNumber::Latest)) .map_err(|e| Error::rpc_response(e.to_string()))?; if let Some(block) = tip_block { + let height = if let Some(number) = block.number { + Height::from_noncosmos_height(number.as_u64()) + } else { + Height::default() + }; Ok(ChainStatus { - height: Height::from_noncosmos_height(tip_block_number), - timestamp: Timestamp::from_nanoseconds(block.timestamp.as_u64() * 100000).unwrap(), + height, + timestamp: to_timestamp(block.timestamp.as_u64())?, }) } else { Ok(ChainStatus { - height: Height::from_noncosmos_height(tip_block_number), + height: Height::default(), timestamp: Timestamp::now(), }) } diff --git a/crates/relayer/src/chain/axon/monitor.rs b/crates/relayer/src/chain/axon/monitor.rs index 70d104ced..c1113a0bd 100644 --- a/crates/relayer/src/chain/axon/monitor.rs +++ b/crates/relayer/src/chain/axon/monitor.rs @@ -144,7 +144,11 @@ impl AxonEventMonitor { if let Some(cmd) = result { match cmd { MonitorCmd::Shutdown => return Next::Abort, - MonitorCmd::Subscribe(tx) => tx.send(self.event_bus.subscribe()).unwrap(), + MonitorCmd::Subscribe(tx) => { + if let Err(e) = tx.send(self.event_bus.subscribe()) { + error!("failed to send back subscription: {e}"); + } + } } } Next::Continue diff --git a/crates/relayer/src/chain/axon/msg.rs b/crates/relayer/src/chain/axon/msg.rs index a1721796f..2aacef53b 100644 --- a/crates/relayer/src/chain/axon/msg.rs +++ b/crates/relayer/src/chain/axon/msg.rs @@ -35,12 +35,14 @@ use ibc_relayer_types::{ }, events::IbcEvent, proofs::Proofs, - timestamp::Timestamp, tx_msg::Msg, Height, }; -use super::contract; +use super::{ + contract, + utils::{to_timestamp, SEC_TO_NANO}, +}; use crate::error::Error; fn into_ethers_client_id(value: Option) -> String { @@ -293,8 +295,7 @@ impl From for Packet { destination_channel: value.destination_channel.as_str().parse().unwrap(), data: value.data.as_ref().to_vec(), timeout_height, - timeout_timestamp: Timestamp::from_nanoseconds(value.timeout_timestamp * 100000) - .unwrap(), + timeout_timestamp: to_timestamp(value.timeout_timestamp).unwrap(), } } } @@ -312,7 +313,7 @@ impl From for contract::PacketData { TimeoutHeight::At(h) => h.into(), TimeoutHeight::Never => Default::default(), }, - timeout_timestamp: value.timeout_timestamp.nanoseconds() / 100000, + timeout_timestamp: value.timeout_timestamp.nanoseconds() / SEC_TO_NANO, } } } diff --git a/crates/relayer/src/chain/axon/utils.rs b/crates/relayer/src/chain/axon/utils.rs index d2a254d94..e5c919394 100644 --- a/crates/relayer/src/chain/axon/utils.rs +++ b/crates/relayer/src/chain/axon/utils.rs @@ -18,8 +18,15 @@ use ibc_relayer_types::{ ics07_ckb::{client_state::CkbClientState, consensus_state::CkbConsensusState}, }, core::{ics02_client::client_type::ClientType, ics24_host::identifier::ClientId}, + timestamp::Timestamp, }; +pub const SEC_TO_NANO: u64 = 1_000_000_000; + +pub fn to_timestamp(seconds: u64) -> Result { + Timestamp::from_nanoseconds(seconds * SEC_TO_NANO).map_err(convert_err) +} + pub fn convert_err(err: T) -> Error { Error::other_error(err.to_string()) } diff --git a/crates/relayer/src/client_state.rs b/crates/relayer/src/client_state.rs index ba4d3c1ce..136d39804 100644 --- a/crates/relayer/src/client_state.rs +++ b/crates/relayer/src/client_state.rs @@ -100,6 +100,9 @@ impl AnyClientState { pub fn trust_threshold(&self) -> Option { match self { AnyClientState::Tendermint(state) => Some(state.trust_threshold), + + // `ONE_THRID` of TrustThreshold is just a mock value to pass runtime check + // for non-cosmos chains AnyClientState::Eth(_) => Some(TrustThreshold::ONE_THIRD), AnyClientState::Ckb(_) => Some(TrustThreshold::ONE_THIRD), AnyClientState::Axon(_) => Some(TrustThreshold::ONE_THIRD),