Skip to content

Commit

Permalink
feat: complete query_* methods in ckb endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
liyukun committed Aug 21, 2023
1 parent ced573f commit 2897c76
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 106 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jsonrpc-core = "18.0"
strum = { version = "0.24.1", features = ["derive"] }
lazy_static = "1.4.0"

ckb-ics-axon = { git = "https://github.com/synapseweb3/ckb-ics.git", rev = "cda7d4e" }
ckb-ics-axon = { git = "https://github.com/synapseweb3/ckb-ics.git", rev = "aa894e3" }
cstr_core = "0.2.6"
rlp = "0.5.2"

Expand Down
85 changes: 59 additions & 26 deletions crates/relayer/src/chain/axon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ use ethers::{
types::{BlockNumber, TransactionRequest, TxHash, U64},
utils::rlp,
};
use ibc_proto::google::protobuf::Any;
use ibc_proto::{
google::protobuf::Any,
ibc::apps::fee::v1::{QueryIncentivizedPacketRequest, QueryIncentivizedPacketResponse},
};
use ibc_relayer_types::{
applications::ics31_icq::response::CrossChainQueryResponse,
clients::ics07_axon::{
Expand All @@ -47,7 +50,7 @@ use ibc_relayer_types::{
msgs::{conn_open_ack, conn_open_confirm, conn_open_init, conn_open_try},
},
ics04_channel::{
channel::{ChannelEnd, IdentifiedChannelEnd},
channel::{ChannelEnd, IdentifiedChannelEnd, Order},
msgs::{
acknowledgement, chan_close_confirm, chan_close_init, chan_open_ack,
chan_open_confirm, chan_open_init, chan_open_try, recv_packet, timeout,
Expand Down Expand Up @@ -610,29 +613,57 @@ impl ChainEndpoint for AxonChain {
.call(),
)
.map_err(convert_err)?;
Ok((vec![has_receipt as u8], None))
if has_receipt {
Ok((vec![1u8], None))
} else {
Ok((vec![], None))
}
}

fn query_unreceived_packets(
&self,
request: QueryUnreceivedPacketsRequest,
) -> Result<Vec<Sequence>, Error> {
let (channel, _) = self.query_channel(
QueryChannelRequest {
port_id: request.port_id.clone(),
channel_id: request.channel_id.clone(),
height: QueryHeight::Latest,
},
IncludeProof::No,
)?;
let mut sequences: Vec<Sequence> = vec![];
for seq in request.packet_commitment_sequences {
let has_receipt = self
.rt
.block_on(
self.contract
.has_packet_receipt(
request.port_id.to_string(),
request.channel_id.to_string(),
seq.into(),
)
.call(),
)
.map_err(convert_err)?;
if !has_receipt {
sequences.push(seq);
if channel.ordering == Order::Ordered {
let (max_recv_seq, _) = self.query_next_sequence_receive(
QueryNextSequenceReceiveRequest {
port_id: request.port_id,
channel_id: request.channel_id,
height: QueryHeight::Latest,
},
IncludeProof::No,
)?;
sequences = request
.packet_commitment_sequences
.into_iter()
.filter(|seq| *seq >= max_recv_seq)
.collect();
} else if channel.ordering == Order::Unordered {
for seq in request.packet_commitment_sequences {
let has_receipt = self
.rt
.block_on(
self.contract
.has_packet_receipt(
request.port_id.to_string(),
request.channel_id.to_string(),
seq.into(),
)
.call(),
)
.map_err(convert_err)?;
if !has_receipt {
sequences.push(seq);
}
}
}
Ok(sequences)
Expand All @@ -643,10 +674,6 @@ impl ChainEndpoint for AxonChain {
request: QueryPacketAcknowledgementRequest,
_include_proof: IncludeProof,
) -> Result<(Vec<u8>, Option<MerkleProof>), Error> {
if matches!(request.height, QueryHeight::Specific(_)) {
// TODO: no implemention for specific acknowledgement query
warn!("search packet acknoledgement at specific height will fallback to latest");
}
let (commitment, _) = self
.rt
.block_on(
Expand Down Expand Up @@ -750,14 +777,20 @@ impl ChainEndpoint for AxonChain {
&self,
_request: QueryHostConsensusStateRequest,
) -> Result<Self::ConsensusState, Error> {
todo!()
// TODO
warn!("axon query_host_consensus_state() not support");
Ok(AxonConsensusState {})
}

fn query_incentivized_packet(
&self,
_request: ibc_proto::ibc::apps::fee::v1::QueryIncentivizedPacketRequest,
) -> Result<ibc_proto::ibc::apps::fee::v1::QueryIncentivizedPacketResponse, Error> {
todo!()
_request: QueryIncentivizedPacketRequest,
) -> Result<QueryIncentivizedPacketResponse, Error> {
// TODO
warn!("axon query_incentivized_packet() not support");
Ok(QueryIncentivizedPacketResponse {
incentivized_packet: None,
})
}

fn build_client_state(
Expand Down
Loading

0 comments on commit 2897c76

Please sign in to comment.