Skip to content

Commit

Permalink
Merge pull request #365 from synapseweb3/impl-query-host-consensus-st…
Browse files Browse the repository at this point in the history
…ate-for-axon

feat: impl query_host_consensus_state for Axon
  • Loading branch information
Flouse authored Nov 7, 2023
2 parents e365f96 + 85f5257 commit d50d44d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
11 changes: 7 additions & 4 deletions crates/relayer-types/src/clients/ics07_axon/consensus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
35 changes: 28 additions & 7 deletions crates/relayer/src/chain/axon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -104,6 +107,7 @@ use super::{
QueryUpgradedConsensusStateRequest,
},
tracking::TrackedMsgs,
SEC_TO_NANO,
};
use tokio::runtime::Runtime as TokioRuntime;

Expand Down Expand Up @@ -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<Self::ConsensusState, Error> {
// 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?
Expand Down Expand Up @@ -1009,7 +1027,10 @@ impl ChainEndpoint for AxonChain {
&self,
_light_block: Self::LightBlock,
) -> Result<Self::ConsensusState, Error> {
Ok(AxonConsensusState {})
Ok(AxonConsensusState {
root: CommitmentRoot::from_bytes(&[]),
timestamp: Timestamp::default(),
})
}

// TODO do we need to implement this?
Expand Down

0 comments on commit d50d44d

Please sign in to comment.