From 663ec5e54b5ce09e9bc6526d322ed368b78bd674 Mon Sep 17 00:00:00 2001 From: jjy Date: Wed, 1 Nov 2023 22:20:30 +0800 Subject: [PATCH 1/2] feat: impl query_host_consensus_state for Axon --- .../src/clients/ics07_axon/consensus_state.rs | 11 +++--- crates/relayer/src/chain/axon.rs | 35 +++++++++++++++---- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/crates/relayer-types/src/clients/ics07_axon/consensus_state.rs b/crates/relayer-types/src/clients/ics07_axon/consensus_state.rs index 84e7b1ec3..b79b64235 100644 --- a/crates/relayer-types/src/clients/ics07_axon/consensus_state.rs +++ b/crates/relayer-types/src/clients/ics07_axon/consensus_state.rs @@ -11,19 +11,22 @@ use crate::core::ics02_client::error::Error as Ics02Error; pub const AXON_CONSENSUS_STATE_TYPE_URL: &str = "/ibc.lightclients.axon.v1.ConsensusState"; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub struct AxonConsensusState {} +pub struct AxonConsensusState { + pub root: CommitmentRoot, + pub timestamp: Timestamp, +} impl crate::core::ics02_client::consensus_state::ConsensusState for AxonConsensusState { fn client_type(&self) -> ClientType { - todo!() + ClientType::Axon } fn root(&self) -> &CommitmentRoot { - todo!() + &self.root } fn timestamp(&self) -> Timestamp { - todo!() + self.timestamp } } diff --git a/crates/relayer/src/chain/axon.rs b/crates/relayer/src/chain/axon.rs index f94423d54..dd9e035d6 100644 --- a/crates/relayer/src/chain/axon.rs +++ b/crates/relayer/src/chain/axon.rs @@ -67,7 +67,10 @@ use ibc_relayer_types::{ }, packet::{PacketMsgType, Sequence}, }, - ics23_commitment::{commitment::CommitmentPrefix, merkle::MerkleProof}, + ics23_commitment::{ + commitment::{CommitmentPrefix, CommitmentRoot}, + merkle::MerkleProof, + }, ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}, }, events::{IbcEvent, WithBlockDataType}, @@ -104,6 +107,7 @@ use super::{ QueryUpgradedConsensusStateRequest, }, tracking::TrackedMsgs, + SEC_TO_NANO, }; use tokio::runtime::Runtime as TokioRuntime; @@ -968,14 +972,28 @@ impl ChainEndpoint for AxonChain { Ok(events) } - // TODO do we need to implement this? fn query_host_consensus_state( &self, - _request: QueryHostConsensusStateRequest, + request: QueryHostConsensusStateRequest, ) -> Result { - // TODO - warn!("axon query_host_consensus_state() not support"); - Ok(AxonConsensusState {}) + let fut = match request.height { + QueryHeight::Latest => self + .rpc_client + .get_block_by_id(BlockId::Number(BlockNumber::Latest)), + QueryHeight::Specific(ibc_height) => { + let number = ibc_height.revision_height(); + self.rpc_client + .get_block_by_id(BlockId::Number(BlockNumber::Number(number.into()))) + } + }; + let block = self + .rt + .block_on(fut)? + .ok_or_else(|| Error::invalid_height_no_source())?; + let root = CommitmentRoot::from_bytes(block.header.state_root.as_bytes()); + let timestamp = Timestamp::from_nanoseconds(block.header.timestamp * SEC_TO_NANO) + .map_err(Error::other)?; + Ok(AxonConsensusState { root, timestamp }) } // TODO do we need to implement this? @@ -1009,7 +1027,10 @@ impl ChainEndpoint for AxonChain { &self, _light_block: Self::LightBlock, ) -> Result { - Ok(AxonConsensusState {}) + Ok(AxonConsensusState { + root: CommitmentRoot::from_bytes(&[]), + timestamp: Timestamp::default(), + }) } // TODO do we need to implement this? From 85f525750f227e77b439edb9d3761a72e619f0a3 Mon Sep 17 00:00:00 2001 From: jjy Date: Thu, 2 Nov 2023 20:48:55 +0800 Subject: [PATCH 2/2] fix: fix clippy --- crates/relayer/src/chain/axon.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/relayer/src/chain/axon.rs b/crates/relayer/src/chain/axon.rs index dd9e035d6..444dc57bb 100644 --- a/crates/relayer/src/chain/axon.rs +++ b/crates/relayer/src/chain/axon.rs @@ -989,7 +989,7 @@ impl ChainEndpoint for AxonChain { let block = self .rt .block_on(fut)? - .ok_or_else(|| Error::invalid_height_no_source())?; + .ok_or_else(Error::invalid_height_no_source)?; let root = CommitmentRoot::from_bytes(block.header.state_root.as_bytes()); let timestamp = Timestamp::from_nanoseconds(block.header.timestamp * SEC_TO_NANO) .map_err(Error::other)?;