Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use latest for queries packet/ack/receipt and return proof height #23

Open
wants to merge 5 commits into
base: astria
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 66 additions & 18 deletions crates/relayer/src/chain/astria/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use ibc_relayer_types::{
ics02_client::{
client_type::ClientType,
events::UpdateClient,
height::Height,
},
ics03_connection::connection::{
ConnectionEnd,
Expand Down Expand Up @@ -1107,7 +1108,7 @@ impl ChainEndpoint for AstriaEndpoint {
&self,
request: QueryPacketCommitmentRequest,
include_proof: IncludeProof,
) -> Result<(Vec<u8>, Option<MerkleProof>), Error> {
) -> Result<(Vec<u8>, Option<(MerkleProof, Height)>), Error> {
let mut client = self.ibc_channel_grpc_client.clone();
let req = ibc_proto::ibc::core::channel::v1::QueryPacketCommitmentRequest {
port_id: request.port_id.to_string(),
Expand All @@ -1132,10 +1133,25 @@ impl ChainEndpoint for AstriaEndpoint {
.into_inner();

match include_proof {
IncludeProof::Yes => Ok((
response.commitment,
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.commitment,
Some((
proof,
// TODO: subtracting from the height is jank but due to penumbra incrementing the proof height
// in the response, and the caller of this method (`build_packet_proofs`) also incrementing the proof
// height. the cosmos endpoint doesn't increment the height in the response (i believe) so changing
// the caller to not increment is potentially more confusing.
// needs a better fix.
Height::new(height.revision_number, height.revision_height - 1)
.map_err(|e| Error::other(Box::new(e)))?,
)),
))
}
IncludeProof::No => Ok((response.commitment, None)),
}
}
Expand Down Expand Up @@ -1176,7 +1192,7 @@ impl ChainEndpoint for AstriaEndpoint {
&self,
request: QueryPacketReceiptRequest,
include_proof: IncludeProof,
) -> Result<(Vec<u8>, Option<MerkleProof>), Error> {
) -> Result<(Vec<u8>, Option<(MerkleProof, Height)>), Error> {
let mut client = self.ibc_channel_grpc_client.clone();
let req = ibc_proto::ibc::core::channel::v1::QueryPacketReceiptRequest {
port_id: request.port_id.to_string(),
Expand All @@ -1200,14 +1216,26 @@ impl ChainEndpoint for AstriaEndpoint {
.map_err(|e| Error::grpc_status(e, "query_packet_receipt".to_owned()))?
.into_inner();

// TODO: is this right?
let value = match response.received {
true => vec![1],
false => vec![0],
};

match include_proof {
IncludeProof::Yes => Ok((value, 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((
value,
Some((
proof,
Height::new(height.revision_number, height.revision_height - 1)
.map_err(|e| Error::other(Box::new(e)))?,
)),
))
}
IncludeProof::No => Ok((value, None)),
}
}
Expand Down Expand Up @@ -1247,7 +1275,7 @@ impl ChainEndpoint for AstriaEndpoint {
&self,
request: QueryPacketAcknowledgementRequest,
include_proof: IncludeProof,
) -> Result<(Vec<u8>, Option<MerkleProof>), Error> {
) -> Result<(Vec<u8>, Option<(MerkleProof, Height)>), Error> {
let mut client = self.ibc_channel_grpc_client.clone();
let req = ibc_proto::ibc::core::channel::v1::QueryPacketAcknowledgementRequest {
port_id: request.port_id.to_string(),
Expand All @@ -1272,10 +1300,20 @@ impl ChainEndpoint for AstriaEndpoint {
.into_inner();

match include_proof {
IncludeProof::Yes => Ok((
response.acknowledgement,
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.acknowledgement,
Some((
proof,
Height::new(height.revision_number, height.revision_height - 1)
.map_err(|e| Error::other(Box::new(e)))?,
)),
))
}
IncludeProof::No => Ok((response.acknowledgement, None)),
}
}
Expand Down Expand Up @@ -1343,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 @@ -1353,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
23 changes: 12 additions & 11 deletions crates/relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,7 @@ impl ChainEndpoint for CosmosSdkChain {
&self,
request: QueryPacketCommitmentRequest,
include_proof: IncludeProof,
) -> Result<(Vec<u8>, Option<MerkleProof>), Error> {
) -> Result<(Vec<u8>, Option<(MerkleProof, ibc_relayer_types::Height)>), Error> {
let res = self.query(
CommitmentsPath {
port_id: request.port_id,
Expand All @@ -1846,8 +1846,8 @@ impl ChainEndpoint for CosmosSdkChain {
match include_proof {
IncludeProof::Yes => {
let proof = res.proof.ok_or_else(Error::empty_response_proof)?;

Ok((res.value, Some(proof)))
let height = ibc_relayer_types::Height::from_tm(res.height, &self.config.id);
Ok((res.value, Some((proof, height))))
}
IncludeProof::No => Ok((res.value, None)),
}
Expand Down Expand Up @@ -1904,7 +1904,7 @@ impl ChainEndpoint for CosmosSdkChain {
&self,
request: QueryPacketReceiptRequest,
include_proof: IncludeProof,
) -> Result<(Vec<u8>, Option<MerkleProof>), Error> {
) -> Result<(Vec<u8>, Option<(MerkleProof, ibc_relayer_types::Height)>), Error> {
let res = self.query(
ReceiptsPath {
port_id: request.port_id,
Expand All @@ -1918,8 +1918,8 @@ impl ChainEndpoint for CosmosSdkChain {
match include_proof {
IncludeProof::Yes => {
let proof = res.proof.ok_or_else(Error::empty_response_proof)?;

Ok((res.value, Some(proof)))
let height = ibc_relayer_types::Height::from_tm(res.height, &self.config.id);
Ok((res.value, Some((proof, height))))
}
IncludeProof::No => Ok((res.value, None)),
}
Expand Down Expand Up @@ -1969,7 +1969,7 @@ impl ChainEndpoint for CosmosSdkChain {
&self,
request: QueryPacketAcknowledgementRequest,
include_proof: IncludeProof,
) -> Result<(Vec<u8>, Option<MerkleProof>), Error> {
) -> Result<(Vec<u8>, Option<(MerkleProof, ibc_relayer_types::Height)>), Error> {
let res = self.query(
AcksPath {
port_id: request.port_id,
Expand All @@ -1983,8 +1983,8 @@ impl ChainEndpoint for CosmosSdkChain {
match include_proof {
IncludeProof::Yes => {
let proof = res.proof.ok_or_else(Error::empty_response_proof)?;

Ok((res.value, Some(proof)))
let height = ibc_relayer_types::Height::from_tm(res.height, &self.config.id);
Ok((res.value, Some((proof, height))))
}
IncludeProof::No => Ok((res.value, None)),
}
Expand Down 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
Loading
Loading