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

Remove ChainHandle dependency for *Querier #367

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thaodt
Copy link

@thaodt thaodt commented Jun 11, 2024

Apart of #214.

Description

Following the guidance in the issue and refactoring items below:

  • CounterpartyChainIdQuerier
  • ReceivedPacketQuerier
  • WriteAckQuerier

PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests: integration (for Hermes) or unit/mock tests (for modules).
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).
  • Tagged one reviewer who will be the one responsible for shepherding this PR.

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

@thaodt thaodt force-pushed the queriers branch 2 times, most recently from 2d8713e to a25a88a Compare July 25, 2024 09:12
@thaodt
Copy link
Author

thaodt commented Jul 25, 2024

hi @soareschen can you please help me do a quick review on ReceivedPacketQuerier & WriteAckQuerier? If they're as expected, I'll continue with the last one.
I run tests already.

@thaodt thaodt marked this pull request as ready for review July 25, 2024 09:14
@thaodt thaodt marked this pull request as draft July 31, 2024 10:06
Copy link
Collaborator

@soareschen soareschen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thaodt thanks for your contribution! Looks pretty good. I have added some suggestions on how to improve the code. Your branch also needs to be updated before we can merge.

+ CanRaiseError<Ics04Error>
+ CanRaiseError<Ics02Error>
+ CanRaiseError<tonic::transport::Error>
+ CanRaiseError<ibc_relayer::error::Error>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following constraints can be safely removed without compilation error:

  • HasErrorType (because we have CanRaiseError which includes it as a supertrait)
  • HasGrpcAddress
  • HasComponents
  • CanRaiseError<Ics04Error>
  • CanRaiseError<tonic::transport::Error>

In general, a constraint can be removed if it does not introduce any compile error.


pub struct QueryReceivedPacketWithChainHandle;

impl<Chain, Counterparty> ReceivedPacketQuerier<Chain, Counterparty>
for QueryReceivedPacketWithChainHandle
where
Chain: HasIbcChainTypes<Counterparty, ChannelId = ChannelId, PortId = PortId>
+ HasBlockingChainHandle,
+ HasGrpcAddress
+ CanRaiseError<eyre::Report>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can check what error is returned from calls like ChannelQueryClient::connect, and add the CanRaiseError constraint for that specific error here.

Copy link
Author

@thaodt thaodt Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it actually returns a tonic::transport::Error, so I guess should CanRaiseError<eyre::Report> be enough?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle, yes. However, eyre::Report is too general and obscures details about what kind of error it is. If we add the constraint CanRaiseError<tonic::transport::Error>, the chain context can easily choose to handle it in different way, e.g. marking the error as retryable.

In addition, the use of CGP and the CanRaiseError trait makes it easy to raise any custom error to the chain context. Hence, we prefer to raise errors that are as specific as possible.

use ibc_relayer::chain::requests::QueryUnreceivedPacketsRequest;
use ibc_relayer_types::core::ics04_channel::packet::Sequence;
use ibc_relayer_types::core::ics24_host::identifier::{ChannelId, PortId};

use crate::traits::chain_handle::HasBlockingChainHandle;
use crate::traits::grpc_address::HasGrpcAddress;

pub struct QueryReceivedPacketWithChainHandle;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component can be renamed too.

source_channel_id: packet.destination_channel.clone(),
source_port_id: packet.destination_port.clone(),
destination_channel_id: packet.source_channel.clone(),
destination_port_id: packet.source_port.clone(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm still not sure which one is the source and which one is the dest data.

Hmm you are right. It looks like the source should match the packet source, and vice versa for destination.

Actually looking at the code, it looks like this component is not used anywhere in the relayer code, other than the mock relayer. So I think we can remove this component (QueryWriteAckEventFromAbci) altogether, if it does not introduce any compile error.

@thaodt
Copy link
Author

thaodt commented Aug 14, 2024

I've pushed the fix from your previous review @soareschen.

And I have some questions while doing the last one - CounterpartyChainIdQuerier.
Upon checking, it's originated from the method counterparty_chain_from_channel in relayer v1 src code:
https://github.com/informalsystems/hermes/blob/f69a6d702785083d8ac05d49a06fc590050eef94/crates/relayer/src/chain/counterparty.rs#L240-L247

which later called to this fn channel_connection_client_no_checks:
https://github.com/informalsystems/hermes/blob/f69a6d702785083d8ac05d49a06fc590050eef94/crates/relayer/src/chain/counterparty.rs#L158-L213

I tried extracting the code from there and follow the abci queries's methods to get necessary data, but very soon after that I discovered that i didn't have the height parameter in the fn arguments.

The expected output of this function is the chain ID of the counterparty chain and requires that the client connection channel be open so that the chain id can be obtained from the client state of that connection.
Can you please give me some guidance on how to achieve this?

@thaodt thaodt requested a review from soareschen August 14, 2024 09:21
@soareschen
Copy link
Collaborator

If you trace the original call, you can find that it is querying from the latest height. So you can add the constraint Chain: CanQueryChainHeight, and then get the latest height from chain.query_chain_height().

For now, you can check whether the channel state condition is open, and if not, we can raise error strings for now. To do that, simply add Chain: CanRaiseError<String> to the constraint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants