Skip to content

Commit

Permalink
update query_next_sequence_receive to also return proof height
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Nov 1, 2024
1 parent f261aad commit cec3472
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 34 deletions.
20 changes: 15 additions & 5 deletions crates/relayer/src/chain/astria/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ impl ChainEndpoint for AstriaEndpoint {
&self,
request: QueryNextSequenceReceiveRequest,
include_proof: IncludeProof,
) -> Result<(Sequence, Option<MerkleProof>), Error> {
) -> Result<(Sequence, Option<(MerkleProof, Height)>), Error> {
let mut client = self.ibc_channel_grpc_client.clone();
let request = tonic::Request::new(request.into());

Expand All @@ -1391,10 +1391,20 @@ impl ChainEndpoint for AstriaEndpoint {
.into_inner();

match include_proof {
IncludeProof::Yes => Ok((
response.next_sequence_receive.into(),
Some(decode_merkle_proof(response.proof)?),
)),
IncludeProof::Yes => {
let proof = decode_merkle_proof(response.proof)?;
let height = response
.proof_height
.ok_or(Error::grpc_response_param("proof_height".to_string()))?;
Ok((
response.next_sequence_receive.into(),
Some((
proof,
Height::new(height.revision_number, height.revision_height - 1)
.map_err(|e| Error::other(Box::new(e)))?,
)),
))
}
IncludeProof::No => Ok((response.next_sequence_receive.into(), None)),
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,7 @@ impl ChainEndpoint for CosmosSdkChain {
&self,
request: QueryNextSequenceReceiveRequest,
include_proof: IncludeProof,
) -> Result<(Sequence, Option<MerkleProof>), Error> {
) -> Result<(Sequence, Option<(MerkleProof, ibc_relayer_types::Height)>), Error> {
crate::time!(
"query_next_sequence_receive",
{
Expand Down Expand Up @@ -2115,7 +2115,8 @@ impl ChainEndpoint for CosmosSdkChain {
let seq: Sequence = Bytes::from(res.value).get_u64().into();

let proof = if prove {
Some(res.proof.ok_or_else(Error::empty_response_proof)?)
let height = ibc_relayer_types::Height::from_tm(res.height, &self.config.id);
Some((res.proof.ok_or_else(Error::empty_response_proof)?, height))
} else {
None
};
Expand Down
42 changes: 21 additions & 21 deletions crates/relayer/src/chain/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ pub trait ChainEndpoint: Sized {
&self,
request: QueryNextSequenceReceiveRequest,
include_proof: IncludeProof,
) -> Result<(Sequence, Option<MerkleProof>), Error>;
) -> Result<(Sequence, Option<(MerkleProof, ICSHeight)>), Error>;

fn query_txs(&self, request: QueryTxRequest) -> Result<Vec<IbcEventWithHeight>, Error>;

Expand Down Expand Up @@ -625,18 +625,18 @@ pub trait ChainEndpoint: Sized {
(proof_and_height.1, proof_and_height.0, None)
}
PacketMsgType::TimeoutOrdered => {
let (_, maybe_packet_proof) = self.query_next_sequence_receive(
let (_, proof_and_height) = self.query_next_sequence_receive(
QueryNextSequenceReceiveRequest {
port_id,
channel_id,
height: QueryHeight::Specific(query_height),
height: QueryHeight::Latest,
},
IncludeProof::Yes,
)?;

let maybe_packet_proof =
maybe_packet_proof.ok_or_else(Error::queried_proof_not_found)?;
(query_height, maybe_packet_proof, None)
let proof_and_height =
proof_and_height.ok_or_else(Error::queried_proof_not_found)?;
(proof_and_height.1, proof_and_height.0, None)
}
PacketMsgType::TimeoutOnCloseUnordered => {
let (_, packet_and_height) = self.query_packet_receipt(
Expand Down Expand Up @@ -675,11 +675,23 @@ pub trait ChainEndpoint: Sized {
(packet_and_height.1, packet_and_height.0, channel_proof)
}
PacketMsgType::TimeoutOnCloseOrdered => {
let (_, packet_and_height) = self.query_next_sequence_receive(
QueryNextSequenceReceiveRequest {
port_id: port_id.clone(),
channel_id: channel_id.clone(),
height: QueryHeight::Latest,
},
IncludeProof::Yes,
)?;

let packet_and_height =
packet_and_height.ok_or_else(Error::queried_proof_not_found)?;

let channel_proof = {
let (_, maybe_channel_proof) = self.query_channel(
QueryChannelRequest {
port_id: port_id.clone(),
channel_id: channel_id.clone(),
port_id,
channel_id,
height: QueryHeight::Specific(query_height),
},
IncludeProof::Yes,
Expand All @@ -694,20 +706,8 @@ pub trait ChainEndpoint: Sized {
.map_err(Error::malformed_proof)?,
)
};
let (_, maybe_packet_proof) = self.query_next_sequence_receive(
QueryNextSequenceReceiveRequest {
port_id,
channel_id,
height: QueryHeight::Specific(query_height),
},
IncludeProof::Yes,
)?;

(
query_height,
maybe_packet_proof.ok_or_else(Error::queried_proof_not_found)?,
channel_proof,
)
(packet_and_height.1, packet_and_height.0, channel_proof)
}
};

Expand Down
4 changes: 2 additions & 2 deletions crates/relayer/src/chain/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ pub enum ChainRequest {
QueryNextSequenceReceive {
request: QueryNextSequenceReceiveRequest,
include_proof: IncludeProof,
reply_to: ReplyTo<(Sequence, Option<MerkleProof>)>,
reply_to: ReplyTo<(Sequence, Option<(MerkleProof, Height)>)>,
},

BuildChannelProofs {
Expand Down Expand Up @@ -546,7 +546,7 @@ pub trait ChainHandle: Clone + Display + Send + Sync + Debug + 'static {
&self,
request: QueryNextSequenceReceiveRequest,
include_proof: IncludeProof,
) -> Result<(Sequence, Option<MerkleProof>), Error>;
) -> Result<(Sequence, Option<(MerkleProof, Height)>), Error>;

/// Performs a query to retrieve all the channels of a chain.
fn query_channels(
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer/src/chain/handle/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl ChainHandle for BaseChainHandle {
&self,
request: QueryNextSequenceReceiveRequest,
include_proof: IncludeProof,
) -> Result<(Sequence, Option<MerkleProof>), Error> {
) -> Result<(Sequence, Option<(MerkleProof, Height)>), Error> {
self.send(|reply_to| ChainRequest::QueryNextSequenceReceive {
request,
include_proof,
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer/src/chain/handle/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl<Handle: ChainHandle> ChainHandle for CachingChainHandle<Handle> {
&self,
request: QueryNextSequenceReceiveRequest,
include_proof: IncludeProof,
) -> Result<(Sequence, Option<MerkleProof>), Error> {
) -> Result<(Sequence, Option<(MerkleProof, Height)>), Error> {
self.inner()
.query_next_sequence_receive(request, include_proof)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer/src/chain/handle/counting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl<Handle: ChainHandle> ChainHandle for CountingChainHandle<Handle> {
&self,
request: QueryNextSequenceReceiveRequest,
include_proof: IncludeProof,
) -> Result<(Sequence, Option<MerkleProof>), Error> {
) -> Result<(Sequence, Option<(MerkleProof, Height)>), Error> {
self.inc_metric("query_next_sequence_receive");
self.inner()
.query_next_sequence_receive(request, include_proof)
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer/src/chain/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ where
&self,
request: QueryNextSequenceReceiveRequest,
include_proof: IncludeProof,
reply_to: ReplyTo<(Sequence, Option<MerkleProof>)>,
reply_to: ReplyTo<(Sequence, Option<(MerkleProof, Height)>)>,
) -> Result<(), Error> {
let result = self
.chain
Expand Down

0 comments on commit cec3472

Please sign in to comment.